use of org.h2.table.Table in project elastic-core-maven by OrdinaryDude.
the class FullTextTrigger method dropAll.
/**
* Drop all fulltext indexes
*
* @param conn SQL connection
* @throws SQLException Unable to drop fulltext indexes
*/
public static void dropAll(Connection conn) throws SQLException {
//
try (Statement qstmt = conn.createStatement();
Statement stmt = conn.createStatement();
ResultSet rs = qstmt.executeQuery("SELECT TABLE FROM FTL.INDEXES")) {
while (rs.next()) {
String table = rs.getString(1);
stmt.execute("DROP TRIGGER IF EXISTS FTL_" + table);
}
stmt.execute("TRUNCATE TABLE FTL.INDEXES");
indexTriggers.clear();
}
//
// Delete the Lucene index
//
removeIndexFiles(conn);
}
use of org.h2.table.Table in project elastic-core-maven by OrdinaryDude.
the class FullTextTrigger method dropIndex.
/**
* Drop the fulltext index for a table
*
* @param conn SQL connection
* @param schema Schema name
* @param table Table name
* @throws SQLException Unable to drop fulltext index
*/
public static void dropIndex(Connection conn, String schema, String table) throws SQLException {
String upperSchema = schema.toUpperCase();
String upperTable = table.toUpperCase();
boolean reindex = false;
//
try (Statement qstmt = conn.createStatement();
Statement stmt = conn.createStatement()) {
try (ResultSet rs = qstmt.executeQuery(String.format("SELECT COLUMNS FROM FTL.INDEXES WHERE SCHEMA = '%s' AND TABLE = '%s'", upperSchema, upperTable))) {
if (rs.next()) {
stmt.execute("DROP TRIGGER IF EXISTS FTL_" + upperTable);
stmt.execute(String.format("DELETE FROM FTL.INDEXES WHERE SCHEMA = '%s' AND TABLE = '%s'", upperSchema, upperTable));
reindex = true;
}
}
}
//
if (reindex) {
reindex(conn);
}
}
use of org.h2.table.Table in project ignite by apache.
the class GridQueryParsingTest method assertDropTableEquals.
/**
* Parse SQL and compare it to expected instance of DROP TABLE.
*/
private void assertDropTableEquals(GridSqlDropTable exp, String sql) throws Exception {
Prepared prepared = parse(sql);
GridSqlStatement stmt = new GridSqlQueryParser(false).parse(prepared);
assertTrue(stmt instanceof GridSqlDropTable);
assertDropTableEquals(exp, (GridSqlDropTable) stmt);
}
use of org.h2.table.Table in project ignite by apache.
the class GridQueryParsingTest method assertCreateTableEquals.
/**
* Parse SQL and compare it to expected instance of DROP TABLE.
*/
private void assertCreateTableEquals(GridSqlCreateTable exp, String sql) throws Exception {
Prepared prepared = parse(sql);
GridSqlStatement stmt = new GridSqlQueryParser(false).parse(prepared);
assertTrue(stmt instanceof GridSqlCreateTable);
assertCreateTableEquals(exp, (GridSqlCreateTable) stmt);
}
use of org.h2.table.Table in project ignite by apache.
the class GridReduceQueryExecutor method createMergeTable.
/**
* @param conn Connection.
* @param qry Query.
* @param explain Explain.
* @return Table.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
private GridMergeTable createMergeTable(JdbcConnection conn, GridCacheSqlQuery qry, boolean explain) throws IgniteCheckedException {
try {
Session ses = (Session) conn.getSession();
CreateTableData data = new CreateTableData();
data.tableName = "T___";
data.schema = ses.getDatabase().getSchema(ses.getCurrentSchemaName());
data.create = true;
if (!explain) {
LinkedHashMap<String, ?> colsMap = qry.columns();
assert colsMap != null;
ArrayList<Column> cols = new ArrayList<>(colsMap.size());
for (Map.Entry<String, ?> e : colsMap.entrySet()) {
String alias = e.getKey();
GridSqlType t = (GridSqlType) e.getValue();
assert !F.isEmpty(alias);
Column c = new Column(alias, t.type(), t.precision(), t.scale(), t.displaySize());
cols.add(c);
}
data.columns = cols;
} else
data.columns = planColumns();
boolean sortedIndex = !F.isEmpty(qry.sortColumns());
GridMergeTable tbl = new GridMergeTable(data);
ArrayList<Index> idxs = new ArrayList<>(2);
if (explain) {
idxs.add(new GridMergeIndexUnsorted(ctx, tbl, sortedIndex ? MERGE_INDEX_SORTED : MERGE_INDEX_UNSORTED));
} else if (sortedIndex) {
List<GridSqlSortColumn> sortCols = (List<GridSqlSortColumn>) qry.sortColumns();
GridMergeIndexSorted sortedMergeIdx = new GridMergeIndexSorted(ctx, tbl, MERGE_INDEX_SORTED, GridSqlSortColumn.toIndexColumns(tbl, sortCols));
idxs.add(GridMergeTable.createScanIndex(sortedMergeIdx));
idxs.add(sortedMergeIdx);
} else
idxs.add(new GridMergeIndexUnsorted(ctx, tbl, MERGE_INDEX_UNSORTED));
tbl.indexes(idxs);
return tbl;
} catch (Exception e) {
U.closeQuiet(conn);
throw new IgniteCheckedException(e);
}
}
Aggregations