/** * Test the case of executing a specific (e.g. PostgreSQL) database script * when no general script is present (therefore no overriding mechanism is required). * * @throws Exception */ @Test public void canExecuteSpecificDialectScript() throws Exception { scriptExecutor.executeScriptUrl("scriptexec/${db.script.dialect}/specific.sql"); String select = "select message from alf_test_script_exec_specific"; List<String> res = jdbcTmpl.queryForList(select, String.class); assertEquals(1, res.size()); if (dialect.getClass().equals(MySQLInnoDBDialect.class)) { assertEquals("mysql", res.get(0)); } else if (dialect.getClass().equals(PostgreSQLDialect.class)) { assertEquals("postgresql", res.get(0)); } else { log.warn("No suitable dialect-specific DB script for test canExecuteSpecificDialectScript()"); } }
/** * Test the case of executing a specific database script (e.g. PostgreSQL) when * a more generic script also exists -- the more generic script is not run. * * @throws Exception */ @Test public void canExecuteSpecificDialectOverridingGenericScript() throws Exception { scriptExecutor.executeScriptUrl("scriptexec/${db.script.dialect}/override.sql"); String select = "select message from alf_test_script_exec_override"; List<String> res = jdbcTmpl.queryForList(select, String.class); assertEquals(1, res.size()); if (dialect.getClass().equals(MySQLInnoDBDialect.class)) { assertEquals("mysql", res.get(0)); } else if (dialect.getClass().equals(PostgreSQLDialect.class)) { assertEquals("postgresql", res.get(0)); } else { log.warn("No suitable dialect-specific DB script for test canExecuteSpecificDialectOverridingGenericScript()"); } }
/** * Checks nesting of two transactions with <code>requiresNew == true</code>, * but where the two transactions get involved in a concurrency struggle. * <p/> * Note: skip test for non-MySQL */ public void testNestedWithoutPropagationConcurrentUntilFailureMySQL() throws InterruptedException { final RetryingTransactionHelper txnHelperForTest = transactionService.getRetryingTransactionHelper(); txnHelperForTest.setMaxRetries(1); if (! (dialect instanceof MySQLInnoDBDialect)) { // NOOP - skip test for non-MySQL DB dialects to avoid hang if concurrently "nested" (in terms of Spring) // since the initial transaction does not complete // see testConcurrencyRetryingNoFailure instead logger.warn("NOTE: Skipping testNestedWithoutPropogationConcurrentUntilFailureMySQLOnly for dialect: "+dialect); } else { RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>() { public Long execute() throws Throwable { RetryingTransactionCallback<Long> callbackInner = new RetryingTransactionCallback<Long>() { public Long execute() throws Throwable { incrementCheckValue(); return getCheckValue(); } }; incrementCheckValue(); txnHelperForTest.doInTransaction(callbackInner, false, true); return getCheckValue(); } }; try { txnHelperForTest.doInTransaction(callback); fail("Concurrent nested access not leading to failure"); } catch (Throwable e) { Throwable validCause = ExceptionStackUtil.getCause(e, RetryingTransactionHelper.RETRY_EXCEPTIONS); assertNotNull("Unexpected cause of the failure", validCause); } } }
@Before public void setMaxStringLength() { stringLen = SchemaBootstrap.getMaxStringLength(); SchemaBootstrap.setMaxStringLength(2000, new MySQLInnoDBDialect()); }
@After public void resetMaxStringLength() { SchemaBootstrap.setMaxStringLength(stringLen, new MySQLInnoDBDialect()); }
public void testJoinedSubclass() { if ( ! supportsCircularCascadeDelete() ) { return; } Statistics statistics = getSessions().getStatistics(); statistics.clear(); Session s = openSession(); Transaction t = s.beginTransaction(); Salesperson mark = new Salesperson(); mark.setName("Mark"); mark.setTitle("internal sales"); mark.setSex('M'); mark.setAddress("buckhead"); mark.setZip("30305"); mark.setCountry("USA"); Person joe = new Person(); joe.setName("Joe"); joe.setAddress("San Francisco"); joe.setZip("XXXXX"); joe.setCountry("USA"); joe.setSex('M'); joe.setSalesperson(mark); mark.getCustomers().add(joe); s.save(mark); t.commit(); assertEquals( statistics.getEntityInsertCount(), 2 ); assertEquals( statistics.getPrepareStatementCount(), 5 ); statistics.clear(); t = s.beginTransaction(); s.delete(mark); t.commit(); assertEquals( statistics.getEntityDeleteCount(), 2 ); if ( !(getDialect() instanceof MySQLDialect) || (getDialect() instanceof MySQLInnoDBDialect) ) { assertEquals( statistics.getPrepareStatementCount(), 1 ); } t = s.beginTransaction(); List names = s.createQuery("select name from Person").list(); assertTrue( names.isEmpty() ); t.commit(); s.close(); }