@Test public void testCreateTable() throws Exception { String tableName = getFreeTableName(); createMyTable(tableName); DBAccessorImpl dbAccessor = injector.getInstance(DBAccessorImpl.class); Statement statement = dbAccessor.getConnection().createStatement(); statement.execute(String.format("insert into %s(id, name) values(1,'hello')", tableName)); ResultSet resultSet = statement.executeQuery(String.format("select * from %s", tableName)); int count = 0; while (resultSet.next()) { assertEquals(resultSet.getString("name"), "hello"); count++; } assertEquals(count, 1); }
@Override public void createTable(String tableName, List<DBColumnInfo> columnInfo, String... primaryKeyColumns) throws SQLException { if (tableExists(tableName)) { return; } primaryKeyColumns = ArrayUtils.nullToEmpty(primaryKeyColumns); String query = dbmsHelper.getCreateTableStatement(tableName, columnInfo, Arrays.asList(primaryKeyColumns)); executeQuery(query); }
DBAccessorImpl implements DBAccessor { @Override public void createTable(String tableName, List<DBColumnInfo> columnInfo, String... primaryKeyColumns) throws SQLException { if (tableExists(tableName)) { return; } primaryKeyColumns = ArrayUtils.nullToEmpty(primaryKeyColumns); String query = dbmsHelper.getCreateTableStatement(tableName, columnInfo, Arrays.asList(primaryKeyColumns)); executeQuery(query); } }
DBAccessorImpl implements DBAccessor { @Override public void createTable(String tableName, List<DBColumnInfo> columnInfo, String... primaryKeyColumns) throws SQLException { if (tableExists(tableName)) { return; } primaryKeyColumns = ArrayUtils.nullToEmpty(primaryKeyColumns); String query = dbmsHelper.getCreateTableStatement(tableName, columnInfo, Arrays.asList(primaryKeyColumns)); executeQuery(query); } @Inject  DBAccessorImpl(Configuration configuration); }
DBAccessorImpl implements DBAccessor { @Override public void createTable(String tableName, List<DBColumnInfo> columnInfo, String... primaryKeyColumns) throws SQLException { if (tableExists(tableName)) { return; } primaryKeyColumns = ArrayUtils.nullToEmpty(primaryKeyColumns); String query = dbmsHelper.getCreateTableStatement(tableName, columnInfo, Arrays.asList(primaryKeyColumns)); executeQuery(query); } @Inject  DBAccessorImpl(Configuration configuration); @Override Connection getConnection(); @Override Connection getNewConnection(); @Override String quoteObjectName(String name); @Override void createTable(String tableName, List<DBColumnInfo> columnInfo,
      String... primaryKeyColumns); @Override boolean tableExists(String tableName); @Override DbType getDbType(); @Override boolean tableHasData(String tableName); @Override boolean tableHasColumn(String tableName, String columnName); @Override boolean tableHasColumn(String tableName, String... columnName); @Override boolean tableHasForeignKey(String tableName, String fkName); String getCheckedForeignKey(String tableName, String fkName); @Override boolean tableHasForeignKey(String tableName, String refTableName,
          String columnName, String refColumnName); @Override boolean tableHasForeignKey(String tableName, String referenceTableName, String[] keyColumns,
          String[] referenceColumns); @Override boolean tableHasIndex(String tableName, boolean unique, String indexName); @Override void createIndex(String indexName, String tableName,
          String... columnNames); @Override void createIndex(String indexName, String tableName, boolean isUnique,
                          String... columnNames); @Override void addFKConstraint(String tableName, String constraintName,
          String keyColumn, String referenceTableName,
          String referenceColumn, boolean ignoreFailure); @Override void addFKConstraint(String tableName, String constraintName,
          String keyColumn, String referenceTableName,
          String referenceColumn, boolean shouldCascadeOnDelete,
          boolean ignoreFailure); @Override void addFKConstraint(String tableName, String constraintName,
          String[] keyColumns, String referenceTableName,
          String[] referenceColumns,
          boolean ignoreFailure); @Override void addFKConstraint(String tableName, String constraintName,
          String[] keyColumns, String referenceTableName,
          String[] referenceColumns, boolean shouldCascadeOnDelete,
          boolean ignoreFailure); boolean tableHasConstraint(String tableName, String constraintName); @Override void addUniqueConstraint(String tableName, String constraintName, String... columnNames); @Override void addPKConstraint(String tableName, String constraintName, boolean ignoreErrors, String... columnName); @Override void addPKConstraint(String tableName, String constraintName, String... columnName); @Override void renameColumn(String tableName, String oldColumnName,
          DBColumnInfo columnInfo); @Override void addColumn(String tableName, DBColumnInfo columnInfo); @Override void alterColumn(String tableName, DBColumnInfo columnInfo); @Override void updateTable(String tableName, DBColumnInfo columnNameFrom,
          DBColumnInfo columnNameTo); @Override boolean insertRow(String tableName, String[] columnNames, String[] values, boolean ignoreFailure); @Override boolean insertRowIfMissing(String tableName, String[] columnNames, String[] values, boolean ignoreFailure); @Override int updateTable(String tableName, String columnName, Object value,
          String whereClause); @Override int executeUpdate(String query); @Override int executeUpdate(String query, boolean ignoreErrors); @Override void executeQuery(String query, String tableName, String hasColumnName); @Override void executeQuery(String query); @Override void executeQuery(String query, boolean ignoreFailure); @Override void dropTable(String tableName); @Override void truncateTable(String tableName); @Override void dropColumn(String tableName, String columnName); @Override void dropSequence(String sequenceName); @Override void dropFKConstraint(String tableName, String constraintName); @Override void dropFKConstraint(String tableName, String constraintName, boolean ignoreFailure); @Override void dropUniqueConstraint(String tableName, String constraintName, boolean ignoreFailure); @Override void dropUniqueConstraint(String tableName, String constraintName); @Override void dropPKConstraint(String tableName, String constraintName, String columnName, boolean cascade); @Override void dropPKConstraint(String tableName, String constraintName, boolean ignoreFailure, boolean cascade); @Override void dropPKConstraint(String tableName, String constraintName, boolean cascade); @Override /** * Execute script with autocommit and error tolerance, like psql and sqlplus * do by default */ void executeScript(String filePath); @Override DatabaseSession getNewDatabaseSession(); @Override boolean tableHasPrimaryKey(String tableName, String columnName); @Override int getColumnType(String tableName, String columnName); @Override Class getColumnClass(String tableName, String columnName); @Override boolean isColumnNullable(String tableName, String columnName); @Override void setColumnNullable(String tableName, DBAccessor.DBColumnInfo columnInfo, boolean nullable); @Override void setColumnNullable(String tableName, String columnName, boolean nullable); @Override void changeColumnType(String tableName, String columnName, Class fromType, Class toType); @Override List<String> getIndexesList(String tableName, boolean unique); @Override String getPrimaryKeyConstraintName(String tableName); @Override void dropPKConstraint(String tableName, String defaultConstraintName); @Override void addDefaultConstraint(String tableName, DBColumnInfo column); }
DBAccessorImpl implements DBAccessor { @Override public void createTable(String tableName, List<DBColumnInfo> columnInfo, String... primaryKeyColumns) throws SQLException { if (tableExists(tableName)) { return; } primaryKeyColumns = ArrayUtils.nullToEmpty(primaryKeyColumns); String query = dbmsHelper.getCreateTableStatement(tableName, columnInfo, Arrays.asList(primaryKeyColumns)); executeQuery(query); } @Inject  DBAccessorImpl(Configuration configuration); @Override Connection getConnection(); @Override Connection getNewConnection(); @Override String quoteObjectName(String name); @Override void createTable(String tableName, List<DBColumnInfo> columnInfo,
      String... primaryKeyColumns); @Override boolean tableExists(String tableName); @Override DbType getDbType(); @Override boolean tableHasData(String tableName); @Override boolean tableHasColumn(String tableName, String columnName); @Override boolean tableHasColumn(String tableName, String... columnName); @Override boolean tableHasForeignKey(String tableName, String fkName); String getCheckedForeignKey(String tableName, String fkName); @Override boolean tableHasForeignKey(String tableName, String refTableName,
          String columnName, String refColumnName); @Override boolean tableHasForeignKey(String tableName, String referenceTableName, String[] keyColumns,
          String[] referenceColumns); @Override boolean tableHasIndex(String tableName, boolean unique, String indexName); @Override void createIndex(String indexName, String tableName,
          String... columnNames); @Override void createIndex(String indexName, String tableName, boolean isUnique,
                          String... columnNames); @Override void addFKConstraint(String tableName, String constraintName,
          String keyColumn, String referenceTableName,
          String referenceColumn, boolean ignoreFailure); @Override void addFKConstraint(String tableName, String constraintName,
          String keyColumn, String referenceTableName,
          String referenceColumn, boolean shouldCascadeOnDelete,
          boolean ignoreFailure); @Override void addFKConstraint(String tableName, String constraintName,
          String[] keyColumns, String referenceTableName,
          String[] referenceColumns,
          boolean ignoreFailure); @Override void addFKConstraint(String tableName, String constraintName,
          String[] keyColumns, String referenceTableName,
          String[] referenceColumns, boolean shouldCascadeOnDelete,
          boolean ignoreFailure); boolean tableHasConstraint(String tableName, String constraintName); @Override void addUniqueConstraint(String tableName, String constraintName, String... columnNames); @Override void addPKConstraint(String tableName, String constraintName, boolean ignoreErrors, String... columnName); @Override void addPKConstraint(String tableName, String constraintName, String... columnName); @Override void renameColumn(String tableName, String oldColumnName,
          DBColumnInfo columnInfo); @Override void addColumn(String tableName, DBColumnInfo columnInfo); @Override void alterColumn(String tableName, DBColumnInfo columnInfo); @Override void updateTable(String tableName, DBColumnInfo columnNameFrom,
          DBColumnInfo columnNameTo); @Override boolean insertRow(String tableName, String[] columnNames, String[] values, boolean ignoreFailure); @Override boolean insertRowIfMissing(String tableName, String[] columnNames, String[] values, boolean ignoreFailure); @Override int updateTable(String tableName, String columnName, Object value,
          String whereClause); @Override int executeUpdate(String query); @Override int executeUpdate(String query, boolean ignoreErrors); @Override void executeQuery(String query, String tableName, String hasColumnName); @Override void executeQuery(String query); @Override void executeQuery(String query, boolean ignoreFailure); @Override void dropTable(String tableName); @Override void truncateTable(String tableName); @Override void dropColumn(String tableName, String columnName); @Override void dropSequence(String sequenceName); @Override void dropFKConstraint(String tableName, String constraintName); @Override void dropFKConstraint(String tableName, String constraintName, boolean ignoreFailure); @Override void dropUniqueConstraint(String tableName, String constraintName, boolean ignoreFailure); @Override void dropUniqueConstraint(String tableName, String constraintName); @Override void dropPKConstraint(String tableName, String constraintName, String columnName, boolean cascade); @Override void dropPKConstraint(String tableName, String constraintName, boolean ignoreFailure, boolean cascade); @Override void dropPKConstraint(String tableName, String constraintName, boolean cascade); @Override /** * Execute script with autocommit and error tolerance, like psql and sqlplus * do by default */ void executeScript(String filePath); @Override DatabaseSession getNewDatabaseSession(); @Override boolean tableHasPrimaryKey(String tableName, String columnName); @Override int getColumnType(String tableName, String columnName); @Override Class getColumnClass(String tableName, String columnName); @Override boolean isColumnNullable(String tableName, String columnName); @Override void setColumnNullable(String tableName, DBAccessor.DBColumnInfo columnInfo, boolean nullable); @Override void setColumnNullable(String tableName, String columnName, boolean nullable); @Override void changeColumnType(String tableName, String columnName, Class fromType, Class toType); @Override List<String> getIndexesList(String tableName, boolean unique); @Override String getPrimaryKeyConstraintName(String tableName); @Override void dropPKConstraint(String tableName, String defaultConstraintName); @Override void addDefaultConstraint(String tableName, DBColumnInfo column);  }