public PreparedStatement prepareStatement(SqlDao dao, String query) throws SQLException { StringBuffer ret = new StringBuffer(); Matcher m = TABLE_PATTERN.matcher(query); while (m.find()) { m.appendReplacement(ret, dao.getDataStore().getTableName(m.group(1), true)); } m.appendTail(ret); return dao.prepareStatement(ret.toString()); }
public void renameTable(SqlDao dao, String oldName, String newName) throws SQLException { final String expandedOld = dao.getDataStore().getTableName(oldName, true); final String expandedNew = dao.getDataStore().getTableName(newName, false); try (PreparedStatement stmt = prepareStatement(dao, "ALTER TABLE `" + expandedOld + "` RENAME `" + expandedNew + "`")) { /*try (PreparedStatement stmt = prepareStatement(dao, dao.getRenameTableQuery())) { stmt.setString(1, expandedOld); stmt.setString(2, expandedNew);*/ stmt.executeUpdate(); } }
public boolean hasTable(SqlDao dao, String table) throws SQLException { return dao.getConnection() .getMetaData() .getTables(null, null, dao.getDataStore().getTableName(table, true).toUpperCase(), null) .next(); // Upper-case for H2 }