use of org.h2.table.Table in project sonarqube by SonarSource.
the class DdlUtilsTest method shouldCreateSchema_without_schema_migrations.
@Test
public void shouldCreateSchema_without_schema_migrations() throws SQLException {
DriverManager.registerDriver(new Driver());
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:sonar_test2")) {
try (Statement statement = connection.createStatement()) {
statement.execute("create table schema_migrations (version varchar(255) not null)");
}
DdlUtils.createSchema(connection, "h2", false);
verifySchemaMigrations(connection);
}
}
use of org.h2.table.Table in project quickstarts by jboss-switchyard.
the class CamelSqlBindingTest method startUp.
@BeforeClass
public static void startUp() throws Exception {
dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:mem:test");
dataSource.setUser("sa");
dataSource.setPassword("sa");
connection = dataSource.getConnection();
String createStatement = "CREATE TABLE greetings (" + "id INT PRIMARY KEY AUTO_INCREMENT, " + "receiver VARCHAR(255), " + "sender VARCHAR(255) " + ");";
connection.createStatement().executeUpdate("DROP TABLE IF EXISTS greetings");
connection.createStatement().executeUpdate(createStatement);
namingMixIn = new NamingMixIn();
namingMixIn.initialize();
bindDataSource(namingMixIn.getInitialContext(), "java:jboss/myDS", dataSource);
}
use of org.h2.table.Table 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.table.Table 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.table.Table in project ignite by apache.
the class DmlAstUtils method getFastUpdateArgs.
/**
* @param update UPDATE statement.
* @return {@code null} if given statement directly updates {@code _val} column with a literal or param value
* and filters by single non expression key (and, optionally, by single non expression value).
*/
public static FastUpdateArguments getFastUpdateArgs(GridSqlUpdate update) {
IgnitePair<GridSqlElement> filter = findKeyValueEqualityCondition(update.where());
if (filter == null)
return null;
if (update.cols().size() != 1)
return null;
Table tbl = update.cols().get(0).column().getTable();
if (!(tbl instanceof GridH2Table))
return null;
GridH2RowDescriptor desc = ((GridH2Table) tbl).rowDescriptor();
if (!desc.isValueColumn(update.cols().get(0).column().getColumnId()))
return null;
GridSqlElement set = update.set().get(update.cols().get(0).columnName());
if (!(set instanceof GridSqlConst || set instanceof GridSqlParameter))
return null;
return new FastUpdateArguments(operandForElement(filter.getKey()), operandForElement(filter.getValue()), operandForElement(set));
}
Aggregations