Tabnine Logo
DBHelper
Code IndexAdd Tabnine to your IDE (free)

How to use
DBHelper
in
co.cask.coopr.store

Best Java code snippets using co.cask.coopr.store.DBHelper (Showing top 20 results out of 315)

origin: caskdata/coopr

@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);
 }
}
origin: caskdata/coopr

@Override
PreparedStatement getSelectAllClusterJobsStatement(Connection conn, Set<Cluster.Status> states) throws SQLException {
 PreparedStatement statement = conn.prepareStatement(
  "SELECT C.cluster, J.job FROM clusters C, jobs J WHERE C.latest_job_num=J.job_num AND C.id=J.cluster_id " +
   "AND C.tenant_id=? AND C.owner_id=? AND C.status IN " + DBHelper.createInString(states.size()) +
   "ORDER BY C.create_time DESC");
 statement.setString(1, tenantId);
 statement.setString(2, userId);
 setInClause(statement, states, 3);
 return statement;
}
origin: caskdata/coopr

@Override
public void setHeartbeat(String provisionerId, long ts) throws IOException {
 try {
  Connection conn = dbConnectionPool.getConnection();
  try {
   PreparedStatement statement = conn.prepareStatement("UPDATE provisioners SET last_heartbeat=? WHERE id=?");
   try {
    statement.setTimestamp(1, DBHelper.getTimestamp(ts));
    statement.setString(2, provisionerId);
    statement.executeUpdate();
   } finally {
    statement.close();
   }
  } finally {
   conn.close();
  }
 } catch (SQLException e) {
  throw new IOException("Exception setting heartbeat time for provisioner " + provisionerId, e);
 }
}
origin: caskdata/coopr

 @AfterClass
 public static void afterClass() {
  DBHelper.dropDerbyDB();
 }
}
origin: caskdata/coopr

@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);
 }
}
origin: caskdata/coopr

 @AfterClass
 public static void afterClass() {
  DBHelper.dropDerbyDB();
 }
}
origin: caskdata/coopr

@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);
 }
}
origin: caskdata/coopr

 @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;
 }
}
origin: caskdata/coopr

@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");
  }
 }
}
origin: caskdata/coopr

 @AfterClass
 public static void afterClass() {
  DBHelper.dropDerbyDB();
 }
}
origin: caskdata/coopr

@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);
  }
 }
}
origin: caskdata/coopr

@Override
PreparedStatement getSelectAllClusterJobsStatement(Connection conn, Set<Cluster.Status> states) throws SQLException {
 PreparedStatement statement = conn.prepareStatement(
  "SELECT C.cluster, J.job FROM clusters C, jobs J WHERE C.latest_job_num=J.job_num AND C.id=J.cluster_id " +
   "AND C.tenant_id=? AND C.status IN " + DBHelper.createInString(states.size()) + " ORDER BY C.create_time DESC");
 statement.setString(1, tenantId);
 setInClause(statement, states, 2);
 return statement;
}
origin: caskdata/coopr

 @Override
 public PreparedStatement createInsertStatement(Connection conn) throws SQLException {
  PreparedStatement statement = conn.prepareStatement(
   "INSERT INTO provisioners (id, last_heartbeat, capacity_total, capacity_free, provisioner) " +
    "VALUES (?, ?, ?, ?, ?)");
  statement.setString(1, provisioner.getId());
  statement.setTimestamp(2, DBHelper.getTimestamp(System.currentTimeMillis()));
  statement.setInt(3, provisioner.getCapacityTotal());
  statement.setInt(4, provisioner.getCapacityFree());
  statement.setBytes(5, provisionerBytes);
  return statement;
 }
}
origin: caskdata/coopr

@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");
  }
 }
}
origin: caskdata/coopr

 @AfterClass
 public static void afterClass() {
  DBHelper.dropDerbyDB();
 }
}
origin: caskdata/coopr

@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);
 }
}
origin: caskdata/coopr

@Override
PreparedStatement getSelectAllClusterJobsStatement(Connection conn, Set<Cluster.Status> states) throws SQLException {
 PreparedStatement statement = conn.prepareStatement(
  "SELECT C.cluster, J.job FROM clusters C, jobs J WHERE C.latest_job_num=J.job_num AND C.id=J.cluster_id " +
   "AND C.status IN " + DBHelper.createInString(states.size()) + " ORDER BY C.create_time DESC");
 setInClause(statement, states, 1);
 return statement;
}
origin: caskdata/coopr

@Override
public void deleteTenantByName(String name) throws IOException {
 try {
  Connection conn = dbConnectionPool.getConnection();
  try {
   PreparedStatement statement = conn.prepareStatement(
    "UPDATE tenants SET deleted=true, delete_time=? WHERE name=? ");
   statement.setTimestamp(1, DBHelper.getTimestamp(System.currentTimeMillis()));
   statement.setString(2, name);
   try {
    statement.executeUpdate();
   } finally {
    statement.close();
   }
  } finally {
   conn.close();
  }
 } catch (SQLException e) {
  LOG.error("Exception deleting tenant {}", name);
  throw new IOException(e);
 }
}
origin: caskdata/coopr

boolean created = DBHelper.createDerbyTableIfNotExists("CREATE TABLE clusters ( " +
                             "id BIGINT, " +
                             "owner_id VARCHAR(255), " +
                            dbConnectionPool);
if (created) {
 DBHelper.createDerbyIndex(dbConnectionPool,
              "clusters_account_index", "clusters", "tenant_id", "owner_id", "id");
 DBHelper.createDerbyIndex(dbConnectionPool, "clusters_ctime_index", "clusters", "create_time");
 DBHelper.createDerbyIndex(dbConnectionPool, "clusters_status_index", "clusters", "status");
created = DBHelper.createDerbyTableIfNotExists("CREATE TABLE jobs ( " +
                         "cluster_id BIGINT, " +
                         "job_num BIGINT, " +
                        dbConnectionPool);
if (created) {
 DBHelper.createDerbyIndex(dbConnectionPool, "jobs_ctime_index", "jobs", "create_time");
 DBHelper.createDerbyIndex(dbConnectionPool, "jobs_status_index", "jobs", "status");
created = DBHelper.createDerbyTableIfNotExists("CREATE TABLE tasks ( " +
                         "cluster_id BIGINT, " +
                         "job_num BIGINT, " +
                        dbConnectionPool);
if (created) {
 DBHelper.createDerbyIndex(dbConnectionPool, "tasks_status_time_index", "tasks", "status_time");
 DBHelper.createDerbyIndex(dbConnectionPool, "tasks_submit_time_index", "tasks", "submit_time");
 DBHelper.createDerbyIndex(dbConnectionPool, "tasks_status_index", "tasks", "status");
origin: caskdata/coopr

@AfterClass
public static void afterClass() {
 DBHelper.dropDerbyDB();
}
co.cask.coopr.storeDBHelper

Javadoc

Helper methods for performing database administrative operations.

Most used methods

  • createDerbyIndex
    Create an index on given columns in a table for an embedded derby table.
  • createDerbyTableIfNotExists
    Try and create a table if it doesn't already exist. Returns whether or not the table was created.
  • createInString
    Create a string for an IN clause in a sql query given the number of arguments that will be in the li
  • dropDerbyDB
    Drop all embedded derby dbs.
  • getTimestamp
    Get a Timestamp for the given timestamp in milliseconds. Returns null if the timestamp is less than

Popular in Java

  • Making http requests using okhttp
  • addToBackStack (FragmentTransaction)
  • getExternalFilesDir (Context)
  • setScale (BigDecimal)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now