DBAccessorImpl implements DBAccessor { @Override public void renameColumn(String tableName, String oldColumnName, DBColumnInfo columnInfo) throws SQLException { String renameColumnStatement = dbmsHelper.getRenameColumnStatement(tableName, oldColumnName, columnInfo); executeQuery(renameColumnStatement); } @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);  }
@Test public void testRenameColumn() throws Exception { String tableName = getFreeTableName(); createMyTable(tableName); DBAccessorImpl dbAccessor = injector.getInstance(DBAccessorImpl.class); dbAccessor.executeQuery("insert into " + tableName + "(id, name, time) values(1, 'Bob', 1234567)"); dbAccessor.renameColumn(tableName, "time", new DBColumnInfo("new_time", Long.class, 0, null, true)); Statement statement = dbAccessor.getConnection().createStatement(); ResultSet resultSet = statement.executeQuery("select new_time from " + tableName + " where id=1"); int count = 0; while (resultSet.next()) { count++; long newTime = resultSet.getLong("new_time"); assertEquals(newTime, 1234567L); } assertEquals(count, 1); }