Search in sources :

Example 11 with Data

use of org.h2.store.Data in project jackrabbit-oak by apache.

the class BlobCache method addGeneration.

@Override
public void addGeneration(int generation, boolean readOnly) {
    CacheMap<Long, byte[]> d = cache.openMap(generation, "data", new MVMap.Builder<Long, byte[]>());
    data.addReadMap(generation, d);
    CacheMap<String, byte[]> m = cache.openMap(generation, "meta", new MVMap.Builder<String, byte[]>());
    meta.addReadMap(generation, m);
    if (!readOnly) {
        // the order is important:
        // if we switch the data first,
        // we could end up with the data in store 1
        // but the metadata in store 2 - which could
        // result in a data block not found if store 1
        // is removed later on
        meta.setWriteMap(m);
        data.setWriteMap(d);
    }
    if (streamStore == null) {
        streamStore = new StreamStore(data);
    }
}
Also used : StreamStore(org.h2.mvstore.StreamStore) MVMap(org.h2.mvstore.MVMap)

Example 12 with Data

use of org.h2.store.Data in project siena by mandubian.

the class FullText method indexExistingRows.

/**
     * Add the existing data to the index.
     *
     * @param conn the database connection
     * @param schema the schema name
     * @param table the table name
     */
protected static void indexExistingRows(Connection conn, String schema, String table) throws SQLException {
    FullText.FullTextTrigger existing = new FullText.FullTextTrigger();
    existing.init(conn, schema, null, table, false, Trigger.INSERT);
    String sql = "SELECT * FROM " + StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table);
    ResultSet rs = conn.createStatement().executeQuery(sql);
    int columnCount = rs.getMetaData().getColumnCount();
    while (rs.next()) {
        Object[] row = new Object[columnCount];
        for (int i = 0; i < columnCount; i++) {
            row[i] = rs.getObject(i + 1);
        }
        existing.fire(conn, null, row);
    }
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

Example 13 with Data

use of org.h2.store.Data in project siena by mandubian.

the class FullText method addColumnData.

private static void addColumnData(ArrayList<String> columns, ArrayList<String> data, Expression expr) {
    if (expr instanceof ConditionAndOr) {
        ConditionAndOr and = (ConditionAndOr) expr;
        Expression left = and.getExpression(true);
        Expression right = and.getExpression(false);
        addColumnData(columns, data, left);
        addColumnData(columns, data, right);
    } else {
        Comparison comp = (Comparison) expr;
        ExpressionColumn ec = (ExpressionColumn) comp.getExpression(true);
        ValueExpression ev = (ValueExpression) comp.getExpression(false);
        String columnName = ec.getColumnName();
        columns.add(columnName);
        if (ev == null) {
            data.add(null);
        } else {
            data.add(ev.getValue(null).getString());
        }
    }
}
Also used : ValueExpression(org.h2.expression.ValueExpression) Expression(org.h2.expression.Expression) Comparison(org.h2.expression.Comparison) ValueExpression(org.h2.expression.ValueExpression) ConditionAndOr(org.h2.expression.ConditionAndOr) ExpressionColumn(org.h2.expression.ExpressionColumn)

Example 14 with Data

use of org.h2.store.Data in project ignite by apache.

the class DbH2ServerStartup method main.

/**
     * Start H2 database TCP server.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If start H2 database TCP server failed.
     */
public static void main(String[] args) throws IgniteException {
    try {
        // Start H2 database TCP server in order to access sample in-memory database from other processes.
        Server.createTcpServer("-tcpDaemon").start();
        populateDatabase();
        // Try to connect to database TCP server.
        JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", "");
        // Create Person table in database.
        RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_PERSON_TABLE));
        // Populates Person table with sample data in database.
        RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_PERSON_TABLE));
    } catch (SQLException e) {
        throw new IgniteException("Failed to start database TCP server", e);
    }
    try {
        do {
            System.out.println("Type 'q' and press 'Enter' to stop H2 TCP server...");
        } while ('q' != System.in.read());
    } catch (IOException ignored) {
    // No-op.
    }
}
Also used : JdbcConnectionPool(org.h2.jdbcx.JdbcConnectionPool) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 15 with Data

use of org.h2.store.Data in project ignite by apache.

the class DbH2ServerStartup method populateDatabase.

/**
     * Populate sample database.
     *
     * @throws SQLException if
     */
public static void populateDatabase() throws SQLException {
    // Try to connect to database TCP server.
    JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", "");
    // Create Person table in database.
    RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_PERSON_TABLE));
    // Populates Person table with sample data in database.
    RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_PERSON_TABLE));
}
Also used : JdbcConnectionPool(org.h2.jdbcx.JdbcConnectionPool) StringReader(java.io.StringReader)

Aggregations

ResultSet (java.sql.ResultSet)5 LinkedHashMap (java.util.LinkedHashMap)4 CacheException (javax.cache.CacheException)4 IgniteException (org.apache.ignite.IgniteException)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 UUID (java.util.UUID)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)3 Index (org.h2.index.Index)3 StringReader (java.io.StringReader)2 PreparedStatement (java.sql.PreparedStatement)2 Collections.singletonList (java.util.Collections.singletonList)2 Map (java.util.Map)2 Random (java.util.Random)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)2