use of org.h2.command.dml.Select in project siena by mandubian.
the class FullText method reindex.
/**
* Re-creates the full text index for this database. Calling this method is
* usually not needed, as the index is kept up-to-date automatically.
*
* @param conn the connection
*/
public static void reindex(Connection conn) throws SQLException {
init(conn);
removeAllTriggers(conn, TRIGGER_PREFIX);
FullTextSettings setting = FullTextSettings.getInstance(conn);
setting.getWordList().clear();
Statement stat = conn.createStatement();
stat.execute("TRUNCATE TABLE " + SCHEMA + ".WORDS");
stat.execute("TRUNCATE TABLE " + SCHEMA + ".ROWS");
stat.execute("TRUNCATE TABLE " + SCHEMA + ".MAP");
ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".FT_INDEXES");
while (rs.next()) {
String schema = rs.getString("SCHEMA");
String table = rs.getString("TABLE");
createTrigger(conn, schema, table);
indexExistingRows(conn, schema, table);
}
}
use of org.h2.command.dml.Select in project siena by mandubian.
the class FullText method removeAllTriggers.
/**
* 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);
}
}
}
use of org.h2.command.dml.Select in project ignite by apache.
the class GridQueryParsingTest method testParseTableFilter.
/**
* Query AST transformation heavily depends on this behavior.
*
* @throws Exception If failed.
*/
public void testParseTableFilter() throws Exception {
Prepared prepared = parse("select Person.old, p1.old, p1.addrId from Person, Person p1 " + "where exists(select 1 from sch2.Address a where a.id = p1.addrId)");
GridSqlSelect select = (GridSqlSelect) new GridSqlQueryParser(false).parse(prepared);
GridSqlJoin join = (GridSqlJoin) select.from();
GridSqlTable tbl1 = (GridSqlTable) join.leftTable();
GridSqlAlias tbl2Alias = (GridSqlAlias) join.rightTable();
GridSqlTable tbl2 = tbl2Alias.child();
// Must be distinct objects, even if it is the same table.
assertNotSame(tbl1, tbl2);
assertNotNull(tbl1.dataTable());
assertNotNull(tbl2.dataTable());
assertSame(tbl1.dataTable(), tbl2.dataTable());
GridSqlColumn col1 = (GridSqlColumn) select.column(0);
GridSqlColumn col2 = (GridSqlColumn) select.column(1);
assertSame(tbl1, col1.expressionInFrom());
// Alias in FROM must be included in column.
assertSame(tbl2Alias, col2.expressionInFrom());
// In EXISTS we must correctly reference the column from the outer query.
GridSqlAst exists = select.where();
GridSqlSubquery subqry = exists.child();
GridSqlSelect subSelect = subqry.child();
GridSqlColumn p1AddrIdCol = (GridSqlColumn) select.column(2);
assertEquals("ADDRID", p1AddrIdCol.column().getName());
assertSame(tbl2Alias, p1AddrIdCol.expressionInFrom());
GridSqlColumn p1AddrIdColExists = subSelect.where().child(1);
assertEquals("ADDRID", p1AddrIdCol.column().getName());
assertSame(tbl2Alias, p1AddrIdColExists.expressionInFrom());
}
use of org.h2.command.dml.Select in project ignite by apache.
the class GridH2CollocationModel method childFilters.
/**
* @param childFilters New child filters.
* @return {@code true} If child filters were updated.
*/
private boolean childFilters(TableFilter[] childFilters) {
assert childFilters != null;
assert view;
Select select = childFilters[0].getSelect();
assert this.select == null || this.select == select;
if (this.select == null) {
this.select = select;
assert this.childFilters == null;
} else if (Arrays.equals(this.childFilters, childFilters))
return false;
if (this.childFilters == null) {
// We have to clone because H2 reuses array and reorders elements.
this.childFilters = childFilters.clone();
children = new GridH2CollocationModel[childFilters.length];
} else {
assert this.childFilters.length == childFilters.length;
// We have to copy because H2 reuses array and reorders elements.
System.arraycopy(childFilters, 0, this.childFilters, 0, childFilters.length);
Arrays.fill(children, null);
}
// Reset results.
type = null;
multiplier = 0;
return true;
}
use of org.h2.command.dml.Select in project ignite by apache.
the class GridH2CollocationModel method buildCollocationModel.
/**
* @param qctx Query context.
* @param info Sub-query info.
* @param filters Filters.
* @param filter Filter.
* @param validate Query validation flag.
* @return Collocation.
*/
public static GridH2CollocationModel buildCollocationModel(GridH2QueryContext qctx, SubQueryInfo info, TableFilter[] filters, int filter, boolean validate) {
GridH2CollocationModel cm;
if (info != null) {
// Go up until we reach the root query.
cm = buildCollocationModel(qctx, info.getUpper(), info.getFilters(), info.getFilter(), validate);
} else {
// We are at the root query.
cm = qctx.queryCollocationModel();
if (cm == null) {
cm = createChildModel(null, -1, null, true, validate);
qctx.queryCollocationModel(cm);
}
}
assert cm.view;
Select select = filters[0].getSelect();
// For sub-queries we will drop collocation models, so that they will be recalculated anyways.
if (cm.select != null && cm.select != select) {
List<GridH2CollocationModel> unions = cm.getOrCreateUnions();
// Start with 1 because at 0 it always will be c.
for (int i = 1; i < unions.size(); i++) {
GridH2CollocationModel u = unions.get(i);
if (u.select == select) {
cm = u;
break;
}
}
// Nothing was found, need to create new child in union.
if (cm.select != select)
cm = createChildModel(cm.upper, cm.filter, unions, true, validate);
}
cm.childFilters(filters);
return cm.child(filter, true);
}
Aggregations