mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 23:28:55 +00:00
No effective change - update H2 specific test
This commit is contained in:
@@ -1,57 +1,48 @@
|
||||
package org.tests.idkeys;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.Platform;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.junit.Test;
|
||||
import org.tests.idkeys.db.GenKeyIdentity;
|
||||
import org.tests.idkeys.db.GenKeySequence;
|
||||
import org.tests.lib.EbeanTestCase;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Test various key generation strategies.
|
||||
* <p>
|
||||
* Notice: The strategy {@link javax.persistence.GenerationType#AUTO} is not easy to test as it is database dependent
|
||||
* which of the strategies will be used.
|
||||
*/
|
||||
public class TestGeneratedKeys extends EbeanTestCase {
|
||||
/**
|
||||
* Test key generation using a sequence.
|
||||
* This should increment the used sequence by one.
|
||||
* EBean should construct a select statement which uses the configured sequence to get the next value
|
||||
* <p/>
|
||||
* Notice: Actually, this test depends on H2 as used database as we are going to fetch the current value from the sequence
|
||||
*/
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestGeneratedKeys extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testSequence() throws SQLException {
|
||||
SpiEbeanServer server = (SpiEbeanServer) getServer();
|
||||
SpiEbeanServer server = spiEbeanServer();
|
||||
IdType idType = server.getDatabasePlatform().getDbIdentity().getIdType();
|
||||
if (!IdType.SEQUENCE.equals(idType)) {
|
||||
// only run this test when SEQUENCE is being used
|
||||
return;
|
||||
}
|
||||
if (server.getDatabasePlatform().getPlatform() == Platform.H2) {
|
||||
if (!isH2()) {
|
||||
// readSequenceValue is H2 specific
|
||||
return;
|
||||
}
|
||||
|
||||
Transaction tx = getServer().beginTransaction();
|
||||
Transaction tx = server.beginTransaction();
|
||||
|
||||
long sequenceStart = readSequenceValue(tx, GenKeySequence.SEQUENCE_NAME);
|
||||
|
||||
GenKeySequence al = new GenKeySequence();
|
||||
al.setDescription("my description");
|
||||
getServer().save(al);
|
||||
server.save(al);
|
||||
|
||||
|
||||
long sequenceCurrent = readSequenceValue(tx, GenKeySequence.SEQUENCE_NAME);
|
||||
|
||||
assertNotNull(al.getId());
|
||||
assertFalse("sequence advanced", sequenceStart == sequenceCurrent);
|
||||
assertEquals("sequence advanced by 20", sequenceStart + 20, sequenceCurrent);
|
||||
assertFalse(sequenceStart == sequenceCurrent);
|
||||
assertEquals(sequenceStart + 20, sequenceCurrent);
|
||||
|
||||
}
|
||||
|
||||
@@ -73,13 +64,10 @@ public class TestGeneratedKeys extends EbeanTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test just checks if a generated value has been passed back from the database.
|
||||
* EBean should simply fetch the generated key after inserting.
|
||||
*/
|
||||
@Test
|
||||
public void testIdentity() throws SQLException {
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer) getServer();
|
||||
SpiEbeanServer server = spiEbeanServer();
|
||||
IdType idType = server.getDatabasePlatform().getDbIdentity().getIdType();
|
||||
|
||||
if (!IdType.IDENTITY.equals(idType)) {
|
||||
@@ -87,11 +75,11 @@ public class TestGeneratedKeys extends EbeanTestCase {
|
||||
return;
|
||||
}
|
||||
|
||||
Transaction tx = getServer().beginTransaction();
|
||||
Transaction tx = server.beginTransaction();
|
||||
|
||||
GenKeyIdentity al = new GenKeyIdentity();
|
||||
al.setDescription("my description");
|
||||
getServer().save(al);
|
||||
server.save(al);
|
||||
|
||||
// For JDBC batching we won't get the id until after
|
||||
// the batch has been flushed explicitly or via commit
|
||||
@@ -100,33 +88,6 @@ public class TestGeneratedKeys extends EbeanTestCase {
|
||||
tx.commit();
|
||||
|
||||
assertNotNull(al.getId());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This should use the next value using max(col)+1 on the table
|
||||
*
|
||||
* AFAIK this is not supported by EBean yet
|
||||
public void testTable() throws SQLException
|
||||
{
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
Transaction tx = server.beginTransaction();
|
||||
|
||||
GenKeyTable al = new GenKeyTable();
|
||||
al.setDescription("my description");
|
||||
server.save(al);
|
||||
|
||||
assertNotNull(al.getId());
|
||||
assertEquals(0L, al.getId().longValue());
|
||||
|
||||
al = new GenKeyTable();
|
||||
al.setDescription("my description - another object");
|
||||
server.save(al);
|
||||
|
||||
assertNotNull(al.getId());
|
||||
assertEquals(1L, al.getId().longValue());
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user