use of org.eclipse.persistence.sequencing.UnaryTableSequence in project eclipselink by eclipse-ee4j.
the class SessionsFactory method buildSequence.
/**
* INTERNAL:
* Builds a Sequence from the given SequenceConfig.
*/
protected Sequence buildSequence(SequenceConfig sequenceConfig) {
if (sequenceConfig == null) {
return null;
}
String name = sequenceConfig.getName();
int size = sequenceConfig.getPreallocationSize();
if (sequenceConfig instanceof DefaultSequenceConfig) {
return new DefaultSequence(name, size);
} else if (sequenceConfig instanceof NativeSequenceConfig) {
return new NativeSequence(name, size);
} else if (sequenceConfig instanceof TableSequenceConfig) {
TableSequenceConfig tsc = (TableSequenceConfig) sequenceConfig;
return new TableSequence(name, size, tsc.getTable(), tsc.getNameField(), tsc.getCounterField());
} else if (sequenceConfig instanceof UnaryTableSequenceConfig) {
UnaryTableSequenceConfig utsc = (UnaryTableSequenceConfig) sequenceConfig;
return new UnaryTableSequence(name, size, utsc.getCounterField());
} else if (sequenceConfig instanceof XMLFileSequenceConfig) {
try {
// Can no longer reference class directly as in a different project.
@SuppressWarnings({ "unchecked" }) Class<Sequence> xmlClass = (Class<Sequence>) Class.forName("org.eclipse.persistence.eis.adapters.xmlfile.XMLFileSequence");
Sequence sequence = xmlClass.getConstructor().newInstance();
sequence.setName(name);
sequence.setInitialValue(size);
return sequence;
} catch (Exception missing) {
return null;
}
} else {
// Unknown SequenceConfig subclass - should never happen
return null;
}
}
use of org.eclipse.persistence.sequencing.UnaryTableSequence in project eclipselink by eclipse-ee4j.
the class ProjectClassGenerator method setDefaultOrAddSequenceString.
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;
}
use of org.eclipse.persistence.sequencing.UnaryTableSequence in project eclipselink by eclipse-ee4j.
the class UnaryTableSequencingTestSuite method setUp.
@BeforeClass
public static void setUp() {
session = createSession();
dynamicHelper = new DynamicHelper(session);
DynamicClassLoader dcl = dynamicHelper.getDynamicClassLoader();
Class<?> dynamicType = dcl.createDynamicClass("simple.sequencing." + ENTITY_TYPE);
DynamicTypeBuilder typeBuilder = new DynamicTypeBuilder(dynamicType, null, TABLE_NAME);
typeBuilder.setPrimaryKeyFields("SID");
typeBuilder.addDirectMapping("id", int.class, "SID");
typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
// configureSequencing
UnaryTableSequence sequence = new UnaryTableSequence(SEQ_TABLE_NAME);
sequence.setCounterFieldName("SEQ_VALUE");
sequence.setPreallocationSize(5);
session.getProject().getLogin().setDefaultSequence(sequence);
sequence.onConnect(session.getPlatform());
typeBuilder.configureSequencing(sequence, SEQ_TABLE_NAME, "SID");
dynamicHelper.addTypes(true, true, typeBuilder.getType());
}
use of org.eclipse.persistence.sequencing.UnaryTableSequence in project eclipselink by eclipse-ee4j.
the class UnaryTableSequencingTestSuite method setUp.
@BeforeClass
public static void setUp() {
emf = DynamicTestHelper.createEMF(DYNAMIC_PERSISTENCE_NAME);
helper = new JPADynamicHelper(emf);
DynamicClassLoader dcl = helper.getDynamicClassLoader();
UnaryTableSequence sequence = new UnaryTableSequence(SEQ_TABLE_NAME);
sequence.setCounterFieldName("SEQ_VALUE");
sequence.setPreallocationSize(5);
helper.getSession().getProject().getLogin().setDefaultSequence(sequence);
sequence.onConnect(helper.getSession().getPlatform());
Class<?> javaType = dcl.createDynamicClass("model.sequencing." + ENTITY_TYPE);
DynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(javaType, null, TABLE_NAME);
typeBuilder.setPrimaryKeyFields("SID");
typeBuilder.addDirectMapping("id", int.class, "SID");
typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
typeBuilder.configureSequencing(sequence, SEQ_TABLE_NAME, "SID");
helper.addTypes(true, true, typeBuilder.getType());
}
Aggregations