Search in sources :

Example 6 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class ServiceDeploymentOutsideBaselineTest method checkDeployFromEachNodes.

/**
 * @param persistence If {@code true}, then persistence will be enabled.
 * @param staticDeploy If {@code true}, then static deployment will be used instead of a dynamic one.
 * @throws Exception If failed.
 */
private void checkDeployFromEachNodes(boolean persistence, boolean staticDeploy) throws Exception {
    this.persistence = persistence;
    CountDownLatch exeLatch = new CountDownLatch(1);
    DummyService.exeLatch(SERVICE_NAME, exeLatch);
    Ignite ignite0 = deployServiceFromNewNode(staticDeploy, 0);
    if (!staticDeploy) {
        IgniteCluster cluster = ignite0.cluster();
        cluster.setBaselineTopology(cluster.topologyVersion());
    }
    assertTrue(exeLatch.await(10, TimeUnit.SECONDS));
    IgniteInternalFuture startFut = GridTestUtils.runAsync(() -> {
        try {
            deployServiceFromNewNode(staticDeploy);
        } catch (Exception e) {
            fail(e.getMessage());
        }
    });
    try {
        startFut.get(10, TimeUnit.SECONDS);
    } catch (IgniteFutureTimeoutCheckedException e) {
        GridStringBuilder sb = new SB().a("Node can not start out of baseline till ").a(10_000L).a("ms").a(U.nl());
        for (Thread t : Thread.getAllStackTraces().keySet()) if (t.getName().startsWith("async-runnable-runner"))
            U.printStackTrace(t.getId(), sb);
        fail(sb.toString());
    }
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteCluster(org.apache.ignite.IgniteCluster) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 7 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class H2IndexingAbstractGeoSelfTest method createDynamicIndex.

/**
 * Create dynamic index.
 *
 * @param cache Cache.
 * @param entity Entity.
 * @param idx Index.
 * @throws Exception If failed.
 */
private void createDynamicIndex(IgniteCache cache, QueryEntity entity, QueryIndex idx) throws Exception {
    boolean spatial = idx.getIndexType() == QueryIndexType.GEOSPATIAL;
    GridStringBuilder sb = new SB("CREATE ").a(spatial ? "SPATIAL " : "").a("INDEX ").a("\"" + idx.getName() + "\"").a(" ON ").a(QueryUtils.tableName(entity)).a(" (");
    boolean first = true;
    for (Map.Entry<String, Boolean> fieldEntry : idx.getFields().entrySet()) {
        if (first)
            first = false;
        else
            sb.a(", ");
        String name = fieldEntry.getKey();
        boolean asc = fieldEntry.getValue();
        sb.a("\"" + name + "\"").a(" ").a(asc ? "ASC" : "DESC");
    }
    sb.a(')');
    String sql = sb.toString();
    cache.query(new SqlFieldsQuery(sql)).getAll();
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Map(java.util.Map) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 8 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class H2DynamicTableSelfTest method doTestCustomNames.

/**
 * Test that appending supplied arguments to {@code CREATE TABLE} results in creating new cache that has settings
 * as expected
 * @param cacheName Cache name, or {@code null} if the name generated by default should be used.
 * @param keyTypeName Key type name, or {@code null} if the name generated by default should be used.
 * @param valTypeName Value type name, or {@code null} if the name generated by default should be used.
 */
private void doTestCustomNames(String cacheName, String keyTypeName, String valTypeName) {
    GridStringBuilder b = new GridStringBuilder("CREATE TABLE \"NameTest\" (id int primary key, x varchar) WITH " + "wrap_key,wrap_value");
    assert !F.isEmpty(cacheName) || !F.isEmpty(keyTypeName) || !F.isEmpty(valTypeName);
    if (!F.isEmpty(cacheName))
        b.a(",\"cache_name=").a(cacheName).a('"');
    if (!F.isEmpty(keyTypeName))
        b.a(",\"key_type=").a(keyTypeName).a('"');
    if (!F.isEmpty(valTypeName))
        b.a(",\"value_type=").a(valTypeName).a('"');
    String res = b.toString();
    if (res.endsWith(","))
        res = res.substring(0, res.length() - 1);
    execute(client(), res);
    String resCacheName = U.firstNotNull(cacheName, cacheName("NameTest"));
    IgniteInternalCache<BinaryObject, BinaryObject> cache = client().cachex(resCacheName);
    assertNotNull(cache);
    CacheConfiguration ccfg = cache.configuration();
    assertEquals(1, ccfg.getQueryEntities().size());
    QueryEntity e = (QueryEntity) ccfg.getQueryEntities().iterator().next();
    if (!F.isEmpty(keyTypeName))
        assertEquals(keyTypeName, e.getKeyType());
    else
        assertTrue(e.getKeyType().startsWith("SQL_PUBLIC"));
    if (!F.isEmpty(valTypeName))
        assertEquals(valTypeName, e.getValueType());
    else
        assertTrue(e.getValueType().startsWith("SQL_PUBLIC"));
    execute(client(), "INSERT INTO \"NameTest\" (id, x) values (1, 'a')");
    List<List<?>> qres = execute(client(), "SELECT id, x from \"NameTest\"");
    assertEqualsCollections(Collections.singletonList(Arrays.asList(1, "a")), qres);
    BinaryObject key = client().binary().builder(e.getKeyType()).setField("ID", 1).build();
    BinaryObject val = (BinaryObject) client().cache(resCacheName).withKeepBinary().get(key);
    BinaryObject exVal = client().binary().builder(e.getValueType()).setField("X", "a").build();
    assertEquals(exVal, val);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) List(java.util.List) ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 9 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class H2Utils method indexColumnsSql.

/**
 * Generate String represenation of given indexed columns.
 *
 * @param idxCols Indexed columns.
 * @return String represenation of given indexed columns.
 */
public static String indexColumnsSql(IndexColumn[] idxCols) {
    GridStringBuilder sb = new SB();
    boolean first = true;
    for (IndexColumn col : idxCols) {
        if (first)
            first = false;
        else
            sb.a(", ");
        sb.a(withQuotes(col.columnName)).a(" ").a(col.sortType == SortOrder.ASCENDING ? "ASC" : "DESC");
    }
    return sb.toString();
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) SB(org.apache.ignite.internal.util.typedef.internal.SB) IndexColumn(org.h2.table.IndexColumn)

Example 10 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class H2Utils method indexCreateSql.

/**
 * Generate {@code CREATE INDEX} SQL statement for given params.
 * @param fullTblName Fully qualified table name.
 * @param h2Idx H2 index.
 * @param ifNotExists Quietly skip index creation if it exists.
 * @return Statement string.
 */
public static String indexCreateSql(String fullTblName, GridH2IndexBase h2Idx, boolean ifNotExists) {
    boolean spatial = F.eq(SPATIAL_IDX_CLS, h2Idx.getClass().getName());
    GridStringBuilder sb = new SB("CREATE ").a(spatial ? "SPATIAL " : "").a("INDEX ").a(ifNotExists ? "IF NOT EXISTS " : "").a(withQuotes(h2Idx.getName())).a(" ON ").a(fullTblName).a(" (");
    sb.a(indexColumnsSql(h2Idx.getIndexColumns()));
    sb.a(')');
    return sb.toString();
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)19 SB (org.apache.ignite.internal.util.typedef.internal.SB)8 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 IgniteCluster (org.apache.ignite.IgniteCluster)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1