List of usage examples for org.springframework.jdbc.core JdbcTemplate execute
@Override public void execute(final String sql) throws DataAccessException
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test update coding scheme by id.// w w w.j a va2 s .c om * * @throws SQLException the SQL exception */ @Test @Transactional public void testUpdateCodingSchemeById() throws SQLException { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion, approxNumConcepts) " + "values ('1', 'csname', 'csuri', 'csversion', 1234)"); int count1 = template.queryForInt("select count(*) from codingscheme"); assertEquals(1, count1); long preUpdateConcepts = template .queryForLong("select approxNumConcepts from codingscheme where codingSchemeGuid = '1'"); assertEquals(1234l, preUpdateConcepts); CodingScheme newCs = new CodingScheme(); newCs.setApproxNumConcepts(11111l); ibatisCodingSchemeDao.updateCodingScheme("1", newCs); int count2 = template.queryForInt("select count(*) from codingscheme"); assertEquals(1, count2); long postUpdateConcepts = template .queryForLong("select approxNumConcepts from codingscheme where codingSchemeGuid = '1'"); assertEquals(11111l, postUpdateConcepts); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct property names./*w w w.ja v a2 s. c o m*/ */ @Test @Transactional public void testDistinctPropertyNames() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into property (propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType) " + "values ('1', '1', 'entity', 'pname1', 'pvalue', 'presentation')"); template.execute( "Insert into property (propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType) " + "values ('2', '1', 'entity', 'pname2', 'pvalue', 'presentation')"); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('1', '1', 'ecode', 'ens')"); List<String> pnames = this.ibatisCodingSchemeDao.getDistinctPropertyNamesOfCodingScheme("1"); assertEquals(2, pnames.size()); assertTrue(pnames.contains("pname1")); assertTrue(pnames.contains("pname2")); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct entity types.//from w w w . j av a2 s . c o m */ @Test @Transactional public void testDistinctEntityTypes() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('1', '1', 'ecode1', 'ens1')"); template.execute("Insert into entityType " + "values ('1', 'etype1')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('2', '1', 'ecode2', 'ens2')"); template.execute("Insert into entityType " + "values ('2', 'etype2')"); List<String> etypes = this.ibatisCodingSchemeDao.getDistinctEntityTypesOfCodingScheme("1"); assertEquals(2, etypes.size()); assertTrue(etypes.contains("etype1")); assertTrue(etypes.contains("etype2")); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct namespaces.// ww w .j ava 2 s.co m */ @Test @Transactional public void testDistinctNamespaces() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('1', '1', 'ecode1', 'ens1')"); template.execute("Insert into entityType " + "values ('1', 'etype1')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('2', '1', 'ecode2', 'ens2')"); template.execute("Insert into entityType " + "values ('2', 'etype2')"); List<String> etypes = this.ibatisCodingSchemeDao.getDistinctNamespacesOfCodingScheme("1"); assertEquals(2, etypes.size()); assertTrue(etypes.contains("ens1")); assertTrue(etypes.contains("ens2")); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct formats./* w w w. j ava2s.c o m*/ */ @Test @Transactional public void testDistinctFormats() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into property (propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType, format) " + "values ('1', '1', 'entity', 'pname1', 'pvalue', 'presentation', 'format1')"); template.execute( "Insert into property (propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType, format) " + "values ('2', '1', 'entity', 'pname2', 'pvalue', 'presentation', 'format2')"); template.execute( "Insert into property (propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType) " + "values ('3', '1', 'entity', 'pname3', 'pvalue', 'presentation')"); template.execute( "Insert into codingScheme (codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('1', '1', 'ecode', 'ens')"); List<String> formats = this.ibatisCodingSchemeDao.getDistinctFormatsOfCodingScheme("1"); assertEquals(2, formats.size()); assertTrue(formats.contains("format1")); assertTrue(formats.contains("format2")); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct languages.//w w w . j av a2 s. c o m */ @Test @Transactional public void testDistinctLanguages() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into property (language, propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType, format) " + "values ('en', '1', '1', 'entity', 'pname1', 'pvalue', 'presentation', 'format1')"); template.execute( "Insert into property (language, propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType, format) " + "values ('fr', '2', '1', 'entity', 'pname2', 'pvalue', 'presentation', 'format2')"); template.execute( "Insert into codingScheme (defaultLanguage, codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('ge', '1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('1', '1', 'ecode', 'ens')"); List<String> langs = this.ibatisCodingSchemeDao.getDistinctLanguagesOfCodingScheme("1"); assertEquals(3, langs.size()); assertTrue(langs.contains("fr")); assertTrue(langs.contains("ge")); assertTrue(langs.contains("en")); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct property qualifier types. */// ww w . j av a2 s . c o m @Test @Transactional public void testDistinctPropertyQualifierTypes() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into property (language, propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType, format) " + "values ('en', '1', '1', 'entity', 'pname1', 'pvalue', 'presentation', 'format1')"); template.execute( "Insert into property (language, propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType, format) " + "values ('fr', '2', '1', 'entity', 'pname2', 'pvalue', 'presentation', 'format2')"); template.execute( "Insert into propertymultiattrib (propMultiAttribGuid, propertyGuid, attributeType, attributeId) " + "values ('1', '1', 'type1', 'name1')"); template.execute( "Insert into propertymultiattrib (propMultiAttribGuid, propertyGuid, attributeType, attributeId) " + "values ('2', '2', 'type2', 'name2')"); template.execute( "Insert into codingScheme (defaultLanguage, codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('ge', '1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('1', '1', 'ecode', 'ens')"); List<String> types = this.ibatisCodingSchemeDao.getDistinctPropertyQualifierTypesOfCodingScheme("1"); assertEquals(2, types.size()); assertTrue(types.contains("type1")); assertTrue(types.contains("type2")); }
From source file:org.lexevs.dao.database.ibatis.codingscheme.IbatisCodingSchemeDaoTest.java
/** * Test distinct property qualifier names. *//*from w ww. j ava 2s . c o m*/ @Test @Transactional public void testDistinctPropertyQualifierNames() { JdbcTemplate template = new JdbcTemplate(this.getDataSource()); template.execute( "Insert into property (language, propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType, format) " + "values ('en', '1', '1', 'entity', 'pname1', 'pvalue', 'presentation', 'format1')"); template.execute( "Insert into property (language, propertyGuid, referenceGuid, referenceType, propertyName, propertyValue, propertyType, format) " + "values ('fr', '2', '1', 'entity', 'pname2', 'pvalue', 'presentation', 'format2')"); template.execute( "Insert into propertymultiattrib (propMultiAttribGuid, propertyGuid, attributeType, attributeId) " + "values ('1', '1', 'type1', 'name1')"); template.execute( "Insert into propertymultiattrib (propMultiAttribGuid, propertyGuid, attributeType, attributeId) " + "values ('2', '2', 'type2', 'name2')"); template.execute( "Insert into codingScheme (defaultLanguage, codingSchemeGuid, codingSchemeName, codingSchemeUri, representsVersion) " + "values ('ge', '1', 'csname', 'csuri', 'csversion')"); template.execute("Insert into entity (entityGuid, codingSchemeGuid, entityCode, entityCodeNamespace) " + "values ('1', '1', 'ecode', 'ens')"); List<String> names = this.ibatisCodingSchemeDao.getDistinctPropertyQualifierNamesOfCodingScheme("1"); assertEquals(2, names.size()); assertTrue(names.contains("name1")); assertTrue(names.contains("name2")); }
From source file:org.lexevs.dao.database.operation.DefaultLexEvsDatabaseOperations.java
public void destroy() throws Exception { //Make sure HSQL is properly shutdown on exit if (this.getDatabaseType().equals(DatabaseType.HSQL)) { JdbcTemplate template = new JdbcTemplate(this.dataSource); template.execute("SHUTDOWN"); }//ww w . j a va 2 s . c o m }
From source file:org.lexevs.dao.database.utility.DefaultDatabaseUtility.java
/** * Do execute script.//from w w w . j av a2 s.com * * @param scriptResource the script resource */ private void doExecuteScript(final String scriptResource) { if (scriptResource == null) { return; } TransactionTemplate transactionTemplate = new TransactionTemplate( new DataSourceTransactionManager(getDataSource())); transactionTemplate.execute(new TransactionCallback() { @SuppressWarnings("unchecked") public Object doInTransaction(TransactionStatus status) { JdbcTemplate jdbcTemplate = getJdbcTemplate(); String[] scripts; try { scripts = StringUtils.delimitedListToStringArray( stripComments(IOUtils.readLines(new StringReader(scriptResource))), ";"); } catch (IOException e) { throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); } for (int i = 0; i < scripts.length; i++) { String script = scripts[i].trim(); if (StringUtils.hasText(script)) { try { jdbcTemplate.execute(script); } catch (DataAccessException e) { throw e; } } } return null; } }); }