/** * {@inheritDoc} */ @Override public MaxValueIncrementerSequenceWrapper clone() { return (MaxValueIncrementerSequenceWrapper) super.clone(); }
public boolean equals(Object obj) { if (obj instanceof Sequence) { return equalNameAndSize(this, (Sequence)obj); } else { return false; } }
/** * INTERNAL: * This method is called when Sequencing object is created. * Don't override this method. */ public void onConnect(Platform platform) { setDatasourcePlatform(platform); if(!isCustomQualifier) { qualifier = getDatasourcePlatform().getTableQualifier(); } onConnect(); depth++; }
/** * INTERNAL: * Indicates whether the existing pk value should always be overridden by the sequence. * As always the version of the method taking seqName is provided for the benefit * of DefaultSequence. */ public boolean shouldAlwaysOverrideExistingValue() { return shouldAlwaysOverrideExistingValue(getName()); }
/** * INTERNAL: * Used in equals. */ public static boolean equalNameAndSize(Sequence seq1, Sequence seq2) { if (seq1 == seq2) { return true; } return seq1.getName().equals(seq2.getName()) && (seq1.getPreallocationSize() == seq2.getPreallocationSize()); }
/** * INTERNAL: * Return the newly-generated sequencing value. * Used only in case preallocation is not used (shouldUsePreallocation()==false). * Accessor may be non-null only in case shouldUseSeparateConnection()==true. * Even in this case accessor could be null - if SequencingControl().shouldUseSeparateConnection()==false; * Therefore in case shouldUseSeparateConnection()==true, implementation should handle * both cases: use a separate connection if provided (accessor != null), or get by * without it (accessor == null). * @param accessor Accessor is a separate sequencing accessor (may be null); * @param writeSession Session is a Session used for writing (either ClientSession or DatabaseSession); */ public Object getGeneratedValue(Accessor accessor, AbstractSession writeSession) { return getGeneratedValue(accessor, writeSession, getName()); }
/** * INTERNAL: * Return a Vector of newly-generated sequencing values. * Used only in case preallocation is used (shouldUsePreallocation()==true). * Accessor may be non-null only in case shouldUseSeparateConnection()==true. * Even in this case accessor could be null - if SequencingControl().shouldUseSeparateConnection()==false; * Therefore in case shouldUseSeparateConnection()==true, implementation should handle * both cases: use a separate connection if provided (accessor != null), or get by * without it (accessor == null). * @param accessor Accessor is a separate sequencing accessor (may be null); * @param writeSession Session is a Session used for writing (either ClientSession or DatabaseSession); */ public Vector getGeneratedVector(Accessor accessor, AbstractSession writeSession) { return getGeneratedVector(accessor, writeSession, getName(), getPreallocationSize()); }
boolean isConnected = sequence.isConnected(); sequence.onConnect(session.getPlatform()); if(sequence.shouldUsePreallocation()) { sequence.getGeneratedVector(null, session); } else { sequence.getGeneratedValue(null, session); sequence.onDisconnect(session.getPlatform());
protected void logDebugSequencingConnected(int nAlreadyConnectedSequences) { Vector[] sequenceVectors = new Vector[NUMBER_OF_STATES]; int size = connectedSequences.size(); for (int i = nAlreadyConnectedSequences; i < size; i++) { Sequence sequence = (Sequence)connectedSequences.get(i); int stateId = getStateId(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction()); Vector v = sequenceVectors[stateId]; if (v == null) { v = new Vector(); sequenceVectors[stateId] = v; } v.addElement(sequence); } for (int i = 0; i < NUMBER_OF_STATES; i++) { Vector v = sequenceVectors[i]; if (v != null) { getOwnerSession().log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequencing_connected", states[i]); for (int j = 0; j < v.size(); j++) { Sequence sequence = (Sequence)v.elementAt(j); Object[] args = { sequence.getName(), Integer.toString(sequence.getPreallocationSize()), Integer.toString(sequence.getInitialValue())}; getOwnerSession().log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequence_without_state", args); } } } }
/** * Set default sequence. In case the passed sequence is of type DefaultSequence - use platformDefaultSequence * with name and size of the passed sequence. */ public void setDefaultSequence(Sequence sequence) { if (sequence instanceof DefaultSequence) { Sequence platformDefaultSequence = createPlatformDefaultSequence(); if (platformDefaultSequence != null) { platformDefaultSequence.setName(sequence.getName()); if (((DefaultSequence)sequence).hasPreallocationSize()) { platformDefaultSequence.setPreallocationSize(sequence.getPreallocationSize()); } } defaultSequence = platformDefaultSequence; } else { defaultSequence = sequence; } }
/** * PUBLIC: * EclipseLink can be configured to use a sequence table * or native sequencing to generate unique object IDs. * Native sequencing uses the ID generation service provided by the database * (e.g. SEQUENCE objects on Oracle and IDENTITY columns on Sybase). * By default a sequence table is used. Using a sequence table is recommended * as it supports preallocation. * (Native sequencing on Sybase/SQL Server/Informix does not support preallocation. * Preallocation can be supported on Oracle by setting the increment size of the * SEQUENCE object to match the preallocation size.) */ public void useNativeSequencing() { if(!shouldUseNativeSequencing()) { getPlatform().setDefaultSequence(new NativeSequence(getPlatform().getDefaultSequence().getName(), getPlatform().getDefaultSequence().getPreallocationSize(), getPlatform().getDefaultSequence().getInitialValue())); } }
protected void sequencesAfterCloneCleanup() { Sequence defaultSequenceClone = null; if (hasDefaultSequence()) { defaultSequenceClone = (Sequence)getDefaultSequence().clone(); setDefaultSequence(defaultSequenceClone); } if (getSequences() != null) { HashMap sequencesCopy = new HashMap(getSequences()); HashMap sequencesDeepClone = new HashMap(getSequences().size()); Iterator it = sequencesCopy.values().iterator(); while (it.hasNext()) { Sequence sequence = (Sequence)it.next(); if ((defaultSequenceClone != null) && (sequence == getDefaultSequence())) { sequencesDeepClone.put(defaultSequenceClone.getName(), defaultSequenceClone); } else { Sequence sequenceClone = (Sequence)sequence.clone(); if (sequenceClone instanceof DefaultSequence) { if (!((DefaultSequence)sequenceClone).hasPreallocationSize()) { continue; } } sequencesDeepClone.put(sequenceClone.getName(), sequenceClone); } } this.setSequences(sequencesDeepClone); } }
public Object clone() { try { Sequence clone = (Sequence)super.clone(); if (isConnected()) { clone.depth = 1; clone.onDisconnect(getDatasourcePlatform()); } return clone; } catch (Exception exception) { throw new InternalError("Clone failed"); } }
@Override public int getSequencePreallocationSize() { return getDefaultSequence().getPreallocationSize(); }
sequence = sequences.get(MetadataProject.DEFAULT_TABLE_GENERATOR); } else { sequence = (Sequence) sequences.get(MetadataProject.DEFAULT_TABLE_GENERATOR).clone(); sequence.setName(m_generator); sequence = sequences.get(MetadataProject.DEFAULT_SEQUENCE_GENERATOR); } else { sequence = (Sequence) sequences.get(MetadataProject.DEFAULT_SEQUENCE_GENERATOR).clone(); sequence.setName(m_generator); sequence = sequences.get(MetadataProject.DEFAULT_IDENTITY_GENERATOR); } else { sequence = (Sequence) sequences.get(MetadataProject.DEFAULT_IDENTITY_GENERATOR).clone(); sequence.setName(m_generator); descriptor.setSequenceNumberName(sequence.getName()); login.addSequence(sequence); } else { seqName = sequences.get(MetadataProject.DEFAULT_AUTO_GENERATOR).getName(); } else { seqName = MetadataProject.DEFAULT_AUTO_GENERATOR;
public int getInitialValue() { return getDefaultSequence().getInitialValue(); }
/** * INTERNAL: * Make sure that the sequence is not used by more than one platform. */ protected void verifyPlatform(Platform otherPlatform) { if (getDatasourcePlatform() != otherPlatform) { String hashCode1 = Integer.toString(System.identityHashCode(getDatasourcePlatform())); String name1 = ((DatasourcePlatform)getDatasourcePlatform()).toString() + '(' + hashCode1 + ')'; String hashCode2 = Integer.toString(System.identityHashCode(otherPlatform)); String name2 = ((DatasourcePlatform)otherPlatform).toString() + '(' + hashCode2 + ')'; throw ValidationException.sequenceCannotBeConnectedToTwoPlatforms(getName(), name1, name2); } }
/** * INTERNAL: * Return the SQL required to create the Oracle sequence object. */ public Writer buildCreationWriter(AbstractSession session, Writer writer) { try { // startWith value calculated using the initial value and increment. // The first time TopLink calls select nextval, the value equal to startWith is returned. // The first sequence value EclipseLink may assign is startWith - getIncrement() + 1. int startWith = sequence.getInitialValue() + sequence.getPreallocationSize() - 1; session.getPlatform().buildSequenceObjectCreationWriter(writer, getFullName(), sequence.getPreallocationSize(), startWith); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; }
public SequenceDefinition(Sequence sequence) { super(); this.sequence = sequence; this.name = sequence.getName(); }
public Object getNextValue(Sequence sequence, AbstractSession writeSession) { return sequence.getGeneratedValue(null, writeSession); } }