/** * Statements needed to upgrade the DB * * @return the table modification string */ public List<String> getTableUpgradeStatements(String tableName, int level) { String smallint = getSmallintType(); String bigint = getBigintType(); if (level == 1) { return Collections.singletonList("alter table " + tableName + " add VERSION " + smallint); } else if (level == 2) { String[] statements = new String[] { "alter table " + tableName + " add SDTYPE " + smallint, "alter table " + tableName + " add SDMAXREVTIME " + bigint, "create index " + tableName + "_VSN on " + tableName + " (VERSION)", "create index " + tableName + "_SDT on " + tableName + " (SDTYPE)" + makeIndexConditionalForColumn("SDTYPE"), "create index " + tableName + "_SDM on " + tableName + " (SDMAXREVTIME)" + makeIndexConditionalForColumn("SDMAXREVTIME"), }; return Arrays.asList(statements); } else { throw new IllegalArgumentException("level must be 1 or 2"); } }
@Override public List<String> getIndexCreationStatements(String tableName, int schema) { List<String> statements = new ArrayList<String>(); String pkName = tableName + "_pk"; statements.add("create unique index " + pkName + " on " + tableName + " ( ID ) cluster"); statements.add("alter table " + tableName + " add constraint " + pkName + " primary key ( ID )"); statements.addAll(super.getIndexCreationStatements(tableName, schema)); return statements; }
System.out.println(); RDBDocumentStoreDB ddb = RDBDocumentStoreDB.getValue(database); RDBBlobStoreDB bdb = RDBBlobStoreDB.getValue(database); System.out.println(" " + ddb.getTableCreationStatement(table, defaultOpts.getInitialSchema())); for (String s : ddb.getIndexCreationStatements(table, defaultOpts.getInitialSchema())) { System.out.println(" " + s); for (String statement : ddb.getTableUpgradeStatements(table, level)) { System.out.println(" " + statement);
String dbUrl = md.getURL(); this.dbInfo = RDBDocumentStoreDB.getValue(md.getDatabaseProductName()); this.db = new RDBDocumentStoreJDBC(this.dbInfo, this.ser, QUERYHITSLIMIT, QUERYTIMELIMIT); this.metadata = ImmutableMap.<String,String>builder() .put("driverVersion", md.getDriverVersion()) .build(); String versionDiags = dbInfo.checkVersion(md); if (!versionDiags.isEmpty()) { LOG.error(versionDiags); if (! "".equals(dbInfo.getInitializationStatement())) { Statement stmt = null; try { stmt = con.createStatement(); stmt.execute(dbInfo.getInitializationStatement()); stmt.close(); con.commit(); String diag = dbInfo.getAdditionalDiagnostics(this.ch, this.tableMeta.get(Collection.NODES).getName());
private void createTableFor(Connection con, Collection<? extends Document> col, RDBTableMetaData tmd, List<String> tablesCreated, List<String> tablesPresent, int initialSchema, int upgradeToSchema) throws SQLException { String dbname = this.dbInfo.toString(); if (con.getMetaData().getURL() != null) { dbname += " (" + con.getMetaData().getURL() + ")"; creatStatement.execute(this.dbInfo.getTableCreationStatement(tableName, initialSchema)); creatStatement.close(); for (String ic : this.dbInfo.getIndexCreationStatements(tableName, initialSchema)) { creatStatement = con.createStatement(); creatStatement.execute(ic);
public long determineServerTimeDifferenceMillis(Connection connection) { String sql = this.dbInfo.getCurrentTimeStampInSecondsSyntax(); LOG.debug("{}: unsupported database, skipping DB server time check", this.dbInfo.toString()); return 0; } else {
public RDBDocumentStoreJDBCTest(DocumentStoreFixture dsf) { super(dsf); assumeTrue(super.rdbDataSource != null); dbInfo = RDBDocumentStoreDB.getValue(((RDBDocumentStore) super.ds).getMetadata().get("db")); RDBDocumentSerializer ser = new RDBDocumentSerializer(super.ds); jdbc = new RDBDocumentStoreJDBC(dbInfo, ser, 100, 10000); }
private <T extends Document> void toMapBuilder(ImmutableMap.Builder<String, String> builder, Collection<T> collection, RDBTableMetaData meta) { String prefix = collection.toString(); builder.put(prefix + ".ns", meta.getCatalog() + "." + meta.getName()); builder.put(prefix + ".schemaInfo", meta.getSchemaInfo()); builder.put(prefix + ".indexInfo", meta.getIndexInfo()); if (Collection.CLUSTER_NODES.equals(collection)) { builder.put(prefix + ".updates", getCnStats()); } // live data Map<String, String> map = this.dbInfo.getAdditionalStatistics(this.ch, meta.getCatalog(), meta.getName()); map.forEach((k, v) -> builder.put(prefix + "." + k, v)); try { long c = queryCount(collection, null, null, Collections.emptyList(), Collections.emptyList()); builder.put(prefix + ".count", Long.toString(c)); } catch (DocumentStoreException ex) { LOG.debug("getting entry count for " + prefix, ex); } }
if (limit != Integer.MAX_VALUE && this.dbInfo.getFetchFirstSyntax() == FETCHFIRSTSYNTAX.TOP) { selectClause.append("TOP " + limit + " "); switch (this.dbInfo.getFetchFirstSyntax()) { case LIMIT: query.append(" LIMIT " + limit);
Long oldmodcount, String appendData) throws SQLException { String appendDataWithComma = "," + appendData; PreparedStatementComponent stringAppend = this.dbInfo.getConcatQuery(appendDataWithComma, tmd.getDataLimitInOctets()); StringBuilder t = new StringBuilder(); t.append("update " + tmd.getName() + " set ");
System.out.println(); RDBDocumentStoreDB ddb = RDBDocumentStoreDB.getValue(database); RDBBlobStoreDB bdb = RDBBlobStoreDB.getValue(database); System.out.println(" " + ddb.getTableCreationStatement(table, defaultOpts.getInitialSchema())); for (String s : ddb.getIndexCreationStatements(table, defaultOpts.getInitialSchema())) { System.out.println(" " + s); for (String statement : ddb.getTableUpgradeStatements(table, level)) { System.out.println(" " + statement);
String dbUrl = md.getURL(); this.dbInfo = RDBDocumentStoreDB.getValue(md.getDatabaseProductName()); this.db = new RDBDocumentStoreJDBC(this.dbInfo, this.ser, QUERYHITSLIMIT, QUERYTIMELIMIT); this.metadata = ImmutableMap.<String,String>builder() .put("driverVersion", md.getDriverVersion()) .build(); String versionDiags = dbInfo.checkVersion(md); if (!versionDiags.isEmpty()) { LOG.error(versionDiags); if (! "".equals(dbInfo.getInitializationStatement())) { Statement stmt = null; try { stmt = con.createStatement(); stmt.execute(dbInfo.getInitializationStatement()); stmt.close(); con.commit(); String diag = dbInfo.getAdditionalDiagnostics(this.ch, this.tableMeta.get(Collection.NODES).getName());
private void createTableFor(Connection con, Collection<? extends Document> col, RDBTableMetaData tmd, List<String> tablesCreated, List<String> tablesPresent, int initialSchema, int upgradeToSchema) throws SQLException { String dbname = this.dbInfo.toString(); if (con.getMetaData().getURL() != null) { dbname += " (" + con.getMetaData().getURL() + ")"; creatStatement.execute(this.dbInfo.getTableCreationStatement(tableName, initialSchema)); creatStatement.close(); for (String ic : this.dbInfo.getIndexCreationStatements(tableName, initialSchema)) { creatStatement = con.createStatement(); creatStatement.execute(ic);
public long determineServerTimeDifferenceMillis(Connection connection) { String sql = this.dbInfo.getCurrentTimeStampInSecondsSyntax(); LOG.debug("{}: unsupported database, skipping DB server time check", this.dbInfo.toString()); return 0; } else {
private <T extends Document> void toMapBuilder(ImmutableMap.Builder<String, String> builder, Collection<T> collection, RDBTableMetaData meta) { String prefix = collection.toString(); builder.put(prefix + ".ns", meta.getCatalog() + "." + meta.getName()); builder.put(prefix + ".schemaInfo", meta.getSchemaInfo()); builder.put(prefix + ".indexInfo", meta.getIndexInfo()); if (Collection.CLUSTER_NODES.equals(collection)) { builder.put(prefix + ".updates", getCnStats()); } // live data Map<String, String> map = this.dbInfo.getAdditionalStatistics(this.ch, meta.getCatalog(), meta.getName()); map.forEach((k, v) -> builder.put(prefix + "." + k, v)); try { long c = queryCount(collection, null, null, Collections.emptyList(), Collections.emptyList()); builder.put(prefix + ".count", Long.toString(c)); } catch (DocumentStoreException ex) { LOG.debug("getting entry count for " + prefix, ex); } }
if (limit != Integer.MAX_VALUE && this.dbInfo.getFetchFirstSyntax() == FETCHFIRSTSYNTAX.TOP) { selectClause.append("TOP " + limit + " "); switch (this.dbInfo.getFetchFirstSyntax()) { case LIMIT: query.append(" LIMIT " + limit);
Long oldmodcount, String appendData) throws SQLException { String appendDataWithComma = "," + appendData; PreparedStatementComponent stringAppend = this.dbInfo.getConcatQuery(appendDataWithComma, tmd.getDataLimitInOctets()); StringBuilder t = new StringBuilder(); t.append("update " + tmd.getName() + " set ");
/** * Statements needed to upgrade the DB * * @return the table modification string */ public List<String> getTableUpgradeStatements(String tableName, int level) { String smallint = getSmallintType(); String bigint = getBigintType(); if (level == 1) { return Collections.singletonList("alter table " + tableName + " add VERSION " + smallint); } else if (level == 2) { String[] statements = new String[] { "alter table " + tableName + " add SDTYPE " + smallint, "alter table " + tableName + " add SDMAXREVTIME " + bigint, "create index " + tableName + "_VSN on " + tableName + " (VERSION)", "create index " + tableName + "_SDT on " + tableName + " (SDTYPE)" + makeIndexConditionalForColumn("SDTYPE"), "create index " + tableName + "_SDM on " + tableName + " (SDMAXREVTIME)" + makeIndexConditionalForColumn("SDMAXREVTIME"), }; return Arrays.asList(statements); } else { throw new IllegalArgumentException("level must be 1 or 2"); } }
@Override public List<String> getIndexCreationStatements(String tableName, int schema) { List<String> statements = new ArrayList<String>(); String pkName = tableName + "_pk"; statements.add("create unique index " + pkName + " on " + tableName + " ( ID ) cluster"); statements.add("alter table " + tableName + " add constraint " + pkName + " primary key ( ID )"); statements.addAll(super.getIndexCreationStatements(tableName, schema)); return statements; }