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();
}
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;
}
}
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();
}
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();
}
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());
}
Aggregations