Search in sources :

Example 1 with Table

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);
    }
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) Driver(org.h2.Driver) Test(org.junit.Test)

Example 2 with Table

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);
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) NamingMixIn(org.switchyard.component.test.mixins.naming.NamingMixIn) BeforeClass(org.junit.BeforeClass)

Example 3 with Table

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);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

Example 4 with 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());
}
Also used : Prepared(org.h2.command.Prepared)

Example 5 with Table

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));
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) Table(org.h2.table.Table) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) FastUpdateArguments(org.apache.ignite.internal.processors.query.h2.dml.FastUpdateArguments)

Aggregations

Column (org.h2.table.Column)11 Statement (java.sql.Statement)8 IndexColumn (org.h2.table.IndexColumn)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)7 PreparedStatement (java.sql.PreparedStatement)6 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)6 Table (org.h2.table.Table)6 Connection (java.sql.Connection)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteException (org.apache.ignite.IgniteException)4 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)4 Prepared (org.h2.command.Prepared)4 Query (org.h2.command.dml.Query)4 ExpressionColumn (org.h2.expression.ExpressionColumn)4 ValueString (org.h2.value.ValueString)4