Search in sources :

Example 1 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class TcpDiscoveryS3IpFinder method key.

/**
     * Gets S3 key for provided address.
     *
     * @param addr Node address.
     * @return Key.
     */
private String key(InetSocketAddress addr) {
    assert addr != null;
    SB sb = new SB();
    sb.a(addr.getAddress().getHostAddress()).a(DELIM).a(addr.getPort());
    return sb.toString();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 2 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class ClientDefaultCacheSelfTest method content.

/**
     * Send HTTP request to Jetty server of node and process result.
     *
     * @param params Command parameters.
     * @return Processed response string.
     * @throws IOException If failed.
     */
private String content(Map<String, String> params) throws IOException {
    SB sb = new SB(TEST_URL);
    for (Map.Entry<String, String> e : params.entrySet()) sb.a(e.getKey()).a('=').a(e.getValue()).a('&');
    String qry = sb.toString();
    try {
        URL url = new URL(qry);
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("Accept-Charset", CHARSET);
        InputStream in = conn.getInputStream();
        StringBuilder buf = new StringBuilder(256);
        try (LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in, "UTF-8"))) {
            for (String line = rdr.readLine(); line != null; line = rdr.readLine()) buf.append(line);
        }
        return buf.toString();
    } catch (IOException e) {
        error("Failed to send HTTP request: " + TEST_URL + "?" + qry, e);
        throw e;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) Map(java.util.Map) URL(java.net.URL) URLConnection(java.net.URLConnection) SB(org.apache.ignite.internal.util.typedef.internal.SB) LineNumberReader(java.io.LineNumberReader)

Example 3 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class JettyRestProcessorAbstractSelfTest method content.

/**
     * @param params Command parameters.
     * @return Returned content.
     * @throws Exception If failed.
     */
protected String content(Map<String, String> params) throws Exception {
    SB sb = new SB(TEST_URL);
    for (Map.Entry<String, String> e : params.entrySet()) sb.a(e.getKey()).a('=').a(e.getValue()).a('&');
    URL url = new URL(sb.toString());
    URLConnection conn = url.openConnection();
    String signature = signature();
    if (signature != null)
        conn.setRequestProperty("X-Signature", signature);
    InputStream in = conn.getInputStream();
    StringBuilder buf = new StringBuilder(256);
    try (LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in, "UTF-8"))) {
        for (String line = rdr.readLine(); line != null; line = rdr.readLine()) buf.append(line);
    }
    return buf.toString();
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) URL(java.net.URL) URLConnection(java.net.URLConnection) SB(org.apache.ignite.internal.util.typedef.internal.SB) LineNumberReader(java.io.LineNumberReader)

Example 4 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class BasicJdbcDialect method where.

/**
     * Construct where part of query.
     *
     * @param keyCols Database key columns.
     * @param keyCnt Key count.
     */
private static String where(Collection<String> keyCols, int keyCnt) {
    SB sb = new SB();
    if (keyCols.size() == 1) {
        String keyCol = keyCols.iterator().next();
        if (keyCnt == 1)
            sb.a(keyCol + "=?");
        else
            sb.a(repeat("?", keyCnt, keyCol + " IN (", ",", ")"));
    } else {
        String keyParams = mkString(keyCols, new C1<String, String>() {

            @Override
            public String apply(String s) {
                return s + "=?";
            }
        }, "(", " AND ", ")");
        sb.a(repeat(keyParams, keyCnt, "", " OR ", ""));
    }
    return sb.toString();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 5 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class BasicJdbcDialect method loadCacheRangeQuery.

/** {@inheritDoc} */
@Override
public String loadCacheRangeQuery(String fullTblName, Collection<String> keyCols, Iterable<String> uniqCols, boolean appendLowerBound, boolean appendUpperBound) {
    assert appendLowerBound || appendUpperBound;
    SB sb = new SB();
    String[] cols = keyCols.toArray(new String[keyCols.size()]);
    if (appendLowerBound) {
        sb.a("(");
        for (int keyCnt = keyCols.size(); keyCnt > 0; keyCnt--) {
            for (int idx = 0; idx < keyCnt; idx++) {
                if (idx == keyCnt - 1)
                    sb.a(cols[idx]).a(" > ? ");
                else
                    sb.a(cols[idx]).a(" = ? AND ");
            }
            if (keyCnt != 1)
                sb.a("OR ");
        }
        sb.a(")");
    }
    if (appendLowerBound && appendUpperBound)
        sb.a(" AND ");
    if (appendUpperBound) {
        sb.a("(");
        for (int keyCnt = keyCols.size(); keyCnt > 0; keyCnt--) {
            for (int idx = 0, lastIdx = keyCnt - 1; idx < keyCnt; idx++) {
                sb.a(cols[idx]);
                // For composite key when not all of the key columns are constrained should use < (strictly less).
                if (idx == lastIdx)
                    sb.a(keyCnt == keyCols.size() ? " <= ? " : " < ? ");
                else
                    sb.a(" = ? AND ");
            }
            if (keyCnt != 1)
                sb.a(" OR ");
        }
        sb.a(")");
    }
    return String.format("SELECT %s FROM %s WHERE %s", mkString(uniqCols, ","), fullTblName, sb.toString());
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

SB (org.apache.ignite.internal.util.typedef.internal.SB)57 Map (java.util.Map)8 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)4 IgfsLogger (org.apache.ignite.internal.igfs.common.IgfsLogger)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 LineNumberReader (java.io.LineNumberReader)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ObjectName (javax.management.ObjectName)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2