1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.sequencing;
import java.util.Vector;
import org.eclipse.persistence.internal.databaseaccess.Accessor;
import org.eclipse.persistence.internal.sessions.AbstractSession;
/**
* <p>
* <b>Purpose</b>: Reference to the default sequence.
* <p>
* <b>Description</b>
* This sequence can be used to provide a sequence using the session's
* default sequencing mechanism but override the pre-allocation size.
*/
public class DefaultSequence extends Sequence {
public DefaultSequence() {
super();
}
/**
* Create a new sequence with the name.
*/
public DefaultSequence(String name) {
super(name, 0);
}
/**
* Create a new sequence with the name and sequence pre-allocation size.
*/
public DefaultSequence(String name, int size) {
super(name, size);
}
public DefaultSequence(String name, int size, int initialValue) {
super(name, size, initialValue);
}
/**
* INTERNAL:
* Return the platform's default sequence.
*/
public Sequence getDefaultSequence() {
return getDatasourcePlatform().getDefaultSequence();
}
public boolean hasPreallocationSize() {
return size != 0;
}
public int getPreallocationSize() {
if ((size != 0) || (getDefaultSequence() == null)) {
return size;
} else {
return getDefaultSequence().getPreallocationSize();
}
}
public int getInitialValue() {
if ((initialValue != 0) || (getDefaultSequence() == null)) {
return initialValue;
} else {
return getDefaultSequence().getInitialValue();
}
}
public boolean equals(Object obj) {
if (obj instanceof DefaultSequence) {
return equalNameAndSize(this, (DefaultSequence)obj);
} else {
return false;
}
}
@Override
public int hashCode() {
return super.hashCode();
}
/**
* INTERNAL:
* Indicates whether sequencing value should be acquired after INSERT.
* Note that preallocation could be used only in case sequencing values
* should be acquired before insert (this method returns false).
* In default implementation, it is true for table sequencing and native
* sequencing on Oracle platform, false for native sequencing on other platforms.
*/
public boolean shouldAcquireValueAfterInsert() {
return getDefaultSequence().shouldAcquireValueAfterInsert();
}
/**
* INTERNAL:
* Indicates whether the existing pk value should always be overridden by the sequence.
*/
public boolean shouldAlwaysOverrideExistingValue(String seqName) {
return this.shouldAlwaysOverrideExistingValue || getDefaultSequence().shouldAlwaysOverrideExistingValue(seqName);
}
/**
* INTERNAL:
* Indicates whether several sequencing values should be acquired at a time
* and be kept by TopLink. This in only possible in case sequencing numbers should
* be acquired before insert (shouldAcquireValueAfterInsert()==false).
* In default implementation, it is true for table sequencing and native
* sequencing on Oracle platform, false for native sequencing on other platforms.
*/
public boolean shouldUsePreallocation() {
return getDefaultSequence().shouldUsePreallocation();
}
/**
* INTERNAL:
* Indicates whether EclipseLink should internally call beginTransaction() before
* getGeneratedValue/Vector, and commitTransaction after.
* In default implementation, it is true for table sequencing and
* false for native sequencing.
*/
public boolean shouldUseTransaction() {
return getDefaultSequence().shouldUseTransaction();
}
/**
* 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);
* @param seqName String is sequencing number field name
*/
public Object getGeneratedValue(Accessor accessor, AbstractSession writeSession, String seqName) {
return getDefaultSequence().getGeneratedValue(accessor, writeSession, seqName);
}
/**
* 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);
* @param seqName String is sequencing number field name
* @param size int number of values to preallocate (output Vector size).
*/
public Vector getGeneratedVector(Accessor accessor, AbstractSession writeSession, String seqName, int size) {
return getDefaultSequence().getGeneratedVector(accessor, writeSession, seqName, size);
}
/**
* INTERNAL:
* This method is called when Sequencing object is created.
* It's a chance to do initialization.
*/
public void onConnect() {
qualifier = getDefaultSequence().getQualifier();
}
/**
* INTERNAL:
* This method is called when Sequencing object is destroyed..
* It's a chance to do deinitialization.
*/
public void onDisconnect() {
qualifier = "";
}
/**
* PUBLIC:
* Indicates that Sequence is connected.
*/
public boolean isConnected() {
return getDefaultSequence().isConnected();
}
/**
* INTERNAL:
* Ignored, getDefaultSequence().getQualifier() used instead.
*/
public void setQualifier(String qualifier) {
}
}
|