@Override protected void finalize() throws Throwable { close(); housekeeperTask = null; super.finalize(); }
@Override public DbConnection createTransactionalConnection() { try { return getConnection(); } catch (Exception e) { return null; } }
DbPrepared(DbPool pool, String queryString, String language) throws MException { this.original = queryString; this.pool = pool; query = pool.getDialect().getQueryParser(language).compileString(queryString); // query = new SimpleQueryParser().compileString(queryString); // query = new SqlCompiler().compileString(queryString); }
/** * Create a pool with the DbProvider. * * @param provider */ public DbPool(DbProvider provider) { doCreateConfig(); setProvider(provider); init(); }
/** * Create a new pool from a configuration. * * @param config Config element or null. null will use the central MApi configuration. * @param activator Activator or null. null will use the central MApi Activator. * @throws Exception */ public DbPool(IConfig config,MActivator activator) throws Exception { this.config = config; if (this.config == null) doCreateConfig(); if (activator == null) activator = MApi.lookup(MActivator.class); DbProvider provider = (DbProvider) activator.createObject(this.config.getExtracted("provider",JdbcProvider.class.getCanonicalName())); provider.doInitialize(this.config,activator); this.provider = provider; init(); }
public void init() { try { URL url = MSystem.locateResource(this, "SqlDbStorage.xml"); DbConnection con = pool.getConnection(); XmlConfigFile data = new XmlConfigFile(url.openStream()); data.setString("prefix", prefix); pool.getDialect().createStructure(data, con, null, false); con.close(); } catch (Exception e) { log().e(e); } }
pool.cleanup(true); Class<? extends Persistable>[] types = schema.getObjectTypes(); DbConnection con = pool.getConnection(); if (con == null) return;
protected synchronized void init() { if (housekeeperTask != null) return; housekeeperTask = new MHousekeeperTask(name) { @Override public void doit() throws Exception { if (!isClosed() && autoCleanup.value()) { log().t(DbPool.this.getName(),"autoCleanup connections"); cleanup(autoCleanupUnused.value()); } if (isClosed()) cancel(); } }; MHousekeeper housekeeper = MApi.lookup(MHousekeeper.class); if (housekeeper != null) { housekeeper.register(housekeeperTask, getConfig().getLong("autoCleanupSleep",300000)); } else { log().w("Housekeeper not found - autoCleanup disabled"); } }
/** * Create a prepared statement using the default language. * * @param sql * @return x * @throws MException */ public DbPrepared createStatement(String sql) throws MException { return createStatement(sql, null); }
public DbManagerJdbc(DbPool pool, DbSchema schema, MActivator activator, boolean cleanup) throws Exception { this.pool = pool; this.schema = schema; this.activator = activator == null ? pool.getProvider().getActivator() : activator; initDatabase(cleanup); }
public void setPool(DbPool pool) { this.poolId = pool.getPoolId(); this.pool = pool; }
DbPrepared query = manager.getPool().createStatement(sql.toString());
/** * Create a new manager instance, a db connection and a database schema is needed. * @param dataSourceName * * @param pool * @param schema * @param cleanup * @throws MException */ public DbManagerJdbc(String dataSourceName, DbPool pool, DbSchema schema, boolean cleanup) throws MException { this.dataSourceName = dataSourceName; this.pool = pool; this.schema = schema; this.activator = pool.getProvider().getActivator(); initDatabase(cleanup); }
/** * Return a statement with a new connection from the pool. * * @return x * @throws Exception */ public DbStatement getStatement() throws Exception { DbConnection con = pool.getConnection(); return con.createStatement(this); }
/** {@inheritDoc} */ @Override public Parser createQueryCompiler(String language) throws MException { if (pool != null) return pool.getDialect().getQueryParser(language); return new SimpleQueryCompiler(); }
/** * <p>close.</p> */ public void close() { if (bundle == null) return; synchronized (bundle) { for (DbPool pool : bundle.values()) pool.close(); bundle = null; } }
sqlPrimary = manager.getPool().createStatement(sql); sqlInsert = manager.getPool().createStatement(sql); sqlUpdate = manager.getPool().createStatement(sql); sqlUpdateForce = manager.getPool().createStatement(sql); sqlDelete = manager.getPool().createStatement(sql);
/** * Return a default connection if no connection is given for the operation with the object. If you want to * work with transactions use this method to return a transaction bound connection. By default a new * connection from the pool are used. You may overwrite the commit() or rollback() methods. * * @param pool * @return x * @throws Exception */ public DbConnection getConnection(DbPool pool) throws Exception { DbConnection con = (DbConnection) DbTransaction.getConnection(pool); if (con != null) return con; return pool.getConnection(); }
@Override public <T> String toQualification(AQuery<T> qualification) { StringBuilder buffer = new StringBuilder(); qualification.setContext(new SqlDialectCreateContext(this, buffer)); getPool().getDialect().createQuery(qualification, qualification); return buffer.toString(); }