Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#setSqlSchema()

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setSqlSchema() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteSqlSplitterSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param schema Schema name.
 */
public void doTestSchemaName(String schema) {
    CacheConfiguration ccfg = cacheConfig("persPartAff", true, Integer.class, Person2.class);

    ccfg.setSqlSchema(schema);

    IgniteCache<Integer, Person2> ppAf = ignite(0).createCache(ccfg);

    try {
        ppAf.put(1, new Person2(10, "Petya"));
        ppAf.put(2, new Person2(10, "Kolya"));

        List<List<?>> res = ppAf.query(new SqlFieldsQuery("select name from " +
            schema + ".Person2 order by _key")).getAll();

        assertEquals("Petya", res.get(0).get(0));
        assertEquals("Kolya", res.get(1).get(0));
    }
    finally {
        ppAf.destroy();
    }
}
 
Example 2
Source File: GridQueryParsingTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param name Cache name.
 * @param clsK Key class.
 * @param clsV Value class.
 * @return Cache configuration.
 */
@SuppressWarnings("unchecked")
private CacheConfiguration cacheConfiguration(@NotNull String name, String sqlSchema, Class<?> clsK,
    Class<?> clsV) {
    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setName(name);
    cc.setCacheMode(CacheMode.PARTITIONED);
    cc.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    cc.setNearConfiguration(null);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setRebalanceMode(SYNC);
    cc.setSqlSchema(sqlSchema);
    cc.setSqlFunctionClasses(GridQueryParsingTest.class);
    cc.setIndexedTypes(clsK, clsV);

    if (!QueryUtils.isSqlType(clsK))
        cc.setKeyConfiguration(new CacheKeyConfiguration(clsK));

    return cc;
}
 
Example 3
Source File: GridCacheDynamicLoadOnClientTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Cache configuration.
 */
private CacheConfiguration<?, ?> cacheConfiguration() {
    CacheConfiguration ccfg = new CacheConfiguration(PERSON_CACHE);

    ccfg.setSqlSchema(PERSON_SCHEMA);
    ccfg.setCacheMode(CacheMode.PARTITIONED);

    QueryEntity person = new QueryEntity();
    person.setKeyType(Integer.class.getName());
    person.setValueType(Person.class.getName());
    person.addQueryField("orgId", Integer.class.getName(), null);
    person.addQueryField("name", String.class.getName(), null);
    person.setIndexes(F.asList(new QueryIndex("orgId"), new QueryIndex("name")));

    ccfg.setQueryEntities(F.asList(person));

    return ccfg;
}
 
Example 4
Source File: IgniteCacheReplicatedFieldsQueryJoinNoPrimaryPartitionsSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<Integer, PartValue> ccfg1 = new CacheConfiguration<>(CACHE_PARTITIONED);

    ccfg1.setCacheMode(PARTITIONED);
    ccfg1.setAtomicityMode(TRANSACTIONAL);
    ccfg1.setWriteSynchronizationMode(FULL_SYNC);
    ccfg1.setIndexedTypes(Integer.class, PartValue.class);
    ccfg1.setSqlSchema(QueryUtils.DFLT_SCHEMA);

    CacheConfiguration<Integer, RepValue> ccfg2 = new CacheConfiguration<>(CACHE_REPLICATED);

    ccfg2.setAffinity(new RendezvousAffinityFunction(false, REP_CNT));
    ccfg2.setCacheMode(REPLICATED);
    ccfg2.setAtomicityMode(TRANSACTIONAL);
    ccfg2.setWriteSynchronizationMode(FULL_SYNC);
    ccfg2.setIndexedTypes(Integer.class, RepValue.class);
    ccfg2.setSqlSchema(QueryUtils.DFLT_SCHEMA);

    cfg.setCacheConfiguration(ccfg1, ccfg2);

    return cfg;
}
 
Example 5
Source File: JdbcConnectionWithoutCacheNameTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<?, ?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setSqlSchema("\"default\"");

    cfg.setCacheConfiguration(cache);

    cfg.setConnectorConfiguration(new ConnectorConfiguration());

    return cfg;
}
 
Example 6
Source File: IgniteCacheInitializer.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CacheConfiguration<?,?> createEntityCacheConfiguration(EntityKeyMetadata entityKeyMetadata, SchemaDefinitionContext context) {
	CacheConfiguration<?,?> cacheConfiguration = new CacheConfiguration<>();
	cacheConfiguration.setStoreKeepBinary( true );
	cacheConfiguration.setSqlSchema( QueryUtils.DFLT_SCHEMA );
	cacheConfiguration.setBackups( 1 );
	cacheConfiguration.setName( StringHelper.stringBeforePoint( entityKeyMetadata.getTable() ) );
	cacheConfiguration.setAtomicityMode( CacheAtomicityMode.TRANSACTIONAL );

	QueryEntity queryEntity = new QueryEntity();
	queryEntity.setTableName( entityKeyMetadata.getTable() );
	queryEntity.setKeyType( getEntityIdClassName( entityKeyMetadata.getTable(), context ).getSimpleName() );
	queryEntity.setValueType( StringHelper.stringAfterPoint( entityKeyMetadata.getTable() ) );

	addTableInfo( queryEntity, context, entityKeyMetadata.getTable() );
	for ( AssociationKeyMetadata associationKeyMetadata : context.getAllAssociationKeyMetadata() ) {
		if ( associationKeyMetadata.getAssociationKind() != AssociationKind.EMBEDDED_COLLECTION
				&& associationKeyMetadata.getTable().equals( entityKeyMetadata.getTable() )
				&& !IgniteAssociationSnapshot.isThirdTableAssociation( associationKeyMetadata ) ) {
			appendIndex( queryEntity, associationKeyMetadata, context );
		}
	}
	addUserIndexes( queryEntity, context, entityKeyMetadata.getTable() );

	log.debugf( "queryEntity: %s", queryEntity );
	cacheConfiguration.setQueryEntities( Arrays.asList( queryEntity ) );
	return cacheConfiguration;
}
 
Example 7
Source File: IgniteCacheDistributedJoinTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<Integer, A> ccfga = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfga.setName("a");
    ccfga.setSqlSchema("A");
    ccfga.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfga.setBackups(1);
    ccfga.setCacheMode(CacheMode.PARTITIONED);
    ccfga.setIndexedTypes(Integer.class, A.class);

    CacheConfiguration<Integer, B> ccfgb = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfgb.setName("b");
    ccfgb.setSqlSchema("B");
    ccfgb.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfgb.setBackups(1);
    ccfgb.setCacheMode(CacheMode.PARTITIONED);
    ccfgb.setIndexedTypes(Integer.class, B.class);

    CacheConfiguration<Integer, C> ccfgc = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfgc.setName("c");
    ccfgc.setSqlSchema("C");
    ccfgc.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfgc.setBackups(1);
    ccfgc.setCacheMode(CacheMode.PARTITIONED);
    ccfgc.setIndexedTypes(Integer.class, C.class);

    cfg.setCacheConfiguration(ccfga, ccfgb, ccfgc);

    return cfg;
}
 
Example 8
Source File: JdbcAuthorizationTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();

    Ignite srv = startSecurityGrid(0,
        new TestSecurityData(EMPTY_PERMS_USER, new SecurityBasicPermissionSet()),
        new TestSecurityData(CACHE_CREATE_SYS_PERM_USER, systemPermissions(CACHE_CREATE)),
        new TestSecurityData(CACHE_DESTROY_SYS_PERMS_USER, systemPermissions(CACHE_DESTROY)),
        new TestSecurityData(CACHE_CREATE_CACHE_PERMS_USER, cachePermissions(TEST_CREATE_TABLE_CACHE, CACHE_CREATE)),
        new TestSecurityData(CACHE_DESTROY_CACHE_PERMS_USER, cachePermissions(TEST_DROP_TABLE_CACHE, CACHE_DESTROY)),
        new TestSecurityData(CACHE_READ_USER, cachePermissions(DEFAULT_CACHE_NAME, CACHE_READ)),
        new TestSecurityData(CACHE_PUT_USER, create().defaultAllowAll(false)
            .appendCachePermissions(DEFAULT_CACHE_NAME, CACHE_PUT)
            .appendCachePermissions(TEST_BULKLOAD_CACHE, CACHE_PUT)
            .build()),
        new TestSecurityData(CACHE_REMOVE_USER, cachePermissions(DEFAULT_CACHE_NAME, CACHE_REMOVE)));

    startSecurityGrid(1);

    srv.cluster().state(ACTIVE);

    CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setIndexedTypes(Integer.class, Integer.class);
    ccfg.setCacheMode(REPLICATED);
    ccfg.setSqlSchema(TEST_DML_SCHEMA);

    srv.createCache(ccfg);
}
 
Example 9
Source File: JoinPartitionPruningSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param ccfg1 Cache config 1.
 * @param ccfg2 Cache config 2.
 * @param compatible Compatible affinity function flag (false when affinity is incompatible).
 */
@SuppressWarnings("unchecked")
private void checkAffinityFunctions(CacheConfiguration ccfg1, CacheConfiguration ccfg2, boolean compatible) {
    // Destroy old caches.
    Ignite cli = client();

    cli.destroyCaches(cli.cacheNames());

    // Start new caches.
    ccfg1.setName("t1");
    ccfg2.setName("t2");

    QueryEntity entity1 = new QueryEntity(KeyClass1.class, ValueClass.class).setTableName("t1");
    QueryEntity entity2 = new QueryEntity(KeyClass2.class, ValueClass.class).setTableName("t2");

    ccfg1.setQueryEntities(Collections.singletonList(entity1));
    ccfg2.setQueryEntities(Collections.singletonList(entity2));

    ccfg1.setKeyConfiguration(new CacheKeyConfiguration(entity1.getKeyType(), "k1"));
    ccfg2.setKeyConfiguration(new CacheKeyConfiguration(entity2.getKeyType(), "ak2"));

    ccfg1.setSqlSchema(QueryUtils.DFLT_SCHEMA);
    ccfg2.setSqlSchema(QueryUtils.DFLT_SCHEMA);

    client().createCache(ccfg1);
    client().createCache(ccfg2);

    // Conduct tests.
    execute("SELECT * FROM t1 INNER JOIN t2 ON t1.k1 = t2.ak2 WHERE t1.k1 = ?",
        (res) -> assertPartitions(
            partition("t1", "1")
        ),
        "1"
    );

    execute("SELECT * FROM t1 INNER JOIN t2 ON t1.k1 = t2.ak2 WHERE t2.ak2 = ?",
        (res) -> assertPartitions(
            partition("t2", "2")
        ),
        "2"
    );

    if (compatible) {
        execute("SELECT * FROM t1 INNER JOIN t2 ON t1.k1 = t2.ak2 WHERE t1.k1 = ? OR t2.ak2 = ?",
            (res) -> assertPartitions(
                partition("t1", "1"),
                partition("t2", "2")
            ),
            "1", "2"
        );
    }
    else {
        execute("SELECT * FROM t1 INNER JOIN t2 ON t1.k1 = t2.ak2 WHERE t1.k1 = ? OR t2.ak2 = ?",
            (res) -> assertNoPartitions(),
            "1", "2"
        );
    }
}
 
Example 10
Source File: ComplexPrimaryKeyUnwrapSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Test don't using PK indexes for table created through cache API.
 */
@Test
public void testIndexesForCachesCreatedThroughCashApi() {
    String tblName = TestValue.class.getSimpleName();

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setSqlSchema("PUBLIC");
    ccfg.setName(tblName);

    QueryEntity qryEntity = new QueryEntity(TestKey.class, TestValue.class);

    ccfg.setQueryEntities(F.asList(qryEntity));

    node().createCache(ccfg);

    List<List<?>> results = executeSql("explain SELECT * FROM " + tblName + " WHERE id=1");

    assertDontUsingPkIndex(results);
}
 
Example 11
Source File: CacheQueryMemoryLeakTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @param node Ignite instance.
 * @return Cache.
 */
private static IgniteCache<Integer, Person> startPeopleCache(Ignite node) {
    CacheConfiguration<Integer, Person> cacheCfg = new CacheConfiguration<>("people");

    QueryEntity qe = new QueryEntity(Integer.class, Person.class);

    qe.setTableName("people");

    cacheCfg.setQueryEntities(Collections.singleton(qe));

    cacheCfg.setSqlSchema("PUBLIC");

    return node.getOrCreateCache(cacheCfg);
}
 
Example 12
Source File: JdbcThinPartitionAwarenessSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Check that affinity cache stores sql queries with their schemas.
 *
 * @throws Exception If failed.
 */
@Test
public void testAffinityCacheStoresSchemaBindedQueries() throws Exception {
    final String cacheName = "yacc";

    CacheConfiguration<Object, Object> cache = prepareCacheConfig(cacheName);
    cache.setSqlSchema(cacheName);

    ignite(0).createCache(cache);

    fillCache(cacheName);

    stmt.execute("select * from \"" + cacheName.toUpperCase() + "\".Person where _key = 1");

    conn.setSchema(cacheName.toUpperCase());

    stmt = conn.createStatement();

    stmt.execute("select * from \"" + cacheName.toUpperCase() + "\".Person where _key = 1");

    AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");

    GridBoundedLinkedHashMap<QualifiedSQLQuery, JdbcThinPartitionResultDescriptor> sqlCache =
        GridTestUtils.getFieldValue(affinityCache, "sqlCache");

    Set<String> schemas = sqlCache.keySet().stream().map(QualifiedSQLQuery::schemaName).collect(Collectors.toSet());

    assertTrue("Affinity cache doesn't contain query  sent to 'default' schema.",
        schemas.contains("default"));
    assertTrue("Affinity cache doesn't contain query  sent to '" + cacheName.toUpperCase() + "' schema.",
        schemas.contains(cacheName.toUpperCase()));
}
 
Example 13
Source File: JdbcAbstractSchemaCaseTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @param name Cache name.
 * @param schema Schema name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
@SuppressWarnings("unchecked")
private CacheConfiguration cacheConfiguration(@NotNull String name, @NotNull String schema) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setIndexedTypes(Integer.class, Integer.class);

    cfg.setName(name);

    cfg.setSqlSchema(schema);

    return cfg;
}