Search in sources :

Example 1 with OSequenceException

use of com.orientechnologies.orient.core.exception.OSequenceException in project orientdb by orientechnologies.

the class SQLSequenceTest method testSequence.

private void testSequence(String sequenceName, OSequence.SEQUENCE_TYPE sequenceType) {
    OSequenceLibrary sequenceLibrary = database.getMetadata().getSequenceLibrary();
    database.command(new OCommandSQL("CREATE SEQUENCE " + sequenceName + " TYPE " + sequenceType)).execute();
    OSequenceException err = null;
    try {
        database.command(new OCommandSQL("CREATE SEQUENCE " + sequenceName + " TYPE " + sequenceType)).execute();
    } 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");
    // Doing it twice to check everything works after reset
    for (int i = 0; i < 2; ++i) {
        Assert.assertEquals(sequenceCurrent(sequenceName), 0L);
        Assert.assertEquals(sequenceNext(sequenceName), 1L);
        Assert.assertEquals(sequenceCurrent(sequenceName), 1L);
        Assert.assertEquals(sequenceNext(sequenceName), 2L);
        Assert.assertEquals(sequenceNext(sequenceName), 3L);
        Assert.assertEquals(sequenceNext(sequenceName), 4L);
        Assert.assertEquals(sequenceCurrent(sequenceName), 4L);
        Assert.assertEquals(sequenceReset(sequenceName), 0L);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary)

Example 2 with OSequenceException

use of com.orientechnologies.orient.core.exception.OSequenceException 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);
    }
}
Also used : OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OSequence(com.orientechnologies.orient.core.metadata.sequence.OSequence) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary)

Example 3 with OSequenceException

use of com.orientechnologies.orient.core.exception.OSequenceException 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);
}
Also used : OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OSequence(com.orientechnologies.orient.core.metadata.sequence.OSequence) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary) Test(org.testng.annotations.Test)

Example 4 with OSequenceException

use of com.orientechnologies.orient.core.exception.OSequenceException 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);
}
Also used : OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OSequence(com.orientechnologies.orient.core.metadata.sequence.OSequence) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary) Test(org.testng.annotations.Test)

Aggregations

OSequenceException (com.orientechnologies.orient.core.exception.OSequenceException)4 OSequenceLibrary (com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary)4 OSequence (com.orientechnologies.orient.core.metadata.sequence.OSequence)3 Test (org.testng.annotations.Test)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1