/** * INTERNAL: * Return the SQL required to insert the sequence row into the sequence table. * Assume that the sequence table exists. */ public Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write("INSERT INTO "); writer.write(getSequenceTableName()); writer.write("(" + getSequenceNameFieldName()); writer.write(", " + getSequenceCounterFieldName()); writer.write(") values ("); writer.write("'" + getName() + "', " + Integer.toString(sequence.getInitialValue() - 1) + ")"); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * PUBLIC: */ public String getSequenceNameFieldName() { return getTableSequence().getNameFieldName(); }
/** * INTERNAL: * Return a TableDefinition specifying sequence table. * Cache the table definition for re-use (during CREATE and DROP) */ public TableDefinition buildTableDefinition() { if (tableDefinition == null) { tableDefinition = new TableDefinition(); tableDefinition.setTable(getSequenceTable()); tableDefinition.setName(getSequenceTableName()); tableDefinition.setQualifier(getSequenceTableQualifier()); tableDefinition.addPrimaryKeyField(getSequenceNameFieldName(), String.class, 50); tableDefinition.addField(getSequenceCounterFieldName(), BigDecimal.class); tableDefinition.setIndexes(getSequenceTableIndexes()); } return tableDefinition; }
/** * INTERAL: * Execute the SQL required to insert the sequence row into the sequence table. * Assume that the sequence table exists. */ public boolean checkIfExist(AbstractSession session) throws DatabaseException { Vector results = session.executeSelectingCall(new org.eclipse.persistence.queries.SQLCall("SELECT * FROM " + getSequenceTableName() + " WHERE " + getSequenceNameFieldName() + " = '" + getName() + "'")); return !results.isEmpty(); }
/** * INTERNAL: * Return the SQL required to insert the sequence row into the sequence table. * Assume that the sequence table exists. */ public Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write("INSERT INTO "); writer.write(getSequenceTableQualifiedName()); writer.write("(" + getSequenceNameFieldName()); writer.write(", " + getSequenceCounterFieldName()); writer.write(") values ("); writer.write("'" + getName() + "', " + Integer.toString(sequence.getInitialValue() - 1) + ")"); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERAL: * Execute the SQL required to insert the sequence row into the sequence table. * Assume that the sequence table exists. */ public boolean checkIfExist(AbstractSession session) throws DatabaseException { StringBuilder buffer = new StringBuilder(); buffer.append("SELECT * FROM "); buffer.append(getSequenceTableQualifiedName()); buffer.append(" WHERE "); buffer.append(getSequenceNameFieldName()); buffer.append(" = '"); buffer.append(getName()); buffer.append("'"); Vector results = session.priviledgedExecuteSelectingCall(new org.eclipse.persistence.queries.SQLCall(buffer.toString())); return !results.isEmpty(); }
/** * INTERNAL: * Return the SQL to delete the row from the sequence table. If we're * dealing with create creation, then delegate to the table so that is * dropped outright since we will delete the schema. */ public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException { if (shouldDropTableDefinition()) { return tableDefinition.buildDeletionWriter(session, writer); } else { try { writer.write("DELETE FROM "); writer.write(getSequenceTableQualifiedName()); writer.write(" WHERE " + getSequenceNameFieldName()); writer.write(" = '" + getName() + "'"); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; } }
/** * INTERNAL: * Return a TableDefinition specifying sequence table. */ public TableDefinition buildTableDefinition() { TableDefinition definition = new TableDefinition(); definition.setName(getSequenceTableName()); definition.addPrimaryKeyField(getSequenceNameFieldName(), String.class, 50); definition.addField(getSequenceCounterFieldName(), BigDecimal.class); return definition; }
TableDefinition tableDefinition = ((TableSequenceDefinition) definition).buildTableDefinition(); if (((TableSequenceDefinition) definition).shouldDropTableDefinition()) { String tableDefinitionTableName = ((TableSequenceDefinition) definition).getSequenceTableName();
/** * PUBLIC: */ public String getSequenceTableQualifier() { return getSequenceTable().getTableQualifier(); }
protected SequenceDefinition buildSequenceDefinition(Sequence sequence) { if (sequence.shouldAcquireValueAfterInsert()) { return null; } if (sequence instanceof TableSequence || (sequence instanceof DefaultSequence && ((DefaultSequence)sequence).getDefaultSequence() instanceof TableSequence)) { return new TableSequenceDefinition(sequence); } else if (sequence instanceof UnaryTableSequence || (sequence instanceof DefaultSequence && ((DefaultSequence)sequence).getDefaultSequence() instanceof UnaryTableSequence)) { return new UnaryTableSequenceDefinition(sequence); } else if (sequence instanceof NativeSequence || (sequence instanceof DefaultSequence && ((DefaultSequence)sequence).getDefaultSequence() instanceof NativeSequence)) { return new SequenceObjectDefinition(sequence); } else { return null; } }
/** * Execute any statements required before the deletion of the object * @param session * @param dropSchemaWriter */ public void preDropObject(AbstractSession session, Writer dropSchemaWriter, boolean createSQLFiles) { if ((session.getPlatform().shouldCreateIndicesForPrimaryKeys()) || (session.getPlatform().shouldCreateIndicesOnUniqueKeys())) { // Do not drop index when database is Symfoware. Index is required for primary keys or unique keys. return; } buildTableDefinition().preDropObject(session, dropSchemaWriter, createSQLFiles); }
/** * INTERNAL: * Return the SQL required to insert the sequence row into the sequence table. * Assume that the sequence table exists. */ public Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write("INSERT INTO "); writer.write(getSequenceTableQualifiedName()); writer.write("(" + getSequenceNameFieldName()); writer.write(", " + getSequenceCounterFieldName()); writer.write(") values ("); writer.write("'" + getName() + "', " + Integer.toString(sequence.getInitialValue() - 1) + ")"); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERNAL: * Return the SQL to delete the row from the sequence table. If we're * dealing with create creation, then delegate to the table so that is * dropped outright since we will delete the schema. */ public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException { if (shouldDropTableDefinition()) { return tableDefinition.buildDeletionWriter(session, writer); } else { try { writer.write("DELETE FROM "); writer.write(getSequenceTableQualifiedName()); writer.write(" WHERE " + getSequenceNameFieldName()); writer.write(" = '" + getName() + "'"); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; } }
/** * INTERNAL: * Return the SQL to delete the row from the sequence table. */ public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write("DELETE FROM "); writer.write(getSequenceTableName()); writer.write(" WHERE " + getSequenceNameFieldName()); writer.write(" = '" + getName() + "'"); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
/** * INTERAL: * Execute the SQL required to insert the sequence row into the sequence table. * Assume that the sequence table exists. */ public boolean checkIfExist(AbstractSession session) throws DatabaseException { StringBuilder buffer = new StringBuilder(); buffer.append("SELECT * FROM "); buffer.append(getSequenceTableQualifiedName()); buffer.append(" WHERE "); buffer.append(getSequenceNameFieldName()); buffer.append(" = '"); buffer.append(getName()); buffer.append("'"); Vector results = session.priviledgedExecuteSelectingCall(new org.eclipse.persistence.queries.SQLCall(buffer.toString())); return !results.isEmpty(); }
TableDefinition tableDefinition = ((TableSequenceDefinition) definition).buildTableDefinition(); if (((TableSequenceDefinition) definition).shouldDropTableDefinition()) { String tableDefinitionTableName = ((TableSequenceDefinition) definition).getSequenceTableName();
/** * PUBLIC: */ public String getSequenceTableQualifiedName() { return getSequenceTable().getQualifiedName(); }
protected SequenceDefinition buildSequenceDefinition(Sequence sequence) { if (sequence.shouldAcquireValueAfterInsert()) { return null; } if (sequence instanceof TableSequence || (sequence instanceof DefaultSequence && ((DefaultSequence)sequence).getDefaultSequence() instanceof TableSequence)) { return new TableSequenceDefinition(sequence, createDatabaseSchemas); } else if (sequence instanceof UnaryTableSequence || (sequence instanceof DefaultSequence && ((DefaultSequence)sequence).getDefaultSequence() instanceof UnaryTableSequence)) { return new UnaryTableSequenceDefinition(sequence, createDatabaseSchemas); } else if (sequence instanceof NativeSequence || (sequence instanceof DefaultSequence && ((DefaultSequence)sequence).getDefaultSequence() instanceof NativeSequence)) { NativeSequence nativeSequence = null; if (sequence instanceof NativeSequence) { nativeSequence = (NativeSequence)sequence; } else { nativeSequence = (NativeSequence)((DefaultSequence)sequence).getDefaultSequence(); } if (nativeSequence.hasDelegateSequence()) { return buildSequenceDefinition(((NativeSequence)sequence).getDelegateSequence()); } return new SequenceObjectDefinition(sequence); } else { return null; } }
/** * Execute any statements required before the deletion of the object * @param session * @param dropSchemaWriter */ public void preDropObject(AbstractSession session, Writer dropSchemaWriter, boolean createSQLFiles) { if ((session.getPlatform().shouldCreateIndicesForPrimaryKeys()) || (session.getPlatform().shouldCreateIndicesOnUniqueKeys())) { // Do not drop index when database is Symfoware. Index is required for primary keys or unique keys. return; } buildTableDefinition().preDropObject(session, dropSchemaWriter, createSQLFiles); }