diff --git a/CHANGES.md b/CHANGES.md index 74713128..5c74cd5c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,7 @@ * Add `ByteStream/IntStream/.../DoubleStream.flatMappToObj(ByteFunction mapper)`. -* Add `JdbcUtil.batchUpdate/batchInsert(PreparedQuery...)`. +* Add `PreparedQuery.batchUpdate/batchInsert`. * Improvements and bug fix. diff --git a/README.md b/README.md index ae3e3558..509b8810 100644 --- a/README.md +++ b/README.md @@ -182,33 +182,33 @@ A general programming library in Java/Android. It's easy to learn and simple to [RemoteExecutor](https://cdn.rawgit.com/landawn/AbacusUtil/master/docs/RemoteExecutor_view.html). * More: -[Charsets](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Charsets.html), -[Ascii](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Ascii.html), -[CalendarUnit](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/CalendarUnit.html), -[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/NamingPolicy.html), -[Properties](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Properties.html), -[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/PropertiesUtil.html), -[Wrapper](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Wrapper.html), -[ArrayHashSet](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/ArrayHashSet.html), -[ArrayHashMap](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/ArrayHashMap.html), -[ClassUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/ClassUtil.html), -[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/EscapeUtil.html), -[RegExUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/RegExUtil.html), -[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/FilenameUtil.html), -[AWSJSONUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/AWSJSONUtil.html), -[AddrUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/AddrUtil.html), -[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/WSSecurityUtil.html), -[EmailUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/EmailUtil.html), -[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/IEEE754rUtil.html), -[Index](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Index.html), -[Median](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Median.html), -[f](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/f.html), -[Iterables](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Iterables.html), -[Matth](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Matth.html), -[SafeInitializer](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/SafeInitializer.html), -[Stopwatch](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Stopwatch.html), -[RateLimiter](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/RateLimiter.html), -[Traverser](https://static.javadoc.io/com.landawn/abacus-util/1.5.6/com/landawn/abacus/util/Traverser.html)(from Apache commons, Google Guava...) ... +[Charsets](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Charsets.html), +[Ascii](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Ascii.html), +[CalendarUnit](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/CalendarUnit.html), +[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/NamingPolicy.html), +[Properties](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Properties.html), +[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/PropertiesUtil.html), +[Wrapper](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Wrapper.html), +[ArrayHashSet](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/ArrayHashSet.html), +[ArrayHashMap](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/ArrayHashMap.html), +[ClassUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/ClassUtil.html), +[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/EscapeUtil.html), +[RegExUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/RegExUtil.html), +[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/FilenameUtil.html), +[AWSJSONUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/AWSJSONUtil.html), +[AddrUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/AddrUtil.html), +[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/WSSecurityUtil.html), +[EmailUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/EmailUtil.html), +[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/IEEE754rUtil.html), +[Index](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Index.html), +[Median](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Median.html), +[f](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/f.html), +[Iterables](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Iterables.html), +[Matth](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Matth.html), +[SafeInitializer](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/SafeInitializer.html), +[Stopwatch](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Stopwatch.html), +[RateLimiter](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/RateLimiter.html), +[Traverser](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Traverser.html)(from Apache commons, Google Guava...) ... ## Download/Installation & [Changes](https://github.com/landawn/AbacusUtil/blob/master/CHANGES.md): @@ -218,22 +218,22 @@ A general programming library in Java/Android. It's easy to learn and simple to * Gradle: ```gradle // JDK 1.8 or above: -compile 'com.landawn:abacus-util:1.5.6' +compile 'com.landawn:abacus-util:1.5.7' // JDK 1.7: -compile 'com.landawn:abacus-util-jdk7:1.5.6' +compile 'com.landawn:abacus-util-jdk7:1.5.7' // Android (Java 1.7): -compile 'abacus-android-jdk7:1.5.6' +compile 'abacus-android-jdk7:1.5.7' // Android-SE (Java 1.7) - small edition without Stream/Matrix/Sheet/...: -compile 'abacus-android-se-jdk7:1.5.6' +compile 'abacus-android-se-jdk7:1.5.7' // Android (Java 1.8 or above): -compile 'com.landawn:abacus-android:1.5.6' +compile 'com.landawn:abacus-android:1.5.7' // Android-SE (Java 1.8 or above) - small edition without Stream/Matrix/Sheet/...: -compile 'com.landawn:abacus-android-se:1.5.6' +compile 'com.landawn:abacus-android-se:1.5.7' ``` ### Functional Programming: (It's very important to learn Lambdas and Stream APIs in Java 8 to get the best user experiences with the APIs provided in AbacusUtil) diff --git a/docs/Stream.gif b/docs/Stream.gif index d85915e8..27ba9b28 100644 Binary files a/docs/Stream.gif and b/docs/Stream.gif differ diff --git a/lib/abacus-android-1.5.6.jar b/lib/abacus-android-1.5.7.jar similarity index 65% rename from lib/abacus-android-1.5.6.jar rename to lib/abacus-android-1.5.7.jar index d2e1e63c..cd6a7119 100644 Binary files a/lib/abacus-android-1.5.6.jar and b/lib/abacus-android-1.5.7.jar differ diff --git a/lib/abacus-android-jdk7-1.5.6.jar b/lib/abacus-android-jdk7-1.5.7.jar similarity index 64% rename from lib/abacus-android-jdk7-1.5.6.jar rename to lib/abacus-android-jdk7-1.5.7.jar index b6623a47..e0af1ef8 100644 Binary files a/lib/abacus-android-jdk7-1.5.6.jar and b/lib/abacus-android-jdk7-1.5.7.jar differ diff --git a/lib/abacus-android-se-1.5.6.jar b/lib/abacus-android-se-1.5.7.jar similarity index 70% rename from lib/abacus-android-se-1.5.6.jar rename to lib/abacus-android-se-1.5.7.jar index 256d9df1..6d31b0fe 100644 Binary files a/lib/abacus-android-se-1.5.6.jar and b/lib/abacus-android-se-1.5.7.jar differ diff --git a/lib/abacus-android-se-jdk7-1.5.6.jar b/lib/abacus-android-se-jdk7-1.5.7.jar similarity index 70% rename from lib/abacus-android-se-jdk7-1.5.6.jar rename to lib/abacus-android-se-jdk7-1.5.7.jar index 05e5cc71..75e063dc 100644 Binary files a/lib/abacus-android-se-jdk7-1.5.6.jar and b/lib/abacus-android-se-jdk7-1.5.7.jar differ diff --git a/lib/abacus-util-1.5.7.jar b/lib/abacus-util-1.5.7.jar index ce2ef0e0..8b52a2c6 100644 Binary files a/lib/abacus-util-1.5.7.jar and b/lib/abacus-util-1.5.7.jar differ diff --git a/lib/abacus-util-jdk7-1.5.7.jar b/lib/abacus-util-jdk7-1.5.7.jar index 6639fec5..999bd779 100644 Binary files a/lib/abacus-util-jdk7-1.5.7.jar and b/lib/abacus-util-jdk7-1.5.7.jar differ diff --git a/src/com/landawn/abacus/android/util/SQLiteExecutor.java b/src/com/landawn/abacus/android/util/SQLiteExecutor.java index c3274946..e23b2ee5 100644 --- a/src/com/landawn/abacus/android/util/SQLiteExecutor.java +++ b/src/com/landawn/abacus/android/util/SQLiteExecutor.java @@ -2079,7 +2079,7 @@ private String parseStringCondition(String expr) { if (!StringUtil.isAsciiAlpha(word.charAt(0))) { sb.append(word); - } else if (i < len - 1 && words.get(i + 1).charAt(0) == WD._PARENTHESES_L) { + } else if (SQLParser.isFunctionName(words, len, i)) { sb.append(word); } else { sb.append(formatName(word)); diff --git a/src/com/landawn/abacus/http/HTTP.java b/src/com/landawn/abacus/http/HTTP.java index e3531c60..bccde65a 100644 --- a/src/com/landawn/abacus/http/HTTP.java +++ b/src/com/landawn/abacus/http/HTTP.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.HttpURLConnection; import java.nio.charset.Charset; import java.util.EnumMap; import java.util.HashMap; @@ -245,6 +246,56 @@ public static OutputStream wrapOutputStream(final OutputStream os, final Content } } + public static ContentFormat getContentFormat(final HttpURLConnection connection) { + return getContentFormat(connection.getHeaderField(HttpHeaders.Names.CONTENT_TYPE), connection.getHeaderField(HttpHeaders.Names.CONTENT_ENCODING)); + } + + public static OutputStream getOutputStream(final HttpURLConnection connection, final ContentFormat contentFormat) throws IOException { + return getOutputStream(connection, contentFormat, HTTP.getContentType(contentFormat), HTTP.getContentEncoding(contentFormat)); + } + + public static OutputStream getOutputStream(final HttpURLConnection connection, final ContentFormat contentFormat, String contentType, + String contentEncoding) throws IOException { + + if (N.isNullOrEmpty(contentType) && contentFormat != null) { + contentType = getContentType(contentFormat); + } + + if (N.notNullOrEmpty(contentType)) { + connection.setRequestProperty(HttpHeaders.Names.CONTENT_TYPE, contentType); + } + + if (N.isNullOrEmpty(contentEncoding) && contentFormat != null) { + contentEncoding = getContentEncoding(contentFormat); + } + + if (N.notNullOrEmpty(contentEncoding)) { + connection.setRequestProperty(HttpHeaders.Names.CONTENT_ENCODING, contentEncoding); + } + + return wrapOutputStream(connection.getOutputStream(), contentFormat); + } + + public static InputStream getInputStream(final HttpURLConnection connection) throws IOException { + return getInputStream(connection, getContentFormat(connection)); + } + + public static InputStream getInputStream(final HttpURLConnection connection, ContentFormat contentFormat) throws IOException { + return wrapInputStream(connection.getInputStream(), contentFormat); + } + + public static InputStream getInputOrErrorStream(final HttpURLConnection connection) throws IOException { + return getInputOrErrorStream(connection, getContentFormat(connection)); + } + + public static InputStream getInputOrErrorStream(final HttpURLConnection connection, ContentFormat contentFormat) throws IOException { + try { + return wrapInputStream(connection.getInputStream(), contentFormat); + } catch (IOException e) { + return wrapInputStream(connection.getErrorStream(), contentFormat); + } + } + public static void flush(OutputStream os) throws IOException { if (os instanceof LZ4BlockOutputStream) { ((LZ4BlockOutputStream) os).finish(); @@ -255,13 +306,26 @@ public static void flush(OutputStream os) throws IOException { os.flush(); } - static Charset getCharset(Map> headers) { + public static Charset getCharset(HttpHeaders headers) { + Charset charset = Charsets.UTF_8; + + if (headers != null && headers.headerNameSet().contains(HttpHeaders.Names.CONTENT_TYPE)) { + String value = N.stringOf(headers.get(HttpHeaders.Names.CONTENT_TYPE)); + if (value.indexOf("charset=") >= 0) { + charset = getCharset(value); + } + } + + return charset; + } + + public static Charset getCharset(Map> headers) { Charset charset = Charsets.UTF_8; if (headers != null && headers.containsKey(HttpHeaders.Names.CONTENT_TYPE)) { for (String value : headers.get(HttpHeaders.Names.CONTENT_TYPE)) { if (value.indexOf("charset=") >= 0) { - charset = Charsets.get(value.substring(value.indexOf("charset=") + "charset=".length())); + charset = getCharset(value); break; } } @@ -269,4 +333,11 @@ static Charset getCharset(Map> headers) { return charset; } + + private static Charset getCharset(String value) { + int fromIndex = value.indexOf("charset="); + int toIndex = value.indexOf(';', fromIndex); + + return Charsets.get(value.substring(fromIndex + "charset=".length(), toIndex > 0 ? toIndex : value.length())); + } } diff --git a/src/com/landawn/abacus/http/HttpClient.java b/src/com/landawn/abacus/http/HttpClient.java index 854dd2d5..a293f245 100644 --- a/src/com/landawn/abacus/http/HttpClient.java +++ b/src/com/landawn/abacus/http/HttpClient.java @@ -19,7 +19,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.net.HttpURLConnection; @@ -161,20 +163,21 @@ private T execute(final Class resultClass, final OutputStream outputStrea final Object request, final HttpSettings settings) { final ContentFormat requestContentFormat = getContentFormat(settings); final HttpURLConnection connection = openConnection(httpMethod, request, request != null, settings); + final Charset requestCharset = HTTP.getCharset(settings == null || settings.headers().isEmpty() ? _settings.headers() : settings.headers()); final long sentRequestAtMillis = System.currentTimeMillis(); InputStream is = null; OutputStream os = null; try { if (request != null && (httpMethod.equals(HttpMethod.POST) || httpMethod.equals(HttpMethod.PUT))) { - os = getOutputStream(connection, requestContentFormat, settings); + os = HTTP.getOutputStream(connection, requestContentFormat, getContentType(settings), getContentEncoding(settings)); Type type = N.typeOf(request.getClass()); if (type.isInputStream()) { IOUtil.write(os, (InputStream) request); } else if (type.isReader()) { - final BufferedWriter bw = Objectory.createBufferedWriter(os); + final BufferedWriter bw = Objectory.createBufferedWriter(new OutputStreamWriter(os, requestCharset)); try { IOUtil.write(bw, (Reader) request); @@ -185,24 +188,25 @@ private T execute(final Class resultClass, final OutputStream outputStrea } } else { if (type.isSerializable()) { - os.write(type.stringOf(request).getBytes()); + os.write(type.stringOf(request).getBytes(requestCharset)); } else { - HTTP.getParser(requestContentFormat).serialize(os, request); + HTTP.getParser(requestContentFormat).serialize(new OutputStreamWriter(os, requestCharset), request); } } - flush(os); + HTTP.flush(os); } + final ContentFormat responseContentFormat = HTTP.getContentFormat(connection); final int code = connection.getResponseCode(); + final Map> respHeaders = connection.getHeaderFields(); + final Charset respCharset = HTTP.getCharset(respHeaders); + is = HTTP.getInputOrErrorStream(connection, responseContentFormat); if ((code < 200 || code >= 300) && (resultClass == null || !resultClass.equals(HttpResponse.class))) { - throw new UncheckedIOException(new IOException(code + ": " + connection.getResponseMessage())); + throw new UncheckedIOException(new IOException(code + ": " + connection.getResponseMessage() + ". " + IOUtil.readString(is, respCharset))); } - final ContentFormat responseContentFormat = getContentFormat(connection); - is = getInputStream(connection, responseContentFormat); - if (isOneWayRequest(settings)) { return null; } else { @@ -211,7 +215,7 @@ private T execute(final Class resultClass, final OutputStream outputStrea return null; } else if (outputWriter != null) { - final BufferedReader br = Objectory.createBufferedReader(is); + final BufferedReader br = Objectory.createBufferedReader(new InputStreamReader(is, respCharset)); try { IOUtil.write(outputWriter, br, true); @@ -221,8 +225,6 @@ private T execute(final Class resultClass, final OutputStream outputStrea return null; } else { - final Map> respHeaders = connection.getHeaderFields(); - if (resultClass != null && resultClass.equals(HttpResponse.class)) { final byte[] respBody = IOUtil.readBytes(is); @@ -230,16 +232,15 @@ private T execute(final Class resultClass, final OutputStream outputStrea respBody, responseContentFormat); } else { final Type type = resultClass == null ? null : N.typeOf(resultClass); - final Charset charset = HTTP.getCharset(respHeaders); if (type == null) { - return (T) IOUtil.readString(is, charset); + return (T) IOUtil.readString(is, respCharset); } else if (byte[].class.equals(resultClass)) { return (T) IOUtil.readBytes(is); } else if (type.isSerializable()) { - return (T) type.valueOf(IOUtil.readString(is, charset)); + return (T) type.valueOf(IOUtil.readString(is, respCharset)); } else { - return HTTP.getParser(responseContentFormat).deserialize(resultClass, IOUtil.newBufferedReader(is, charset)); + return HTTP.getParser(responseContentFormat).deserialize(resultClass, IOUtil.newBufferedReader(is, respCharset)); } } } @@ -251,68 +252,23 @@ private T execute(final Class resultClass, final OutputStream outputStrea } } - public OutputStream getOutputStream(final HttpURLConnection connection, final ContentFormat contentFormat) throws IOException { - return getOutputStream(connection, contentFormat, null); - } - - public OutputStream getOutputStream(final HttpURLConnection connection, final HttpSettings settings) throws IOException { - return getOutputStream(connection, null, settings); - } - - private OutputStream getOutputStream(final HttpURLConnection connection, final ContentFormat contentFormat, final HttpSettings settings) - throws IOException { - String contentType = getContentType(settings); - - if (N.isNullOrEmpty(contentType) && contentFormat != null) { - contentType = HTTP.getContentType(contentFormat); - } - - if (N.notNullOrEmpty(contentType)) { - connection.setRequestProperty(HttpHeaders.Names.CONTENT_TYPE, contentType); - } - - String contentEncoding = getContentEncoding(settings); - - if (N.isNullOrEmpty(contentEncoding) && contentFormat != null) { - contentEncoding = HTTP.getContentEncoding(contentFormat); - } - - if (N.notNullOrEmpty(contentEncoding)) { - connection.setRequestProperty(HttpHeaders.Names.CONTENT_ENCODING, contentEncoding); - } - - return HTTP.wrapOutputStream(connection.getOutputStream(), contentFormat == null ? getContentFormat(settings) : contentFormat); - } - - public InputStream getInputStream(final HttpURLConnection connection) throws IOException { - return getInputStream(connection, getContentFormat(connection)); - } - - public InputStream getInputStream(final HttpURLConnection connection, ContentFormat contentFormat) throws IOException { - return HTTP.wrapInputStream(connection.getInputStream(), contentFormat); - } - - ContentFormat getContentFormat(final HttpURLConnection connection) { - return HTTP.getContentFormat(connection.getHeaderField(HttpHeaders.Names.CONTENT_TYPE), connection.getHeaderField(HttpHeaders.Names.CONTENT_ENCODING)); - } - - public HttpURLConnection openConnection(HttpMethod httpMethod) { + HttpURLConnection openConnection(HttpMethod httpMethod) { return openConnection(httpMethod, HttpMethod.POST.equals(httpMethod) || HttpMethod.PUT.equals(httpMethod)); } - public HttpURLConnection openConnection(HttpMethod httpMethod, boolean doOutput) { + HttpURLConnection openConnection(HttpMethod httpMethod, boolean doOutput) { return openConnection(httpMethod, doOutput, _settings); } - public HttpURLConnection openConnection(HttpMethod httpMethod, HttpSettings settings) { + HttpURLConnection openConnection(HttpMethod httpMethod, HttpSettings settings) { return openConnection(httpMethod, HttpMethod.POST.equals(httpMethod) || HttpMethod.PUT.equals(httpMethod), settings); } - public HttpURLConnection openConnection(HttpMethod httpMethod, boolean doOutput, HttpSettings settings) { + HttpURLConnection openConnection(HttpMethod httpMethod, boolean doOutput, HttpSettings settings) { return openConnection(httpMethod, null, doOutput, settings); } - public HttpURLConnection openConnection(HttpMethod httpMethod, final Object queryParameters, boolean doOutput, HttpSettings settings) { + HttpURLConnection openConnection(HttpMethod httpMethod, final Object queryParameters, boolean doOutput, HttpSettings settings) { HttpURLConnection connection = null; if (_activeConnectionCounter.incrementAndGet() > _maxConnection) { @@ -379,22 +335,7 @@ public HttpURLConnection openConnection(HttpMethod httpMethod, final Object quer } } - void close(OutputStream os, InputStream is, HttpURLConnection connection) { - try { - IOUtil.closeQuietly(os); - IOUtil.closeQuietly(is); - } finally { - _activeConnectionCounter.decrementAndGet(); - } - - // connection.disconnect(); - } - - protected void flush(OutputStream os) throws IOException { - HTTP.flush(os); - } - - private void setHttpProperties(HttpURLConnection connection, HttpSettings settings) { + void setHttpProperties(HttpURLConnection connection, HttpSettings settings) { final HttpHeaders headers = settings.headers(); if (headers != null) { @@ -419,4 +360,15 @@ private void setHttpProperties(HttpURLConnection connection, HttpSettings settin } } } + + void close(OutputStream os, InputStream is, HttpURLConnection connection) { + try { + IOUtil.closeQuietly(os); + IOUtil.closeQuietly(is); + } finally { + _activeConnectionCounter.decrementAndGet(); + } + + // connection.disconnect(); + } } diff --git a/src/com/landawn/abacus/http/HttpProxy.java b/src/com/landawn/abacus/http/HttpProxy.java index 7677f264..6bf418e9 100644 --- a/src/com/landawn/abacus/http/HttpProxy.java +++ b/src/com/landawn/abacus/http/HttpProxy.java @@ -21,10 +21,12 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.net.HttpURLConnection; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; @@ -409,7 +411,7 @@ private Object execute(final Method method, final Object[] args) { try { if (requestParameter != null && (operationConfig.httpMethod == HttpMethod.POST || operationConfig.httpMethod == HttpMethod.PUT)) { - os = httpClient.getOutputStream(connection, _contentFormat); + os = HTTP.getOutputStream(connection, _contentFormat); switch (_contentFormat) { case JSON: @@ -451,6 +453,7 @@ private Object execute(final Method method, final Object[] args) { HTTP.flush(os); } else { String contentType = HTTP.getContentType(_contentFormat); + // TODO if (N.notNullOrEmpty(contentType)) { connection.setRequestProperty(HttpHeaders.Names.CONTENT_TYPE, contentType); @@ -463,11 +466,13 @@ private Object execute(final Method method, final Object[] args) { } } - final ContentFormat responseContentFormat = httpClient.getContentFormat(connection); + final ContentFormat responseContentFormat = HTTP.getContentFormat(connection); + final Map> respHeaders = connection.getHeaderFields(); + final Charset charset = HTTP.getCharset(respHeaders); final Parser, DeserializationConfig> responseParser = responseContentFormat == _contentFormat ? _config.parser : HTTP.getParser(responseContentFormat); - is = httpClient.getInputStream(connection, responseContentFormat); + is = HTTP.getInputStream(connection, responseContentFormat); if (void.class.equals(returnType)) { return null; @@ -484,9 +489,9 @@ private Object execute(final Method method, final Object[] args) { type = N.typeOf(returnType); if (type.isSerializable()) { - result = type.valueOf(IOUtil.readString(is)); + result = type.valueOf(IOUtil.readString(is, charset)); } else { - result = responseParser.deserialize(returnType, is, _config.dc); + result = responseParser.deserialize(returnType, IOUtil.newBufferedReader(is, charset), _config.dc); } break; @@ -495,7 +500,7 @@ private Object execute(final Method method, final Object[] args) { case XML_LZ4: case XML_SNAPPY: case XML_GZIP: - result = responseParser.deserialize(returnType, is, _config.dc); + result = responseParser.deserialize(returnType, IOUtil.newBufferedReader(is, charset), _config.dc); break; case KRYO: diff --git a/src/com/landawn/abacus/http/OKHttpClient.java b/src/com/landawn/abacus/http/OKHttpClient.java index f6559ff7..37e86c16 100644 --- a/src/com/landawn/abacus/http/OKHttpClient.java +++ b/src/com/landawn/abacus/http/OKHttpClient.java @@ -19,7 +19,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.nio.charset.Charset; @@ -183,18 +185,20 @@ public void execute(final Writer output, final HttpMethod httpMethod, final Obje execute(null, null, output, httpMethod, request, settings); } + @SuppressWarnings("resource") private T execute(final Class resultClass, final OutputStream outputStream, final Writer outputWriter, final HttpMethod httpMethod, final Object request, final HttpSettings settings) { - final ContentFormat requestContentFormat = getContentFormat(settings); - final String contentType = getContentType(settings); - final String contentEncoding = getContentEncoding(settings); - if (_activeConnectionCounter.incrementAndGet() > _maxConnection) { _activeConnectionCounter.decrementAndGet(); throw new AbacusException("Can not get connection, exceeded max connection number: " + _maxConnection); } + final ContentFormat requestContentFormat = getContentFormat(settings); + final String contentType = getContentType(settings); + final String contentEncoding = getContentEncoding(settings); + final Charset requestCharset = HTTP.getCharset(settings == null || settings.headers().isEmpty() ? _settings.headers() : settings.headers()); + okhttp3.Request httpRequest = null; okhttp3.Response httpResponse = null; boolean closeOkHttpResponse = true; @@ -230,7 +234,7 @@ private T execute(final Class resultClass, final OutputStream outputStrea if (type.isInputStream()) { IOUtil.write(os, (InputStream) request); } else if (type.isReader()) { - final BufferedWriter bw = Objectory.createBufferedWriter(os); + final BufferedWriter bw = Objectory.createBufferedWriter(new OutputStreamWriter(os, requestCharset)); try { IOUtil.write(bw, (Reader) request); @@ -241,9 +245,9 @@ private T execute(final Class resultClass, final OutputStream outputStrea } } else { if (type.isSerializable()) { - IOUtil.write(os, type.stringOf(request).getBytes()); + IOUtil.write(os, type.stringOf(request).getBytes(requestCharset)); } else { - IOUtil.write(os, HTTP.getParser(requestContentFormat).serialize(request).getBytes()); + HTTP.getParser(requestContentFormat).serialize(new OutputStreamWriter(os, requestCharset), request); } } @@ -269,9 +273,17 @@ private T execute(final Class resultClass, final OutputStream outputStrea httpRequest = requestBuilder.build(); httpResponse = client.newCall(httpRequest).execute(); + final Map> respHeaders = httpResponse.headers().toMultimap(); + final Charset charset = HTTP.getCharset(respHeaders); + final ContentFormat responseContentFormat = HTTP.getContentFormat(httpResponse.header(HttpHeaders.Names.CONTENT_TYPE), + httpResponse.header(HttpHeaders.Names.CONTENT_ENCODING)); + + final InputStream is = httpResponse.isSuccessful() ? HTTP.wrapInputStream(httpResponse.body().byteStream(), responseContentFormat) + : httpResponse.body().byteStream(); + if (httpResponse.isSuccessful() == false && (resultClass == null || !(resultClass.equals(HttpResponse.class) || resultClass.equals(okhttp3.Response.class)))) { - throw new UncheckedIOException(new IOException(httpResponse.code() + ": " + httpResponse.message())); + throw new UncheckedIOException(new IOException(httpResponse.code() + ": " + httpResponse.message() + ". " + IOUtil.readString(is, charset))); } if (isOneWayRequest(settings)) { @@ -281,17 +293,12 @@ private T execute(final Class resultClass, final OutputStream outputStrea return (T) httpResponse; } else { - final ContentFormat responseContentFormat = HTTP.getContentFormat(httpResponse.header(HttpHeaders.Names.CONTENT_TYPE), - httpResponse.header(HttpHeaders.Names.CONTENT_ENCODING)); - - final InputStream is = HTTP.wrapInputStream(httpResponse.body().byteStream(), responseContentFormat); - if (outputStream != null) { IOUtil.write(outputStream, is, true); return null; } else if (outputWriter != null) { - final BufferedReader br = Objectory.createBufferedReader(is); + final BufferedReader br = Objectory.createBufferedReader(new InputStreamReader(is, charset)); try { IOUtil.write(outputWriter, br, true); @@ -301,14 +308,11 @@ private T execute(final Class resultClass, final OutputStream outputStrea return null; } else { - Map> respHeaders = httpResponse.headers().toMultimap(); - if (resultClass != null && resultClass.equals(HttpResponse.class)) { return (T) new HttpResponse(httpResponse.sentRequestAtMillis(), httpResponse.receivedResponseAtMillis(), httpResponse.code(), httpResponse.message(), respHeaders, IOUtil.readBytes(is), responseContentFormat); } else { final Type type = resultClass == null ? null : N.typeOf(resultClass); - final Charset charset = HTTP.getCharset(respHeaders); if (type == null) { return (T) IOUtil.readString(is, charset); diff --git a/src/com/landawn/abacus/util/Array.java b/src/com/landawn/abacus/util/Array.java index 9abf3c43..f58056eb 100644 --- a/src/com/landawn/abacus/util/Array.java +++ b/src/com/landawn/abacus/util/Array.java @@ -263,6 +263,17 @@ public static String[] of(final String... a) { return a; } + /** + * Returns the input array + * + * @param a + * @return + */ + @SafeVarargs + public static T[] oF(final T... a) { + return a; + } + // /** // * Returns the input array // * diff --git a/src/com/landawn/abacus/util/CQLBuilder.java b/src/com/landawn/abacus/util/CQLBuilder.java index 86cb10af..1e7e1e43 100644 --- a/src/com/landawn/abacus/util/CQLBuilder.java +++ b/src/com/landawn/abacus/util/CQLBuilder.java @@ -726,7 +726,7 @@ private void appendStringExpr(final String expr) { if (!StringUtil.isAsciiAlpha(word.charAt(0))) { sb.append(word); - } else if (i < len - 1 && words.get(i + 1).charAt(0) == WD._PARENTHESES_L) { + } else if (SQLParser.isFunctionName(words, len, i)) { sb.append(word); } else { sb.append(formalizeColumnName(propColumnNameMap, word)); @@ -845,7 +845,7 @@ public final CQLBuilder set(final String... columnNames) { sb.append(_SPACE_SET_SPACE); if (columnNames.length == 1 && SQLParser.parse(columnNames[0]).contains(WD.EQUAL)) { - sb.append(columnNames[0]); + appendStringExpr(columnNames[0]); } else { final Map propColumnNameMap = getPropColumnNameMap(); @@ -1139,7 +1139,7 @@ public CQLBuilder usingTimestamp(String timestamp) { return this; } - public CQLBuilder iff(final String expr) { + public CQLBuilder iF(final String expr) { init(true); sb.append(_SPACE_IF_SPACE); @@ -1154,7 +1154,7 @@ public CQLBuilder iff(final String expr) { * @param cond any literal written in Expression condition won't be formalized * @return */ - public CQLBuilder iff(final Condition cond) { + public CQLBuilder iF(final Condition cond) { init(true); sb.append(_SPACE_IF_SPACE); diff --git a/src/com/landawn/abacus/util/CSVUtil.java b/src/com/landawn/abacus/util/CSVUtil.java index 9bf47f31..e9112cb4 100644 --- a/src/com/landawn/abacus/util/CSVUtil.java +++ b/src/com/landawn/abacus/util/CSVUtil.java @@ -62,15 +62,16 @@ public final class CSVUtil { private static final JSONParser jsonParser = ParserFactory.createJSONParser(); - public static DataSet loadCSV(final File csvFile) { + public static DataSet loadCSV(final File csvFile) throws UncheckedIOException { return loadCSV(csvFile, (Collection) null); } - public static DataSet loadCSV(final File csvFile, final Collection selectColumnNames) { + public static DataSet loadCSV(final File csvFile, final Collection selectColumnNames) throws UncheckedIOException { return loadCSV(csvFile, selectColumnNames, 0, Long.MAX_VALUE); } - public static DataSet loadCSV(final File csvFile, final Collection selectColumnNames, final long offset, final long count) { + public static DataSet loadCSV(final File csvFile, final Collection selectColumnNames, final long offset, final long count) + throws UncheckedIOException { return loadCSV(csvFile, selectColumnNames, offset, count, Fn. alwaysTrue()); } @@ -85,7 +86,7 @@ public static DataSet loadCSV(final File csvFile, final Collection selec * @return */ public static DataSet loadCSV(final File csvFile, final Collection selectColumnNames, final long offset, final long count, - final Try.Predicate filter) throws E { + final Try.Predicate filter) throws UncheckedIOException, E { InputStream csvInputStream = null; try { @@ -99,15 +100,16 @@ public static DataSet loadCSV(final File csvFile, final Co } } - public static DataSet loadCSV(final InputStream csvInputStream) { + public static DataSet loadCSV(final InputStream csvInputStream) throws UncheckedIOException { return loadCSV(csvInputStream, (Collection) null); } - public static DataSet loadCSV(final InputStream csvInputStream, final Collection selectColumnNames) { + public static DataSet loadCSV(final InputStream csvInputStream, final Collection selectColumnNames) throws UncheckedIOException { return loadCSV(csvInputStream, selectColumnNames, 0, Long.MAX_VALUE); } - public static DataSet loadCSV(final InputStream csvInputStream, final Collection selectColumnNames, final long offset, final long count) { + public static DataSet loadCSV(final InputStream csvInputStream, final Collection selectColumnNames, final long offset, final long count) + throws UncheckedIOException { return loadCSV(csvInputStream, selectColumnNames, offset, count, Fn. alwaysTrue()); } @@ -122,21 +124,21 @@ public static DataSet loadCSV(final InputStream csvInputStream, final Collection * @return */ public static DataSet loadCSV(final InputStream csvInputStream, final Collection selectColumnNames, final long offset, - final long count, final Try.Predicate filter) throws E { + final long count, final Try.Predicate filter) throws UncheckedIOException, E { final Reader csvReader = new InputStreamReader(csvInputStream); return loadCSV(csvReader, selectColumnNames, offset, count, filter); } - public static DataSet loadCSV(final Reader csvReader) { + public static DataSet loadCSV(final Reader csvReader) throws UncheckedIOException { return loadCSV(csvReader, (Collection) null); } - public static DataSet loadCSV(final Reader csvReader, final Collection selectColumnNames) { + public static DataSet loadCSV(final Reader csvReader, final Collection selectColumnNames) throws UncheckedIOException { return loadCSV(csvReader, selectColumnNames, 0, Long.MAX_VALUE); } - public static DataSet loadCSV(final Reader csvReader, final Collection selectColumnNames, long offset, long count) { + public static DataSet loadCSV(final Reader csvReader, final Collection selectColumnNames, long offset, long count) throws UncheckedIOException { return loadCSV(csvReader, selectColumnNames, offset, count, Fn. alwaysTrue()); } @@ -151,7 +153,7 @@ public static DataSet loadCSV(final Reader csvReader, final Collection s * @return */ public static DataSet loadCSV(final Reader csvReader, final Collection selectColumnNames, long offset, long count, - final Try.Predicate filter) throws E { + final Try.Predicate filter) throws UncheckedIOException, E { N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count); final BufferedReader br = csvReader instanceof BufferedReader ? (BufferedReader) csvReader : Objectory.createBufferedReader(csvReader); @@ -211,16 +213,16 @@ public static DataSet loadCSV(final Reader csvReader, fina } } - public static DataSet loadCSV(final Class entityClass, final File csvFile) { + public static DataSet loadCSV(final Class entityClass, final File csvFile) throws UncheckedIOException { return loadCSV(entityClass, csvFile, null); } - public static DataSet loadCSV(final Class entityClass, final File csvFile, final Collection selectColumnNames) { + public static DataSet loadCSV(final Class entityClass, final File csvFile, final Collection selectColumnNames) throws UncheckedIOException { return loadCSV(entityClass, csvFile, selectColumnNames, 0, Long.MAX_VALUE); } public static DataSet loadCSV(final Class entityClass, final File csvFile, final Collection selectColumnNames, final long offset, - final long count) { + final long count) throws UncheckedIOException { return loadCSV(entityClass, csvFile, selectColumnNames, offset, count, Fn. alwaysTrue()); } @@ -236,7 +238,7 @@ public static DataSet loadCSV(final Class entityClass, final File csvFile, fi * @return */ public static DataSet loadCSV(final Class entityClass, final File csvFile, final Collection selectColumnNames, - final long offset, final long count, final Try.Predicate filter) throws E { + final long offset, final long count, final Try.Predicate filter) throws UncheckedIOException, E { InputStream csvInputStream = null; try { @@ -250,16 +252,17 @@ public static DataSet loadCSV(final Class entityClass, } } - public static DataSet loadCSV(final Class entityClass, final InputStream csvInputStream) { + public static DataSet loadCSV(final Class entityClass, final InputStream csvInputStream) throws UncheckedIOException { return loadCSV(entityClass, csvInputStream, null); } - public static DataSet loadCSV(final Class entityClass, final InputStream csvInputStream, final Collection selectColumnNames) { + public static DataSet loadCSV(final Class entityClass, final InputStream csvInputStream, final Collection selectColumnNames) + throws UncheckedIOException { return loadCSV(entityClass, csvInputStream, selectColumnNames, 0, Long.MAX_VALUE); } public static DataSet loadCSV(final Class entityClass, final InputStream csvInputStream, final Collection selectColumnNames, final long offset, - final long count) { + final long count) throws UncheckedIOException { return loadCSV(entityClass, csvInputStream, selectColumnNames, offset, count, Fn. alwaysTrue()); } @@ -275,20 +278,22 @@ public static DataSet loadCSV(final Class entityClass, final InputStream csvI * @return */ public static DataSet loadCSV(final Class entityClass, final InputStream csvInputStream, - final Collection selectColumnNames, final long offset, final long count, final Try.Predicate filter) throws E { + final Collection selectColumnNames, final long offset, final long count, final Try.Predicate filter) + throws UncheckedIOException, E { final Reader csvReader = new InputStreamReader(csvInputStream); return loadCSV(entityClass, csvReader, selectColumnNames, offset, count, filter); } - public static DataSet loadCSV(final Class entityClass, final Reader csvReader) { + public static DataSet loadCSV(final Class entityClass, final Reader csvReader) throws UncheckedIOException { return loadCSV(entityClass, csvReader, null); } - public static DataSet loadCSV(final Class entityClass, final Reader csvReader, final Collection selectColumnNames) { + public static DataSet loadCSV(final Class entityClass, final Reader csvReader, final Collection selectColumnNames) throws UncheckedIOException { return loadCSV(entityClass, csvReader, selectColumnNames, 0, Long.MAX_VALUE); } - public static DataSet loadCSV(final Class entityClass, final Reader csvReader, final Collection selectColumnNames, long offset, long count) { + public static DataSet loadCSV(final Class entityClass, final Reader csvReader, final Collection selectColumnNames, long offset, long count) + throws UncheckedIOException { return loadCSV(entityClass, csvReader, selectColumnNames, offset, count, Fn. alwaysTrue()); } @@ -302,9 +307,11 @@ public static DataSet loadCSV(final Class entityClass, final Reader csvReader * @param count * @param filter * @return + * @throws UncheckedIOException + * @throws E */ public static DataSet loadCSV(final Class entityClass, final Reader csvReader, final Collection selectColumnNames, - long offset, long count, final Try.Predicate filter) throws E { + long offset, long count, final Try.Predicate filter) throws UncheckedIOException, E { N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count); final BufferedReader br = csvReader instanceof BufferedReader ? (BufferedReader) csvReader : Objectory.createBufferedReader(csvReader); @@ -374,12 +381,13 @@ public static DataSet loadCSV(final Class entityClass, } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final File csvFile, final Map columnTypeMap) { + public static DataSet loadCSV(final File csvFile, final Map columnTypeMap) throws UncheckedIOException { return loadCSV(csvFile, 0, Long.MAX_VALUE, columnTypeMap); } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final File csvFile, final long offset, final long count, final Map columnTypeMap) { + public static DataSet loadCSV(final File csvFile, final long offset, final long count, final Map columnTypeMap) + throws UncheckedIOException { return loadCSV(csvFile, offset, count, Fn. alwaysTrue(), columnTypeMap); } @@ -395,7 +403,7 @@ public static DataSet loadCSV(final File csvFile, final long offset, final long */ @SuppressWarnings("rawtypes") public static DataSet loadCSV(final File csvFile, final long offset, final long count, final Try.Predicate filter, - final Map columnTypeMap) throws E { + final Map columnTypeMap) throws UncheckedIOException, E { InputStream csvInputStream = null; try { @@ -410,12 +418,13 @@ public static DataSet loadCSV(final File csvFile, final lo } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final InputStream csvInputStream, final Map columnTypeMap) { + public static DataSet loadCSV(final InputStream csvInputStream, final Map columnTypeMap) throws UncheckedIOException { return loadCSV(csvInputStream, 0, Long.MAX_VALUE, columnTypeMap); } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final InputStream csvInputStream, final long offset, final long count, final Map columnTypeMap) { + public static DataSet loadCSV(final InputStream csvInputStream, final long offset, final long count, final Map columnTypeMap) + throws UncheckedIOException { return loadCSV(csvInputStream, offset, count, Fn. alwaysTrue(), columnTypeMap); } @@ -431,19 +440,20 @@ public static DataSet loadCSV(final InputStream csvInputStream, final long offse */ @SuppressWarnings("rawtypes") public static DataSet loadCSV(final InputStream csvInputStream, final long offset, final long count, - final Try.Predicate filter, final Map columnTypeMap) throws E { + final Try.Predicate filter, final Map columnTypeMap) throws UncheckedIOException, E { final Reader csvReader = new InputStreamReader(csvInputStream); return loadCSV(csvReader, offset, count, filter, columnTypeMap); } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final Reader csvReader, final Map columnTypeMap) { + public static DataSet loadCSV(final Reader csvReader, final Map columnTypeMap) throws UncheckedIOException { return loadCSV(csvReader, 0, Long.MAX_VALUE, columnTypeMap); } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final Reader csvReader, long offset, long count, final Map columnTypeMap) { + public static DataSet loadCSV(final Reader csvReader, long offset, long count, final Map columnTypeMap) + throws UncheckedIOException { return loadCSV(csvReader, offset, count, Fn. alwaysTrue(), columnTypeMap); } @@ -459,7 +469,7 @@ public static DataSet loadCSV(final Reader csvReader, long offset, long count, f */ @SuppressWarnings("rawtypes") public static DataSet loadCSV(final Reader csvReader, long offset, long count, final Try.Predicate filter, - final Map columnTypeMap) throws E { + final Map columnTypeMap) throws UncheckedIOException, E { N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count); if (N.isNullOrEmpty(columnTypeMap)) { @@ -525,12 +535,13 @@ public static DataSet loadCSV(final Reader csvReader, long } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final File csvFile, final List columnTypeList) { + public static DataSet loadCSV(final File csvFile, final List columnTypeList) throws UncheckedIOException { return loadCSV(csvFile, 0, Long.MAX_VALUE, columnTypeList); } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final File csvFile, final long offset, final long count, final List columnTypeList) { + public static DataSet loadCSV(final File csvFile, final long offset, final long count, final List columnTypeList) + throws UncheckedIOException { return loadCSV(csvFile, offset, count, Fn. alwaysTrue(), columnTypeList); } @@ -546,7 +557,7 @@ public static DataSet loadCSV(final File csvFile, final long offset, final long */ @SuppressWarnings("rawtypes") public static DataSet loadCSV(final File csvFile, final long offset, final long count, final Try.Predicate filter, - final List columnTypeList) throws E { + final List columnTypeList) throws UncheckedIOException, E { InputStream csvInputStream = null; try { @@ -561,12 +572,13 @@ public static DataSet loadCSV(final File csvFile, final lo } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final InputStream csvInputStream, final List columnTypeList) { + public static DataSet loadCSV(final InputStream csvInputStream, final List columnTypeList) throws UncheckedIOException { return loadCSV(csvInputStream, 0, Long.MAX_VALUE, columnTypeList); } @SuppressWarnings("rawtypes") - public static DataSet loadCSV(final InputStream csvInputStream, final long offset, final long count, final List columnTypeList) { + public static DataSet loadCSV(final InputStream csvInputStream, final long offset, final long count, final List columnTypeList) + throws UncheckedIOException { return loadCSV(csvInputStream, offset, count, Fn. alwaysTrue(), columnTypeList); } @@ -610,7 +622,7 @@ public static DataSet loadCSV(final Reader csvReader, long offset, long count, f */ @SuppressWarnings("rawtypes") public static DataSet loadCSV(final Reader csvReader, long offset, long count, final Try.Predicate filter, - final List columnTypeList) throws E { + final List columnTypeList) throws UncheckedIOException, E { N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count); if (N.isNullOrEmpty(columnTypeList)) { @@ -676,7 +688,7 @@ public static DataSet loadCSV(final Reader csvReader, long * @param querySQL * @return */ - public static long exportCSV(final File out, final Connection conn, final String querySQL) { + public static long exportCSV(final File out, final Connection conn, final String querySQL) throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, conn, querySQL, 0, Long.MAX_VALUE, true, true); } @@ -693,7 +705,7 @@ public static long exportCSV(final File out, final Connection conn, final String * @return */ public static long exportCSV(final File out, final Connection conn, final String querySQL, final long offset, final long count, final boolean writeTitle, - final boolean quoted) { + final boolean quoted) throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, conn, querySQL, null, offset, count, writeTitle, quoted); } @@ -711,7 +723,7 @@ public static long exportCSV(final File out, final Connection conn, final String * @return */ public static long exportCSV(final File out, final Connection conn, final String querySQL, final Collection selectColumnNames, final long offset, - final long count, final boolean writeTitle, final boolean quoted) { + final long count, final boolean writeTitle, final boolean quoted) throws UncheckedSQLException, UncheckedIOException { final NamedSQL namedSQL = NamedSQL.parse(querySQL); PreparedStatement stmt = null; @@ -735,7 +747,7 @@ public static long exportCSV(final File out, final Connection conn, final String * @return */ @SuppressWarnings("unchecked") - public static long exportCSV(final File out, final PreparedStatement stmt) { + public static long exportCSV(final File out, final PreparedStatement stmt) throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, stmt, 0, Long.MAX_VALUE, true, true); } @@ -751,7 +763,7 @@ public static long exportCSV(final File out, final PreparedStatement stmt) { * @return */ public static long exportCSV(final File out, final PreparedStatement stmt, final long offset, final long count, final boolean writeTitle, - final boolean quoted) { + final boolean quoted) throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, stmt, null, offset, count, writeTitle, quoted); } @@ -768,7 +780,7 @@ public static long exportCSV(final File out, final PreparedStatement stmt, final * @return */ public static long exportCSV(final File out, final PreparedStatement stmt, final Collection selectColumnNames, final long offset, final long count, - final boolean writeTitle, final boolean quoted) { + final boolean writeTitle, final boolean quoted) throws UncheckedSQLException, UncheckedIOException { ResultSet rs = null; try { @@ -790,7 +802,7 @@ public static long exportCSV(final File out, final PreparedStatement stmt, final * @param rs * @return */ - public static long exportCSV(final File out, final ResultSet rs) { + public static long exportCSV(final File out, final ResultSet rs) throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, rs, 0, Long.MAX_VALUE, true, true); } @@ -805,7 +817,8 @@ public static long exportCSV(final File out, final ResultSet rs) { * @param quoted * @return */ - public static long exportCSV(final File out, final ResultSet rs, final long offset, final long count, final boolean writeTitle, final boolean quoted) { + public static long exportCSV(final File out, final ResultSet rs, final long offset, final long count, final boolean writeTitle, final boolean quoted) + throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, rs, null, offset, count, writeTitle, quoted); } @@ -821,7 +834,7 @@ public static long exportCSV(final File out, final ResultSet rs, final long offs * @return */ public static long exportCSV(final File out, final ResultSet rs, final Collection selectColumnNames, final long offset, final long count, - final boolean writeTitle, final boolean quoted) { + final boolean writeTitle, final boolean quoted) throws UncheckedSQLException, UncheckedIOException { OutputStream os = null; try { @@ -850,7 +863,7 @@ public static long exportCSV(final File out, final ResultSet rs, final Collectio * @param rs * @return */ - public static long exportCSV(final OutputStream out, final ResultSet rs) { + public static long exportCSV(final OutputStream out, final ResultSet rs) throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, rs, 0, Long.MAX_VALUE, true, true); } @@ -866,7 +879,7 @@ public static long exportCSV(final OutputStream out, final ResultSet rs) { * @return */ public static long exportCSV(final OutputStream out, final ResultSet rs, final long offset, final long count, final boolean writeTitle, - final boolean quoted) { + final boolean quoted) throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, rs, null, offset, count, writeTitle, quoted); } @@ -883,7 +896,7 @@ public static long exportCSV(final OutputStream out, final ResultSet rs, final l * @return */ public static long exportCSV(final OutputStream out, final ResultSet rs, final Collection selectColumnNames, final long offset, final long count, - final boolean writeTitle, final boolean quoted) { + final boolean writeTitle, final boolean quoted) throws UncheckedSQLException, UncheckedIOException { Writer writer = null; try { @@ -906,7 +919,7 @@ public static long exportCSV(final OutputStream out, final ResultSet rs, final C * @param rs * @return */ - public static long exportCSV(final Writer out, final ResultSet rs) { + public static long exportCSV(final Writer out, final ResultSet rs) throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, rs, 0, Long.MAX_VALUE, true, true); } @@ -921,7 +934,8 @@ public static long exportCSV(final Writer out, final ResultSet rs) { * @param quoted * @return */ - public static long exportCSV(final Writer out, final ResultSet rs, final long offset, final long count, final boolean writeTitle, final boolean quoted) { + public static long exportCSV(final Writer out, final ResultSet rs, final long offset, final long count, final boolean writeTitle, final boolean quoted) + throws UncheckedSQLException, UncheckedIOException { return exportCSV(out, rs, null, offset, count, writeTitle, quoted); } @@ -938,7 +952,7 @@ public static long exportCSV(final Writer out, final ResultSet rs, final long of * @return */ public static long exportCSV(final Writer out, final ResultSet rs, final Collection selectColumnNames, long offset, final long count, - final boolean writeTitle, final boolean quoted) { + final boolean writeTitle, final boolean quoted) throws UncheckedSQLException, UncheckedIOException { N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count); final JSONSerializationConfig config = JSC.create(); @@ -1054,13 +1068,14 @@ public static long exportCSV(final Writer out, final ResultSet rs, final Collect } @SuppressWarnings("rawtypes") - public static long importCSV(final File file, final Connection conn, final String insertSQL, final List columnTypeList) { + public static long importCSV(final File file, final Connection conn, final String insertSQL, final List columnTypeList) + throws UncheckedSQLException, UncheckedIOException { return importCSV(file, 0, Long.MAX_VALUE, true, conn, insertSQL, 200, 0, columnTypeList); } @SuppressWarnings({ "unchecked", "rawtypes" }) public static long importCSV(final File file, final long offset, final long count, final boolean skipTitle, final Connection conn, final String insertSQL, - final int batchSize, final int batchInterval, final List columnTypeList) { + final int batchSize, final int batchInterval, final List columnTypeList) throws UncheckedSQLException, UncheckedIOException { return importCSV(file, offset, count, skipTitle, Fn. alwaysTrue(), conn, insertSQL, batchSize, batchInterval, columnTypeList); } @@ -1082,7 +1097,7 @@ public static long importCSV(final File file, final long offset, final long coun @SuppressWarnings("rawtypes") public static long importCSV(final File file, final long offset, final long count, final boolean skipTitle, final Try.Predicate filter, final Connection conn, final String insertSQL, final int batchSize, final int batchInterval, - final List columnTypeList) throws E { + final List columnTypeList) throws UncheckedSQLException, UncheckedIOException, E { PreparedStatement stmt = null; try { @@ -1097,13 +1112,14 @@ public static long importCSV(final File file, final long o } @SuppressWarnings("rawtypes") - public static long importCSV(final File file, final PreparedStatement stmt, final List columnTypeList) { + public static long importCSV(final File file, final PreparedStatement stmt, final List columnTypeList) + throws UncheckedSQLException, UncheckedIOException { return importCSV(file, 0, Long.MAX_VALUE, true, stmt, 200, 0, columnTypeList); } @SuppressWarnings({ "unchecked", "rawtypes" }) public static long importCSV(final File file, long offset, final long count, final boolean skipTitle, final PreparedStatement stmt, final int batchSize, - final int batchInterval, final List columnTypeList) { + final int batchInterval, final List columnTypeList) throws UncheckedSQLException, UncheckedIOException { return importCSV(file, offset, count, skipTitle, Fn. alwaysTrue(), stmt, batchSize, batchInterval, columnTypeList); } @@ -1124,7 +1140,7 @@ public static long importCSV(final File file, long offset, final long count, fin @SuppressWarnings("rawtypes") public static long importCSV(final File file, final long offset, final long count, final boolean skipTitle, final Try.Predicate filter, final PreparedStatement stmt, final int batchSize, final int batchInterval, - final List columnTypeList) throws E { + final List columnTypeList) throws UncheckedSQLException, UncheckedIOException, E { Reader reader = null; try { @@ -1139,13 +1155,14 @@ public static long importCSV(final File file, final long o } @SuppressWarnings("rawtypes") - public static long importCSV(final InputStream is, final PreparedStatement stmt, final List columnTypeList) { + public static long importCSV(final InputStream is, final PreparedStatement stmt, final List columnTypeList) + throws UncheckedSQLException, UncheckedIOException { return importCSV(is, 0, Long.MAX_VALUE, true, stmt, 200, 0, columnTypeList); } @SuppressWarnings({ "unchecked", "rawtypes" }) public static long importCSV(final InputStream is, long offset, final long count, final boolean skipTitle, final PreparedStatement stmt, - final int batchSize, final int batchInterval, final List columnTypeList) { + final int batchSize, final int batchInterval, final List columnTypeList) throws UncheckedSQLException, UncheckedIOException { return importCSV(is, offset, count, skipTitle, Fn. alwaysTrue(), stmt, batchSize, batchInterval, columnTypeList); } @@ -1166,20 +1183,21 @@ public static long importCSV(final InputStream is, long offset, final long count @SuppressWarnings("rawtypes") public static long importCSV(final InputStream is, final long offset, final long count, final boolean skipTitle, final Try.Predicate filter, final PreparedStatement stmt, final int batchSize, final int batchInterval, - final List columnTypeList) throws E { + final List columnTypeList) throws UncheckedSQLException, UncheckedIOException, E { final Reader reader = new InputStreamReader(is); return importCSV(reader, offset, count, skipTitle, filter, stmt, batchSize, batchInterval, columnTypeList); } @SuppressWarnings("rawtypes") - public static long importCSV(final Reader reader, final PreparedStatement stmt, final List columnTypeList) { + public static long importCSV(final Reader reader, final PreparedStatement stmt, final List columnTypeList) + throws UncheckedSQLException, UncheckedIOException { return importCSV(reader, 0, Long.MAX_VALUE, true, stmt, 200, 0, columnTypeList); } @SuppressWarnings({ "unchecked", "rawtypes" }) public static long importCSV(final Reader reader, long offset, final long count, final boolean skipTitle, final PreparedStatement stmt, final int batchSize, - final int batchInterval, final List columnTypeList) { + final int batchInterval, final List columnTypeList) throws UncheckedSQLException, UncheckedIOException { return importCSV(reader, offset, count, skipTitle, Fn. alwaysTrue(), stmt, batchSize, batchInterval, columnTypeList); } @@ -1200,7 +1218,7 @@ public static long importCSV(final Reader reader, long offset, final long count, @SuppressWarnings({ "unchecked", "rawtypes" }) public static long importCSV(final Reader reader, long offset, final long count, final boolean skipTitle, final Try.Predicate filter, final PreparedStatement stmt, final int batchSize, final int batchInterval, - final List columnTypeList) throws E { + final List columnTypeList) throws UncheckedSQLException, UncheckedIOException, E { N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count); N.checkArgument(batchSize > 0 && batchInterval >= 0, "'batchSize'=%s must be greater than 0 and 'batchInterval'=%s can't be negative", batchSize, batchInterval); @@ -1277,13 +1295,14 @@ public static long importCSV(final Reader reader, long off * @return */ @SuppressWarnings("rawtypes") - public static long importCSV(final File file, final Connection conn, final String insertSQL, final Map columnTypeMap) { + public static long importCSV(final File file, final Connection conn, final String insertSQL, final Map columnTypeMap) + throws UncheckedSQLException, UncheckedIOException { return importCSV(file, 0, Long.MAX_VALUE, conn, insertSQL, 200, 0, columnTypeMap); } @SuppressWarnings("rawtypes") public static long importCSV(final File file, final long offset, final long count, final Connection conn, final String insertSQL, final int batchSize, - final int batchInterval, final Map columnTypeMap) { + final int batchInterval, final Map columnTypeMap) throws UncheckedSQLException, UncheckedIOException { return importCSV(file, offset, count, Fn. alwaysTrue(), conn, insertSQL, batchSize, batchInterval, columnTypeMap); } @@ -1303,7 +1322,7 @@ public static long importCSV(final File file, final long offset, final long coun @SuppressWarnings("rawtypes") public static long importCSV(final File file, final long offset, final long count, final Try.Predicate filter, final Connection conn, final String insertSQL, final int batchSize, final int batchInterval, final Map columnTypeMap) - throws E { + throws UncheckedSQLException, UncheckedIOException, E { PreparedStatement stmt = null; try { @@ -1318,13 +1337,14 @@ public static long importCSV(final File file, final long o } @SuppressWarnings("rawtypes") - public static long importCSV(final File file, final PreparedStatement stmt, final Map columnTypeMap) { + public static long importCSV(final File file, final PreparedStatement stmt, final Map columnTypeMap) + throws UncheckedSQLException, UncheckedIOException { return importCSV(file, 0, Long.MAX_VALUE, stmt, 200, 0, columnTypeMap); } @SuppressWarnings("rawtypes") public static long importCSV(final File file, final long offset, final long count, final PreparedStatement stmt, final int batchSize, - final int batchInterval, final Map columnTypeMap) { + final int batchInterval, final Map columnTypeMap) throws UncheckedSQLException, UncheckedIOException { return importCSV(file, offset, count, Fn. alwaysTrue(), stmt, batchSize, batchInterval, columnTypeMap); } @@ -1343,7 +1363,8 @@ public static long importCSV(final File file, final long offset, final long coun */ @SuppressWarnings("rawtypes") public static long importCSV(final File file, final long offset, final long count, final Try.Predicate filter, - final PreparedStatement stmt, final int batchSize, final int batchInterval, final Map columnTypeMap) throws E { + final PreparedStatement stmt, final int batchSize, final int batchInterval, final Map columnTypeMap) + throws UncheckedSQLException, UncheckedIOException, E { Reader reader = null; try { @@ -1358,13 +1379,14 @@ public static long importCSV(final File file, final long o } @SuppressWarnings("rawtypes") - public static long importCSV(final InputStream is, final PreparedStatement stmt, final Map columnTypeMap) { + public static long importCSV(final InputStream is, final PreparedStatement stmt, final Map columnTypeMap) + throws UncheckedSQLException, UncheckedIOException { return importCSV(is, 0, Long.MAX_VALUE, stmt, 200, 0, columnTypeMap); } @SuppressWarnings("rawtypes") public static long importCSV(final InputStream is, final long offset, final long count, final PreparedStatement stmt, final int batchSize, - final int batchInterval, final Map columnTypeMap) { + final int batchInterval, final Map columnTypeMap) throws UncheckedSQLException, UncheckedIOException { return importCSV(is, offset, count, Fn. alwaysTrue(), stmt, batchSize, batchInterval, columnTypeMap); } @@ -1383,19 +1405,21 @@ public static long importCSV(final InputStream is, final long offset, final long */ @SuppressWarnings("rawtypes") public static long importCSV(final InputStream is, long offset, final long count, final Try.Predicate filter, - final PreparedStatement stmt, final int batchSize, final int batchInterval, final Map columnTypeMap) throws E { + final PreparedStatement stmt, final int batchSize, final int batchInterval, final Map columnTypeMap) + throws UncheckedSQLException, UncheckedIOException, E { final Reader reader = new InputStreamReader(is); return importCSV(reader, offset, count, filter, stmt, batchSize, batchInterval, columnTypeMap); } @SuppressWarnings("rawtypes") - public static long importCSV(final Reader reader, final PreparedStatement stmt, final Map columnTypeMap) { + public static long importCSV(final Reader reader, final PreparedStatement stmt, final Map columnTypeMap) + throws UncheckedSQLException, UncheckedIOException { return importCSV(reader, 0, Long.MAX_VALUE, stmt, 200, 0, columnTypeMap); } @SuppressWarnings({ "unchecked", "rawtypes" }) public static long importCSV(final Reader reader, long offset, final long count, final PreparedStatement stmt, final int batchSize, final int batchInterval, - final Map columnTypeMap) { + final Map columnTypeMap) throws UncheckedSQLException, UncheckedIOException { return importCSV(reader, offset, count, Fn. alwaysTrue(), stmt, batchSize, batchInterval, columnTypeMap); } @@ -1414,7 +1438,8 @@ public static long importCSV(final Reader reader, long offset, final long count, */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static long importCSV(final Reader reader, long offset, final long count, final Try.Predicate filter, - final PreparedStatement stmt, final int batchSize, final int batchInterval, final Map columnTypeMap) throws E { + final PreparedStatement stmt, final int batchSize, final int batchInterval, final Map columnTypeMap) + throws UncheckedSQLException, UncheckedIOException, E { N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count); N.checkArgument(batchSize > 0 && batchInterval >= 0, "'batchSize'=%s must be greater than 0 and 'batchInterval'=%s can't be negative", batchSize, batchInterval); @@ -1513,12 +1538,13 @@ public static long importCSV(final Reader reader, long off * @return */ public static long importCSV(final File file, final Connection conn, final String insertSQL, - final Try.BiConsumer stmtSetter) { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException { return importCSV(file, 0, Long.MAX_VALUE, conn, insertSQL, 200, 0, stmtSetter); } public static long importCSV(final File file, final long offset, final long count, final Connection conn, final String insertSQL, final int batchSize, - final int batchInterval, final Try.BiConsumer stmtSetter) { + final int batchInterval, final Try.BiConsumer stmtSetter) + throws UncheckedSQLException, UncheckedIOException { return importCSV(file, offset, count, Fn. alwaysTrue(), conn, insertSQL, batchSize, batchInterval, stmtSetter); } @@ -1537,7 +1563,7 @@ public static long importCSV(final File file, final long offset, final long coun */ public static long importCSV(final File file, final long offset, final long count, final Try.Predicate filter, final Connection conn, final String insertSQL, final int batchSize, final int batchInterval, - final Try.BiConsumer stmtSetter) throws E { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException, E { PreparedStatement stmt = null; try { @@ -1552,12 +1578,13 @@ public static long importCSV(final File file, final long o } public static long importCSV(final File file, final PreparedStatement stmt, - final Try.BiConsumer stmtSetter) { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException { return importCSV(file, 0, Long.MAX_VALUE, stmt, 200, 0, stmtSetter); } public static long importCSV(final File file, final long offset, final long count, final PreparedStatement stmt, final int batchSize, - final int batchInterval, final Try.BiConsumer stmtSetter) { + final int batchInterval, final Try.BiConsumer stmtSetter) + throws UncheckedSQLException, UncheckedIOException { return importCSV(file, offset, count, Fn. alwaysTrue(), stmt, batchSize, batchInterval, stmtSetter); } @@ -1576,7 +1603,7 @@ public static long importCSV(final File file, final long offset, final long coun */ public static long importCSV(final File file, final long offset, final long count, final Try.Predicate filter, final PreparedStatement stmt, final int batchSize, final int batchInterval, - final Try.BiConsumer stmtSetter) throws E { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException, E { Reader reader = null; try { @@ -1591,12 +1618,13 @@ public static long importCSV(final File file, final long o } public static long importCSV(final InputStream is, final PreparedStatement stmt, - final Try.BiConsumer stmtSetter) { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException { return importCSV(is, 0, Long.MAX_VALUE, stmt, 200, 0, stmtSetter); } public static long importCSV(final InputStream is, final long offset, final long count, final PreparedStatement stmt, final int batchSize, - final int batchInterval, final Try.BiConsumer stmtSetter) { + final int batchInterval, final Try.BiConsumer stmtSetter) + throws UncheckedSQLException, UncheckedIOException { return importCSV(is, offset, count, Fn. alwaysTrue(), stmt, batchSize, batchInterval, stmtSetter); } @@ -1615,19 +1643,19 @@ public static long importCSV(final InputStream is, final long offset, final long */ public static long importCSV(final InputStream is, long offset, final long count, final Try.Predicate filter, final PreparedStatement stmt, final int batchSize, final int batchInterval, - final Try.BiConsumer stmtSetter) throws E { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException, E { final Reader reader = new InputStreamReader(is); return importCSV(reader, offset, count, filter, stmt, batchSize, batchInterval, stmtSetter); } public static long importCSV(final Reader reader, final PreparedStatement stmt, - final Try.BiConsumer stmtSetter) { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException { return importCSV(reader, 0, Long.MAX_VALUE, stmt, 200, 0, stmtSetter); } @SuppressWarnings({ "unchecked" }) public static long importCSV(final Reader reader, long offset, final long count, final PreparedStatement stmt, final int batchSize, final int batchInterval, - final Try.BiConsumer stmtSetter) { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException { return importCSV(reader, offset, count, Fn. alwaysTrue(), stmt, batchSize, batchInterval, stmtSetter); } @@ -1647,7 +1675,7 @@ public static long importCSV(final Reader reader, long offset, final long count, @SuppressWarnings({ "unchecked" }) public static long importCSV(final Reader reader, long offset, final long count, final Try.Predicate filter, final PreparedStatement stmt, final int batchSize, final int batchInterval, - final Try.BiConsumer stmtSetter) throws E { + final Try.BiConsumer stmtSetter) throws UncheckedSQLException, UncheckedIOException, E { N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count); N.checkArgument(batchSize > 0 && batchInterval >= 0, "'batchSize'=%s must be greater than 0 and 'batchInterval'=%s can't be negative", batchSize, batchInterval); diff --git a/src/com/landawn/abacus/util/ClassUtil.java b/src/com/landawn/abacus/util/ClassUtil.java index 94fa4071..02217b00 100644 --- a/src/com/landawn/abacus/util/ClassUtil.java +++ b/src/com/landawn/abacus/util/ClassUtil.java @@ -1653,7 +1653,7 @@ static boolean isPropName(final Class cls, String inputPropName, final String || (inputPropName.startsWith(GET) && inputPropName.substring(3).equalsIgnoreCase(propNameByMethod)) || (inputPropName.startsWith(SET) && inputPropName.substring(3).equalsIgnoreCase(propNameByMethod)) || (inputPropName.startsWith(IS) && inputPropName.substring(2).equalsIgnoreCase(propNameByMethod)) - || (inputPropName.startsWith(HAS) && inputPropName.substring(2).equalsIgnoreCase(propNameByMethod)); + || (inputPropName.startsWith(HAS) && inputPropName.substring(3).equalsIgnoreCase(propNameByMethod)); } /** diff --git a/src/com/landawn/abacus/util/ExceptionalStream.java b/src/com/landawn/abacus/util/ExceptionalStream.java index 078237ac..df4aabcb 100644 --- a/src/com/landawn/abacus/util/ExceptionalStream.java +++ b/src/com/landawn/abacus/util/ExceptionalStream.java @@ -1434,7 +1434,7 @@ public Stream apply(List t) { } public ExceptionalStream, E> slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ExceptionalIterator, E>() { private List prev = null; diff --git a/src/com/landawn/abacus/util/Fn.java b/src/com/landawn/abacus/util/Fn.java index 355d5b1a..659755ec 100644 --- a/src/com/landawn/abacus/util/Fn.java +++ b/src/com/landawn/abacus/util/Fn.java @@ -39,6 +39,8 @@ import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; +import java.util.Timer; +import java.util.TimerTask; import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; @@ -135,6 +137,8 @@ public final class Fn extends Comparators { private static final Object NONE = new Object(); + private static final Timer timer = new Timer(); + @SuppressWarnings("rawtypes") public static final IntFunction> FACTORY_OF_MAP = (IntFunction) Factory.MAP_FACTORY; @SuppressWarnings("rawtypes") @@ -1694,16 +1698,31 @@ public boolean test(T t, U u) { public static Predicate timeLimit(final long timeInMillis) { N.checkArgNotNegative(timeInMillis, "timeInMillis"); - return new Predicate() { - private final long now = System.currentTimeMillis(); + final MutableBoolean ongoing = MutableBoolean.of(true); + + final TimerTask task = new TimerTask() { + @Override + public void run() { + ongoing.setFalse(); + } + }; + + timer.schedule(task, timeInMillis); + return new Predicate() { @Override public boolean test(T t) { - return System.currentTimeMillis() - now < timeInMillis; + return ongoing.value(); } }; } + public static Predicate timeLimit(final Duration duration) { + N.checkArgNotNull(duration, "duration"); + + return timeLimit(duration.toMillis()); + } + /** * Returns a stateful Function which should not be used in parallel stream. * diff --git a/src/com/landawn/abacus/util/Indexed.java b/src/com/landawn/abacus/util/Indexed.java index 3fce80f3..53be4025 100644 --- a/src/com/landawn/abacus/util/Indexed.java +++ b/src/com/landawn/abacus/util/Indexed.java @@ -85,7 +85,7 @@ public boolean equals(Object obj) { return true; } - if (obj instanceof Timed) { + if (obj instanceof Indexed) { final Indexed other = (Indexed) obj; return this.index == other.index && N.equals(this.value, other.value); diff --git a/src/com/landawn/abacus/util/Iterators.java b/src/com/landawn/abacus/util/Iterators.java index bec6bd5a..b11779a9 100644 --- a/src/com/landawn/abacus/util/Iterators.java +++ b/src/com/landawn/abacus/util/Iterators.java @@ -451,7 +451,7 @@ public static void forEachPair(final Iterator iter, throws E { N.checkArgNotNull(action); final int windowSize = 2; - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); if (iter == null) { return; @@ -492,7 +492,7 @@ public static void forEachTriple(final Iterator iter final int increment) throws E { N.checkArgNotNull(action); final int windowSize = 3; - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); if (iter == null) { return; diff --git a/src/com/landawn/abacus/util/JdbcUtil.java b/src/com/landawn/abacus/util/JdbcUtil.java index 0a8ccb19..3eff9e63 100644 --- a/src/com/landawn/abacus/util/JdbcUtil.java +++ b/src/com/landawn/abacus/util/JdbcUtil.java @@ -183,6 +183,12 @@ public static DBVersion getDBVersion(final Connection conn) throws UncheckedSQLE dbVersion = DBVersion.MYSQL_6; } else if (dbProudctVersion.startsWith("7")) { dbVersion = DBVersion.MYSQL_7; + } else if (dbProudctVersion.startsWith("8")) { + dbVersion = DBVersion.MYSQL_8; + } else if (dbProudctVersion.startsWith("9")) { + dbVersion = DBVersion.MYSQL_9; + } else if (dbProudctVersion.startsWith("10")) { + dbVersion = DBVersion.MYSQL_10; } else { dbVersion = DBVersion.MYSQL_OTHERS; } @@ -197,6 +203,10 @@ public static DBVersion getDBVersion(final Connection conn) throws UncheckedSQLE dbVersion = DBVersion.POSTGRESQL_9_5; } else if (dbProudctVersion.startsWith("10")) { dbVersion = DBVersion.POSTGRESQL_10; + } else if (dbProudctVersion.startsWith("11")) { + dbVersion = DBVersion.POSTGRESQL_11; + } else if (dbProudctVersion.startsWith("12")) { + dbVersion = DBVersion.POSTGRESQL_12; } else { dbVersion = DBVersion.POSTGRESQL_OTHERS; } @@ -1249,7 +1259,7 @@ public static PreparedQuery prepareQuery(final javax.sql.DataSource ds, final St * @throws SQLException */ public static PreparedQuery prepareQuery(final Connection conn, final String sql) throws SQLException { - return new PreparedQuery(prepareStatement(conn, sql)); + return new PreparedQuery(conn.prepareStatement(sql)); } /** @@ -1317,17 +1327,6 @@ public static PreparedQuery prepareQuery(final Connection conn, final Try.Functi return new PreparedQuery(stmtCreator.apply(conn)); } - // /** - // * - // * @param stmtCreator the created {@code PreparedStatement} will be closed after any execution methods in {@code PreparedQuery/PreparedCallableQuery} is called. - // * An execution method is a method which will trigger the backed {@code PreparedStatement/CallableStatement} to be executed, for example: get/query/queryForInt/Long/../findFirst/list/execute/.... - // * @return - // * @throws SQLException - // */ - // public static PreparedQuery prepareQuery(final Try.Supplier stmtCreator) throws SQLException { - // return new PreparedQuery(stmtCreator.get()); - // } - public static PreparedCallableQuery prepareCallableQuery(final javax.sql.DataSource ds, final String sql) throws SQLException { PreparedCallableQuery result = null; Connection conn = null; @@ -1358,7 +1357,7 @@ public static PreparedCallableQuery prepareCallableQuery(final javax.sql.DataSou * @throws SQLException */ public static PreparedCallableQuery prepareCallableQuery(final Connection conn, final String sql) throws SQLException { - return new PreparedCallableQuery(prepareCall(conn, sql)); + return new PreparedCallableQuery(conn.prepareCall(sql)); } /** @@ -1407,148 +1406,6 @@ public static PreparedCallableQuery prepareCallableQuery(final Connection conn, return new PreparedCallableQuery(stmtCreator.apply(conn)); } - // /** - // * - // * @param stmtCreator the created {@code CallableStatement} will be closed after any execution methods in {@code PreparedQuery/PreparedCallableQuery} is called. - // * An execution method is a method which will trigger the backed {@code PreparedStatement/CallableStatement} to be executed, for example: get/query/queryForInt/Long/../findFirst/list/execute/.... - // * @return - // * @throws SQLException - // */ - // public static PreparedCallableQuery prepareCallableQuery(final Try.Supplier stmtCreator) throws SQLException { - // return new PreparedCallableQuery(stmtCreator.get()); - // } - - /** - * Generally, this method should be executed in transaction. - * - * @param query - * @param batchSize - * @param batchParameters - * @param paramSetter - * @return - * @throws SQLException - * @throws E - */ - public static , T, E extends Exception> int batchUpdate(final Q query, - final int batchSize, final Collection batchParameters, Try.EE.BiConsumer paramSetter) - throws SQLException, E { - return batchUpdate(query, batchSize, batchParameters.iterator(), paramSetter); - } - - /** - * Generally, this method should be executed in transaction. - * - * @param query - * @param batchSize - * @param batchParameters - * @param paramSetter - * @return - * @throws SQLException - * @throws E - */ - public static , T, E extends Exception> int batchUpdate(final Q query, - final int batchSize, final Iterator batchParameters, Try.EE.BiConsumer paramSetter) - throws SQLException, E { - N.checkArgNotNull(query); - N.checkArgPositive(batchSize, "batchSize"); - N.checkArgNotNull(batchParameters); - N.checkArgNotNull(paramSetter); - - long result = 0; - final boolean closeAfterExecution = query.closeAfterExecution(); - query.closeAfterExecution(false); - long cnt = 0; - - try { - while (batchParameters.hasNext()) { - query.settParameters(batchParameters.next(), paramSetter); - query.addBatch(); - - if (++cnt % batchSize == 0) { - result += N.sum(query.batchUpdate()); - } - } - - if (cnt % batchSize != 0) { - result += N.sum(query.batchUpdate()); - } - - } finally { - query.closeAfterExecution(closeAfterExecution); - - if (closeAfterExecution) { - query.close(); - } - } - - return result >= Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) result; - } - - /** - * Generally, this method should be executed in transaction. - * - * @param query - * @param batchSize - * @param batchParameters - * @param paramSetter - * @return - * @throws SQLException - * @throws E - */ - public static , T, ID, E extends Exception> List batchInsert(final Q query, - final int batchSize, final Collection batchParameters, Try.EE.BiConsumer paramSetter) - throws SQLException, E { - return batchInsert(query, batchSize, batchParameters.iterator(), paramSetter); - } - - /** - * Generally, this method should be executed in transaction. - * - * @param query - * @param batchSize - * @param batchParameters - * @param paramSetter - * @return - * @throws SQLException - * @throws E - */ - public static , T, ID, E extends Exception> List batchInsert(final Q query, - final int batchSize, final Iterator batchParameters, Try.EE.BiConsumer paramSetter) - throws SQLException, E { - N.checkArgNotNull(query); - N.checkArgPositive(batchSize, "batchSize"); - N.checkArgNotNull(batchParameters); - N.checkArgNotNull(paramSetter); - - final List result = new ArrayList<>(); - final boolean closeAfterExecution = query.closeAfterExecution(); - query.closeAfterExecution(false); - long cnt = 0; - - try { - while (batchParameters.hasNext()) { - query.settParameters(batchParameters.next(), paramSetter); - query.addBatch(); - - if (++cnt % batchSize == 0) { - result.addAll(query. batchInsert()); - } - } - - if (cnt % batchSize != 0) { - result.addAll(query. batchInsert()); - } - } finally { - query.closeAfterExecution(closeAfterExecution); - - if (closeAfterExecution) { - query.close(); - } - } - - return result; - } - @SafeVarargs public static PreparedStatement prepareStatement(final Connection conn, final String sql, final Object... parameters) throws SQLException { final NamedSQL namedSQL = NamedSQL.parse(sql); @@ -1661,7 +1518,7 @@ public static int executeBatchUpdate(final Connection conn, final String sql, fi public static int executeBatchUpdate(final Connection conn, final String sql, final List parametersListList, final int batchSize) throws SQLException { N.checkArgNotNull(conn); N.checkArgNotNull(sql); - N.checkArgument(batchSize > 0, "'batchSize' can't be 0 or negative"); + N.checkArgPositive(batchSize, "batchSize"); if (N.isNullOrEmpty(parametersListList)) { return 0; @@ -5428,25 +5285,29 @@ public List batchInsert() throws SQLException { assertNotClosed(); try { - stmt.executeBatch(); + return executeBatchInsert(); + } finally { + closeAfterExecutionIfAllowed(); + } + } - try (ResultSet rs = stmt.getGeneratedKeys()) { - final List result = new ArrayList<>(); + private List executeBatchInsert() throws SQLException { + stmt.executeBatch(); - while (rs.next()) { - result.add((T) JdbcUtil.getColumnValue(rs, 1)); - } + try (ResultSet rs = stmt.getGeneratedKeys()) { + final List result = new ArrayList<>(); - return result; - } finally { - stmt.clearBatch(); + while (rs.next()) { + result.add((T) JdbcUtil.getColumnValue(rs, 1)); } + + return result; } finally { - closeAfterExecutionIfAllowed(); + stmt.clearBatch(); } } - public int upate() throws SQLException { + public int update() throws SQLException { assertNotClosed(); try { @@ -5460,14 +5321,20 @@ public int[] batchUpdate() throws SQLException { assertNotClosed(); try { - final int[] result = stmt.executeBatch(); - stmt.clearBatch(); - return result; + return executeBatchUpdate(); } finally { closeAfterExecutionIfAllowed(); } } + private int[] executeBatchUpdate() throws SQLException { + try { + return stmt.executeBatch(); + } finally { + stmt.clearBatch(); + } + } + public long largeUpate() throws SQLException { assertNotClosed(); @@ -5490,6 +5357,117 @@ public long[] largeBatchUpdate() throws SQLException { } } + /** + * Generally, this method should be executed in transaction. + * + * @param batchSize + * @param batchParameters + * @param paramSetter + * @return + * @throws SQLException + * @throws E + */ + public int batchUpdate(final int batchSize, final Collection batchParameters, + Try.EE.BiConsumer paramSetter) throws SQLException, E { + return batchUpdate(batchSize, batchParameters == null ? N. emptyIterator() : batchParameters.iterator(), paramSetter); + } + + /** + * Generally, this method should be executed in transaction. + * + * @param batchSize + * @param batchParameters + * @param paramSetter + * @return + * @throws SQLException + * @throws E + */ + public int batchUpdate(final int batchSize, final Iterator batchParameters, + final Try.EE.BiConsumer paramSetter) throws SQLException, E { + checkArg(batchSize > 0, "'batchSize' must be bigger than 0"); + checkArgNotNull(paramSetter, "paramSetter"); + + final Iterator iter = batchParameters == null ? N. emptyIterator() : batchParameters; + long result = 0; + + try { + long cnt = 0; + + while (iter.hasNext()) { + paramSetter.accept((Q) this, iter.next()); + addBatch(); + + if (++cnt % batchSize == 0) { + result += N.sum(executeBatchUpdate()); + } + } + + if (cnt % batchSize != 0) { + result += N.sum(executeBatchUpdate()); + } + + } finally { + closeAfterExecutionIfAllowed(); + } + + return result >= Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) result; + } + + /** + * Generally, this method should be executed in transaction. + * + * @param batchSize + * @param batchParameters + * @param paramSetter + * @return + * @throws SQLException + * @throws E + */ + public List batchInsert(final int batchSize, final Collection batchParameters, + Try.EE.BiConsumer paramSetter) throws SQLException, E { + return batchInsert(batchSize, batchParameters.iterator(), paramSetter); + } + + /** + * Generally, this method should be executed in transaction. + * + * @param batchSize + * @param batchParameters + * @param paramSetter + * @return + * @throws SQLException + * @throws E + */ + public List batchInsert(final int batchSize, final Iterator batchParameters, + Try.EE.BiConsumer paramSetter) throws SQLException, E { + checkArg(batchSize > 0, "'batchSize' must be bigger than 0"); + checkArgNotNull(paramSetter, "paramSetter"); + + final Iterator iter = batchParameters == null ? N. emptyIterator() : batchParameters; + final List result = new ArrayList<>(); + + try { + long cnt = 0; + + while (iter.hasNext()) { + paramSetter.accept((Q) this, iter.next()); + addBatch(); + + if (++cnt % batchSize == 0) { + result.addAll(this. executeBatchInsert()); + } + } + + if (cnt % batchSize != 0) { + result.addAll(this. executeBatchInsert()); + } + } finally { + closeAfterExecutionIfAllowed(); + } + + return result; + } + public boolean execute() throws SQLException { assertNotClosed(); @@ -5706,320 +5684,251 @@ void assertNotClosed() { } } - /** - * The backed {@code PreparedStatement/CallableStatement} will be closed by default - * after any execution methods(which will trigger the backed {@code PreparedStatement/CallableStatement} to be executed, for example: get/query/queryForInt/Long/../findFirst/list/execute/...). - * except the {@code 'closeAfterExecution'} flag is set to {@code false} by calling {@code #closeAfterExecution(false)}. - * - *
- * Generally, don't cache or reuse the instance of this class, - * except the {@code 'closeAfterExecution'} flag is set to {@code false} by calling {@code #closeAfterExecution(false)}. - * - *
- * The {@code ResultSet} returned by query will always be closed after execution, even {@code 'closeAfterExecution'} flag is set to {@code false}. - * - *
- * Remember: parameter/column index in {@code PreparedStatement/ResultSet} starts from 1, not 0. - * - * @author haiyangl - * - * @see {@link com.landawn.abacus.annotation.ReadOnly} - * @see {@link com.landawn.abacus.annotation.ReadOnlyId} - * @see {@link com.landawn.abacus.annotation.NonUpdatable} - * @see {@link com.landawn.abacus.annotation.Transient} - * @see {@link com.landawn.abacus.annotation.Table} - * @see {@link com.landawn.abacus.annotation.Column} - * - * @see http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html - * @see http://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html - * @see http://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html - * @see http://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html - */ - public static class PreparedQuery extends AbstractPreparedQuery { - - PreparedQuery(PreparedStatement stmt) { - super(stmt); - } - - PreparedQuery(PreparedStatement stmt, AsyncExecutor asyncExecutor) { - super(stmt, asyncExecutor); - } - } - - /** - * The backed {@code PreparedStatement/CallableStatement} will be closed by default - * after any execution methods(which will trigger the backed {@code PreparedStatement/CallableStatement} to be executed, for example: get/query/queryForInt/Long/../findFirst/list/execute/...). - * except the {@code 'closeAfterExecution'} flag is set to {@code false} by calling {@code #closeAfterExecution(false)}. - * - *
- * Generally, don't cache or reuse the instance of this class, - * except the {@code 'closeAfterExecution'} flag is set to {@code false} by calling {@code #closeAfterExecution(false)}. - * - *
- * The {@code ResultSet} returned by query will always be closed after execution, even {@code 'closeAfterExecution'} flag is set to {@code false}. - * - *
- * Remember: parameter/column index in {@code PreparedStatement/ResultSet} starts from 1, not 0. - * - * @author haiyangl - * - * @see {@link com.landawn.abacus.annotation.ReadOnly} - * @see {@link com.landawn.abacus.annotation.ReadOnlyId} - * @see {@link com.landawn.abacus.annotation.NonUpdatable} - * @see {@link com.landawn.abacus.annotation.Transient} - * @see {@link com.landawn.abacus.annotation.Table} - * @see {@link com.landawn.abacus.annotation.Column} - * - * @see http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html - * @see http://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html - * @see http://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html - * @see http://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html - */ - public static class PreparedCallableQuery extends AbstractPreparedQuery { - private final CallableStatement stmt; + static class AbstractPreparedCallableQuery> extends AbstractPreparedQuery { + final S stmt; - PreparedCallableQuery(CallableStatement stmt) { + AbstractPreparedCallableQuery(S stmt) { super(stmt); this.stmt = stmt; } - PreparedCallableQuery(CallableStatement stmt, AsyncExecutor asyncExecutor) { + AbstractPreparedCallableQuery(S stmt, AsyncExecutor asyncExecutor) { super(stmt, asyncExecutor); this.stmt = stmt; } - public PreparedCallableQuery setNull(String parameterName, int sqlType) throws SQLException { + public Q setNull(String parameterName, int sqlType) throws SQLException { stmt.setNull(parameterName, sqlType); - return this; + return (Q) this; } - public PreparedCallableQuery setNull(String parameterName, int sqlType, String typeName) throws SQLException { + public Q setNull(String parameterName, int sqlType, String typeName) throws SQLException { stmt.setNull(parameterName, sqlType, typeName); - return this; + return (Q) this; } - public PreparedCallableQuery setBoolean(String parameterName, boolean x) throws SQLException { + public Q setBoolean(String parameterName, boolean x) throws SQLException { stmt.setBoolean(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setBoolean(String parameterName, Boolean x) throws SQLException { + public Q setBoolean(String parameterName, Boolean x) throws SQLException { stmt.setBoolean(parameterName, Primitives.unboxOrDefault(x)); - return this; + return (Q) this; } - public PreparedCallableQuery setByte(String parameterName, byte x) throws SQLException { + public Q setByte(String parameterName, byte x) throws SQLException { stmt.setByte(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setByte(String parameterName, Byte x) throws SQLException { + public Q setByte(String parameterName, Byte x) throws SQLException { stmt.setByte(parameterName, Primitives.unboxOrDefault(x)); - return this; + return (Q) this; } - public PreparedCallableQuery setShort(String parameterName, short x) throws SQLException { + public Q setShort(String parameterName, short x) throws SQLException { stmt.setShort(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setShort(String parameterName, Short x) throws SQLException { + public Q setShort(String parameterName, Short x) throws SQLException { stmt.setShort(parameterName, Primitives.unboxOrDefault(x)); - return this; + return (Q) this; } - public PreparedCallableQuery setInt(String parameterName, int x) throws SQLException { + public Q setInt(String parameterName, int x) throws SQLException { stmt.setInt(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setInt(String parameterName, Integer x) throws SQLException { + public Q setInt(String parameterName, Integer x) throws SQLException { stmt.setInt(parameterName, Primitives.unboxOrDefault(x)); - return this; + return (Q) this; } - public PreparedCallableQuery setLong(String parameterName, long x) throws SQLException { + public Q setLong(String parameterName, long x) throws SQLException { stmt.setLong(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setLong(String parameterName, Long x) throws SQLException { + public Q setLong(String parameterName, Long x) throws SQLException { stmt.setLong(parameterName, Primitives.unboxOrDefault(x)); - return this; + return (Q) this; } - public PreparedCallableQuery setFloat(String parameterName, float x) throws SQLException { + public Q setFloat(String parameterName, float x) throws SQLException { stmt.setFloat(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setFloat(String parameterName, Float x) throws SQLException { + public Q setFloat(String parameterName, Float x) throws SQLException { stmt.setFloat(parameterName, Primitives.unboxOrDefault(x)); - return this; + return (Q) this; } - public PreparedCallableQuery setDouble(String parameterName, double x) throws SQLException { + public Q setDouble(String parameterName, double x) throws SQLException { stmt.setDouble(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setDouble(String parameterName, Double x) throws SQLException { + public Q setDouble(String parameterName, Double x) throws SQLException { stmt.setDouble(parameterName, Primitives.unboxOrDefault(x)); - return this; + return (Q) this; } - public PreparedCallableQuery setBigDecimal(String parameterName, BigDecimal x) throws SQLException { + public Q setBigDecimal(String parameterName, BigDecimal x) throws SQLException { stmt.setBigDecimal(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setString(String parameterName, String x) throws SQLException { + public Q setString(String parameterName, String x) throws SQLException { stmt.setString(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setTime(String parameterName, java.sql.Time x) throws SQLException { + public Q setTime(String parameterName, java.sql.Time x) throws SQLException { stmt.setTime(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setDate(String parameterName, java.sql.Date x) throws SQLException { + public Q setDate(String parameterName, java.sql.Date x) throws SQLException { stmt.setDate(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setTimestamp(String parameterName, java.sql.Timestamp x) throws SQLException { + public Q setTimestamp(String parameterName, java.sql.Timestamp x) throws SQLException { stmt.setTimestamp(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setBytes(String parameterName, byte[] x) throws SQLException { + public Q setBytes(String parameterName, byte[] x) throws SQLException { stmt.setBytes(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setAsciiStream(String parameterName, InputStream inputStream) throws SQLException { + public Q setAsciiStream(String parameterName, InputStream inputStream) throws SQLException { stmt.setAsciiStream(parameterName, inputStream); - return this; + return (Q) this; } - public PreparedCallableQuery setAsciiStream(String parameterName, InputStream inputStream, long length) throws SQLException { + public Q setAsciiStream(String parameterName, InputStream inputStream, long length) throws SQLException { stmt.setAsciiStream(parameterName, inputStream, length); - return this; + return (Q) this; } - public PreparedCallableQuery setBinaryStream(String parameterName, InputStream inputStream) throws SQLException { + public Q setBinaryStream(String parameterName, InputStream inputStream) throws SQLException { stmt.setBinaryStream(parameterName, inputStream); - return this; + return (Q) this; } - public PreparedCallableQuery setBinaryStream(String parameterName, InputStream inputStream, long length) throws SQLException { + public Q setBinaryStream(String parameterName, InputStream inputStream, long length) throws SQLException { stmt.setBinaryStream(parameterName, inputStream, length); - return this; + return (Q) this; } - public PreparedCallableQuery setCharacterStream(String parameterName, Reader reader) throws SQLException { + public Q setCharacterStream(String parameterName, Reader reader) throws SQLException { stmt.setCharacterStream(parameterName, reader); - return this; + return (Q) this; } - public PreparedCallableQuery setCharacterStream(String parameterName, Reader reader, long length) throws SQLException { + public Q setCharacterStream(String parameterName, Reader reader, long length) throws SQLException { stmt.setCharacterStream(parameterName, reader, length); - return this; + return (Q) this; } - public PreparedCallableQuery setNCharacterStream(String parameterName, Reader reader) throws SQLException { + public Q setNCharacterStream(String parameterName, Reader reader) throws SQLException { stmt.setNCharacterStream(parameterName, reader); - return this; + return (Q) this; } - public PreparedCallableQuery setNCharacterStream(String parameterName, Reader reader, long length) throws SQLException { + public Q setNCharacterStream(String parameterName, Reader reader, long length) throws SQLException { stmt.setNCharacterStream(parameterName, reader, length); - return this; + return (Q) this; } - public PreparedCallableQuery setBlob(String parameterName, java.sql.Blob x) throws SQLException { + public Q setBlob(String parameterName, java.sql.Blob x) throws SQLException { stmt.setBlob(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setBlob(String parameterName, InputStream inputStream) throws SQLException { + public Q setBlob(String parameterName, InputStream inputStream) throws SQLException { stmt.setBlob(parameterName, inputStream); - return this; + return (Q) this; } - public PreparedCallableQuery setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { + public Q setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { stmt.setBlob(parameterName, inputStream, length); - return this; + return (Q) this; } - public PreparedCallableQuery setClob(String parameterName, java.sql.Clob x) throws SQLException { + public Q setClob(String parameterName, java.sql.Clob x) throws SQLException { stmt.setClob(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setClob(String parameterName, Reader reader) throws SQLException { + public Q setClob(String parameterName, Reader reader) throws SQLException { stmt.setClob(parameterName, reader); - return this; + return (Q) this; } - public PreparedCallableQuery setClob(String parameterName, Reader reader, long length) throws SQLException { + public Q setClob(String parameterName, Reader reader, long length) throws SQLException { stmt.setClob(parameterName, reader, length); - return this; + return (Q) this; } - public PreparedCallableQuery setNClob(String parameterName, java.sql.NClob x) throws SQLException { + public Q setNClob(String parameterName, java.sql.NClob x) throws SQLException { stmt.setNClob(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setNClob(String parameterName, Reader reader) throws SQLException { + public Q setNClob(String parameterName, Reader reader) throws SQLException { stmt.setNClob(parameterName, reader); - return this; + return (Q) this; } - public PreparedCallableQuery setNClob(String parameterName, Reader reader, long length) throws SQLException { + public Q setNClob(String parameterName, Reader reader, long length) throws SQLException { stmt.setNClob(parameterName, reader, length); - return this; + return (Q) this; } /** @@ -6029,10 +5938,10 @@ public PreparedCallableQuery setNClob(String parameterName, Reader reader, long * @return * @throws SQLException */ - public PreparedCallableQuery setURL(String parameterName, URL x) throws SQLException { + public Q setURL(String parameterName, URL x) throws SQLException { stmt.setURL(parameterName, x); - return this; + return (Q) this; } /** @@ -6042,10 +5951,10 @@ public PreparedCallableQuery setURL(String parameterName, URL x) throws SQLExcep * @return * @throws SQLException */ - public PreparedCallableQuery setSQLXML(String parameterName, java.sql.SQLXML x) throws SQLException { + public Q setSQLXML(String parameterName, java.sql.SQLXML x) throws SQLException { stmt.setSQLXML(parameterName, x); - return this; + return (Q) this; } /** @@ -6055,54 +5964,42 @@ public PreparedCallableQuery setSQLXML(String parameterName, java.sql.SQLXML x) * @return * @throws SQLException */ - public PreparedCallableQuery setRowId(String parameterName, java.sql.RowId x) throws SQLException { + public Q setRowId(String parameterName, java.sql.RowId x) throws SQLException { stmt.setRowId(parameterName, x); - return this; + return (Q) this; } - public PreparedCallableQuery setObject(String parameterName, Object x) throws SQLException { + public Q setObject(String parameterName, Object x) throws SQLException { if (x == null) { stmt.setObject(parameterName, x); } else { N.typeOf(x.getClass()).set(stmt, parameterName, x); } - return this; - } - - public PreparedCallableQuery setObject(String parameterName, Object x, int sqlType) throws SQLException { - stmt.setObject(parameterName, x, sqlType); - - return this; - } - - public PreparedCallableQuery setObject(String parameterName, Object x, int sqlType, int scaleOrLength) throws SQLException { - stmt.setObject(parameterName, x, sqlType, scaleOrLength); - - return this; + return (Q) this; } - public PreparedCallableQuery setObject(String parameterName, Object x, SQLType sqlType) throws SQLException { + public Q setObject(String parameterName, Object x, int sqlType) throws SQLException { stmt.setObject(parameterName, x, sqlType); - return this; + return (Q) this; } - public PreparedCallableQuery setObject(String parameterName, Object x, SQLType sqlType, int scaleOrLength) throws SQLException { + public Q setObject(String parameterName, Object x, int sqlType, int scaleOrLength) throws SQLException { stmt.setObject(parameterName, x, sqlType, scaleOrLength); - return this; + return (Q) this; } - public PreparedCallableQuery setParameters(Map parameters) throws SQLException { + public Q setParameters(Map parameters) throws SQLException { checkArgNotNull(parameters, "parameters"); for (Map.Entry entry : parameters.entrySet()) { setObject(entry.getKey(), entry.getValue()); } - return this; + return (Q) this; } /** @@ -6116,7 +6013,7 @@ public PreparedCallableQuery setParameters(Map parameters) throw * @see {@link ClassUtil#getPropNameListExclusively(Class, Collection)} * @see {@link JdbcUtil#getNamedParameters(String)} */ - public PreparedCallableQuery setParameters(List parameterNames, Object entity) throws SQLException { + public Q setParameters(List parameterNames, Object entity) throws SQLException { checkArgNotNull(parameterNames, "parameterNames"); checkArgNotNull(entity, "entity"); @@ -6124,7 +6021,7 @@ public PreparedCallableQuery setParameters(List parameterNames, Object e setObject(parameterName, ClassUtil.getPropValue(entity, parameterName)); } - return this; + return (Q) this; } /** @@ -6134,10 +6031,10 @@ public PreparedCallableQuery setParameters(List parameterNames, Object e * @return * @throws SQLException */ - public PreparedCallableQuery registerOutParameter(int parameterIndex, int sqlType) throws SQLException { + public Q registerOutParameter(int parameterIndex, int sqlType) throws SQLException { stmt.registerOutParameter(parameterIndex, sqlType); - return this; + return (Q) this; } /** @@ -6148,10 +6045,10 @@ public PreparedCallableQuery registerOutParameter(int parameterIndex, int sqlTyp * @return * @throws SQLException */ - public PreparedCallableQuery registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { + public Q registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { stmt.registerOutParameter(parameterIndex, sqlType, scale); - return this; + return (Q) this; } /** @@ -6162,10 +6059,28 @@ public PreparedCallableQuery registerOutParameter(int parameterIndex, int sqlTyp * @return * @throws SQLException */ - public PreparedCallableQuery registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { + public Q registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { stmt.registerOutParameter(parameterIndex, sqlType, typeName); - return this; + return (Q) this; + } + + public Q registerOutParameter(String parameterName, int sqlType) throws SQLException { + stmt.registerOutParameter(parameterName, sqlType); + + return (Q) this; + } + + public Q registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { + stmt.registerOutParameter(parameterName, sqlType, scale); + + return (Q) this; + } + + public Q registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException { + stmt.registerOutParameter(parameterName, sqlType, typeName); + + return (Q) this; } /** @@ -6175,10 +6090,10 @@ public PreparedCallableQuery registerOutParameter(int parameterIndex, int sqlTyp * @return * @throws SQLException */ - public PreparedCallableQuery registerOutParameter(int parameterIndex, SQLType sqlType) throws SQLException { + public Q registerOutParameter(int parameterIndex, SQLType sqlType) throws SQLException { stmt.registerOutParameter(parameterIndex, sqlType); - return this; + return (Q) this; } /** @@ -6189,10 +6104,10 @@ public PreparedCallableQuery registerOutParameter(int parameterIndex, SQLType sq * @return * @throws SQLException */ - public PreparedCallableQuery registerOutParameter(int parameterIndex, SQLType sqlType, int scale) throws SQLException { + public Q registerOutParameter(int parameterIndex, SQLType sqlType, int scale) throws SQLException { stmt.registerOutParameter(parameterIndex, sqlType, scale); - return this; + return (Q) this; } /** @@ -6203,49 +6118,31 @@ public PreparedCallableQuery registerOutParameter(int parameterIndex, SQLType sq * @return * @throws SQLException */ - public PreparedCallableQuery registerOutParameter(int parameterIndex, SQLType sqlType, String typeName) throws SQLException { + public Q registerOutParameter(int parameterIndex, SQLType sqlType, String typeName) throws SQLException { stmt.registerOutParameter(parameterIndex, sqlType, typeName); - return this; - } - - public PreparedCallableQuery registerOutParameter(String parameterName, int sqlType) throws SQLException { - stmt.registerOutParameter(parameterName, sqlType); - - return this; - } - - public PreparedCallableQuery registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { - stmt.registerOutParameter(parameterName, sqlType, scale); - - return this; - } - - public PreparedCallableQuery registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException { - stmt.registerOutParameter(parameterName, sqlType, typeName); - - return this; + return (Q) this; } - public PreparedCallableQuery registerOutParameter(String parameterName, SQLType sqlType) throws SQLException { + public Q registerOutParameter(String parameterName, SQLType sqlType) throws SQLException { stmt.registerOutParameter(parameterName, sqlType); - return this; + return (Q) this; } - public PreparedCallableQuery registerOutParameter(String parameterName, SQLType sqlType, int scale) throws SQLException { + public Q registerOutParameter(String parameterName, SQLType sqlType, int scale) throws SQLException { stmt.registerOutParameter(parameterName, sqlType, scale); - return this; + return (Q) this; } - public PreparedCallableQuery registerOutParameter(String parameterName, SQLType sqlType, String typeName) throws SQLException { + public Q registerOutParameter(String parameterName, SQLType sqlType, String typeName) throws SQLException { stmt.registerOutParameter(parameterName, sqlType, typeName); - return this; + return (Q) this; } - public PreparedCallableQuery registerOutParameters(final Try.EE.Consumer register) + public Q registerOutParameters(final Try.EE.Consumer register) throws SQLException, E { checkArgNotNull(register, "register"); @@ -6261,7 +6158,7 @@ public PreparedCallableQuery registerOutParameters(final T } } - return this; + return (Q) this; } public Optional call(final ResultExtractor resultExtrator1) throws SQLException, E1 { @@ -6465,6 +6362,113 @@ public + * Generally, don't cache or reuse the instance of this class, + * except the {@code 'closeAfterExecution'} flag is set to {@code false} by calling {@code #closeAfterExecution(false)}. + * + *
+ * The {@code ResultSet} returned by query will always be closed after execution, even {@code 'closeAfterExecution'} flag is set to {@code false}. + * + *
+ * Remember: parameter/column index in {@code PreparedStatement/ResultSet} starts from 1, not 0. + * + * @author haiyangl + * + * @see {@link com.landawn.abacus.annotation.ReadOnly} + * @see {@link com.landawn.abacus.annotation.ReadOnlyId} + * @see {@link com.landawn.abacus.annotation.NonUpdatable} + * @see {@link com.landawn.abacus.annotation.Transient} + * @see {@link com.landawn.abacus.annotation.Table} + * @see {@link com.landawn.abacus.annotation.Column} + * + * @see http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html + * @see http://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html + * @see http://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html + * @see http://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html + */ + public static class PreparedQuery extends AbstractPreparedQuery { + + PreparedQuery(PreparedStatement stmt) { + super(stmt); + } + + PreparedQuery(PreparedStatement stmt, AsyncExecutor asyncExecutor) { + super(stmt, asyncExecutor); + } + } + + /** + * The backed {@code PreparedStatement/CallableStatement} will be closed by default + * after any execution methods(which will trigger the backed {@code PreparedStatement/CallableStatement} to be executed, for example: get/query/queryForInt/Long/../findFirst/list/execute/...). + * except the {@code 'closeAfterExecution'} flag is set to {@code false} by calling {@code #closeAfterExecution(false)}. + * + *
+ * Generally, don't cache or reuse the instance of this class, + * except the {@code 'closeAfterExecution'} flag is set to {@code false} by calling {@code #closeAfterExecution(false)}. + * + *
+ * The {@code ResultSet} returned by query will always be closed after execution, even {@code 'closeAfterExecution'} flag is set to {@code false}. + * + *
+ * Remember: parameter/column index in {@code PreparedStatement/ResultSet} starts from 1, not 0. + * + * @author haiyangl + * + * @see {@link com.landawn.abacus.annotation.ReadOnly} + * @see {@link com.landawn.abacus.annotation.ReadOnlyId} + * @see {@link com.landawn.abacus.annotation.NonUpdatable} + * @see {@link com.landawn.abacus.annotation.Transient} + * @see {@link com.landawn.abacus.annotation.Table} + * @see {@link com.landawn.abacus.annotation.Column} + * + * @see http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html + * @see http://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html + * @see http://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html + * @see http://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html + */ + public static class PreparedCallableQuery extends AbstractPreparedCallableQuery { + PreparedCallableQuery(CallableStatement stmt) { + super(stmt); + } + + PreparedCallableQuery(CallableStatement stmt, AsyncExecutor asyncExecutor) { + super(stmt, asyncExecutor); + } + } + + // public static class PreparedCallableQueryII extends AbstractPreparedCallableQuery { + // private final NamedSQL namedSQL; + // + // PreparedCallableQueryII(String sql, CallableStatement stmt) { + // super(stmt); + // this.namedSQL = NamedSQL.parse(sql); + // } + // + // PreparedCallableQueryII(String sql, CallableStatement stmt, AsyncExecutor asyncExecutor) { + // super(stmt, asyncExecutor); + // this.namedSQL = NamedSQL.parse(sql); + // } + // + // /** + // * + // * @param entity + // * @return + // * @throws SQLException + // */ + // public PreparedCallableQueryII setParameters(final Object entity) throws SQLException { + // checkArgNotNull(entity, "entity"); + // + // SQLExecutor.StatementSetter.DEFAULT.setParameters(namedSQL, stmt, N.asArray(entity)); + // + // return this; + // } + // } + public static class SimpleTransaction { static final Map threadTransacionMap = new ConcurrentHashMap<>(); static final Map attachedThreadTransacionMap = new ConcurrentHashMap<>(); diff --git a/src/com/landawn/abacus/util/SQLBuilder.java b/src/com/landawn/abacus/util/SQLBuilder.java index b1570a63..dbc29ed3 100644 --- a/src/com/landawn/abacus/util/SQLBuilder.java +++ b/src/com/landawn/abacus/util/SQLBuilder.java @@ -1105,7 +1105,7 @@ private void appendStringExpr(final String expr) { if (!StringUtil.isAsciiAlpha(word.charAt(0))) { sb.append(word); - } else if (i < len - 1 && words.get(i + 1).charAt(0) == WD._PARENTHESES_L) { + } else if (SQLParser.isFunctionName(words, len, i)) { sb.append(word); } else { sb.append(formalizeColumnName(propColumnNameMap, word)); @@ -1624,8 +1624,8 @@ public SQLBuilder set(final String expr) { public final SQLBuilder set(final String... columnNames) { init(false); - if (columnNames.length == 1 && SQLParser.parse(columnNames[0]).contains(WD.EQUAL)) { - sb.append(columnNames[0]); + if (columnNames.length == 1 && columnNames[0].contains(WD.EQUAL)) { + appendStringExpr(columnNames[0]); } else { final Map propColumnNameMap = getPropColumnNameMap(); diff --git a/src/com/landawn/abacus/util/SQLExecutor.java b/src/com/landawn/abacus/util/SQLExecutor.java index 6dc112f9..7250d940 100644 --- a/src/com/landawn/abacus/util/SQLExecutor.java +++ b/src/com/landawn/abacus/util/SQLExecutor.java @@ -4049,7 +4049,7 @@ public List batchGet(final List ids, final Collection selectPropNa * @return */ public List batchGet(final Connection conn, final List ids, final Collection selectPropNames, final int batchSize) { - N.checkArgument(batchSize > 0, "The specified batch size must be greater than 0"); + N.checkArgPositive(batchSize, "batchSize"); if (N.isNullOrEmpty(ids)) { return new ArrayList<>(); @@ -5271,7 +5271,7 @@ public List batchAdd(final Connection conn, final Collection List batchAdd(final Connection conn, final Collection entities, final int batchSize, final IsolationLevel isolationLevel) { - N.checkArgument(batchSize > 0, "The specified batch size must be greater than 0"); + N.checkArgPositive(batchSize, "batchSize"); if (N.isNullOrEmpty(entities)) { return new ArrayList<>(); @@ -5685,7 +5685,7 @@ public int batchUpdate(final Connection conn, final Collection enti private int batchUpdate(final Connection conn, final Collection entities, final Collection updatePropNames, final int batchSize, final IsolationLevel isolationLevel) { - N.checkArgument(batchSize > 0, "The specified batch size must be greater than 0"); + N.checkArgPositive(batchSize, "batchSize"); if (N.isNullOrEmpty(entities)) { return 0; @@ -5924,7 +5924,7 @@ public int batchDelete(final Connection conn, final Collection idsOrEntities, } private int batchDelete(final Connection conn, final Collection idsOrEntities, final int batchSize, final IsolationLevel isolationLevel) { - N.checkArgument(batchSize > 0, "The specified batch size must be greater than 0"); + N.checkArgPositive(batchSize, "batchSize"); if (N.isNullOrEmpty(idsOrEntities)) { return 0; diff --git a/src/com/landawn/abacus/util/SQLParser.java b/src/com/landawn/abacus/util/SQLParser.java index 043182c7..e16adf11 100644 --- a/src/com/landawn/abacus/util/SQLParser.java +++ b/src/com/landawn/abacus/util/SQLParser.java @@ -15,9 +15,10 @@ package com.landawn.abacus.util; import java.util.ArrayList; -import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; /** * @@ -28,33 +29,90 @@ public final class SQLParser { private static final char TAB = '\t'; private static final char ENTER = '\n'; - private static final Map seperators = new HashMap<>(); + private static final Set seperators = new HashSet<>(); static { - seperators.put(TAB, TAB); - seperators.put(ENTER, ENTER); - seperators.put(WD._SPACE, WD._SPACE); - seperators.put(WD._COMMA, WD._COMMA); - seperators.put(WD._SEMICOLON, WD._SEMICOLON); - seperators.put(WD._PARENTHESES_L, WD._PARENTHESES_L); - seperators.put(WD._PARENTHESES_R, WD._PARENTHESES_R); - seperators.put(WD._EQUAL, WD._EQUAL); - seperators.put(WD.NOT_EQUAL, WD.NOT_EQUAL); - seperators.put(WD.NOT_EQUAL2, WD.NOT_EQUAL2); - seperators.put(WD._GREATER_THAN, WD._GREATER_THAN); - seperators.put(WD.GREATER_EQUAL, WD.GREATER_EQUAL); - seperators.put(WD._LESS_THAN, WD._LESS_THAN); - seperators.put(WD.LESS_EQUAL, WD.LESS_EQUAL); - seperators.put(WD._PLUS, WD._PLUS); - seperators.put(WD._MINUS, WD._MINUS); - seperators.put(WD._PERCENT, WD._PERCENT); - seperators.put(WD._SLASH, WD._SLASH); - seperators.put(WD._ASTERISK, WD._ASTERISK); - seperators.put(WD._AMPERSAND, WD._AMPERSAND); - seperators.put(WD._VERTICALBAR, WD._VERTICALBAR); - seperators.put(WD._CIRCUMFLEX, WD._CIRCUMFLEX); - seperators.put(WD._UNARYBIT, WD._UNARYBIT); - seperators.put(WD._EXCLAMATION, WD._EXCLAMATION); + seperators.add(TAB); + seperators.add(ENTER); + seperators.add(' '); + seperators.add('?'); + seperators.add(','); + seperators.add('~'); + seperators.add('!'); + seperators.add('@'); + seperators.add('^'); + seperators.add('#'); + seperators.add("!!"); + seperators.add(';'); + seperators.add('('); + seperators.add(')'); + seperators.add('='); + seperators.add("=="); + seperators.add(":="); + seperators.add("^="); + seperators.add("~="); + seperators.add("+="); + seperators.add("-="); + seperators.add("*="); + seperators.add("/="); + seperators.add("%="); + seperators.add("&="); + seperators.add("|="); + seperators.add("!="); + seperators.add("!<"); + seperators.add("!>"); + seperators.add('>'); + seperators.add(">>"); + seperators.add(">="); + seperators.add("@>"); + seperators.add("&>"); + seperators.add(">^"); + seperators.add('<'); + seperators.add("<<"); + seperators.add("<="); + seperators.add("<@"); + seperators.add("&<"); + seperators.add("<^"); + seperators.add('+'); + seperators.add('-'); + seperators.add('%'); + seperators.add('/'); + seperators.add('*'); + seperators.add('&'); + seperators.add("&&"); + seperators.add('|'); + seperators.add("||"); + seperators.add("|/"); + seperators.add("||/"); + seperators.add('^'); + seperators.add('~'); + seperators.add('!'); + seperators.add("->"); + seperators.add('#'); + seperators.add("##"); + seperators.add("@@"); + seperators.add("@-@"); + seperators.add("@@@"); + seperators.add("->>"); + seperators.add("<->"); + seperators.add("<=>"); + seperators.add(">>="); + seperators.add("<<="); + seperators.add("<<|"); + seperators.add("|>>"); + seperators.add("&<|"); + seperators.add("|&>"); + seperators.add("|>>"); + seperators.add("(+)"); + seperators.add("?#"); + seperators.add("?-"); + seperators.add("?-"); + seperators.add("?|"); + seperators.add("?-|"); + seperators.add("?||"); + seperators.add("~*"); + seperators.add("!~"); + seperators.add("!~*"); } private static final Map compositeWords = new ObjectPool(64); @@ -81,6 +139,8 @@ public final class SQLParser { compositeWords.put(WD.IS_NOT_EMPTY, new String[] { "IS", "NOT", "EMPTY" }); compositeWords.put(WD.IS_BLANK, new String[] { "IS", "BLANK" }); compositeWords.put(WD.IS_NOT_BLANK, new String[] { "IS", "NOT", "BLANK" }); + compositeWords.put(WD.NOT_IN, new String[] { "NOT", "IN" }); + compositeWords.put(WD.NOT_EXISTS, new String[] { "NOT", "EXISTS" }); List list = new ArrayList<>(compositeWords.keySet()); @@ -107,6 +167,7 @@ public static List parse(String sql) { final StringBuilder sb = Objectory.createStringBuilder(); final List words = new ArrayList<>(); + String temp = ""; char quoteChar = 0; for (int index = 0; index < sqlLength; index++) { @@ -115,13 +176,6 @@ public static List parse(String sql) { // char c = sqlCharArray[charIndex]; char c = sql.charAt(index); - if ((WD._BACKSLASH == c) && (index < (sqlLength - 1))) { - sb.append(c); - sb.charAt(++index); - - continue; - } - // is it in a quoted identifier? if (quoteChar != 0) { sb.append(c); @@ -133,49 +187,37 @@ public static List parse(String sql) { quoteChar = 0; } - } else { - if (seperators.containsKey(c)) { - if (sb.length() > 0) { - words.add(sb.toString()); - sb.setLength(0); - } + } else if (isSeperator(sql, sqlLength, index, c)) { + if (sb.length() > 0) { + words.add(sb.toString()); + sb.setLength(0); + } - if ((index < (sqlLength - 1))) { - String temp = sql.substring(index, index + 2); - - if (seperators.containsKey(temp)) { - words.add(temp); - index++; - } else { - if ((c == WD._SPACE) || (c == TAB) || (c == ENTER)) { - if ((words.size() > 0) && !words.get(words.size() - 1).equals(WD.SPACE)) { - words.add(WD.SPACE); - } - } else { - words.add(String.valueOf(c)); - } - } - } else { - if ((c == WD._SPACE) || (c == TAB) || (c == ENTER)) { - if ((words.size() > 0) && !words.get(words.size() - 1).equals(WD.SPACE)) { - words.add(WD.SPACE); - } - } else { - words.add(String.valueOf(c)); - } + if ((index < (sqlLength - 2)) && seperators.contains(temp = sql.substring(index, index + 3))) { + words.add(temp); + index += 2; + } else if ((index < (sqlLength - 1)) && seperators.contains(temp = sql.substring(index, index + 2))) { + words.add(temp); + index += 1; + } else if (c == WD._SPACE || c == TAB || c == ENTER) { + if ((words.size() > 0) && !words.get(words.size() - 1).equals(WD.SPACE)) { + words.add(WD.SPACE); } } else { - sb.append(c); + words.add(String.valueOf(c)); + } + } else { + sb.append(c); - if ((c == WD._QUOTATION_S) || (c == WD._QUOTATION_D)) { - quoteChar = c; - } + if ((c == WD._QUOTATION_S) || (c == WD._QUOTATION_D)) { + quoteChar = c; } } + } - if ((index == (sqlLength - 1)) && (sb.length() > 0)) { - words.add(sb.toString()); - } + if (sb.length() > 0) { + words.add(sb.toString()); + sb.setLength(0); } Objectory.recycle(sb); @@ -184,8 +226,6 @@ public static List parse(String sql) { } public static int indexWord(String sql, String word, int fromIndex, boolean caseSensitive) { - int result = -1; - String[] subWords = compositeWords.get(word); if (subWords == null) { @@ -194,30 +234,26 @@ public static int indexWord(String sql, String word, int fromIndex, boolean case } if ((subWords == null) || (subWords.length <= 1)) { + int result = N.INDEX_NOT_FOUND; + final StringBuilder sb = Objectory.createStringBuilder(); final int sqlLength = sql.length(); + String temp = ""; char quoteChar = 0; for (int index = fromIndex; index < sqlLength; index++) { char c = sql.charAt(index); - if ((WD._BACKSLASH == c) && (index < (sqlLength - 1))) { - sb.append(c); - sb.charAt(++index); - - continue; - } - // is it in a quoted identifier? if (quoteChar != 0) { sb.append(c); // end in quote. if (c == quoteChar) { - String temp = sb.toString(); + temp = sb.toString(); if (word.equals(temp) || (!caseSensitive && word.equalsIgnoreCase(temp))) { - result = index - word.length(); + result = index - word.length() + 1; break; } @@ -225,57 +261,65 @@ public static int indexWord(String sql, String word, int fromIndex, boolean case sb.setLength(0); quoteChar = 0; } - } else { - if (seperators.containsKey(c)) { - if ((sb.length() == 0) && (c != WD._SPACE) && (c != TAB) && (c != ENTER)) { - if ((index < (sqlLength - 1))) { - String temp = sql.substring(index, index + 2); - - if (seperators.containsKey(temp)) { - sb.append(temp); - index++; - } else { - sb.append(c); - } - } else { - sb.append(c); - } - } + } else if (isSeperator(sql, sqlLength, index, c)) { + if (sb.length() > 0) { + temp = sb.toString(); + + if (word.equals(temp) || (!caseSensitive && word.equalsIgnoreCase(temp))) { + result = index - word.length(); - if (sb.length() > 0) { - String temp = sb.toString(); + break; + } - if (word.equals(temp) || (!caseSensitive && word.equalsIgnoreCase(temp))) { - result = index - word.length(); + sb.setLength(0); + } else if (c == WD._SPACE || c == TAB || c == ENTER) { + // skip white char + continue; + } - break; - } + if ((index < (sqlLength - 2)) && seperators.contains(temp = sql.substring(index, index + 3))) { + if (word.equals(temp) || (!caseSensitive && word.equalsIgnoreCase(temp))) { + result = index; - sb.setLength(0); + break; } - } else { - sb.append(c); - if ((c == WD._QUOTATION_S) || (c == WD._QUOTATION_D)) { - quoteChar = c; - } - } - } + index += 2; + } else if ((index < (sqlLength - 1)) && seperators.contains(temp = sql.substring(index, index + 2))) { + if (word.equals(temp) || (!caseSensitive && word.equalsIgnoreCase(temp))) { + result = index; - if ((index == (sqlLength - 1)) && (sb.length() > 0)) { - String temp = sb.toString(); + break; + } - if (word.equals(temp) || (!caseSensitive && word.equalsIgnoreCase(temp))) { - result = sqlLength - word.length(); + index += 1; + } else if (word.equals(String.valueOf(c)) || (!caseSensitive && word.equalsIgnoreCase(String.valueOf(c)))) { + result = index; break; } + } else { + sb.append(c); + + if ((c == WD._QUOTATION_S) || (c == WD._QUOTATION_D)) { + quoteChar = c; + } + } + } + + if (result < 0 && sb.length() > 0) { + temp = sb.toString(); + + if (word.equals(temp) || (!caseSensitive && word.equalsIgnoreCase(temp))) { + result = sqlLength - word.length(); } } Objectory.recycle(sb); + + return result; } else { - result = indexWord(sql, subWords[0], fromIndex, caseSensitive); + int result = indexWord(sql, subWords[0], fromIndex, caseSensitive); if (result >= 0) { int tmpIndex = result + subWords[0].length(); @@ -284,7 +328,7 @@ public static int indexWord(String sql, String word, int fromIndex, boolean case for (int i = 1; i < subWords.length; i++) { nextWord = nextWord(sql, tmpIndex); - if ((nextWord != null) && (nextWord.equals(subWords[i]) || (!caseSensitive && nextWord.equalsIgnoreCase(subWords[i])))) { + if (N.notNullOrEmpty(nextWord) && (nextWord.equals(subWords[i]) || (!caseSensitive && nextWord.equalsIgnoreCase(subWords[i])))) { tmpIndex += (subWords[i].length() + 1); } else { result = -1; @@ -293,27 +337,21 @@ public static int indexWord(String sql, String word, int fromIndex, boolean case } } } - } - return result; + return result; + } } public static String nextWord(String sql, int fromIndex) { final int sqlLength = sql.length(); final StringBuilder sb = Objectory.createStringBuilder(); + String temp = ""; char quoteChar = 0; for (int index = fromIndex; index < sqlLength; index++) { char c = sql.charAt(index); - if ((WD._BACKSLASH == c) && (index < (sqlLength - 1))) { - sb.append(c); - sb.charAt(++index); - - continue; - } - // is it in a quoted identifier? if (quoteChar != 0) { sb.append(c); @@ -322,38 +360,66 @@ public static String nextWord(String sql, int fromIndex) { if (c == quoteChar) { break; } - } else { - if (seperators.containsKey(c)) { - if ((sb.length() == 0) && (c != WD._SPACE) && (c != TAB) && (c != ENTER)) { - if ((index < (sqlLength - 1))) { - String temp = sql.substring(index, index + 2); - - if (seperators.containsKey(temp)) { - sb.append(temp); - } else { - sb.append(c); - } - } else { - sb.append(c); - } - } + } else if (isSeperator(sql, sqlLength, index, c)) { + if (sb.length() > 0) { + break; + } else if (c == WD._SPACE || c == TAB || c == ENTER) { + // skip white char + continue; + } - if (sb.length() > 0) { - break; - } + if (((index < (sqlLength - 2)) && seperators.contains(temp = sql.substring(index, index + 3))) + || ((index < (sqlLength - 1)) && seperators.contains(temp = sql.substring(index, index + 2)))) { + sb.append(temp); } else { sb.append(c); + } - if ((c == WD._QUOTATION_S) || (c == WD._QUOTATION_D)) { - quoteChar = c; - } + break; + } else { + sb.append(c); + + if ((c == WD._QUOTATION_S) || (c == WD._QUOTATION_D)) { + quoteChar = c; } } } - String st = (sb.length() == 0) ? null : sb.toString(); + String st = (sb.length() == 0) ? "" : sb.toString(); Objectory.recycle(sb); return st; } + + public static void registerSeperator(char seperator) { + N.checkArgPositive(seperator, "seperator"); + + seperators.add(seperator); + } + + public static void registerSeperator(String seperator) { + N.checkArgNotNull(seperator, "seperator"); + + seperators.add(seperator); + + if (seperator.length() == 1) { + seperators.add(seperator.charAt(0)); + } + } + + public static boolean isSeperator(String str, int len, int index, char ch) { + // for Ibatis/Mybatis + if (ch == '#' && index < len - 1 && str.charAt(index + 1) == '{') { + return false; + } + + return seperators.contains(ch); + } + + public static boolean isFunctionName(final List words, int len, int index) { + // return (i < len - 1 && words.get(i + 1).charAt(0) == WD._PARENTHESES_L) + // || (i < len - 2 && WD.SPACE.equals(words.get(i + 1)) && words.get(i + 2).charAt(0) == WD._PARENTHESES_L); + + return (index < len - 1 && words.get(index + 1).charAt(0) == WD._PARENTHESES_L); + } } diff --git a/src/com/landawn/abacus/util/Seq.java b/src/com/landawn/abacus/util/Seq.java index b5239773..df60edb7 100644 --- a/src/com/landawn/abacus/util/Seq.java +++ b/src/com/landawn/abacus/util/Seq.java @@ -465,7 +465,7 @@ public void forEachPair(final Try.BiConsumer void forEachPair(final Try.BiConsumer action, final int increment) throws E { N.checkArgNotNull(action); final int windowSize = 2; - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); if (N.isNullOrEmpty(coll)) { return; @@ -482,7 +482,7 @@ public void forEachTriple(final Try.TriConsumer void forEachTriple(final Try.TriConsumer action, final int increment) throws E { N.checkArgNotNull(action); final int windowSize = 3; - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); if (N.isNullOrEmpty(coll)) { return; @@ -2058,7 +2058,7 @@ public List> sliding(final int windowSize) { } public List> sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); if (N.isNullOrEmpty(coll)) { return new ArrayList<>(); diff --git a/src/com/landawn/abacus/util/Timed.java b/src/com/landawn/abacus/util/Timed.java index d2fd8850..f3b82e9e 100644 --- a/src/com/landawn/abacus/util/Timed.java +++ b/src/com/landawn/abacus/util/Timed.java @@ -24,7 +24,7 @@ public class Timed { private final long timeInMillis; private final T value; - private Timed(T value, long timeInMillis) { + Timed(T value, long timeInMillis) { this.value = value; this.timeInMillis = timeInMillis; } @@ -37,7 +37,7 @@ public static Timed of(T value, long timeInMillis) { * * @return time in milliseconds. */ - public long time() { + public long timestamp() { return timeInMillis; } diff --git a/src/com/landawn/abacus/util/stream/ArrayByteStream.java b/src/com/landawn/abacus/util/stream/ArrayByteStream.java index c1a0a230..4dae7409 100644 --- a/src/com/landawn/abacus/util/stream/ArrayByteStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayByteStream.java @@ -741,7 +741,7 @@ public Stream splitAt(final int where) { @Override public Stream sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -792,7 +792,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; diff --git a/src/com/landawn/abacus/util/stream/ArrayCharStream.java b/src/com/landawn/abacus/util/stream/ArrayCharStream.java index 8b664b91..d2070575 100644 --- a/src/com/landawn/abacus/util/stream/ArrayCharStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayCharStream.java @@ -741,7 +741,7 @@ public Stream splitAt(final int where) { @Override public Stream sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -792,7 +792,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; diff --git a/src/com/landawn/abacus/util/stream/ArrayDoubleStream.java b/src/com/landawn/abacus/util/stream/ArrayDoubleStream.java index ce8de686..a0446506 100644 --- a/src/com/landawn/abacus/util/stream/ArrayDoubleStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayDoubleStream.java @@ -969,7 +969,7 @@ public Stream splitAt(final int where) { @Override public Stream sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -1020,7 +1020,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -1070,7 +1070,7 @@ public void skip(long n) { @Override public DoubleStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); if (n >= toIndex - fromIndex) { return this; diff --git a/src/com/landawn/abacus/util/stream/ArrayFloatStream.java b/src/com/landawn/abacus/util/stream/ArrayFloatStream.java index d745818d..33926877 100644 --- a/src/com/landawn/abacus/util/stream/ArrayFloatStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayFloatStream.java @@ -969,7 +969,7 @@ public Stream splitAt(final int where) { @Override public Stream sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -1020,7 +1020,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -1070,7 +1070,7 @@ public void skip(long n) { @Override public FloatStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); if (n >= toIndex - fromIndex) { return this; diff --git a/src/com/landawn/abacus/util/stream/ArrayIntStream.java b/src/com/landawn/abacus/util/stream/ArrayIntStream.java index 7d2a99d9..1e06f3bf 100644 --- a/src/com/landawn/abacus/util/stream/ArrayIntStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayIntStream.java @@ -1312,7 +1312,7 @@ public Stream splitAt(final int where) { @Override public Stream sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -1362,7 +1362,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -1413,7 +1413,7 @@ public void skip(long n) { @Override public IntStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); if (n >= toIndex - fromIndex) { return this; diff --git a/src/com/landawn/abacus/util/stream/ArrayLongStream.java b/src/com/landawn/abacus/util/stream/ArrayLongStream.java index 9246d539..2f9c487e 100644 --- a/src/com/landawn/abacus/util/stream/ArrayLongStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayLongStream.java @@ -970,7 +970,7 @@ public Stream splitAt(final int where) { @Override public Stream sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -1021,7 +1021,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -1071,7 +1071,7 @@ public void skip(long n) { @Override public LongStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); if (n >= toIndex - fromIndex) { return this; diff --git a/src/com/landawn/abacus/util/stream/ArrayShortStream.java b/src/com/landawn/abacus/util/stream/ArrayShortStream.java index f455a83b..f787dcbb 100644 --- a/src/com/landawn/abacus/util/stream/ArrayShortStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayShortStream.java @@ -742,7 +742,7 @@ public Stream splitAt(final int where) { @Override public Stream sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -793,7 +793,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -843,7 +843,7 @@ public void skip(long n) { @Override public ShortStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); if (n >= toIndex - fromIndex) { return this; diff --git a/src/com/landawn/abacus/util/stream/ArrayStream.java b/src/com/landawn/abacus/util/stream/ArrayStream.java index 30ab7967..e2a844ce 100644 --- a/src/com/landawn/abacus/util/stream/ArrayStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayStream.java @@ -407,7 +407,7 @@ public A[] toArray(A[] a) { public Stream slidingMap(final BiFunction mapper, final int increment, final boolean ignoreNotPaired) { final int windowSize = 2; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -459,7 +459,7 @@ public R next() { public Stream slidingMap(final TriFunction mapper, final int increment, final boolean ignoreNotPaired) { final int windowSize = 3; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); return newStream(new ObjIteratorEx() { private int cursor = fromIndex; @@ -2007,7 +2007,7 @@ public void skip(long n) { @Override public Stream> sliding(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx>() { private int cursor = fromIndex; @@ -2057,7 +2057,7 @@ public void skip(long n) { @Override public Stream> slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx>() { private int cursor = fromIndex; @@ -2108,7 +2108,7 @@ public void skip(long n) { @Override public > Stream sliding(final int windowSize, final int increment, final IntFunction collectionSupplier) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); N.checkArgNotNull(collectionSupplier); return newStream(new ObjIteratorEx() { @@ -2164,7 +2164,7 @@ public void skip(long n) { @Override public Stream sliding(final int windowSize, final int increment, final Collector collector) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); N.checkArgNotNull(collector); final Supplier supplier = collector.supplier(); @@ -2224,7 +2224,7 @@ public void skip(long n) { @Override public Stream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); if (n >= toIndex - fromIndex) { return this; @@ -2373,7 +2373,7 @@ public void forEach(Try.Consumer action) thr @Override public void forEachPair(final Try.BiConsumer action, final int increment) throws E { final int windowSize = 2; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); assertNotClosed(); try { @@ -2392,7 +2392,7 @@ public void forEachPair(final Try.BiConsumer void forEachTriple(final Try.TriConsumer action, final int increment) throws E { final int windowSize = 3; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); assertNotClosed(); try { diff --git a/src/com/landawn/abacus/util/stream/IteratorByteStream.java b/src/com/landawn/abacus/util/stream/IteratorByteStream.java index 4b87128b..014c751d 100644 --- a/src/com/landawn/abacus/util/stream/IteratorByteStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorByteStream.java @@ -640,7 +640,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private ByteList prev = null; diff --git a/src/com/landawn/abacus/util/stream/IteratorCharStream.java b/src/com/landawn/abacus/util/stream/IteratorCharStream.java index c5323964..ff12e859 100644 --- a/src/com/landawn/abacus/util/stream/IteratorCharStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorCharStream.java @@ -640,7 +640,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private CharList prev = null; diff --git a/src/com/landawn/abacus/util/stream/IteratorDoubleStream.java b/src/com/landawn/abacus/util/stream/IteratorDoubleStream.java index 39a722c3..fa926d81 100644 --- a/src/com/landawn/abacus/util/stream/IteratorDoubleStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorDoubleStream.java @@ -840,7 +840,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private DoubleList prev = null; @@ -960,7 +960,7 @@ public DoubleStream top(int n) { @Override public DoubleStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); return newStream(new DoubleIteratorEx() { private boolean initialized = false; diff --git a/src/com/landawn/abacus/util/stream/IteratorFloatStream.java b/src/com/landawn/abacus/util/stream/IteratorFloatStream.java index 5c23e87e..bbb71ac4 100644 --- a/src/com/landawn/abacus/util/stream/IteratorFloatStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorFloatStream.java @@ -836,7 +836,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private FloatList prev = null; @@ -956,7 +956,7 @@ public FloatStream top(int n) { @Override public FloatStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); return newStream(new FloatIteratorEx() { private boolean initialized = false; diff --git a/src/com/landawn/abacus/util/stream/IteratorIntStream.java b/src/com/landawn/abacus/util/stream/IteratorIntStream.java index 0ad41354..7cd5bf26 100644 --- a/src/com/landawn/abacus/util/stream/IteratorIntStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorIntStream.java @@ -1130,7 +1130,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private IntList prev = null; @@ -1250,7 +1250,7 @@ public IntStream top(int n) { @Override public IntStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); return newStream(new IntIteratorEx() { private boolean initialized = false; diff --git a/src/com/landawn/abacus/util/stream/IteratorLongStream.java b/src/com/landawn/abacus/util/stream/IteratorLongStream.java index dedc19b5..31004600 100644 --- a/src/com/landawn/abacus/util/stream/IteratorLongStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorLongStream.java @@ -841,7 +841,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private LongList prev = null; @@ -961,7 +961,7 @@ public LongStream top(int n) { @Override public LongStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); return newStream(new LongIteratorEx() { private boolean initialized = false; diff --git a/src/com/landawn/abacus/util/stream/IteratorShortStream.java b/src/com/landawn/abacus/util/stream/IteratorShortStream.java index 2da96b4c..ea75ee14 100644 --- a/src/com/landawn/abacus/util/stream/IteratorShortStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorShortStream.java @@ -645,7 +645,7 @@ public void skip(long n) { @Override public Stream slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private ShortList prev = null; @@ -765,7 +765,7 @@ public ShortStream top(int n) { @Override public ShortStream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); return newStream(new ShortIteratorEx() { private boolean initialized = false; diff --git a/src/com/landawn/abacus/util/stream/IteratorStream.java b/src/com/landawn/abacus/util/stream/IteratorStream.java index faea18d4..33b07fb9 100644 --- a/src/com/landawn/abacus/util/stream/IteratorStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorStream.java @@ -365,7 +365,7 @@ public R next() { public Stream slidingMap(final BiFunction mapper, final int increment, final boolean ignoreNotPaired) { final int windowSize = 2; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); return newStream(new ObjIteratorEx() { @SuppressWarnings("unchecked") @@ -417,7 +417,7 @@ public R next() { public Stream slidingMap(final TriFunction mapper, final int increment, final boolean ignoreNotPaired) { final int windowSize = 3; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); return newStream(new ObjIteratorEx() { @SuppressWarnings("unchecked") @@ -1709,7 +1709,7 @@ public void skip(long n) { @Override public Stream> slidingToList(final int windowSize, final int increment) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx>() { private List prev = null; @@ -1816,7 +1816,7 @@ public void skip(long n) { @Override public > Stream sliding(final int windowSize, final int increment, final IntFunction collectionSupplier) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); return newStream(new ObjIteratorEx() { private Deque queue = null; @@ -1944,7 +1944,7 @@ public void skip(long n) { @Override public Stream sliding(final int windowSize, final int increment, final Collector collector) { - N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment); + N.checkArgument(windowSize > 0 && increment > 0, "windowSize=%s and increment=%s must be bigger than 0", windowSize, increment); N.checkArgNotNull(collector); final Supplier supplier = collector.supplier(); @@ -2077,7 +2077,7 @@ public void skip(long n) { @Override public Stream top(final int n, final Comparator comparator) { - N.checkArgument(n > 0, "'n' must be bigger than 0"); + N.checkArgPositive(n, "n"); return newStream(new ObjIteratorEx() { private boolean initialized = false; @@ -2304,7 +2304,7 @@ public void forEach(Try.Consumer action) thr @Override public void forEachPair(final Try.BiConsumer action, final int increment) throws E { final int windowSize = 2; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); assertNotClosed(); try { @@ -2339,7 +2339,7 @@ public void forEachPair(final Try.BiConsumer void forEachTriple(final Try.TriConsumer action, final int increment) throws E { final int windowSize = 3; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); assertNotClosed(); try { diff --git a/src/com/landawn/abacus/util/stream/ParallelArrayStream.java b/src/com/landawn/abacus/util/stream/ParallelArrayStream.java index e26eba77..59a443d7 100644 --- a/src/com/landawn/abacus/util/stream/ParallelArrayStream.java +++ b/src/com/landawn/abacus/util/stream/ParallelArrayStream.java @@ -537,7 +537,7 @@ public Stream slidingMap(final BiFunction mapper final int windowSize = 2; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); final List> iters = new ArrayList<>(maxThreadNum); final MutableInt curIndex = MutableInt.of(fromIndex); @@ -585,7 +585,7 @@ public Stream slidingMap(final TriFunction 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); final List> iters = new ArrayList<>(maxThreadNum); final MutableInt curIndex = MutableInt.of(fromIndex); @@ -2542,7 +2542,7 @@ public void forEachPair(final Try.BiConsumer 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); final int threadNum = N.min(maxThreadNum, (toIndex - fromIndex)); final List> futureList = new ArrayList<>(threadNum); @@ -2591,7 +2591,7 @@ public void forEachTriple(final Try.TriConsumer 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); final int threadNum = N.min(maxThreadNum, (toIndex - fromIndex)); final List> futureList = new ArrayList<>(threadNum); diff --git a/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java b/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java index ddee81c2..966c08a4 100644 --- a/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java +++ b/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java @@ -405,7 +405,7 @@ public Stream slidingMap(final BiFunction mapper final int windowSize = 2; - N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); final List> iters = new ArrayList<>(maxThreadNum); final MutableBoolean isFirst = MutableBoolean.of(true); @@ -479,7 +479,7 @@ public Stream slidingMap(final TriFunction 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); final List> iters = new ArrayList<>(maxThreadNum); final MutableBoolean isFirst = MutableBoolean.of(true); @@ -1700,7 +1700,7 @@ public void forEachPair(final Try.BiConsumer 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); final List> futureList = new ArrayList<>(maxThreadNum); final Holder eHolder = new Holder<>(); @@ -1771,7 +1771,7 @@ public void forEachTriple(final Try.TriConsumer 0, "'increment'=%s must not be less than 1", increment); + N.checkArgPositive(increment, "increment"); final List> futureList = new ArrayList<>(maxThreadNum); final Holder eHolder = new Holder<>(); diff --git a/src/com/landawn/abacus/util/stream/Stream.java b/src/com/landawn/abacus/util/stream/Stream.java index 6a87ac4b..fcebae34 100644 --- a/src/com/landawn/abacus/util/stream/Stream.java +++ b/src/com/landawn/abacus/util/stream/Stream.java @@ -824,9 +824,6 @@ public Stream distinctBy(final Function keyExtractor, final public abstract Optional findFirstOrLast(Try.Predicate predicateForFirst, Try.Predicate predicateForLast) throws E, E2; - @ParallelSupported - public abstract Optional findAny(Try.Predicate predicate) throws E; - /** *
* This method only run sequentially, even in parallel stream. @@ -853,6 +850,9 @@ public abstract Optional findF public abstract Optional findFirstOrLast(final Function preFunc, final Try.BiPredicate predicateForFirst, final Try.BiPredicate predicateForLast) throws E, E2; + @ParallelSupported + public abstract Optional findAny(Try.Predicate predicate) throws E; + @SequentialOnly public abstract boolean containsAll(T... a); @@ -3083,7 +3083,7 @@ public T next() { } public static Stream observe(final BlockingQueue queue, final Predicate isLast, final long maxWaitIntervalInMillis) { - N.checkArgument(maxWaitIntervalInMillis > 0, "'maxWaitIntervalInMillis' can't be %s. It must be positive"); + N.checkArgPositive(maxWaitIntervalInMillis, "maxWaitIntervalInMillis"); final Iterator iter = new ObjIterator() { private T next = null; @@ -3100,7 +3100,7 @@ public boolean hasNext() { } isDone = isLast.test(next); - } while (next != null && isDone == false); + } while (next == null && isDone == false); } return next != null;