/** * INTERNAL: * Return the drop table statement. */ public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write("DROP TABLE " + getFullName()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Returns query to check whether given table exists. * Query execution throws an exception when no such table exists. * @param table database table meta-data * @return query to check whether given table exists */ protected DataReadQuery getTableExistsQuery(final TableDefinition table) { final String sql = "SELECT 1 FROM " + table.getFullName(); final DataReadQuery query = new DataReadQuery(sql); query.setMaxRows(1); return query; }
/** * INTERNAL: * Returns query to check whether given table exists. * Query execution returns a row when table exists or empty result otherwise. * @param table database table meta-data * @return query to check whether given table exists */ @Override protected DataReadQuery getTableExistsQuery(final TableDefinition table) { final DataReadQuery query = new DataReadQuery("SHOW TABLES LIKE '" + table.getFullName() + "'"); query.setMaxRows(1); return query; }
/** * INTERNAL: * Return the alter table statement to add a field to the table. */ public Writer buildAddFieldWriter(AbstractSession session, FieldDefinition field, Writer writer) throws ValidationException { try { writer.write("ALTER TABLE " + getFullName() + " "); session.getPlatform().writeAddColumnClause(writer, session, this, field); writer.write(" "); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Returns query to check whether given table exists. * Query execution returns a row when table exists or empty result otherwise. * @param table database table meta-data * @return query to check whether given table exists */ @Override protected DataReadQuery getTableExistsQuery(final TableDefinition table) { final DataReadQuery query = new DataReadQuery( "SELECT table_name FROM user_tables WHERE table_name='" + table.getFullName() + "'"); query.setMaxRows(1); return query; }
/** * INTERNAL: * Return the drop table statement. */ @Override public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write("DROP TABLE " + getFullName() + session.getPlatform().getDropCascadeString()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the alter table statement to add a field to the table. */ public Writer buildAddFieldWriter(AbstractSession session, FieldDefinition field, Writer writer) throws ValidationException { try { writer.write("ALTER TABLE " + getFullName() + " "); session.getPlatform().writeAddColumnClause(writer, session, this, field); writer.write(" "); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the drop table statement. */ public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write("DROP TABLE " + getFullName() + session.getPlatform().getDropCascadeString()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the alter table statement to drop the constraints. * This is done separately to allow constraints to be dropped before the tables. */ public Writer buildConstraintDeletionWriter(AbstractSession session, ForeignKeyConstraint foreignKey, Writer writer) throws ValidationException { try { writer.write("ALTER TABLE " + getFullName()); writer.write(session.getPlatform().getConstraintDeletionString() + foreignKey.getName()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * Build a foreign key constraint. */ protected ForeignKeyConstraint buildForeignKeyConstraint(Vector fkFieldNames, Vector pkFieldNames, TableDefinition targetTable, DatabasePlatform platform) { assert fkFieldNames.size() > 0 && fkFieldNames.size() == pkFieldNames.size(); ForeignKeyConstraint fkConstraint = new ForeignKeyConstraint(); for(int i=0; i<fkFieldNames.size(); i++) { fkConstraint.getSourceFields().add(fkFieldNames.get(i)); fkConstraint.getTargetFields().add(pkFieldNames.get(i)); } fkConstraint.setTargetTable(targetTable.getFullName()); String fkFieldName = (String)fkFieldNames.get(0); String name = buildForeignKeyConstraintName(this.getName(), fkFieldName, platform.getMaxForeignKeyNameSize(), platform); fkConstraint.setName(name); return fkConstraint; }
/** * INTERNAL: * Return the alter table statement to drop the constraints. * This is done separately to allow constraints to be dropped before the tables. */ public Writer buildConstraintDeletionWriter(AbstractSession session, ForeignKeyConstraint foreignKey, Writer writer) throws ValidationException { try { writer.write("ALTER TABLE " + getFullName()); writer.write(session.getPlatform().getConstraintDeletionString() + foreignKey.getName()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the alter table statement to drop the constraints. * This is done separately to allow constraints to be dropped before the tables. */ public Writer buildUniqueConstraintDeletionWriter(AbstractSession session, UniqueKeyConstraint uniqueKey, Writer writer) throws ValidationException { try { writer.write("ALTER TABLE " + getFullName()); writer.write(session.getPlatform().getUniqueConstraintDeletionString() + uniqueKey.getName()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the alter table statement to drop the constraints. * This is done separately to allow constraints to be dropped before the tables. */ public Writer buildUniqueConstraintDeletionWriter(AbstractSession session, UniqueKeyConstraint uniqueKey, Writer writer) throws ValidationException { try { writer.write("ALTER TABLE " + getFullName()); writer.write(session.getPlatform().getUniqueConstraintDeletionString() + uniqueKey.getName()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the alter table statement to drop the constraints. * This is done separately to allow constraints to be dropped before the tables. */ public Writer buildConstraintDeletionWriter(AbstractSession session, ForeignKeyConstraint foreignKey, Writer writer) throws ValidationException { try { writer.write("ALTER TABLE " + getFullName()); writer.write(session.getPlatform().getConstraintDeletionString() + foreignKey.getName()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the alter table statement to drop the constraints. * This is done separately to allow constraints to be dropped before the tables. */ public Writer buildUniqueConstraintDeletionWriter(AbstractSession session, UniqueKeyConstraint uniqueKey, Writer writer) throws ValidationException { try { writer.write("ALTER TABLE " + getFullName()); writer.write(session.getPlatform().getConstraintDeletionString() + uniqueKey.getName()); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the index drop statement. */ public Writer buildIndexDeletionWriter(AbstractSession session, String key, Writer writer) throws ValidationException { try { String indexName = buildIndexName(getName(), key, session.getPlatform().getMaxIndexNameSize(), session.getPlatform()); writer.write(session.getPlatform().buildDropIndex(getFullName(), indexName)); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the index creation statement. */ public IndexDefinition buildIndex(AbstractSession session, String key, List<String> columnNames, boolean isUniqueSetOnField) { String indexName = buildIndexName(getName(), key, session.getPlatform().getIndexNamePrefix(isUniqueSetOnField), session.getPlatform().getMaxIndexNameSize(), session.getPlatform()); IndexDefinition index = new IndexDefinition(); index.setName(indexName); index.setTargetTable(getFullName()); index.getFields().addAll(columnNames); return index; }
/** * INTERNAL: * Return the index creation statement. */ public IndexDefinition buildIndex(AbstractSession session, String key, List<String> columnNames, boolean isUniqueSetOnField) { String indexName = buildIndexName(getName(), key, session.getPlatform().getIndexNamePrefix(isUniqueSetOnField), session.getPlatform().getMaxIndexNameSize(), session.getPlatform()); IndexDefinition index = new IndexDefinition(); index.setName(indexName); index.setTargetTable(getFullName()); index.getFields().addAll(columnNames); return index; }
/** * INTERNAL: * Return the index drop statement. */ public Writer buildIndexDeletionWriter(AbstractSession session, String key, Writer writer, boolean isUniqueSetOnField) { String indexName = buildIndexName(getName(), key, session.getPlatform().getIndexNamePrefix(isUniqueSetOnField), session.getPlatform().getMaxIndexNameSize(), session.getPlatform()); IndexDefinition index = new IndexDefinition(); index.setName(indexName); index.setTargetTable(getFullName()); index.buildDeletionWriter(session, writer); return writer; }
/** * INTERNAL: * Return the index drop statement. */ public Writer buildIndexDeletionWriter(AbstractSession session, String key, Writer writer, boolean isUniqueSetOnField) { String indexName = buildIndexName(getName(), key, session.getPlatform().getIndexNamePrefix(isUniqueSetOnField), session.getPlatform().getMaxIndexNameSize(), session.getPlatform()); IndexDefinition index = new IndexDefinition(); index.setName(indexName); index.setTargetTable(getFullName()); index.buildDeletionWriter(session, writer); return writer; }