use of org.h2.expression.Operation in project elastic-core-maven by OrdinaryDude.
the class FullTextTrigger method init.
/**
* Initialize the trigger (Trigger interface)
*
* @param conn Database connection
* @param schema Database schema name
* @param trigger Database trigger name
* @param table Database table name
* @param before TRUE if trigger is called before database operation
* @param type Trigger type
* @throws SQLException A SQL error occurred
*/
@Override
public void init(Connection conn, String schema, String trigger, String table, boolean before, int type) throws SQLException {
//
if (!isActive || table.contains("_COPY_")) {
return;
}
//
// Access the Lucene index
//
// We need to get the access just once, either in a trigger or in a function alias
//
getIndexAccess(conn);
//
// Get table and index information
//
tableName = schema + "." + table;
try (Statement stmt = conn.createStatement()) {
//
try (ResultSet rs = stmt.executeQuery("SHOW COLUMNS FROM " + table + " FROM " + schema)) {
int index = 0;
while (rs.next()) {
String columnName = rs.getString("FIELD");
String columnType = rs.getString("TYPE");
columnType = columnType.substring(0, columnType.indexOf('('));
columnNames.add(columnName);
columnTypes.add(columnType);
if (columnName.equals("DB_ID")) {
dbColumn = index;
}
index++;
}
}
if (dbColumn < 0) {
Logger.logErrorMessage("DB_ID column not found for table " + tableName);
return;
}
//
try (ResultSet rs = stmt.executeQuery(String.format("SELECT COLUMNS FROM FTL.INDEXES WHERE SCHEMA = '%s' AND TABLE = '%s'", schema, table))) {
if (rs.next()) {
String[] columns = rs.getString(1).split(",");
for (String column : columns) {
int pos = columnNames.indexOf(column);
if (pos >= 0) {
if (columnTypes.get(pos).equals("VARCHAR")) {
indexColumns.add(pos);
} else {
Logger.logErrorMessage("Indexed column " + column + " in table " + tableName + " is not a string");
}
} else {
Logger.logErrorMessage("Indexed column " + column + " not found in table " + tableName);
}
}
}
}
if (indexColumns.isEmpty()) {
Logger.logErrorMessage("No indexed columns found for table " + tableName);
return;
}
//
// Trigger is enabled
//
isEnabled = true;
indexTriggers.put(tableName, this);
} catch (SQLException exc) {
Logger.logErrorMessage("Unable to get table information", exc);
}
}
Aggregations