Search in sources :

Example 1 with H2RowFactory

use of org.apache.ignite.internal.processors.query.h2.database.H2RowFactory in project ignite by apache.

the class IgniteH2Indexing method createTable.

/**
     * Create db table by using given table descriptor.
     *
     * @param schemaName Schema name.
     * @param schema Schema.
     * @param tbl Table descriptor.
     * @param conn Connection.
     * @throws SQLException If failed to create db table.
     * @throws IgniteCheckedException If failed.
     */
private void createTable(String schemaName, H2Schema schema, H2TableDescriptor tbl, Connection conn) throws SQLException, IgniteCheckedException {
    assert schema != null;
    assert tbl != null;
    String keyType = dbTypeFromClass(tbl.type().keyClass());
    String valTypeStr = dbTypeFromClass(tbl.type().valueClass());
    SB sql = new SB();
    String keyValVisibility = tbl.type().fields().isEmpty() ? " VISIBLE" : " INVISIBLE";
    sql.a("CREATE TABLE ").a(tbl.fullTableName()).a(" (").a(KEY_FIELD_NAME).a(' ').a(keyType).a(keyValVisibility).a(" NOT NULL");
    sql.a(',').a(VAL_FIELD_NAME).a(' ').a(valTypeStr).a(keyValVisibility);
    sql.a(',').a(VER_FIELD_NAME).a(" OTHER INVISIBLE");
    for (Map.Entry<String, Class<?>> e : tbl.type().fields().entrySet()) sql.a(',').a(H2Utils.withQuotes(e.getKey())).a(' ').a(dbTypeFromClass(e.getValue()));
    sql.a(')');
    if (log.isDebugEnabled())
        log.debug("Creating DB table with SQL: " + sql);
    GridH2RowDescriptor rowDesc = new H2RowDescriptor(this, tbl, tbl.type(), schema);
    H2RowFactory rowFactory = tbl.rowFactory(rowDesc);
    GridH2Table h2Tbl = H2TableEngine.createTable(conn, sql.toString(), rowDesc, rowFactory, tbl);
    for (GridH2IndexBase usrIdx : tbl.createUserIndexes()) addInitialUserIndex(schemaName, tbl, usrIdx);
    if (dataTables.putIfAbsent(h2Tbl.identifier(), h2Tbl) != null)
        throw new IllegalStateException("Table already exists: " + h2Tbl.identifierString());
}
Also used : GridH2IndexBase(org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) H2RowFactory(org.apache.ignite.internal.processors.query.h2.database.H2RowFactory) GridH2RowFactory(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowFactory) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridBoundedConcurrentLinkedHashMap(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)1 H2RowFactory (org.apache.ignite.internal.processors.query.h2.database.H2RowFactory)1 GridH2IndexBase (org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase)1 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)1 GridH2RowFactory (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowFactory)1 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)1 GridBoundedConcurrentLinkedHashMap (org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap)1 SB (org.apache.ignite.internal.util.typedef.internal.SB)1