primaryKey
Set the primary key to select by.
- Parameters:
_primaryKey- is the _primaryKey to use.- Returns:
- this.
Use this class to get access to the global database connections, create a new connection, and execute sql against them.
Sample call
Timestamp lastSuccess = new GcDbAccess().sql("select max(ended_time) from grouper_loader_log where job_name = ?")
.addBindVar("CHANGE_LOG_consumer_recentMemberships").select(Timestamp.class);
From a database external system
Integer theOne = new GcDbAccess().connectionName(externalSystemConfigId).sql("select 1 from dual")
.select(Integer.class);
static class static voidaccumulateQueryMillis(boolean _accumulateQueryMillis) addBindVar(Object _bindVar) addBindVars(Collection<?> _bindVar) batchBindVars(List<List<Object>> _batchBindVars) batchSize(int theBatchSize) cacheMinutes(Integer _cacheMinutes) <T> TcallbackCallableStatement(GcCallableStatementCallback<T> callableStatementCallback) <T> TcallbackConnection(GcConnectionCallback<T> connectionCallback) <T> voidcallbackEntity(Class<T> clazz,
GcEntityCallback<T> entityCallback) <T> TcallbackPreparedStatement(GcPreparedStatementCallback<T> preparedStatementCallback) <T> TcallbackResultSet(GcResultSetCallback<T> resultSetCallback) <T> TcallbackTransaction(GcTransactionCallback<T> transactionCallback) static ConnectionconnectionCreateNew(String connectionName,
String[] url) static ConnectionconnectionGetFromPool(String connectionName,
String[] url) static ConnectionconnectionHelper(String connectionName,
String[] url) connectionName(String theConnectionName) static StringcreateInString(int numberOfBindVariables) voidint[]intstatic Map<MultiKey,GcDbQueryCache> static Map<String,GcQueryReport> static booleanbooleanstatic voidloadBoundDataConversion(GcBoundDataConversion _boundDataConversion) primaryKey(Object... _primaryKey) queryTimeoutSeconds(Integer _queryTimeoutSeconds) static voidreportQueriesAndMillisAndTurnOffAccumulation(String fileLocation) <T> T<T> List<T>selectList(Class<T> clazz) <K,
V> Map<K,V> <K,
V> Map<K,V> selectMapMultipleRows(Class<K> keyClass,
Class<V> valueClass) static voidsetGrouperIsStarted(boolean theGrouperIsStarted) <T> intstoreBatchToDatabase(List<T> objects,
int batchSize) <T> intstoreBatchToDatabase(List<T> objects,
int batchSize,
boolean omitPrimaryKeyPopulation) <T> voidstoreListToDatabase(List<T> objects) <T> booleanstoreToDatabase(T t) static voidthreadLocalQueryCountIncrement(int queriesToAdd) static voidstatic intstatic voidtransactionEnd(GcTransactionEnd transactionEnd,
boolean endOnlyIfStarted) static voidtransactionEnd(GcTransactionEnd transactionEnd,
boolean endOnlyIfStarted,
String connectionName) theGrouperIsStarted - the grouperIsStarted to settheBatchSize - queriesToAdd - theTableName - theConnectionName - transactionEnd - endOnlyIfStarted - transactionEnd - endOnlyIfStarted - connectionName - _boundDataConversion - the boundDataConversion to set.numberOfBindVariables - is the number of bind variables to use._bindVars - are the variables to add to the list._bindVar - is the variable to add to the list._bindVar - is the variable to add to the list._batchBindVars - are the variables to set.Cache the results of a SELECT query for the allotted minutes. Note that cached objects are not immutable; if you modify them you are modifying them in the cache as well.
_cacheMinutes - is how long to persist the object(s) in cache for after the initial selection._sql - is the sql to use._example - is the example to use._queryTimeoutSeconds - is the amount of seconds to set.If true, the map queryAndTime will be populated with the time spent in each unique query (unique by query string, not considering bind variable values) - BE SURE TO TURN THIS OFF when done debugging, this is ONLY for debugging on the desktop!Turning it off CLEARS the stats, so write it off first! Example: 1. DbAccess.accumulateQueryMillis(true); 2. use application normally 3. Get the results: Map<String, Long> timeSpentInQueries =
_accumulateQueryMillis - is whether to accumulate them or not.Write the stats of queries and time spent in them to a file at the given location, then stop collection stats. accumulateQueryMillis(true) must be called first to turn on debugging.
fileLocation - is the location of the file to write._primaryKey - is the _primaryKey to use.Whether this class has already been saved to the database, looks for a field(s) with annotation @Persistable(primaryKeyField=true), assumes that it is a number, and returns true if it is null or larger than 0.
o - is the object to store to the database.o - is the object to delete from the database.T - is the type to store.objects - are the object to store to the database.T - is the type to store.t - is the object to store to the database.Store the given objects to the database in a batch - the objects should have appropriate annotations from the PersistableX annotations. You cannot have both inserts and updates in the list of objects to store; they MUST all have the same action (insert or update) being taken against them as jdbc statements supoprt mutliple sqls in a batch but do not support bind variables when using this capability.
T - is the type to store.objects - is the list of objects to store to the database.batchSize - is the size of the batch to insert or update in.Store the given objects to the database in a batch - the objects should have appropriate annotations from the PersistableX annotations. You cannot have both inserts and updates in the list of objects to store; they MUST all have the same action (insert or update) being taken against them as jdbc statements supoprt mutliple sqls in a batch but do not support bind variables when using this capability.
T - is the type being stored.objects - is the list of objects to store to the database.batchSize - is the size of the batch to insert or update in.omitPrimaryKeyPopulation - if you DON'T need primary keys populated into your objects, you can set this and save some query time since
we will just set the primary key population as "some_sequence.nextval" instead of selecting it manually before storing the object.For each row of a given resultset, hydrate an object and pass it to the callback.
T - clazz - is the type of thing passed to the entity callback.entityCallback - is the callback object that receives this dbAccess with a session set up.Use a transaction for all calls that happen within this callback. Upon success with no exceptions thrown, commit is called automatically. Upon failure, rollback it called. You may also call dbAccess.setTransactionEnd() within the callback block.
T - is the type of thing being returned.transactionCallback - is the callback object that receives this dbAccess with a session set up.K - V - keyClass - is the class of the key.valueClass - is the class of the value.K - V - keyClass - is the class of the key.valueClass - is the class of the value.Select a map of key : column name and value : column value from the database - set sql() before calling. Example: select first_name, last_name, middle_name from person: Map key Map value first_name Fred last_name Jones middle_name Percival
T - is the type of object that will be returned.clazz - is the type of object that will be returned.T - is the type of object that will be returned.clazz - is the type of object that will be returned.connectionName - url - ClassNotFoundExceptionSQLExceptionconnectionName - url - ClassNotFoundExceptionSQLExceptionT - is what you are returning, must be a type but you can return null.callableStatementCallback - is the callback object.T - is what you are returning, must be a type but you can return null.preparedStatementCallback - is the callback object.T - is what you are returning, must be a type but you can return null.connectionCallback - is the callback object.T - is the type of object that will be returned.resultSetCallback - is the object to callback.connectionName - url - ClassNotFoundExceptionSQLException