TableSequence sequence = new TableSequence(); sequence.setName(m_generatorName); } else { sequence.setName(m_pkColumnValue); sequence.setPreallocationSize(m_allocationSize == null ? Integer.valueOf(50) : m_allocationSize); sequence.setInitialValue(m_initialValue == null ? Integer.valueOf(0) : m_initialValue); sequence.setTable(getDatabaseTable()); sequence.setNameFieldName(m_pkColumnName); sequence.setCounterFieldName(m_valueColumnName);
public boolean equals(Object obj) { if (obj instanceof TableSequence) { TableSequence other = (TableSequence)obj; if (equalNameAndSize(this, other)) { return getTableName().equals(other.getTableName()) && getCounterFieldName().equals(other.getCounterFieldName()) && getNameFieldName().equals(other.getNameFieldName()); } else { return false; } } else { return false; } }
public String getQualifiedTableName() { return getQualified(getTable().getName()); }
public String getQualifiedTableName() { return getQualified(getTableName()); }
@Override public int hashCode() { int result = super.hashCode(); String tableName = getTableName(); String counterFieldName = getCounterFieldName(); String nameFieldName = getNameFieldName(); result = 31 * result + (tableName != null ? tableName.hashCode() : 0); result = 31 * result + (counterFieldName != null ? counterFieldName.hashCode() : 0); result = 31 * result + (nameFieldName != null ? nameFieldName.hashCode() : 0); return result; }
protected String setDefaultOrAddSequenceString(Sequence sequence, boolean isSetDefault) { String prefix; if (isSetDefault) { prefix = "login.setDefaultSequence(new "; } else { prefix = "login.addSequence(new "; } String str; if (sequence instanceof TableSequence) { TableSequence ts = (TableSequence)sequence; str = "TableSequence(\"" + ts.getName() + "\", " + ts.getPreallocationSize() + ", \"" + ts.getTableName() + "\", \"" + ts.getNameFieldName() + "\", \"" + ts.getCounterFieldName() + "\"));"; } else if (sequence instanceof UnaryTableSequence) { UnaryTableSequence uts = (UnaryTableSequence)sequence; str = "UnaryTableSequence(\"" + uts.getName() + "\", " + uts.getPreallocationSize() + ", \"" + uts.getCounterFieldName() + "\"));"; } else { String typeName = Helper.getShortClassName(sequence); str = typeName + "(\"" + sequence.getName() + "\", " + sequence.getPreallocationSize() + "));"; } return prefix + str; }
protected ValueReadQuery buildSelectQuery() { ValueReadQuery query = new ValueReadQuery(); query.addArgument(getNameFieldName()); StringWriter writer = new StringWriter(); writer.write("SELECT " + getCounterFieldName()); writer.write(" FROM " + getQualifiedTableName()); writer.write(" WHERE " + getNameFieldName()); writer.write(" = #" + getNameFieldName()); query.setSQLString(writer.toString()); return query; }
public void setSequenceTableName(String name) { if (getDefaultSequence() instanceof TableSequence) { ((TableSequence)getDefaultSequence()).setTableName(name); } else { if (!name.equals((new TableSequence()).getTableName())) { throw ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "setTableName"); } } }
public void setSequenceCounterFieldName(String name) { if (getDefaultSequence() instanceof TableSequence) { ((TableSequence)getDefaultSequence()).setCounterFieldName(name); } else { if (!name.equals((new TableSequence()).getCounterFieldName())) { ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "setCounterFieldName"); } } }
public void setSequenceNameFieldName(String name) { if (getDefaultSequence() instanceof TableSequence) { ((TableSequence)getDefaultSequence()).setNameFieldName(name); } else { if (!name.equals((new TableSequence()).getNameFieldName())) { throw ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "setNameFieldName"); } } }
/** * INTERNAL: * Create platform-default Sequence */ @Override protected Sequence createPlatformDefaultSequence() { return new TableSequence(); }
/** * PUBLIC: */ public String getSequenceTableName() { return getTableSequence().getTableName(); }
/** * Return the database table for the sequence. */ public DatabaseTable getSequenceTable() { return getTableSequence().getTable(); }
/** * PUBLIC: */ public String getSequenceNameFieldName() { return getTableSequence().getNameFieldName(); }
/** * PUBLIC: */ public String getSequenceCounterFieldName() { return getTableSequence().getCounterFieldName(); }
@Override public void customize(final Session session) throws Exception { if (JPAThreadContext.infos.containsKey("properties")) { final String prefix = ((Properties) JPAThreadContext.infos.get("properties")).getProperty("openejb.jpa.table_prefix"); final List<DatabaseTable> tables = new ArrayList<DatabaseTable>(); for (final ClassDescriptor cd : session.getDescriptors().values()) { for (final DatabaseTable table : cd.getTables()) { update(prefix, tables, table); } for (final DatabaseMapping mapping : cd.getMappings()) { if (mapping instanceof ManyToManyMapping) { update(prefix, tables, ((ManyToManyMapping) mapping).getRelationTable()); } else if (mapping instanceof DirectCollectionMapping) { update(prefix, tables, ((DirectCollectionMapping) mapping).getReferenceTable()); } // TODO: else check we need to update something } } final Sequence sequence = session.getDatasourcePlatform().getDefaultSequence(); if (sequence instanceof TableSequence) { final TableSequence ts = ((TableSequence) sequence); ts.setName(prefix + ts.getName()); } } }
/** * This returns the Sequence Table's qualified name, without delimiting. * @param session * @return the qualified table name */ protected String getSequenceTableName(Session session) { String sequenceTableName = null; if (session.getProject().usesSequencing()) { Sequence sequence = session.getLogin().getDefaultSequence(); if (sequence instanceof TableSequence) { sequenceTableName = ((TableSequence)sequence).getQualifiedTableName(); } } return sequenceTableName; }
protected String setDefaultOrAddSequenceString(Sequence sequence, boolean isSetDefault) { String prefix; if (isSetDefault) { prefix = "login.setDefaultSequence(new "; } else { prefix = "login.addSequence(new "; } String str; if (sequence instanceof TableSequence) { TableSequence ts = (TableSequence)sequence; str = "TableSequence(\"" + ts.getName() + "\", " + ts.getPreallocationSize() + ", \"" + ts.getTableName() + "\", \"" + ts.getNameFieldName() + "\", \"" + ts.getCounterFieldName() + "\"));"; } else if (sequence instanceof UnaryTableSequence) { UnaryTableSequence uts = (UnaryTableSequence)sequence; str = "UnaryTableSequence(\"" + uts.getName() + "\", " + uts.getPreallocationSize() + ", \"" + uts.getCounterFieldName() + "\"));"; } else { String typeName = Helper.getShortClassName(sequence); str = typeName + "(\"" + sequence.getName() + "\", " + sequence.getPreallocationSize() + "));"; } return prefix + str; }
definition.addArgument("SEQ_NAME", String.class, 100); definition.addArgument("PREALLOC_SIZE", java.math.BigDecimal.class, 10); definition.addStatement("UPDATE " + ((TableSequence)login.getDefaultSequence()).getTableName() + " SET " + ((TableSequence)login.getDefaultSequence()).getCounterFieldName() + " = " + ((TableSequence)login.getDefaultSequence()).getCounterFieldName() + " + " + getSession().getPlatform().getStoredProcedureParameterPrefix() + "PREALLOC_SIZE WHERE " + ((TableSequence)login.getDefaultSequence()).getNameFieldName() + " = " + getSession().getPlatform().getStoredProcedureParameterPrefix() + "SEQ_NAME"); definition.addStatement("SELECT " + ((TableSequence)login.getDefaultSequence()).getCounterFieldName() + " FROM " + ((TableSequence)login.getDefaultSequence()).getTableName() + " WHERE " + ((TableSequence)login.getDefaultSequence()).getNameFieldName() + " = " + getSession().getPlatform().getStoredProcedureParameterPrefix() + "SEQ_NAME"); sequenceProcedures.put("SELECT", definition);
protected ValueReadQuery buildSelectQuery() { ValueReadQuery query = new ValueReadQuery(); query.addArgument(getNameFieldName()); StringWriter writer = new StringWriter(); writer.write("SELECT " + getCounterFieldName()); writer.write(" FROM " + getQualifiedTableName()); writer.write(" WHERE " + getNameFieldName()); writer.write(" = #" + getNameFieldName()); query.setSQLString(writer.toString()); return query; }