use of jodd.db.oom.DbOomManager in project jodd by oblac.
the class DefaultAppCore method startDb.
/**
* Initializes database. First, creates connection pool.
* and transaction manager. Then, Jodds DbOomManager is
* configured. It is also configured automagically, by scanning
* the class path for entities.
*/
@SuppressWarnings("unchecked")
protected void startDb() {
if (!useDatabase) {
log.info("database is not used");
return;
}
log.info("database initialization");
// connection pool
connectionProvider = createConnectionProvider();
petite.addBean(PETITE_DBPOOL, connectionProvider);
connectionProvider.init();
checkConnectionProvider();
// transactions manager
jtxManager = createJtxTransactionManager(connectionProvider);
jtxManager.setValidateExistingTransaction(true);
AnnotationTxAdviceManager annTxAdviceManager = new AnnotationTxAdviceManager(jtxManager, jtxScopePattern);
annTxAdviceManager.registerAnnotations(jtxAnnotations);
AnnotationTxAdviceSupport.manager = annTxAdviceManager;
DbSessionProvider sessionProvider = new DbJtxSessionProvider(jtxManager);
// global settings
DbManager dbManager = DbManager.getInstance();
dbManager.setConnectionProvider(connectionProvider);
dbManager.setSessionProvider(sessionProvider);
petite.addBean(PETITE_DB, dbManager);
DbOomManager dbOomManager = DbOomManager.getInstance();
petite.addBean(PETITE_DBOOM, dbOomManager);
// automatic configuration
registerDbEntities(dbOomManager);
}
use of jodd.db.oom.DbOomManager in project jodd by oblac.
the class DbIdGenerator method nextId.
/**
* Returns next ID for given entity type.
* On the first call, it finds the max value of all IDs and stores it.
* On later calls, stored id is incremented and returned.
*/
public synchronized long nextId(Class entityType) {
MutableLong lastId = entityIdsMap.get(entityType);
if (lastId == null) {
DbOomManager dbOomManager = DbOomManager.getInstance();
DbEntityDescriptor ded = dbOomManager.lookupType(entityType);
String tableName = ded.getTableName();
String idColumn = ded.getIdColumnName();
DbOomQuery dbOomQuery = query("select max(" + idColumn + ") from " + tableName);
long lastLong = dbOomQuery.autoClose().executeCount();
if (log.isDebugEnabled()) {
log.debug("Last id for " + entityType.getName() + " is " + lastLong);
}
lastId = new MutableLong(lastLong);
entityIdsMap.put(entityType, lastId);
}
lastId.value++;
return lastId.value;
}
Aggregations