/** * Get a {@link Connection} from the pool with auto commit on. * * @return Connection from the pool with autocommit. * @throws SQLException */ public Connection getConnection() throws SQLException { return getConnection(true); }
@Override protected void startUp() throws Exception { if (dbConnectionPool.isEmbeddedDerbyDB()) { DBHelper.createDerbyTableIfNotExists( "CREATE TABLE users ( " + "user_id VARCHAR(256), " + "tenant_id VARCHAR(64), " + "profile BLOB )", dbConnectionPool); } }
protected void clearData() throws SQLException { Connection conn = dbConnectionPool.getConnection(); try { Statement stmt = conn.createStatement(); try { stmt.execute("DELETE FROM nodes"); } finally { stmt.close(); } } finally { conn.close(); } }
@Override protected void startUp() throws Exception { if (dbConnectionPool.isEmbeddedDerbyDB()) { DBHelper.createDerbyTableIfNotExists( "CREATE TABLE sensitiveFields ( " + "tenant_id VARCHAR(64), " + "cluster_id VARCHAR(255), " + "fields BLOB )", dbConnectionPool); } }
public void clearData() throws SQLException { Connection conn = dbConnectionPool.getConnection(); try { Statement stmt = conn.createStatement(); try { stmt.executeUpdate("DELETE FROM pluginMeta"); } finally { stmt.close(); } } finally { conn.close(); } }
@Override protected void startUp() throws Exception { if (dbConnectionPool.isEmbeddedDerbyDB()) { LOG.warn("Initializing Derby DB... Tables are not optimized for performance."); boolean created = DBHelper.createDerbyTableIfNotExists("CREATE TABLE nodes ( " + "cluster_id BIGINT, " + "id VARCHAR(64), " + "node BLOB, " + "PRIMARY KEY (id) )", dbConnectionPool ); if (created) { DBHelper.createDerbyIndex(dbConnectionPool, "nodes_cluster_index", "nodes", "cluster_id", "id"); } } }
public void clearData() throws SQLException { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement stmt = conn.prepareStatement("DELETE FROM users"); try { stmt.executeUpdate(); } finally { stmt.close(); } } finally { conn.close(); } }
@Override protected void startUp() throws Exception { if (dbConnectionPool.isEmbeddedDerbyDB()) { boolean created = DBHelper.createDerbyTableIfNotExists( "CREATE TABLE pluginMeta (" + "tenant_id VARCHAR(255), " + "plugin_type VARCHAR(16), " + "plugin_name VARCHAR(255), " + "resource_type VARCHAR(255), " + "name VARCHAR(255), " + "version INTEGER, " + "live BOOLEAN, " + "slated BOOLEAN, " + "deleted BOOLEAN, " + "create_time TIMESTAMP," + "delete_time TIMESTAMP," + "PRIMARY KEY(tenant_id, plugin_type, plugin_name, resource_type, name, version) )", dbConnectionPool); if (created) { DBHelper.createDerbyIndex(dbConnectionPool, "plugin_meta_index", "pluginMeta", "tenant_id", "plugin_type", "plugin_name", "resource_type", "name", "version"); } } }
public void clearData() throws SQLException { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement stmt = conn.prepareStatement("DELETE FROM tenants WHERE id<>?"); try { stmt.setString(1, Constants.SUPERADMIN_TENANT); stmt.executeUpdate(); } finally { stmt.close(); } } finally { conn.close(); } }
@Override protected void startUp() throws Exception { if (dbConnectionPool.isEmbeddedDerbyDB()) { for (BaseEntityStoreView.EntityType entityType : BaseEntityStoreView.EntityType.values()) { String entityName = entityType.getId(); // immune to sql injection since it comes from the enum String createString = "CREATE TABLE " + entityName + "s ( name VARCHAR(255), version BIGINT, tenant_id VARCHAR(255), " + entityName + " BLOB, PRIMARY KEY (tenant_id, name, version))"; DBHelper.createDerbyTableIfNotExists(createString, dbConnectionPool); } } }
@Override public void deleteNode(String nodeId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("DELETE FROM nodes WHERE id=? "); try { statement.setString(1, nodeId); statement.executeUpdate(); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override protected void startUp() throws Exception { if (dbConnectionPool.isEmbeddedDerbyDB()) { DBHelper.createDerbyTableIfNotExists( "CREATE TABLE tenants ( " + "id VARCHAR(255), " + "name VARCHAR(255), " + "workers INT, " + "deleted BOOLEAN, " + "create_time TIMESTAMP, " + "delete_time TIMESTAMP, " + "tenant BLOB )", dbConnectionPool); } // add superadmin if it doesn't exist Tenant superadminTenant = getTenantByName(Constants.SUPERADMIN_TENANT); if (superadminTenant == null) { writeTenant(Tenant.DEFAULT_SUPERADMIN); } }
@Override public void wipe() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement stmt = conn.prepareStatement("DELETE FROM sensitiveFields"); try { stmt.executeUpdate(); } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception wiping credential store.", e); throw new IOException(e); } }
@Override protected void startUp() throws Exception { if (dbConnectionPool.isEmbeddedDerbyDB()) { DBHelper.createDerbyTableIfNotExists("CREATE TABLE provisioners (" + "id VARCHAR(255), " + "last_heartbeat TIMESTAMP, " + "capacity_total INTEGER, " + "capacity_free INTEGER, " + "provisioner BLOB, " + "PRIMARY KEY (id) )", dbConnectionPool); DBHelper.createDerbyIndex(dbConnectionPool, "provisioners_heartbeat_index", "provisioners", "last_heartbeat"); DBHelper.createDerbyTableIfNotExists("CREATE TABLE provisionerWorkers (" + "provisioner_id VARCHAR(255), " + "tenant_id VARCHAR(255), " + "num_assigned INTEGER, " + "num_live INTEGER, " + "PRIMARY KEY (tenant_id, provisioner_id) )", dbConnectionPool); } }
@Override public ResourceMeta get(String name, int version) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { return getMeta(conn, name, version); } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting metadata of version {} of resource {} for tenant {}.", version, name, tenant, e); throw new IOException(e); } }
public void clearData() throws SQLException { Connection conn = dbConnectionPool.getConnection(); try { Statement stmt = conn.createStatement(); try { stmt.execute("DELETE FROM clusters"); stmt = conn.createStatement(); stmt.execute("DELETE FROM jobs"); stmt = conn.createStatement(); stmt.execute("DELETE FROM tasks"); stmt = conn.createStatement(); stmt.execute("DELETE FROM nodes"); } finally { stmt.close(); } } finally { conn.close(); } }
public void clearData() throws SQLException { Connection conn = dbConnectionPool.getConnection(); try { Statement stmt = conn.createStatement(); try { stmt.execute("DELETE FROM provisioners"); } finally { stmt.close(); } stmt = conn.createStatement(); try { stmt.execute("DELETE FROM provisionerWorkers"); } finally { stmt.close(); } } finally { conn.close(); } }
/** * Create an index on given columns in a table for an embedded derby table. * * @param dbConnectionPool Connection pool to use to create the index. * @param indexName Name of the index. * @param table Name of the table to create the index on. * @param columns Columns of the table to index. * @throws SQLException */ public static void createDerbyIndex(DBConnectionPool dbConnectionPool, String indexName, String table, String... columns) throws SQLException { String statementStr = "CREATE INDEX " + indexName + " ON " + table + "(" + Joiner.on(',').join(columns) + ")"; Connection conn = dbConnectionPool.getConnection(); try { Statement statement = conn.createStatement(); try { statement.executeUpdate(statementStr); } finally { statement.close(); } } finally { conn.close(); } }
@Override public Collection<Provisioner> getAllProvisioners() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT provisioner FROM provisioners"); try { return dbQueryExecutor.getQueryList(statement, Provisioner.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all provisioners", e); } }
@Override public int getFreeCapacity() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT SUM(capacity_free) FROM provisioners"); try { return dbQueryExecutor.getNum(statement); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting amount of free capacity", e); } }