/** * Returns the database dialect object. (Delegated to DbProvider). * @return x */ public Dialect getDialect() { return provider.getDialect(); }
public DbPrepared getStatement(String name) throws MException { String[] query = provider.getQuery(name); return new DbPrepared(this, query[1], query[0]); }
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); }
@Override public DbConnection getConnection() throws Exception { if (closed) throw new Exception("Pool is closed"); try { InternalDbConnection out = getProvider().createConnection(); out.setPool(this); out.setUsed(true); return out; } catch (Exception e) { // special behavior for e.g. mysql, retry to get a connection after gc() // Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections if (e.getMessage().indexOf("Too many connections") > -1) { printStackTrace(); } throw e; } }
/** * Set a DbProvider for this pool. * * @param provider */ protected void setProvider(DbProvider provider) { this.provider = provider; name = provider.getName(); if (name == null) name = "pool"; name = name + MApi.lookup(UniqueId.class).nextUniqueId(); }
/** * 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(); }
/** * 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); }
/** * Overwrite to configure new created connections before use. * * @return created connection or null if not possible * @throws Exception */ protected DbConnection createConnection() throws Exception { try { InternalDbConnection con = getProvider().createConnection(); if (con == null) return null; con.setPool(this); pool.add(con); if (tracePoolSize.value()) log().d("Create DB Connection",pool.size()); con.setUsed(true); //getDialect().initializeConnection(con, this); return new DbConnectionProxy(this, con); } catch (Exception e) { // special behavior for e.g. mysql, retry to get a connection after gc() // Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections if (e.getMessage() != null && e.getMessage().indexOf("Too many connections") > -1) { printStackTrace(); } throw e; } }
/** {@inheritDoc} */ @Override public DbStatement createStatement(String sql) throws MException { return createStatement(sql, provider.getDialect().detectLanguage(sql)); }
/** {@inheritDoc} */ @Override public DbStatement getStatement(String name) throws MException { synchronized (this) { if (closed) throw new MException("Connection not valid"); String[] query = provider.getQuery(name); if (query == null) return null; return new JdbcStatement(this, query[1],query[0]); } }