Search in sources :

Example 11 with Cache

use of org.h2.util.Cache in project ignite by apache.

the class GridReduceQueryExecutor method stableDataNodes.

/**
 * @param isReplicatedOnly If we must only have replicated caches.
 * @param topVer Topology version.
 * @param cacheIds Participating cache IDs.
 * @param parts Partitions.
 * @return Data nodes or {@code null} if repartitioning started and we need to retry.
 */
private Map<ClusterNode, IntArray> stableDataNodes(boolean isReplicatedOnly, AffinityTopologyVersion topVer, List<Integer> cacheIds, int[] parts) {
    GridCacheContext<?, ?> cctx = cacheContext(cacheIds.get(0));
    Map<ClusterNode, IntArray> map = stableDataNodesMap(topVer, cctx, parts);
    Set<ClusterNode> nodes = map.keySet();
    if (F.isEmpty(map))
        throw new CacheException("Failed to find data nodes for cache: " + cctx.name());
    for (int i = 1; i < cacheIds.size(); i++) {
        GridCacheContext<?, ?> extraCctx = cacheContext(cacheIds.get(i));
        String extraCacheName = extraCctx.name();
        if (extraCctx.isLocal())
            // No consistency guaranties for local caches.
            continue;
        if (isReplicatedOnly && !extraCctx.isReplicated())
            throw new CacheException("Queries running on replicated cache should not contain JOINs " + "with partitioned tables [replicatedCache=" + cctx.name() + ", partitionedCache=" + extraCacheName + "]");
        Set<ClusterNode> extraNodes = stableDataNodesMap(topVer, extraCctx, parts).keySet();
        if (F.isEmpty(extraNodes))
            throw new CacheException("Failed to find data nodes for cache: " + extraCacheName);
        boolean disjoint;
        if (extraCctx.isReplicated()) {
            if (isReplicatedOnly) {
                nodes.retainAll(extraNodes);
                disjoint = map.isEmpty();
            } else
                disjoint = !extraNodes.containsAll(nodes);
        } else
            disjoint = !extraNodes.equals(nodes);
        if (disjoint) {
            if (isPreloadingActive(cacheIds))
                // Retry.
                return null;
            else
                throw new CacheException("Caches have distinct sets of data nodes [cache1=" + cctx.name() + ", cache2=" + extraCacheName + "]");
        }
    }
    return map;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IntArray(org.h2.util.IntArray) CacheException(javax.cache.CacheException)

Example 12 with Cache

use of org.h2.util.Cache in project ignite by apache.

the class H2DynamicTableSelfTest method testCacheSelfDrop.

/**
 * Test that attempting to execute {@code DROP TABLE} via API of cache being dropped yields an error.
 * @throws Exception if failed.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testCacheSelfDrop() throws Exception {
    execute("CREATE TABLE IF NOT EXISTS \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + "\"template=cache\"");
    GridTestUtils.assertThrows(null, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            client().cache(QueryUtils.createTableCacheName(QueryUtils.DFLT_SCHEMA, "Person")).query(new SqlFieldsQuery("DROP TABLE \"Person\"")).getAll();
            return null;
        }
    }, IgniteSQLException.class, "DROP TABLE cannot be called from the same cache that holds the table " + "being dropped");
    execute("DROP TABLE \"Person\"");
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) JdbcSQLException(org.h2.jdbc.JdbcSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 13 with Cache

use of org.h2.util.Cache in project ignite by apache.

the class H2DynamicTableSelfTest method testDataRegion.

/**
 * Test data region.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings({ "ThrowableNotThrown", "unchecked" })
public void testDataRegion() throws Exception {
    // Empty region name.
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            execute("CREATE TABLE TEST_DATA_REGION (name varchar primary key, code int) WITH \"data_region=\"");
            return null;
        }
    }, IgniteSQLException.class, "Parameter value cannot be empty: DATA_REGION");
    // Valid region name.
    execute("CREATE TABLE TEST_DATA_REGION (name varchar primary key, code int) WITH \"data_region=" + DATA_REGION_NAME + "\"");
    CacheConfiguration ccfg = client().cache("SQL_PUBLIC_TEST_DATA_REGION").getConfiguration(CacheConfiguration.class);
    assertEquals(DATA_REGION_NAME, ccfg.getDataRegionName());
}
Also used : IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) JdbcSQLException(org.h2.jdbc.JdbcSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 14 with Cache

use of org.h2.util.Cache in project h2database by h2database.

the class Parser method parseAlterSequence.

private AlterSequence parseAlterSequence() {
    boolean ifExists = readIfExists(false);
    String sequenceName = readIdentifierWithSchema();
    AlterSequence command = new AlterSequence(session, getSchema());
    command.setSequenceName(sequenceName);
    command.setIfExists(ifExists);
    while (true) {
        if (readIf("RESTART")) {
            read("WITH");
            command.setStartWith(readExpression());
        } else if (readIf("INCREMENT")) {
            read("BY");
            command.setIncrement(readExpression());
        } else if (readIf("MINVALUE")) {
            command.setMinValue(readExpression());
        } else if (readIf("NOMINVALUE")) {
            command.setMinValue(null);
        } else if (readIf("MAXVALUE")) {
            command.setMaxValue(readExpression());
        } else if (readIf("NOMAXVALUE")) {
            command.setMaxValue(null);
        } else if (readIf("CYCLE")) {
            command.setCycle(true);
        } else if (readIf("NOCYCLE")) {
            command.setCycle(false);
        } else if (readIf("NO")) {
            if (readIf("MINVALUE")) {
                command.setMinValue(null);
            } else if (readIf("MAXVALUE")) {
                command.setMaxValue(null);
            } else if (readIf("CYCLE")) {
                command.setCycle(false);
            } else if (readIf("CACHE")) {
                command.setCacheSize(ValueExpression.get(ValueLong.get(1)));
            } else {
                break;
            }
        } else if (readIf("CACHE")) {
            command.setCacheSize(readExpression());
        } else if (readIf("NOCACHE")) {
            command.setCacheSize(ValueExpression.get(ValueLong.get(1)));
        } else {
            break;
        }
    }
    return command;
}
Also used : AlterSequence(org.h2.command.dml.AlterSequence) ValueString(org.h2.value.ValueString)

Example 15 with Cache

use of org.h2.util.Cache in project h2database by h2database.

the class Parser method parseCreateSequence.

private CreateSequence parseCreateSequence() {
    boolean ifNotExists = readIfNotExists();
    String sequenceName = readIdentifierWithSchema();
    CreateSequence command = new CreateSequence(session, getSchema());
    command.setIfNotExists(ifNotExists);
    command.setSequenceName(sequenceName);
    while (true) {
        if (readIf("START")) {
            readIf("WITH");
            command.setStartWith(readExpression());
        } else if (readIf("INCREMENT")) {
            readIf("BY");
            command.setIncrement(readExpression());
        } else if (readIf("MINVALUE")) {
            command.setMinValue(readExpression());
        } else if (readIf("NOMINVALUE")) {
            command.setMinValue(null);
        } else if (readIf("MAXVALUE")) {
            command.setMaxValue(readExpression());
        } else if (readIf("NOMAXVALUE")) {
            command.setMaxValue(null);
        } else if (readIf("CYCLE")) {
            command.setCycle(true);
        } else if (readIf("NOCYCLE")) {
            command.setCycle(false);
        } else if (readIf("NO")) {
            if (readIf("MINVALUE")) {
                command.setMinValue(null);
            } else if (readIf("MAXVALUE")) {
                command.setMaxValue(null);
            } else if (readIf("CYCLE")) {
                command.setCycle(false);
            } else if (readIf("CACHE")) {
                command.setCacheSize(ValueExpression.get(ValueLong.get(1)));
            } else {
                break;
            }
        } else if (readIf("CACHE")) {
            command.setCacheSize(readExpression());
        } else if (readIf("NOCACHE")) {
            command.setCacheSize(ValueExpression.get(ValueLong.get(1)));
        } else if (readIf("BELONGS_TO_TABLE")) {
            command.setBelongsToTable(true);
        } else if (readIf("ORDER")) {
        // Oracle compatibility
        } else {
            break;
        }
    }
    return command;
}
Also used : CreateSequence(org.h2.command.ddl.CreateSequence) ValueString(org.h2.value.ValueString)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 Connection (java.sql.Connection)11 PreparedStatement (java.sql.PreparedStatement)10 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)10 ResultSet (java.sql.ResultSet)9 SQLException (java.sql.SQLException)9 CacheException (javax.cache.CacheException)9 Statement (java.sql.Statement)7 ArrayList (java.util.ArrayList)7 IgniteException (org.apache.ignite.IgniteException)7 List (java.util.List)5 UUID (java.util.UUID)5 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 Prepared (org.h2.command.Prepared)5 IntArray (org.h2.util.IntArray)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4