use of com.orientechnologies.orient.core.metadata.sequence.OSequence in project orientdb by orientechnologies.
the class OCommandExecutorSQLAlterSequence method execute.
@Override
public Object execute(Map<Object, Object> iArgs) {
if (this.sequenceName == null) {
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
}
final ODatabaseDocument database = getDatabase();
OSequence sequence = database.getMetadata().getSequenceLibrary().getSequence(this.sequenceName);
boolean result = sequence.updateParams(this.params);
sequence.reset();
return result;
}
use of com.orientechnologies.orient.core.metadata.sequence.OSequence in project orientdb by orientechnologies.
the class SequenceTest method testSequence.
private void testSequence(String sequenceName, SEQUENCE_TYPE sequenceType) {
OSequenceLibrary sequenceLibrary = database.getMetadata().getSequenceLibrary();
OSequence seq = sequenceLibrary.createSequence(sequenceName, sequenceType, null);
OSequenceException err = null;
try {
sequenceLibrary.createSequence(sequenceName, sequenceType, null);
} catch (OSequenceException se) {
err = se;
}
Assert.assertTrue(err == null || err.getMessage().toLowerCase(Locale.ENGLISH).contains("already exists"), "Creating a second " + sequenceType.toString() + " sequences with same name doesn't throw an exception");
OSequence seqSame = sequenceLibrary.getSequence(sequenceName);
Assert.assertEquals(seqSame, seq);
// Doing it twice to check everything works after reset
for (int i = 0; i < 2; ++i) {
Assert.assertEquals(seq.next(), 1L);
Assert.assertEquals(seq.current(), 1L);
Assert.assertEquals(seq.next(), 2L);
Assert.assertEquals(seq.next(), 3L);
Assert.assertEquals(seq.next(), 4L);
Assert.assertEquals(seq.current(), 4L);
Assert.assertEquals(seq.reset(), 0L);
}
}
use of com.orientechnologies.orient.core.metadata.sequence.OSequence in project orientdb by orientechnologies.
the class AbstractServerClusterSequenceTest method executeCachedSequenceTest.
private void executeCachedSequenceTest(final ODatabaseDocumentTx[] dbs, final String sequenceName) {
// Assuming seq2.next() is called once after calling seq1.next() once, and cache size is
// C, seq2.current() - seq1.current() = C
OSequence seq1 = dbs[0].getMetadata().getSequenceLibrary().createSequence(sequenceName, SEQUENCE_TYPE.CACHED, new OSequence.CreateParams().setDefaults().setCacheSize(CACHE_SIZE));
OSequence seq2 = dbs[1].getMetadata().getSequenceLibrary().getSequence(sequenceName);
Assert.assertEquals(seq1.getName(), seq2.getName());
Assert.assertEquals(seq1.getName(), sequenceName);
Assert.assertEquals(seq1.getSequenceType(), seq2.getSequenceType());
Assert.assertEquals(seq1.getSequenceType(), SEQUENCE_TYPE.CACHED);
ODatabaseRecordThreadLocal.INSTANCE.set(dbs[0]);
long v1 = seq1.next();
ODatabaseRecordThreadLocal.INSTANCE.set(dbs[1]);
long v2 = seq2.next();
Assert.assertEquals((long) CACHE_SIZE, v2 - v1);
}
use of com.orientechnologies.orient.core.metadata.sequence.OSequence in project orientdb by orientechnologies.
the class SequenceTest method testOrdered.
@Test
public void testOrdered() {
OSequenceLibrary sequenceManager = database.getMetadata().getSequenceLibrary();
OSequence seq = sequenceManager.createSequence("seqOrdered", SEQUENCE_TYPE.ORDERED, null);
OSequenceException err = null;
try {
sequenceManager.createSequence("seqOrdered", SEQUENCE_TYPE.ORDERED, null);
} catch (OSequenceException se) {
err = se;
}
Assert.assertTrue(err == null || err.getMessage().toLowerCase(Locale.ENGLISH).contains("already exists"), "Creating two ordered sequences with same name doesn't throw an exception");
OSequence seqSame = sequenceManager.getSequence("seqOrdered");
Assert.assertEquals(seqSame, seq);
testUsage(seq, FIRST_START);
//
seq.updateParams(new OSequence.CreateParams().setStart(SECOND_START).setCacheSize(13));
testUsage(seq, SECOND_START);
}
use of com.orientechnologies.orient.core.metadata.sequence.OSequence in project orientdb by orientechnologies.
the class SQLSequenceTest method testFree.
@Test
public void testFree() {
OSequenceLibrary sequenceManager = database.getMetadata().getSequenceLibrary();
OSequence seq = sequenceManager.createSequence("seqSQLOrdered", OSequence.SEQUENCE_TYPE.ORDERED, null);
OSequenceException err = null;
try {
sequenceManager.createSequence("seqSQLOrdered", OSequence.SEQUENCE_TYPE.ORDERED, null);
} catch (OSequenceException se) {
err = se;
}
Assert.assertTrue(err == null || err.getMessage().toLowerCase(Locale.ENGLISH).contains("already exists"), "Creating two ordered sequences with same name doesn't throw an exception");
OSequence seqSame = sequenceManager.getSequence("seqSQLOrdered");
Assert.assertEquals(seqSame, seq);
testUsage(seq, FIRST_START);
//
seq.updateParams(new OSequence.CreateParams().setStart(SECOND_START).setCacheSize(13));
testUsage(seq, SECOND_START);
}
Aggregations