List of usage examples for org.springframework.jdbc.core JdbcOperations execute
void execute(String sql) throws DataAccessException;
From source file:no.trank.openpipe.jdbc.store.IdStateHolder.java
@SuppressWarnings({ "unchecked" }) private static void createTable(JdbcOperations op, Table table, SQLGenerator generator) { log.debug("Creating table: {}", table.getName()); final Collection<String> create = generator.getCreate(table, true); for (String sql : create) { log.debug(sql);//from w w w .j a v a 2 s . com op.execute(sql); } }
From source file:no.trank.openpipe.jdbc.store.IdStateHolder.java
/** * Creates an id state holder with the given configuration.<br/> * A {@link SimpleJdbcTemplate} and {@link DataSourceTransactionManager} is created from the given * <tt>dataSource</tt>.<br/> * A table matching <tt>desc</tt> is created using SQL's created by <tt>sqlFactory</tt> if one doesn't already * exists. If a table matching {@link TableDescription#getTableName() desc.getTableName()} already exists, it is * validated against <tt>desc</tt>. * * @param dataSource the datasource to use. * @param sqlFactory the factory to use for creating SQL's. * @param desc the description of the table to use. *///from w ww.ja v a 2 s . c o m public IdStateHolder(DataSource dataSource, SQLFactory sqlFactory, TableDescription desc) { jdbcTemplate = new SimpleJdbcTemplate(dataSource); transactionManager = new DataSourceTransactionManager(dataSource); this.sqlFactory = sqlFactory; final JdbcOperations op = jdbcTemplate.getJdbcOperations(); final Schema schema = (Schema) op.execute(new SchemaCallback(sqlFactory)); Table table = schema.getTable(desc.getTableName()); final SQLGenerator generator = sqlFactory.newSQLGenerator(); final StringColumn colId; final Column colUpd; if (table != null) { final Column id = table.getColumn(desc.getIdColumnName()); colUpd = table.getColumn(desc.getUpdColumnName()); validateTable(id, colUpd, desc.getIdMaxLength()); colId = (StringColumn) id; } else { table = schema.newTable(desc.getTableName()); colId = (StringColumn) table.newColumn(desc.getIdColumnName(), VARCHAR); colUpd = table.newColumn(desc.getUpdColumnName(), TIMESTAMP); colId.setNullable(false); colId.setLength(desc.getIdMaxLength()); table.newPrimaryKey().addColumn(colId); colUpd.setNullable(false); createTable(op, table, generator); } createSqls(table, generator, colId, colUpd); }
From source file:edu.wisc.jmeter.dao.JdbcMonitorDao.java
private void setupTables() { final JdbcOperations jdbcOperations = this.jdbcTemplate.getJdbcOperations(); for (final Map.Entry<String, String> tableConfigEntry : TABLE_CONFIG.entrySet()) { jdbcOperations.execute(new ConnectionCallback<Object>() { @Override/*from www.j av a 2 s.c o m*/ public Object doInConnection(Connection con) throws SQLException, DataAccessException { final DatabaseMetaData metaData = con.getMetaData(); final String tableName = tableConfigEntry.getKey(); final ResultSet tables = metaData.getTables(null, null, tableName, null); try { if (!tables.next()) { log.warn("'" + tableName + "' table does not exist, creating."); jdbcOperations.update(tableConfigEntry.getValue()); } else { log.info("'" + tableName + "' table already exists, skipping."); } } finally { tables.close(); } return null; } }); } }