List of usage examples for org.springframework.jdbc.core JdbcTemplate execute
@Override public void execute(final String sql) throws DataAccessException
From source file:org.kuali.rice.kew.test.TestUtilities.java
public static void clearTables(final PlatformTransactionManager transactionManager, final DataSource dataSource, final String edenSchemaName, final List<String> dontClear) { LOG.info("Clearing tables for schema " + edenSchemaName); if (dataSource == null) { Assert.fail("Null data source given"); }/*from w w w. j av a 2s.c o m*/ if (edenSchemaName == null || edenSchemaName.equals("")) { Assert.fail("Empty eden schema name given"); } new TransactionTemplate(transactionManager).execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { verifyTestEnvironment(dataSource); JdbcTemplate template = new JdbcTemplate(dataSource); return template.execute(new StatementCallback() { public Object doInStatement(Statement statement) throws SQLException { List<String> reEnableConstraints = new ArrayList<String>(); ResultSet resultSet = statement.getConnection().getMetaData().getTables(null, edenSchemaName, null, new String[] { "TABLE" }); while (resultSet.next()) { String tableName = resultSet.getString("TABLE_NAME"); if (tableName.startsWith("EN_") && !dontClear.contains(tableName)) { ResultSet keyResultSet = statement.getConnection().getMetaData() .getExportedKeys(null, edenSchemaName, tableName); while (keyResultSet.next()) { String fkName = keyResultSet.getString("FK_NAME"); String fkTableName = keyResultSet.getString("FKTABLE_NAME"); statement.addBatch( "ALTER TABLE " + fkTableName + " DISABLE CONSTRAINT " + fkName); reEnableConstraints .add("ALTER TABLE " + fkTableName + " ENABLE CONSTRAINT " + fkName); } keyResultSet.close(); statement.addBatch("DELETE FROM " + tableName); } } for (String constraint : reEnableConstraints) { statement.addBatch(constraint); } statement.executeBatch(); resultSet.close(); return null; } }); } }); LOG.info("Tables successfully cleared for schema " + edenSchemaName); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
@Test @Transactional// w w w .j a v a2 s . c o m public void testInsertSupportedHierarchy() throws SQLException { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); SupportedHierarchy hier = new SupportedHierarchy(); hier.setLocalId("test"); hier.setAssociationNames(new String[] { "test", "test2", "test3" }); ibatisCodingSchemeDao.insertURIMap("1", hier); template.queryForObject("Select * from cssupportedattrib", new RowMapper() { public Object mapRow(ResultSet rs, int arg1) throws SQLException { assertEquals("test,test2,test3", rs.getString(7)); return true; } }); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
@Test public void testUpdateCodingSchemeSource() throws SQLException { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute(//from ww w . jav a 2 s . c o m "Insert into csmultiattrib " + "values ('1', '1', 'source', 'a source', 'subRef', 'role', null)"); Source source = new Source(); source.setContent("a source"); source.setSubRef("updatedSubRef"); source.setRole("updated role"); ibatisCodingSchemeDao.insertOrUpdateCodingSchemeSource("1", source); assertEquals(1, template.queryForInt("select count(*) from csmultiattrib")); template.queryForObject("Select * from csmultiattrib", new RowMapper() { public Object mapRow(ResultSet rs, int arg1) throws SQLException { assertEquals(rs.getString(4), "a source"); assertEquals(rs.getString(5), "updatedSubRef"); assertEquals(rs.getString(6), "updated role"); return true; } }); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct namespaces./*from w w w.j a va 2 s .c o m*/ */ @Test @Transactional public void testUpdateUriMap() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into cssupportedattrib " + "values ('1', '1', 'CodingScheme', 'id', 'uri', null, null, null, null, null, null, null, null, null, null, null)"); SupportedCodingScheme scs = new SupportedCodingScheme(); scs.setIsImported(true); scs.setLocalId("id"); scs.setUri("changedUri"); ibatisCodingSchemeDao.insertOrUpdateURIMap("1", scs); assertEquals(1, template.queryForInt("Select count(*) from cssupportedattrib")); template.queryForObject("Select * from cssupportedattrib", new RowMapper() { public Object mapRow(ResultSet rs, int arg1) throws SQLException { assertEquals("changedUri", rs.getString(5)); assertTrue(rs.getBoolean(10)); return true; } }); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct namespaces.//from w w w . j a v a 2 s. c o m */ @Test @Transactional public void testDeleteUriMapsOfCodingScheme() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into cssupportedattrib " + "values ('1', '1', 'CodingScheme', 'id1', 'uri1', null, null, null, null, null, null, null, null, null, null, null)"); template.execute("Insert into cssupportedattrib " + "values ('2', '1', 'CodingScheme', 'id2', 'uri2', null, null, null, null, null, null, null, null, null, null, null)"); assertEquals(2, template.queryForInt("Select count(*) from cssupportedattrib")); ibatisCodingSchemeDao.deleteCodingSchemeMappings("1"); assertEquals(0, template.queryForInt("Select count(*) from cssupportedattrib")); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
@Test public void testGetCodingSchemeByUidEntryState() throws SQLException { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion, entrystateguid) " + "values ('1', 'csname', 'csuri', 'csversion', '1')"); template.execute(/*from www . j a va 2s. c o m*/ "Insert into revision (revisionguid, revisionId, revAppliedDate) " + "values ('1', 'rid', NOW() )"); template.execute("Insert into entrystate (entrystateguid, entryguid, entrytype, changetype, relativeorder) " + "values ('1', '1', 'cs', 'NEW', '0')"); CodingScheme returnedCs = ibatisCodingSchemeDao.getCodingSchemeByNameAndVersion("csname", "csversion"); EntryState es = returnedCs.getEntryState(); assertNotNull(es); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
@Test public void testGetMappings() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute(/*from w ww .ja v a 2s .co m*/ "Insert into cssupportedattrib (csSuppAttribGuid, codingSchemeGuid, supportedAttributeTag, id, assnCodingScheme, assnEntityCode, assnNamespace) " + "values ('1', '1', 'Association', 'test-assoc', 'csname', 'ae-code', 'ae-codens')"); Mappings mappings = ibatisCodingSchemeDao.getMappings("1"); assertNotNull(mappings); assertEquals(1, mappings.getSupportedAssociationCount()); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
@Test public void testGetSupportedNamespaceUriMap() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute(//from w w w .java2 s . c o m "Insert into cssupportedattrib (csSuppAttribGuid, codingSchemeGuid, supportedAttributeTag, id, idValue, uri, equivalentCodingScheme) " + "values ('1', '1', 'Namespace', 'test-ns', 'test-ns', 'a-uri', 'eq-cs')"); Mappings mappings = ibatisCodingSchemeDao.getMappings("1"); assertNotNull(mappings); assertEquals(1, mappings.getSupportedNamespaceCount()); SupportedNamespace ns = mappings.getSupportedNamespace()[0]; assertEquals("test-ns", ns.getContent()); assertEquals("test-ns", ns.getLocalId()); assertEquals("a-uri", ns.getUri()); assertEquals("eq-cs", ns.getEquivalentCodingScheme()); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
@Test public void testGetSupportedNamespaceUriMapNullEquivalentCodingScheme() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute(//ww w. j a va 2 s. c om "Insert into cssupportedattrib (csSuppAttribGuid, codingSchemeGuid, supportedAttributeTag, id, idValue, uri) " + "values ('1', '1', 'Namespace', 'test-ns', 'test-ns', 'a-uri')"); Mappings mappings = ibatisCodingSchemeDao.getMappings("1"); assertNotNull(mappings); assertEquals(1, mappings.getSupportedNamespaceCount()); SupportedNamespace ns = mappings.getSupportedNamespace()[0]; assertEquals("test-ns", ns.getContent()); assertEquals("test-ns", ns.getLocalId()); assertEquals("a-uri", ns.getUri()); assertNull(ns.getEquivalentCodingScheme()); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
@Test public void testGetSupportedHierarchyUriMap() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute(// w w w . j ava 2 s .c o m "Insert into cssupportedattrib (csSuppAttribGuid, codingSchemeGuid, supportedAttributeTag, id, idValue, associationNames, rootCode, isForwardNavigable) " + "values ('1', '1', 'Hierarchy', 'test-h', 'test-h', 'test-assoc', 'root', '1')"); Mappings mappings = ibatisCodingSchemeDao.getMappings("1"); assertNotNull(mappings); assertEquals(1, mappings.getSupportedHierarchyCount()); SupportedHierarchy ns = mappings.getSupportedHierarchy()[0]; assertEquals("test-h", ns.getContent()); assertEquals("test-h", ns.getLocalId()); assertEquals("test-assoc", ns.getAssociationNames(0)); assertEquals("root", ns.getRootCode()); assertTrue(ns.getIsForwardNavigable()); }