public long getJobNum() { return jobId.getJobNum(); }
@Override public PreparedStatement createUpdateStatement(Connection conn) throws SQLException { PreparedStatement updateStatement = conn.prepareStatement("UPDATE jobs SET job=?, status=? WHERE job_num=? AND cluster_id=?"); updateStatement.setBytes(1, jobBytes); updateStatement.setString(2, clusterJob.getJobStatus().name()); updateStatement.setLong(3, jobId.getJobNum()); updateStatement.setLong(4, clusterId); return updateStatement; }
@Override public PreparedStatement createInsertStatement(Connection conn) throws SQLException { PreparedStatement statement = conn.prepareStatement( "INSERT INTO jobs (job_num, cluster_id, status, create_time, job) VALUES (?, ?, ?, ?, ?)"); statement.setLong(1, jobId.getJobNum()); statement.setLong(2, clusterId); statement.setString(3, clusterJob.getJobStatus().name()); statement.setTimestamp(4, DBHelper.getTimestamp(System.currentTimeMillis())); statement.setBytes(5, jobBytes); return statement; } }
@Override public void deleteClusterJob(JobId jobId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("DELETE FROM jobs WHERE job_num=? AND cluster_id=?"); try { statement.setLong(1, jobId.getJobNum()); statement.setLong(2, Long.parseLong(jobId.getClusterId())); statement.executeUpdate(); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override public ClusterJob getClusterJob(JobId jobId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT job FROM jobs WHERE job_num=? AND cluster_id=?"); try { statement.setLong(1, jobId.getJobNum()); statement.setLong(2, Long.parseLong(jobId.getClusterId())); return dbQueryExecutor.getQueryItem(statement, ClusterJob.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting cluster job {}", jobId, e); throw new IOException("Exception getting cluster job " + jobId, e); } }
@Override protected PreparedStatement getSetClusterStatement( Connection conn, long id, Cluster cluster, byte[] clusterBytes) throws SQLException { PreparedStatement statement = conn.prepareStatement( "UPDATE clusters SET cluster=?, owner_id=?, tenant_id=?, status=?, expire_time=?, latest_job_num=? WHERE id=?"); statement.setBytes(1, clusterBytes); statement.setString(2, cluster.getAccount().getUserId()); statement.setString(3, cluster.getAccount().getTenantId()); statement.setString(4, cluster.getStatus().name()); statement.setTimestamp(5, DBHelper.getTimestamp(cluster.getExpireTime())); statement.setLong(6, JobId.fromString(cluster.getLatestJobId()).getJobNum()); // where clause statement.setLong(7, id); return statement; }
private PreparedStatement getInsertClusterStatement( Connection conn, long id, Cluster cluster, byte[] clusterBytes) throws SQLException { PreparedStatement statement = conn.prepareStatement( "INSERT INTO clusters (cluster, owner_id, tenant_id, status, expire_time," + " create_time, name, id, latest_job_num) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); statement.setBytes(1, clusterBytes); statement.setString(2, cluster.getAccount().getUserId()); statement.setString(3, cluster.getAccount().getTenantId()); statement.setString(4, cluster.getStatus().name()); statement.setTimestamp(5, DBHelper.getTimestamp(cluster.getExpireTime())); statement.setTimestamp(6, DBHelper.getTimestamp(cluster.getCreateTime())); statement.setString(7, cluster.getName()); statement.setLong(8, id); String latestJobStr = cluster.getLatestJobId(); long latestJobNum = latestJobStr == null ? 0 : JobId.fromString(latestJobStr).getJobNum(); statement.setLong(9, latestJobNum); return statement; }