Package com.jk.data.dataaccess.core
Class JKDataAccessImpl
java.lang.Object
com.jk.data.dataaccess.core.JKDataAccessImpl
- All Implemented Interfaces:
JKDataAccessService
- Direct Known Subclasses:
H2DataAccess
,JKOracleDataAccess
,MysqlDataAccess
The Class JKDataAccessImpl.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The Constant acceptedTimeInMillis.static final int
The Constant bufferSize.protected JKLogger
The logger.static final int
The Constant maxAcceptedTimeInMillis. -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new JK data access impl.JKDataAccessImpl
(JKDataSource dataSource) Instantiates a new JK data access impl.JKDataAccessImpl
(String dataSourcePrefix) Instantiates a new JK data access impl. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addQueryLog
(String query, Instant startTimer, Instant endTimer) Adds the query log.void
Begin transaction.protected void
close
(Connection connection) Close.protected void
Close.protected void
close
(PreparedStatement ps, Connection c) Close.protected void
Close.protected void
close
(ResultSet rs, PreparedStatement ps, Connection c) Close.protected void
Close.void
closeTransaction
(boolean commit) Close transaction.describeTable
(String name) Describe table.void
Drop table.int
Execute.Object[]
executeQueryAsArray
(String query, Object... params) Execute query as array.executeQueryAsCachedRowSet
(String query, Object... params) Execute query as cached row set.executeQueryAsIdValue
(String query, Object... params) Execute query as id value.executeQueryAsList
(String query, Object... params) Execute query as list.executeQueryAsString
(String query, Object... params) Execute query as string.executeQueryAsString
(String query, String fieldSeparator, String recordsSepartor, Object... params) Execute query as string.executeSingleOutputQuery
(String query, Object... params) Exeute single output query.executeUpdate
(JKUpdater updater) Execute update.executeUpdate
(JKUpdater updater, boolean ignoreRecordNotFoundException) Execute update.executeUpdate
(String sql, Object... objects) Execute update.<T> T
find
(String query, JKPopulator<T> populator, Object... params) Find.<T> T
findAndCacheRecord
(String key, String query, JKPopulator<T> populator, Object... params) Find and cache record.<T> T
findRecord
(JKFinder finder) Find record.<T> T
findRecord
(JKFinder finder, String tableName, Object recordId) Find record.static String
Gets the caller.protected Connection
Gets the connection.protected Connection
getConnection
(boolean query) Gets the connection.protected JKDataSource
Gets the data source.protected Object
Gets the generated key.<T> List<T>
Gets the list.<T> List<T>
Gets the list.<T> List<T>
getList
(String query, JKPopulator<T> populator, Object... params) Gets the list.<T> List<T>
getListAndCache
(String key, String query, JKPopulator<T> populator, Object... params) Gets the list and cache.Gets the next id.Gets the next id.protected Long
getNextId
(Connection connectoin, String tableName, String fieldName) Gets the next id.protected Long
getNextId
(Connection con, String tableName, String fieldName, String condition) Gets the next id.int
getRowsCount
(String query, Object... params) Gets the rows count.Gets the system date.boolean
Checks if is in transaction.boolean
isTableExists
(String tableName) Checks if is table exists.protected PreparedStatement
prepareQueryStatement
(Connection connection, JKFinder finder) Prepare query statement.protected PreparedStatement
prepareQueryStatement
(Connection connection, String sql, Object... params) Prepare query statement.protected PreparedStatement
prepareStatement
(Connection connection, boolean returnGeneratedKeys, JKUpdater updater) Prepare statement.protected PreparedStatement
prepareStatement
(Connection connection, boolean returnGeneratedKeys, String sql, Object... params) Prepare statement.protected PreparedStatement
prepareStatement
(Connection connection, String sql, Object... params) Prepare statement.protected void
Prints the record result set.protected void
printRecordResultSet
(ResultSet rs, boolean all, PrintStream out) Prints the record result set.static void
Reset cache.void
Run script.protected PreparedStatement
setParams
(PreparedStatement prepareStatement, Object... params) Sets the params.void
setSession
(JKSession session) Sets the session.protected void
Write log.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jk.data.dataaccess.core.JKDataAccessService
executeQueryAsDouble, executeQueryAsInteger, executeQueryAsListOfObjects, executeQueryAsListOfObjects, executeQueryAsLong, executeQueryAsMap, executeQueryAsRow
-
Field Details
-
acceptedTimeInMillis
public static final int acceptedTimeInMillisThe Constant acceptedTimeInMillis. -
maxAcceptedTimeInMillis
public static final int maxAcceptedTimeInMillisThe Constant maxAcceptedTimeInMillis. -
bufferSize
public static final int bufferSizeThe Constant bufferSize. -
logger
The logger.
-
-
Constructor Details
-
JKDataAccessImpl
public JKDataAccessImpl()Instantiates a new JK data access impl. -
JKDataAccessImpl
Instantiates a new JK data access impl.- Parameters:
dataSourcePrefix
- the data source prefix
-
JKDataAccessImpl
Instantiates a new JK data access impl.- Parameters:
dataSource
- the data source
-
-
Method Details
-
close
Close.- Parameters:
connection
- the connection
-
close
Close.- Parameters:
ps
- the ps
-
close
Close.- Parameters:
ps
- the psc
- the c
-
close
Close.- Parameters:
rs
- the rs
-
close
Close.- Parameters:
rs
- the rsps
- the psc
- the c
-
close
Close.- Parameters:
ps
- the ps
-
executeQueryAsCachedRowSet
Execute query as cached row set.- Specified by:
executeQueryAsCachedRowSet
in interfaceJKDataAccessService
- Parameters:
query
- the queryparams
- the params- Returns:
- the cached row set
-
executeQueryAsIdValue
Execute query as id value.- Specified by:
executeQueryAsIdValue
in interfaceJKDataAccessService
- Parameters:
query
- the queryparams
- the params- Returns:
- the list
-
executeQueryAsString
Execute query as string.- Specified by:
executeQueryAsString
in interfaceJKDataAccessService
- Parameters:
query
- the queryparams
- the params- Returns:
- the string
-
executeQueryAsString
public String executeQueryAsString(String query, String fieldSeparator, String recordsSepartor, Object... params) Execute query as string.- Specified by:
executeQueryAsString
in interfaceJKDataAccessService
- Parameters:
query
- the queryfieldSeparator
- the field separatorrecordsSepartor
- the records separtorparams
- the params- Returns:
- the string
-
executeUpdate
Execute update.- Specified by:
executeUpdate
in interfaceJKDataAccessService
- Parameters:
updater
- the updater- Returns:
- the int
- Throws:
JKDataAccessException
- the JK data access exception
-
prepareStatement
protected PreparedStatement prepareStatement(Connection connection, boolean returnGeneratedKeys, JKUpdater updater) throws SQLException Prepare statement.- Parameters:
connection
- the connectionreturnGeneratedKeys
- the return generated keysupdater
- the updater- Returns:
- the prepared statement
- Throws:
SQLException
- the SQL exception
-
prepareQueryStatement
protected PreparedStatement prepareQueryStatement(Connection connection, JKFinder finder) throws SQLException Prepare query statement.- Parameters:
connection
- the connectionfinder
- the finder- Returns:
- the prepared statement
- Throws:
SQLException
- the SQL exception
-
executeUpdate
Execute update.- Specified by:
executeUpdate
in interfaceJKDataAccessService
- Parameters:
updater
- the updaterignoreRecordNotFoundException
- the ignore record not found exception- Returns:
- the int
-
execute
Execute.- Specified by:
execute
in interfaceJKDataAccessService
- Parameters:
statement
- the statementparams
- the params- Returns:
- the int
- Throws:
JKDataAccessException
- the JK data access exception
-
executeQueryAsArray
Execute query as array.- Specified by:
executeQueryAsArray
in interfaceJKDataAccessService
- Parameters:
query
- the queryparams
- the params- Returns:
- the object[]
-
executeQueryAsList
Execute query as list.- Specified by:
executeQueryAsList
in interfaceJKDataAccessService
- Parameters:
query
- the queryparams
- the params- Returns:
- the list
-
executeSingleOutputQuery
Exeute single output query.- Specified by:
executeSingleOutputQuery
in interfaceJKDataAccessService
- Parameters:
query
- the queryparams
- the params- Returns:
- the object
-
findRecord
Find record.- Specified by:
findRecord
in interfaceJKDataAccessService
- Type Parameters:
T
- the generic type- Parameters:
finder
- the finder- Returns:
- the t
-
findRecord
Find record.- Specified by:
findRecord
in interfaceJKDataAccessService
- Type Parameters:
T
- the generic type- Parameters:
finder
- the findertableName
- the table namerecordId
- the record id- Returns:
- the t
-
getConnection
Gets the connection.- Returns:
- the connection
-
getConnection
Gets the connection.- Parameters:
query
- the query- Returns:
- the connection
-
getDataSource
Gets the data source.- Returns:
- the data source
-
getGeneratedKey
Gets the generated key.- Parameters:
ps
- the ps- Returns:
- the generated key
- Throws:
SQLException
- the SQL exception
-
getNextId
protected Long getNextId(Connection connectoin, String tableName, String fieldName) throws JKDataAccessException Gets the next id.- Parameters:
connectoin
- the connectointableName
- the table namefieldName
- the field name- Returns:
- the next id
- Throws:
JKDataAccessException
- the JK data access exception
-
getNextId
Gets the next id.- Parameters:
con
- the contableName
- the table namefieldName
- the field namecondition
- the condition- Returns:
- the next id
-
getNextId
Gets the next id.- Specified by:
getNextId
in interfaceJKDataAccessService
- Parameters:
tableName
- the table namefieldName
- the field name- Returns:
- the next id
-
getNextId
Gets the next id.- Specified by:
getNextId
in interfaceJKDataAccessService
- Parameters:
tableName
- the table namefieldName
- the field namecondition
- the condition- Returns:
- the next id
-
getRowsCount
Gets the rows count.- Specified by:
getRowsCount
in interfaceJKDataAccessService
- Parameters:
query
- the queryparams
- the params- Returns:
- the rows count
-
getSystemDate
Gets the system date.- Specified by:
getSystemDate
in interfaceJKDataAccessService
- Returns:
- the system date
-
getList
Gets the list.- Specified by:
getList
in interfaceJKDataAccessService
- Type Parameters:
T
- the generic type- Parameters:
finder
- the finder- Returns:
- the list
-
getList
Gets the list.- Specified by:
getList
in interfaceJKDataAccessService
- Type Parameters:
T
- the generic type- Parameters:
finder
- the finderkey
- the key- Returns:
- the list
-
prepareQueryStatement
protected PreparedStatement prepareQueryStatement(Connection connection, String sql, Object... params) throws SQLException Prepare query statement.- Parameters:
connection
- the connectionsql
- the sqlparams
- the params- Returns:
- the prepared statement
- Throws:
SQLException
- the SQL exception
-
prepareStatement
protected PreparedStatement prepareStatement(Connection connection, String sql, Object... params) throws SQLException Prepare statement.- Parameters:
connection
- the connectionsql
- the sqlparams
- the params- Returns:
- the prepared statement
- Throws:
SQLException
- the SQL exception
-
prepareStatement
protected PreparedStatement prepareStatement(Connection connection, boolean returnGeneratedKeys, String sql, Object... params) throws SQLException Prepare statement.- Parameters:
connection
- the connectionreturnGeneratedKeys
- the return generated keyssql
- the sqlparams
- the params- Returns:
- the prepared statement
- Throws:
SQLException
- the SQL exception
-
setParams
protected PreparedStatement setParams(PreparedStatement prepareStatement, Object... params) throws SQLException Sets the params.- Parameters:
prepareStatement
- the prepare statementparams
- the params- Returns:
- the prepared statement
- Throws:
SQLException
- the SQL exception
-
printRecordResultSet
Prints the record result set.- Parameters:
rs
- the rs
-
printRecordResultSet
Prints the record result set.- Parameters:
rs
- the rsall
- the allout
- the out
-
resetCache
public static void resetCache()Reset cache. -
runScript
Run script.- Specified by:
runScript
in interfaceJKDataAccessService
- Parameters:
fileName
- the file name
-
isTableExists
Checks if is table exists.- Specified by:
isTableExists
in interfaceJKDataAccessService
- Parameters:
tableName
- the table name- Returns:
- true, if is table exists
-
setSession
Sets the session.- Parameters:
session
- the new session
-
describeTable
Describe table.- Specified by:
describeTable
in interfaceJKDataAccessService
- Parameters:
name
- the name- Returns:
- the map
-
dropTable
Drop table.- Specified by:
dropTable
in interfaceJKDataAccessService
- Parameters:
tableName
- the table name
-
executeUpdate
Execute update.- Specified by:
executeUpdate
in interfaceJKDataAccessService
- Parameters:
sql
- the sqlobjects
- the objects- Returns:
- the object
-
find
Find.- Specified by:
find
in interfaceJKDataAccessService
- Type Parameters:
T
- the generic type- Parameters:
query
- the querypopulator
- the populatorparams
- the params- Returns:
- the t
-
getList
Gets the list.- Specified by:
getList
in interfaceJKDataAccessService
- Type Parameters:
T
- the generic type- Parameters:
query
- the querypopulator
- the populatorparams
- the params- Returns:
- the list
-
findAndCacheRecord
public <T> T findAndCacheRecord(String key, String query, JKPopulator<T> populator, Object... params) Find and cache record.- Specified by:
findAndCacheRecord
in interfaceJKDataAccessService
- Type Parameters:
T
- the generic type- Parameters:
key
- the keyquery
- the querypopulator
- the populatorparams
- the params- Returns:
- the t
-
getListAndCache
public <T> List<T> getListAndCache(String key, String query, JKPopulator<T> populator, Object... params) Gets the list and cache.- Specified by:
getListAndCache
in interfaceJKDataAccessService
- Type Parameters:
T
- the generic type- Parameters:
key
- the keyquery
- the querypopulator
- the populatorparams
- the params- Returns:
- the list and cache
-
beginTransaction
public void beginTransaction()Begin transaction.- Specified by:
beginTransaction
in interfaceJKDataAccessService
-
isInTransaction
public boolean isInTransaction()Checks if is in transaction.- Returns:
- true, if is in transaction
-
closeTransaction
public void closeTransaction(boolean commit) Close transaction.- Specified by:
closeTransaction
in interfaceJKDataAccessService
- Parameters:
commit
- the commit
-
addQueryLog
Adds the query log.- Parameters:
query
- the querystartTimer
- the start timerendTimer
- the end timer
-
getCaller
Gets the caller.- Returns:
- the caller
-
writeLog
Write log.- Parameters:
query
- the queryduration
- the durationcaller
- the caller
-