/** * Render "SELECT * FROM <tableName> LIMIT 1" in the database specific dialect */ public String renderMetadataQuery(final String tableName) { return "SELECT * FROM " + withSchema(tableName) + " LIMIT 1"; }
/** * Render "SELECT * FROM <tableName> LIMIT 1" in the database specific dialect */ public String renderMetadataQuery(final String tableName) { return "SELECT * FROM " + withSchema(tableName) + " LIMIT 1"; }
protected SQLAction renderInsert(DDLTable ddlTable, DDLValue[] ddlValues) { final StringBuilder columns = new StringBuilder(); final StringBuilder values = new StringBuilder(); for (DDLValue v : ddlValues) { columns.append(processID(v.getField().getName())).append(","); values.append(renderValue(v.getValue())).append(","); } columns.deleteCharAt(columns.length() - 1); values.deleteCharAt(values.length() - 1); return SQLAction.of(new StringBuilder() .append("INSERT INTO ").append(withSchema(ddlTable.getName())) .append("(").append(columns).append(")") .append(" VALUES (").append(values).append(")")); }
protected SQLAction renderInsert(DDLTable ddlTable, DDLValue[] ddlValues) { final StringBuilder columns = new StringBuilder(); final StringBuilder values = new StringBuilder(); for (DDLValue v : ddlValues) { columns.append(processID(v.getField().getName())).append(","); values.append(renderValue(v.getValue())).append(","); } columns.deleteCharAt(columns.length() - 1); values.deleteCharAt(values.length() - 1); return SQLAction.of(new StringBuilder() .append("INSERT INTO ").append(withSchema(ddlTable.getName())) .append("(").append(columns).append(")") .append(" VALUES (").append(values).append(")")); }
/** * Generates the appropriate database-specific DDL statement to * drop the specified table representation. The default implementation * is merely <code>"DROP TABLE tablename"</code>. This is suitable * for every database that I am aware of. Any dependent database * objects (such as triggers, functions, etc) must be rendered in * one of the other delegate methods (such as <code>renderDropTriggers(DDLTable)</code>). * * @param table The table representation which is to be dropped. * @return A database-specific DDL statement which drops the specified * table. */ protected SQLAction renderDropTableStatement(DDLTable table) { return SQLAction.of("DROP TABLE " + withSchema(table.getName())); }
/** * Generates the appropriate database-specific DDL statement to * drop the specified table representation. The default implementation * is merely <code>"DROP TABLE tablename"</code>. This is suitable * for every database that I am aware of. Any dependent database * objects (such as triggers, functions, etc) must be rendered in * one of the other delegate methods (such as <code>renderDropTriggers(DDLTable)</code>). * * @param table The table representation which is to be dropped. * @return A database-specific DDL statement which drops the specified * table. */ protected SQLAction renderDropTableStatement(DDLTable table) { return SQLAction.of("DROP TABLE " + withSchema(table.getName())); }
/** * Renders the specified foreign key representation into the * database-specific DDL. The implementation <i>must</i> name the * foreign key according to the <code>DDLForeignKey#getFKName()</code> * value otherwise migrations will no longer function appropriately. * * @param key The database-agnostic foreign key representation. * @return The database-pecific DDL fragment corresponding to the * foreign key in question. */ protected String renderForeignKey(DDLForeignKey key) { StringBuilder back = new StringBuilder(); back.append("CONSTRAINT ").append(processID(key.getFKName())); back.append(" FOREIGN KEY (").append(processID(key.getField())).append(") REFERENCES "); back.append(withSchema(key.getTable())).append('(').append(processID(key.getForeignField())).append(")"); return back.toString(); }
/** * Renders the specified foreign key representation into the * database-specific DDL. The implementation <i>must</i> name the * foreign key according to the <code>DDLForeignKey#getFKName()</code> * value otherwise migrations will no longer function appropriately. * * @param key The database-agnostic foreign key representation. * @return The database-pecific DDL fragment corresponding to the * foreign key in question. */ protected String renderForeignKey(DDLForeignKey key) { StringBuilder back = new StringBuilder(); back.append("CONSTRAINT ").append(processID(key.getFKName())); back.append(" FOREIGN KEY (").append(processID(key.getField())).append(") REFERENCES "); back.append(withSchema(key.getTable())).append('(').append(processID(key.getForeignField())).append(")"); return back.toString(); }
protected final String queryTableName(Query query, TableNameConverter converter) { final String queryTable = query.getTable(); final String tableName = queryTable != null ? queryTable : converter.getName(query.getTableType()); final StringBuilder queryTableName = new StringBuilder().append(withSchema(tableName)); if (query.getAlias(query.getTableType()) != null) { queryTableName.append(" ").append(query.getAlias(query.getTableType())); } return queryTableName.toString(); }
protected final String queryTableName(Query query, TableNameConverter converter) { final String queryTable = query.getTable(); final String tableName = queryTable != null ? queryTable : converter.getName(query.getTableType()); final StringBuilder queryTableName = new StringBuilder().append(withSchema(tableName)); if (query.getAlias(query.getTableType()) != null) { queryTableName.append(" ").append(query.getAlias(query.getTableType())); } return queryTableName.toString(); }
/** * Generates the database-specific DDL statement required to drop * an index. The syntax for this operation is highly standardized * and thus it is unlikely this method will be overridden. If the * database in question does not support indexes, a warning should * be printed to stderr and <code>null</code> returned. * * @param indexNameConverter * @param index The index to drop. This single instance contains all * of the data necessary to drop the index, thus no separate * parameters (such as a <code>DDLTable</code>) are required. * @return A DDL statement to be executed, or <code>null</code>. */ protected SQLAction renderDropIndex(IndexNameConverter indexNameConverter, DDLIndex index) { final String indexName = index.getIndexName(); final String tableName = index.getTable(); if (hasIndex(tableName, indexName)) { return SQLAction.of("DROP INDEX " + withSchema(indexName) + " ON " + withSchema(tableName)); } else { return null; } }
/** * Generates the database-specific DDL statement required to add a * foreign key to a table. For databases which do not support such * a statement, a warning should be printed to stderr and a * <code>null</code> value returned. * * @param key The foreign key to be added. As this instance contains * all necessary data (such as domestic table, field, etc), no * additional parameters are required. * @return A DDL statement to be executed, or <code>null</code>. * @see #renderForeignKey(DDLForeignKey) */ protected SQLAction renderAlterTableAddKey(DDLForeignKey key) { return SQLAction.of("ALTER TABLE " + withSchema(key.getDomesticTable()) + " ADD " + renderForeignKey(key)); }
/** * Generates the database-specific DDL statement required to add a * foreign key to a table. For databases which do not support such * a statement, a warning should be printed to stderr and a * <code>null</code> value returned. * * @param key The foreign key to be added. As this instance contains * all necessary data (such as domestic table, field, etc), no * additional parameters are required. * @return A DDL statement to be executed, or <code>null</code>. * @see #renderForeignKey(DDLForeignKey) */ protected SQLAction renderAlterTableAddKey(DDLForeignKey key) { return SQLAction.of("ALTER TABLE " + withSchema(key.getDomesticTable()) + " ADD " + renderForeignKey(key)); }
/** * Generates the database-specific DDL statement for adding a column, * but not including any corresponding sequences, triggers, etc. * * @param nameConverters * @param table The table which should receive the new column. * @param field The column to add to the specified table. * @return A DDL statements to execute. */ protected SQLAction renderAlterTableAddColumnStatement(NameConverters nameConverters, DDLTable table, DDLField field) { String addStmt = "ALTER TABLE " + withSchema(table.getName()) + " ADD COLUMN " + renderField(nameConverters, table, field, new RenderFieldOptions(true, true, true)); return SQLAction.of(addStmt); }
protected SQLAction renderAlterTableDropColumnStatement(DDLTable table, DDLField field) { String dropStmt = "ALTER TABLE " + withSchema(table.getName()) + " DROP COLUMN " + processID(field.getName()); return SQLAction.of(dropStmt); }
protected SQLAction renderAlterTableDropColumnStatement(DDLTable table, DDLField field) { String dropStmt = "ALTER TABLE " + withSchema(table.getName()) + " DROP COLUMN " + processID(field.getName()); return SQLAction.of(dropStmt); }
/** * Generates the database-specific DDL statement for adding a column, * but not including any corresponding sequences, triggers, etc. * * @param nameConverters * @param table The table which should receive the new column. * @param field The column to add to the specified table. * @return A DDL statements to execute. */ protected SQLAction renderAlterTableAddColumnStatement(NameConverters nameConverters, DDLTable table, DDLField field) { String addStmt = "ALTER TABLE " + withSchema(table.getName()) + " ADD COLUMN " + renderField(nameConverters, table, field, new RenderFieldOptions(true, true, true)); return SQLAction.of(addStmt); }
/** * Generates the database-specific DDL statement required to remove a * foreign key from a table. For databases which do not support such * a statement, a warning should be printed to stderr and a * <code>null</code> value returned. This method assumes that the * {@link #renderForeignKey(DDLForeignKey)} method properly names * the foreign key according to the {@link DDLForeignKey#getFKName()} * method. * * @param key The foreign key to be removed. As this instance contains * all necessary data (such as domestic table, field, etc), no * additional parameters are required. * @return A DDL statement to be executed, or <code>null</code>. */ protected SQLAction renderAlterTableDropKey(DDLForeignKey key) { return SQLAction.of("ALTER TABLE " + withSchema(key.getDomesticTable()) + " DROP FOREIGN KEY " + processID(key.getFKName())); }
/** * Generates the database-specific DDL statement required to remove a * foreign key from a table. For databases which do not support such * a statement, a warning should be printed to stderr and a * <code>null</code> value returned. This method assumes that the * {@link #renderForeignKey(DDLForeignKey)} method properly names * the foreign key according to the {@link DDLForeignKey#getFKName()} * method. * * @param key The foreign key to be removed. As this instance contains * all necessary data (such as domestic table, field, etc), no * additional parameters are required. * @return A DDL statement to be executed, or <code>null</code>. */ protected SQLAction renderAlterTableDropKey(DDLForeignKey key) { return SQLAction.of("ALTER TABLE " + withSchema(key.getDomesticTable()) + " DROP FOREIGN KEY " + processID(key.getFKName())); }
/** * Get the table name of the given class entity * * @param entityType the class of the entity * @param escape whether or not to escape the table name * @return the table name */ public static String getTableName(EntityManager em, Class<? extends RawEntity<?>> entityType, boolean escape) { final String tableName = em.getProvider().shorten(em.getTableNameConverter().getName(entityType)); return escape ? em.getProvider().withSchema(tableName) : tableName; }