/** * 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); }
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(); } }
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(); } }
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(); } }
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 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); } }
@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); } }
@Override public void deleteNode(String nodeId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getDeleteNodeStatement(conn, nodeId); try { statement.executeUpdate(); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception deleting node " + nodeId, e); } }
@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); } }
public void clearData() throws SQLException { Connection conn = dbConnectionPool.getConnection(); try { for (BaseEntityStoreView.EntityType type : BaseEntityStoreView.EntityType.values()) { Statement stmt = conn.createStatement(); try { stmt.execute("DELETE FROM " + type.getId() + "s"); } finally { stmt.close(); } } } finally { conn.close(); } }
@Override public void writeProfile(Account account, Map<String, Object> profile) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { DBPut profilePut = new ProfileDBPut(account, profile); profilePut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception writing profile for account {}.", account, e); throw new IOException(e); } }
@Override void setValue(String tenantId, String clusterId, byte[] val) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { DBPut profilePut = new FieldsDBPut(tenantId, clusterId, val); profilePut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception writing sensitive fields for tenant {} and cluster {}.", tenantId, clusterId, e); throw new IOException(e); } }
@Override public Set<Node> getAllNodes() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectAllNodesStatement(conn); try { return dbQueryExecutor.getQuerySet(statement, Node.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all nodes"); } }
@Override public List<ClusterSummary> getAllClusterSummaries() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectAllClusterJobsStatement(conn); try { return getSummaries(statement); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all clusters"); } }
@Override public List<Cluster> getNonTerminatedClusters() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectNonTerminatedClusters(conn); try { return dbQueryExecutor.getQueryList(statement, Cluster.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all clusters"); } }
@Override protected void writeEntity(EntityType entityType, String entityName, int version, byte[] data) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { DBPut entityPut = new EntityDBPut(entityType, entityName, version, data); entityPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception writing entity of type " + entityType.name().toLowerCase() + " with name " + entityName + accountErrorSnippet); } }
@Override public void writeTenant(Tenant tenant) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { DBPut tenantPut = new TenantDBPut(tenant, dbQueryExecutor.toBytes(tenant, Tenant.class)); tenantPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception writing tenant {}", tenant); throw new IOException(e); } }
@Override public void writeNode(Node node) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { byte[] nodeBytes = dbQueryExecutor.toBytes(node, Node.class); DBPut nodePut = new NodeDBPut(node, nodeBytes); nodePut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override public void writeClusterJob(ClusterJob clusterJob) throws IOException { JobId jobId = JobId.fromString(clusterJob.getJobId()); long clusterId = Long.parseLong(jobId.getClusterId()); try { Connection conn = dbConnectionPool.getConnection(); try { byte[] jobBytes = dbQueryExecutor.toBytes(clusterJob, ClusterJob.class); DBPut jobPut = new ClusterJobDBPut(clusterJob, jobBytes, jobId, clusterId); jobPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override public void writeClusterTask(ClusterTask clusterTask) throws IOException { TaskId taskId = TaskId.fromString(clusterTask.getTaskId()); long clusterId = Long.parseLong(taskId.getClusterId()); try { Connection conn = dbConnectionPool.getConnection(); try { byte[] taskBytes = dbQueryExecutor.toBytes(clusterTask, ClusterTask.class); DBPut taskPut = new ClusterTaskDBPut(clusterTask, taskBytes, taskId, clusterId); taskPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }