@Override public String getSQL() { if (table == null) { return "*"; } return StringUtils.quoteIdentifier(table) + ".*"; }
private static String translate(String key, String... params) { String message = null; if (MESSAGES != null) { // Tomcat sets final static fields to null sometimes message = MESSAGES.getProperty(key); } if (message == null) { message = "(Message " + key + " not found)"; } if (params != null) { for (int i = 0; i < params.length; i++) { String s = params[i]; if (s != null && s.length() > 0) { params[i] = StringUtils.quoteIdentifier(s); } } message = MessageFormat.format(message, (Object[]) params); } return message; }
private static void createOrDropTrigger(Connection conn, String schema, String table, boolean create) throws SQLException { Statement stat = conn.createStatement(); String trigger = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(TRIGGER_PREFIX + table); stat.execute("DROP TRIGGER IF EXISTS " + trigger); if (create) { StringBuilder buff = new StringBuilder( "CREATE TRIGGER IF NOT EXISTS "); // the trigger is also called on rollback because transaction // rollback will not undo the changes in the Lucene index buff.append(trigger). append(" AFTER INSERT, UPDATE, DELETE, ROLLBACK ON "). append(StringUtils.quoteIdentifier(schema)). append('.'). append(StringUtils.quoteIdentifier(table)). append(" FOR EACH ROW CALL \""). append(FullTextLucene.FullTextTrigger.class.getName()). append('\"'); stat.execute(buff.toString()); } }
/** * Generates an optimized multi-dimensional range query. The query contains * parameters. It can only be used with the H2 database. * * @param table the table name * @param columns the list of columns * @param scalarColumn the column name of the computed scalar column * @return the query */ public String generatePreparedQuery(String table, String scalarColumn, String[] columns) { StringBuilder buff = new StringBuilder("SELECT D.* FROM "); buff.append(StringUtils.quoteIdentifier(table)). append(" D, TABLE(_FROM_ BIGINT=?, _TO_ BIGINT=?) WHERE "). append(StringUtils.quoteIdentifier(scalarColumn)). append(" BETWEEN _FROM_ AND _TO_"); for (String col : columns) { buff.append(" AND ").append(StringUtils.quoteIdentifier(col)). append("+1 BETWEEN ?+1 AND ?+1"); } return buff.toString(); }
/** * Remove all triggers that start with the given prefix. * * @param conn the database connection * @param prefix the prefix */ protected static void removeAllTriggers(Connection conn, String prefix) throws SQLException { Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery("SELECT * FROM INFORMATION_SCHEMA.TRIGGERS"); Statement stat2 = conn.createStatement(); while (rs.next()) { String schema = rs.getString("TRIGGER_SCHEMA"); String name = rs.getString("TRIGGER_NAME"); if (name.startsWith(prefix)) { name = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(name); stat2.execute("DROP TRIGGER " + name); } } }
/** * Add double quotes around an identifier if required. * * @param s the identifier * @return the quoted identifier */ public static String quoteIdentifier(String s) { if (s == null) { return "\"\""; } if (ParserUtil.isSimpleIdentifier(s, false)) { return s; } return StringUtils.quoteIdentifier(s); }
/** * @param identifier * identifier to quote if required * @param alwaysQuote * if {@code true} identifier will be quoted unconditionally * @return specified identifier quoted if required or explicitly requested */ @Override public String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException { if (alwaysQuote || !isSimpleIdentifier(identifier)) { return StringUtils.quoteIdentifier(identifier); } return identifier; }
private void appendTableName(StatementBuilder buff) { if (schemaName != null && schemaName.length() > 0) { buff.append(StringUtils.quoteIdentifier(schemaName)).append('.'); } buff.append(StringUtils.quoteIdentifier(tableName)); }
private static void createOrDropTrigger(Connection conn, String schema, String table, boolean create) throws SQLException { try (Statement stat = conn.createStatement()) { String trigger = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(TRIGGER_PREFIX + table); stat.execute("DROP TRIGGER IF EXISTS " + trigger); if (create) { boolean multiThread = FullTextTrigger.isMultiThread(conn); StringBuilder buff = new StringBuilder( "CREATE TRIGGER IF NOT EXISTS "); // unless multithread, trigger needs to be called on rollback as well, // because we use the init connection do to changes in the index // (not the user connection) buff.append(trigger). append(" AFTER INSERT, UPDATE, DELETE"); if(!multiThread) { buff.append(", ROLLBACK"); } buff.append(" ON "). append(StringUtils.quoteIdentifier(schema)). append('.'). append(StringUtils.quoteIdentifier(table)). append(" FOR EACH ROW CALL \""). append(FullText.FullTextTrigger.class.getName()). append('\"'); stat.execute(buff.toString()); } } }
/** * Add the existing data to the index. * * @param conn the database connection * @param schema the schema name * @param table the table name */ private static void indexExistingRows(Connection conn, String schema, String table) throws SQLException { FullText.FullTextTrigger existing = new FullText.FullTextTrigger(); existing.init(conn, schema, null, table, false, Trigger.INSERT); String sql = "SELECT * FROM " + StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table); ResultSet rs = conn.createStatement().executeQuery(sql); int columnCount = rs.getMetaData().getColumnCount(); while (rs.next()) { Object[] row = new Object[columnCount]; for (int i = 0; i < columnCount; i++) { row[i] = rs.getObject(i + 1); } existing.fire(conn, null, row); } }
/** * Add the existing data to the index. * * @param conn the database connection * @param schema the schema name * @param table the table name */ private static void indexExistingRows(Connection conn, String schema, String table) throws SQLException { FullTextLucene.FullTextTrigger existing = new FullTextLucene.FullTextTrigger(); existing.init(conn, schema, null, table, false, Trigger.INSERT); String sql = "SELECT * FROM " + StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table); ResultSet rs = conn.createStatement().executeQuery(sql); int columnCount = rs.getMetaData().getColumnCount(); while (rs.next()) { Object[] row = new Object[columnCount]; for (int i = 0; i < columnCount; i++) { row[i] = rs.getObject(i + 1); } existing.insert(row, false); } existing.commitIndex(); }
stat = conn.createStatement(); stat.execute("CREATE SCHEMA IF NOT EXISTS " + StringUtils.quoteIdentifier(targetSchema)); StringBuilder buff = new StringBuilder(); buff.append("DROP TABLE IF EXISTS "). append(StringUtils.quoteIdentifier(targetSchema)). append('.'). append(StringUtils.quoteIdentifier(table)); stat.execute(buff.toString()); buff = new StringBuilder(); buff.append("CREATE LINKED TABLE "). append(StringUtils.quoteIdentifier(targetSchema)). append('.'). append(StringUtils.quoteIdentifier(table)). append('('). append(StringUtils.quoteStringSQL(driver)).
1.0); } else { String query = StringUtils.quoteIdentifier(index.schema) + "." + StringUtils.quoteIdentifier(index.table) + " WHERE " + key; result.addRow(query, 1.0);
private void appendColumnList(StatementBuilder buff, boolean set) { buff.resetCount(); for (int i = 0; i < columnCount; i++) { buff.appendExceptFirst(","); String col = result.getColumnName(i); buff.append(StringUtils.quoteIdentifier(col)); if (set) { buff.append("=? "); } } }
private void appendKeyCondition(StatementBuilder buff) { buff.append(" WHERE "); buff.resetCount(); for (String k : key) { buff.appendExceptFirst(" AND "); buff.append(StringUtils.quoteIdentifier(k)).append("=?"); } }
private String getQuery(Object[] row) throws SQLException { StatementBuilder buff = new StatementBuilder(); if (schema != null) { buff.append(StringUtils.quoteIdentifier(schema)).append('.'); } buff.append(StringUtils.quoteIdentifier(table)).append(" WHERE "); for (int columnIndex : keys) { buff.appendExceptFirst(" AND "); buff.append(StringUtils.quoteIdentifier(columns[columnIndex])); Object o = row[columnIndex]; if (o == null) { buff.append(" IS NULL"); } else { buff.append('=').append(FullText.quoteSQL(o, columnTypes[columnIndex])); } } return buff.toString(); } }
private String getKey(Object[] row) throws SQLException { StatementBuilder buff = new StatementBuilder(); for (int columnIndex : index.keys) { buff.appendExceptFirst(" AND "); buff.append(StringUtils.quoteIdentifier(index.columns[columnIndex])); Object o = row[columnIndex]; if (o == null) { buff.append(" IS NULL"); } else { buff.append('=').append(quoteSQL(o, columnTypes[columnIndex])); } } return buff.toString(); }
buff.append(StringUtils.quoteIdentifier(tableEngine)); for (String parameter : tableEngineParams) { buff.appendExceptFirst(", "); buff.append(StringUtils.quoteIdentifier(parameter));
for (String p : path) { buff.appendExceptFirst(", "); buff.append(StringUtils.quoteIdentifier(p)); "SET SCHEMA " + StringUtils.quoteIdentifier(schema) );
private void appendColumnList(StringBuffer buff, boolean set) { for (int i = 0; i < columnCount; i++) { if (i > 0) { buff.append(','); } String col = result.getColumnName(i); buff.append(StringUtils.quoteIdentifier(col)); if (set) { buff.append("=? "); } } }