use of java.sql.Statement in project hibernate-orm by hibernate.
the class CollectionLoaderTest method init.
@Before
public void init() {
doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate(String.format("ALTER TABLE person %s valid %s", getDialect().getAddColumnString(), getDialect().getTypeName(Types.BOOLEAN)));
statement.executeUpdate(String.format("ALTER TABLE Person_phones %s valid %s", getDialect().getAddColumnString(), getDialect().getTypeName(Types.BOOLEAN)));
}
});
});
}
use of java.sql.Statement in project hibernate-orm by hibernate.
the class CustomSQLSecondaryTableTest method init.
@Before
public void init() {
doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("ALTER TABLE person ADD COLUMN valid boolean");
statement.executeUpdate("ALTER TABLE person_details ADD COLUMN valid boolean");
}
});
});
}
use of java.sql.Statement in project hibernate-orm by hibernate.
the class DiscriminatorNotNullSingleTableTest method test.
@Test
public void test() {
doInJPA(this::entityManagerFactory, entityManager -> {
entityManager.unwrap(Session.class).doWork(connection -> {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("ALTER TABLE Account ALTER COLUMN DTYPE SET NULL");
}
});
DebitAccount debitAccount = new DebitAccount();
debitAccount.setId(1L);
debitAccount.setOwner("John Doe");
debitAccount.setBalance(BigDecimal.valueOf(100));
debitAccount.setInterestRate(BigDecimal.valueOf(1.5d));
debitAccount.setOverdraftFee(BigDecimal.valueOf(25));
CreditAccount creditAccount = new CreditAccount();
creditAccount.setId(2L);
creditAccount.setOwner("John Doe");
creditAccount.setBalance(BigDecimal.valueOf(1000));
creditAccount.setInterestRate(BigDecimal.valueOf(1.9d));
creditAccount.setCreditLimit(BigDecimal.valueOf(5000));
Account account = new Account();
account.setId(3L);
account.setOwner("John Doe");
account.setBalance(BigDecimal.valueOf(1000));
account.setInterestRate(BigDecimal.valueOf(1.9d));
entityManager.persist(debitAccount);
entityManager.persist(creditAccount);
entityManager.persist(account);
entityManager.unwrap(Session.class).doWork(connection -> {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("insert into Account (DTYPE, active, balance, interestRate, owner, id) " + "values ('Other', true, 25, 0.5, 'Vlad', 4)");
}
});
});
doInJPA(this::entityManagerFactory, entityManager -> {
Map<Long, Account> accounts = entityManager.createQuery("select a from Account a", Account.class).getResultList().stream().collect(Collectors.toMap(Account::getId, Function.identity()));
assertEquals(4, accounts.size());
assertEquals(DebitAccount.class, accounts.get(1L).getClass());
assertEquals(CreditAccount.class, accounts.get(2L).getClass());
assertEquals(Account.class, accounts.get(3L).getClass());
assertEquals(OtherAccount.class, accounts.get(4L).getClass());
});
}
use of java.sql.Statement in project hibernate-orm by hibernate.
the class DiscriminatorOptionsNotNullSingleTableTest method test.
@Test
public void test() {
doInJPA(this::entityManagerFactory, entityManager -> {
entityManager.unwrap(Session.class).doWork(connection -> {
try (Statement statement = connection.createStatement()) {
}
});
DebitAccount debitAccount = new DebitAccount();
debitAccount.setId(1L);
debitAccount.setOwner("John Doe");
debitAccount.setBalance(BigDecimal.valueOf(100));
debitAccount.setInterestRate(BigDecimal.valueOf(1.5d));
debitAccount.setOverdraftFee(BigDecimal.valueOf(25));
CreditAccount creditAccount = new CreditAccount();
creditAccount.setId(2L);
creditAccount.setOwner("John Doe");
creditAccount.setBalance(BigDecimal.valueOf(1000));
creditAccount.setInterestRate(BigDecimal.valueOf(1.9d));
creditAccount.setCreditLimit(BigDecimal.valueOf(5000));
Account account = new Account();
account.setId(3L);
account.setOwner("John Doe");
account.setBalance(BigDecimal.valueOf(1000));
account.setInterestRate(BigDecimal.valueOf(1.9d));
entityManager.persist(debitAccount);
entityManager.persist(creditAccount);
entityManager.persist(account);
entityManager.unwrap(Session.class).doWork(connection -> {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("insert into Account (DTYPE, active, balance, interestRate, owner, id) " + "values ('Other', true, 25, 0.5, 'Vlad', 4)");
}
});
});
doInJPA(this::entityManagerFactory, entityManager -> {
Map<Long, Account> accounts = entityManager.createQuery("select a from Account a", Account.class).getResultList().stream().collect(Collectors.toMap(Account::getId, Function.identity()));
assertEquals(4, accounts.size());
assertEquals(DebitAccount.class, accounts.get(1L).getClass());
assertEquals(CreditAccount.class, accounts.get(2L).getClass());
assertEquals(Account.class, accounts.get(3L).getClass());
assertEquals(OtherAccount.class, accounts.get(4L).getClass());
});
}
use of java.sql.Statement in project hibernate-orm by hibernate.
the class JdbcCompatibilityTest method testJdbc42.
@Test
@TestForIssue(jiraKey = "HHH-11308")
public void testJdbc42() {
doInHibernate(this::sessionFactory, session -> {
for (int i = 0; i < 5; i++) {
IrrelevantEntity entity = new IrrelevantEntity();
entity.setName(getClass().getName());
session.persist(entity);
}
session.flush();
session.doWork(connection -> {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("DELETE FROM IrrelevantEntity");
assertEquals(5, statement.getLargeUpdateCount());
}
});
});
}
Aggregations