diff --git a/.classpath b/.classpath index a79d8a34..2bdf37b3 100644 --- a/.classpath +++ b/.classpath @@ -5,7 +5,7 @@ - + diff --git a/CHANGES.md b/CHANGES.md index 5848d591..4172c1df 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,12 @@ +### 1.7.4 + +* Add `Stream.reduce(U identity, BiFunction accumulator, BinaryOperator combiner)`. + +* Rename `JdbcUtil.RecordGetter/RecordConsumer/RecordPredicate` to `RowMapper/RowConsumer/RowFilter`. + +* Improvements and bug fix. + + ### 1.7.3 * Add `ContinuableFuture.map`. diff --git a/README.md b/README.md index b6847690..253c5aae 100644 --- a/README.md +++ b/README.md @@ -183,32 +183,32 @@ 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.7.3/com/landawn/abacus/util/Charsets.html), -[Ascii](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/Ascii.html), -[CalendarUnit](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/CalendarUnit.html), -[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/NamingPolicy.html), -[Properties](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/Properties.html), -[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/PropertiesUtil.html), -[Wrapper](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/Wrapper.html), -[ArrayHashSet](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/ArrayHashSet.html), -[ArrayHashMap](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/ArrayHashMap.html), -[ClassUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/ClassUtil.html), -[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/EscapeUtil.html), -[RegExUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/RegExUtil.html), -[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/FilenameUtil.html), -[AWSJSONUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/AWSJSONUtil.html), -[AddrUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/AddrUtil.html), -[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/WSSecurityUtil.html), -[EmailUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/EmailUtil.html), -[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/IEEE754rUtil.html), -[Index](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/Index.html), -[Median](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/Median.html), -[f](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/f.html), -[Matth](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/Matth.html), -[SafeInitializer](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/SafeInitializer.html), -[Stopwatch](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/Stopwatch.html), -[RateLimiter](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/RateLimiter.html), -[Traverser](https://static.javadoc.io/com.landawn/abacus-util/1.7.3/com/landawn/abacus/util/Traverser.html)(from Apache commons, Google Guava...) ... +[Charsets](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/Charsets.html), +[Ascii](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/Ascii.html), +[CalendarUnit](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/CalendarUnit.html), +[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/NamingPolicy.html), +[Properties](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/Properties.html), +[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/PropertiesUtil.html), +[Wrapper](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/Wrapper.html), +[ArrayHashSet](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/ArrayHashSet.html), +[ArrayHashMap](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/ArrayHashMap.html), +[ClassUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/ClassUtil.html), +[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/EscapeUtil.html), +[RegExUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/RegExUtil.html), +[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/FilenameUtil.html), +[AWSJSONUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/AWSJSONUtil.html), +[AddrUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/AddrUtil.html), +[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/WSSecurityUtil.html), +[EmailUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/EmailUtil.html), +[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/IEEE754rUtil.html), +[Index](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/Index.html), +[Median](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/Median.html), +[f](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/f.html), +[Matth](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/Matth.html), +[SafeInitializer](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/SafeInitializer.html), +[Stopwatch](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/Stopwatch.html), +[RateLimiter](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/com/landawn/abacus/util/RateLimiter.html), +[Traverser](https://static.javadoc.io/com.landawn/abacus-util/1.7.4/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.7.3' +compile 'com.landawn:abacus-util:1.7.4' // JDK 1.7: -compile 'com.landawn:abacus-util-jdk7:1.7.3' +compile 'com.landawn:abacus-util-jdk7:1.7.4' // Android (Java 1.7): -compile 'abacus-android-jdk7:1.7.3' +compile 'abacus-android-jdk7:1.7.4' // Android-SE (Java 1.7) - small edition without Stream/Matrix/Sheet/...: -compile 'abacus-android-se-jdk7:1.7.3' +compile 'abacus-android-se-jdk7:1.7.4' // Android (Java 1.8 or above): -compile 'com.landawn:abacus-android:1.7.3' +compile 'com.landawn:abacus-android:1.7.4' // Android-SE (Java 1.8 or above) - small edition without Stream/Matrix/Sheet/...: -compile 'com.landawn:abacus-android-se:1.7.3' +compile 'com.landawn:abacus-android-se:1.7.4' ``` ### 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/ExceptionalStream.gif b/docs/ExceptionalStream.gif index 0ce29a29..5a2993d3 100644 Binary files a/docs/ExceptionalStream.gif and b/docs/ExceptionalStream.gif differ diff --git a/docs/Seq.gif b/docs/Seq.gif index 617b0517..182d822c 100644 Binary files a/docs/Seq.gif and b/docs/Seq.gif differ diff --git a/lib/abacus-android-1.7.3.jar b/lib/abacus-android-1.7.4.jar similarity index 83% rename from lib/abacus-android-1.7.3.jar rename to lib/abacus-android-1.7.4.jar index ef257be8..50c4b9c6 100644 Binary files a/lib/abacus-android-1.7.3.jar and b/lib/abacus-android-1.7.4.jar differ diff --git a/lib/abacus-android-jdk7-1.7.3.jar b/lib/abacus-android-jdk7-1.7.4.jar similarity index 82% rename from lib/abacus-android-jdk7-1.7.3.jar rename to lib/abacus-android-jdk7-1.7.4.jar index 74c28cb2..83cc8afe 100644 Binary files a/lib/abacus-android-jdk7-1.7.3.jar and b/lib/abacus-android-jdk7-1.7.4.jar differ diff --git a/lib/abacus-android-se-1.7.3.jar b/lib/abacus-android-se-1.7.4.jar similarity index 82% rename from lib/abacus-android-se-1.7.3.jar rename to lib/abacus-android-se-1.7.4.jar index c0a7ef33..ecc929a6 100644 Binary files a/lib/abacus-android-se-1.7.3.jar and b/lib/abacus-android-se-1.7.4.jar differ diff --git a/lib/abacus-android-se-jdk7-1.7.3.jar b/lib/abacus-android-se-jdk7-1.7.4.jar similarity index 82% rename from lib/abacus-android-se-jdk7-1.7.3.jar rename to lib/abacus-android-se-jdk7-1.7.4.jar index 89bbaecd..497bc3e2 100644 Binary files a/lib/abacus-android-se-jdk7-1.7.3.jar and b/lib/abacus-android-se-jdk7-1.7.4.jar differ diff --git a/lib/abacus-util-1.7.3.jar b/lib/abacus-util-1.7.4.jar similarity index 81% rename from lib/abacus-util-1.7.3.jar rename to lib/abacus-util-1.7.4.jar index e9b29536..efe8cef8 100644 Binary files a/lib/abacus-util-1.7.3.jar and b/lib/abacus-util-1.7.4.jar differ diff --git a/lib/abacus-util-jdk7-1.7.3.jar b/lib/abacus-util-jdk7-1.7.4.jar similarity index 81% rename from lib/abacus-util-jdk7-1.7.3.jar rename to lib/abacus-util-jdk7-1.7.4.jar index 8bc40b8a..1110329c 100644 Binary files a/lib/abacus-util-jdk7-1.7.3.jar and b/lib/abacus-util-jdk7-1.7.4.jar differ diff --git a/src/com/landawn/abacus/DataSet.java b/src/com/landawn/abacus/DataSet.java index 1ec3ad2e..7a6738ba 100644 --- a/src/com/landawn/abacus/DataSet.java +++ b/src/com/landawn/abacus/DataSet.java @@ -52,6 +52,7 @@ * @author Haiyang Li * * @see com.landawn.abacus.util.DataSetUtil + * @see com.landawn.abacus.util.Build.DataSetBuilder * @see com.landawn.abacus.util.JdbcUtil * @see com.landawn.abacus.util.CSVUtil * @see com.landawn.abacus.util.function.IntFunction @@ -186,6 +187,8 @@ public interface DataSet { void swapRows(int rowIndexA, int rowIndexB); /** + * There is NO underline auto-conversion from column value to target type: {@code T}. + * So the column values must be the type which is assignable to target type. * * @param rowIndex * @param columnIndex @@ -194,12 +197,17 @@ public interface DataSet { T get(int rowIndex, int columnIndex); /** - * @param targetClass + * There is NO underline auto-conversion from column value to target type: {@code T}. + * So the column values must be the type which is assignable to target type. + * + * @param targetType * @param rowIndex * @param columnIndex * @return + * @deprecated may be misused because it implies there is an underline auto-conversion from column values to target return type but actually there is not. */ - T get(Class targetClass, int rowIndex, int columnIndex); + @Deprecated + T get(Class targetType, int rowIndex, int columnIndex); /** * @@ -217,39 +225,54 @@ public interface DataSet { */ boolean isNull(int rowIndex, int columnIndex); - /** + /** + * There is NO underline auto-conversion from column value to target type: {@code T}. + * So the column values must be the type which is assignable to target type. * * @param columnIndex * @return */ T get(int columnIndex); - /** + /** + * There is NO underline auto-conversion from column value to target type: {@code T}. + * So the column values must be the type which is assignable to target type. * - * @param targetClass - * @param columnIndex + * @param columnName * @return */ - T get(Class targetClass, int columnIndex); + T get(String columnName); /** + * There is NO underline auto-conversion from column value to target type: {@code T}. + * So the column values must be the type which is assignable to target type. * - * @param columnName + * @param targetType + * @param columnIndex * @return + * @deprecated may be misused because it implies there is an underline auto-conversion from column values to target return type but actually there is not. */ - T get(String columnName); + @Deprecated + T get(Class targetType, int columnIndex); - /** + /** + * There is NO underline auto-conversion from column value to target type: {@code T}. + * So the column values must be the type which is assignable to target type. * - * @param targetClass + * @param targetType * @param columnName * @return + * @deprecated may be misused because it implies there is an underline auto-conversion from column values to target return type but actually there is not. */ - T get(Class targetClass, String columnName); + @Deprecated + T get(Class targetType, String columnName); /** * Returns the value from the current row and specified column if the specified {@code columnIndex} is equal or bigger than zero, * or the specified {@code defaultValue} otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code T}. + * So the column values must be the type which is assignable to target type. * * @param columnIndex * @param defaultValue @@ -262,6 +285,9 @@ public interface DataSet { /** * Returns the value from the current row and specified column if the specified {@code columnName} exists, * or the specified {@code defaultValue} otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code T}. + * So the column values must be the type which is assignable to target type. * * @param columnName * @param defaultValue @@ -273,6 +299,9 @@ public interface DataSet { /** * Return default value (false) if the property is null. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Boolean}. + * So the column values must be the type which is assignable to target type. * * @param columnIndex * @return @@ -281,6 +310,9 @@ public interface DataSet { /** * Return default value (false) if the property is null. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Boolean}. + * So the column values must be the type which is assignable to target type. * * @param columnName * @return @@ -289,6 +321,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Character}. + * So the column values must be the type which is assignable to target type. * * @param columnIndex * @return @@ -297,6 +332,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Character}. + * So the column values must be the type which is assignable to target type. * * @param columnName * @return @@ -305,6 +343,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. Return Number.byteValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Byte}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnIndex * @return @@ -313,6 +354,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. Return Number.byteValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Byte}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnName * @return @@ -321,6 +365,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. Return Number.shortValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Short}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnIndex * @return @@ -329,6 +376,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. Return Number.shortValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Short}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnName * @return @@ -337,6 +387,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. Return Number.intValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Integer}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnIndex * @return @@ -345,6 +398,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. Return Number.intValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Integer}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnName * @return @@ -353,6 +409,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. Return Number.longValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Long}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnIndex * @return @@ -361,6 +420,9 @@ public interface DataSet { /** * Return default value (0) if the property is null. Return Number.longValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Long}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnName * @return @@ -369,6 +431,9 @@ public interface DataSet { /** * Return default value (0f) if the property is null. Return Number.floatValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Float}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnIndex * @return @@ -377,6 +442,9 @@ public interface DataSet { /** * Return default value (0f) if the property is null. Return Number.floatValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Float}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnName * @return @@ -385,6 +453,9 @@ public interface DataSet { /** * Return default value (0d) if the property is null. Return Number.doubleValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Double}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnIndex * @return @@ -393,6 +464,9 @@ public interface DataSet { /** * Return default value (0d) if the property is null. Return Number.doubleValue() otherwise. + *
+ * There is NO underline auto-conversion from column value to target type: {@code Double}. + * So the column values must be the type which is assignable to target type, or {@code Number}. * * @param columnName * @return diff --git a/src/com/landawn/abacus/cache/SpyMemcached.java b/src/com/landawn/abacus/cache/SpyMemcached.java index 6c1c0943..1bc708d8 100644 --- a/src/com/landawn/abacus/cache/SpyMemcached.java +++ b/src/com/landawn/abacus/cache/SpyMemcached.java @@ -39,7 +39,7 @@ * @author Haiyang Li */ public class SpyMemcached extends AbstractDistributedCacheClient { - private static final Logger logger = LoggerFactory.getLogger(SpyMemcached.class); + static final Logger logger = LoggerFactory.getLogger(SpyMemcached.class); private MemcachedClient mc; public SpyMemcached(final String serverUrl) { @@ -218,9 +218,7 @@ protected net.spy.memcached.MemcachedClient createSpyMemcachedClient(String serv try { return new net.spy.memcached.MemcachedClient(connFactory, AddrUtil.getAddressList(serverUrl)); } catch (IOException e) { - String msg = "Failed to create Memcached client."; - logger.warn(msg, e); - throw new UncheckedIOException(msg, e); + throw new UncheckedIOException("Failed to create Memcached client.", e); } } } diff --git a/src/com/landawn/abacus/core/RowDataSet.java b/src/com/landawn/abacus/core/RowDataSet.java index d44cc72c..75b7319b 100644 --- a/src/com/landawn/abacus/core/RowDataSet.java +++ b/src/com/landawn/abacus/core/RowDataSet.java @@ -458,10 +458,10 @@ public T get(final int rowIndex, final int columnIndex) { } @Override - public T get(final Class targetClass, final int rowIndex, final int columnIndex) { + public T get(final Class targetType, final int rowIndex, final int columnIndex) { T rt = (T) _columnList.get(columnIndex).get(rowIndex); - return (rt == null) ? N.defaultValueOf(targetClass) : rt; + return (rt == null) ? N.defaultValueOf(targetType) : rt; } @Override @@ -485,10 +485,10 @@ public T get(final int columnIndex) { } @Override - public T get(final Class targetClass, final int columnIndex) { + public T get(final Class targetType, final int columnIndex) { T rt = get(columnIndex); - return (rt == null) ? N.defaultValueOf(targetClass) : rt; + return (rt == null) ? N.defaultValueOf(targetType) : rt; } @SuppressWarnings("unchecked") @@ -498,8 +498,8 @@ public T get(final String columnName) { } @Override - public T get(final Class targetClass, final String columnName) { - return get(targetClass, checkColumnName(columnName)); + public T get(final Class targetType, final String columnName) { + return get(targetType, checkColumnName(columnName)); } @Override diff --git a/src/com/landawn/abacus/dataSource/AbstractConnectionManager.java b/src/com/landawn/abacus/dataSource/AbstractConnectionManager.java index 777203ca..2089479b 100644 --- a/src/com/landawn/abacus/dataSource/AbstractConnectionManager.java +++ b/src/com/landawn/abacus/dataSource/AbstractConnectionManager.java @@ -60,7 +60,7 @@ * @author Haiyang Li */ abstract class AbstractConnectionManager implements ConnectionManager { - private static final Logger logger = LoggerFactory.getLogger(AbstractConnectionManager.class); + static final Logger logger = LoggerFactory.getLogger(AbstractConnectionManager.class); protected final Map properties; protected final Properties connectionProperties; @@ -253,9 +253,7 @@ protected DataSource createJNDIDataSource(Map properties) { return (DataSource) ctx.lookup(jndiName); } catch (NamingException e) { - String msg = "Failed to bind to JNDI: " + jndiName + ". " + AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedException(msg, e); + throw new UncheckedException("Failed to bind to JNDI: " + jndiName + ". " + AbacusException.getErrorMsg(e), e); } } diff --git a/src/com/landawn/abacus/dataSource/C3P0ConnectionManager.java b/src/com/landawn/abacus/dataSource/C3P0ConnectionManager.java index 8929ddd8..d1fe488c 100644 --- a/src/com/landawn/abacus/dataSource/C3P0ConnectionManager.java +++ b/src/com/landawn/abacus/dataSource/C3P0ConnectionManager.java @@ -39,7 +39,7 @@ * @author Haiyang Li */ class C3P0ConnectionManager extends AbstractConnectionManager { - private static final Logger logger = LoggerFactory.getLogger(C3P0ConnectionManager.class); + static final Logger logger = LoggerFactory.getLogger(C3P0ConnectionManager.class); private final DataSource ds; private final com.mchange.v2.c3p0.ComboPooledDataSource cpds; @@ -101,9 +101,7 @@ public int getNumActive() { try { return cpds.getNumConnections(); } catch (SQLException e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedSQLException(msg, e); + throw new UncheckedSQLException(AbacusException.getErrorMsg(e), e); } } @@ -112,9 +110,7 @@ public Connection getConnection() { try { return ds.getConnection(); } catch (SQLException e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedSQLException(msg, e); + throw new UncheckedSQLException(AbacusException.getErrorMsg(e), e); } } @@ -124,9 +120,7 @@ public void closeConnection(Connection conn) { try { conn.close(); } catch (SQLException e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedSQLException(msg, e); + throw new UncheckedSQLException(AbacusException.getErrorMsg(e), e); } } } diff --git a/src/com/landawn/abacus/dataSource/DBCPConnectionManager.java b/src/com/landawn/abacus/dataSource/DBCPConnectionManager.java index fec5c5b4..9f7c8122 100644 --- a/src/com/landawn/abacus/dataSource/DBCPConnectionManager.java +++ b/src/com/landawn/abacus/dataSource/DBCPConnectionManager.java @@ -31,6 +31,7 @@ import com.landawn.abacus.exception.UncheckedSQLException; import com.landawn.abacus.logging.Logger; import com.landawn.abacus.logging.LoggerFactory; +import com.landawn.abacus.util.N; /** * @@ -39,7 +40,7 @@ * @author Haiyang Li */ class DBCPConnectionManager extends AbstractConnectionManager { - private static final Logger logger = LoggerFactory.getLogger(DBCPConnectionManager.class); + static final Logger logger = LoggerFactory.getLogger(DBCPConnectionManager.class); private final DataSource ds; private final org.apache.commons.dbcp.BasicDataSource bds; @@ -54,9 +55,7 @@ public DBCPConnectionManager(Map props) { try { bds = (org.apache.commons.dbcp.BasicDataSource) org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource(new Properties()); } catch (Exception e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new RuntimeException(msg, e); + throw N.toRuntimeException(e); } bds.setDriverClassName(properties.get(DRIVER)); @@ -101,9 +100,7 @@ public Connection getConnection() { try { return ds.getConnection(); } catch (SQLException e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedSQLException(msg, e); + throw new UncheckedSQLException(AbacusException.getErrorMsg(e), e); } } @@ -113,9 +110,7 @@ public void closeConnection(Connection conn) { try { conn.close(); } catch (SQLException e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedSQLException(msg, e); + throw new UncheckedSQLException(AbacusException.getErrorMsg(e), e); } } } @@ -131,9 +126,7 @@ public void close() { try { bds.close(); } catch (SQLException e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedSQLException(msg, e); + throw new UncheckedSQLException(AbacusException.getErrorMsg(e), e); } } } diff --git a/src/com/landawn/abacus/dataSource/HikariConnectionManager.java b/src/com/landawn/abacus/dataSource/HikariConnectionManager.java index 9911e4dc..41dc9967 100644 --- a/src/com/landawn/abacus/dataSource/HikariConnectionManager.java +++ b/src/com/landawn/abacus/dataSource/HikariConnectionManager.java @@ -31,7 +31,7 @@ * @author Haiyang Li */ class HikariConnectionManager extends AbstractConnectionManager { - private static final Logger logger = LoggerFactory.getLogger(HikariConnectionManager.class); + static final Logger logger = LoggerFactory.getLogger(HikariConnectionManager.class); private final com.zaxxer.hikari.HikariDataSource ds; @@ -74,9 +74,7 @@ public Connection getConnection() { try { return ds.getConnection(); } catch (SQLException e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedSQLException(msg, e); + throw new UncheckedSQLException(AbacusException.getErrorMsg(e), e); } } @@ -86,9 +84,7 @@ public void closeConnection(Connection conn) { try { conn.close(); } catch (SQLException e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new UncheckedSQLException(msg, e); + throw new UncheckedSQLException(AbacusException.getErrorMsg(e), e); } } } diff --git a/src/com/landawn/abacus/dataSource/PoolableConnection.java b/src/com/landawn/abacus/dataSource/PoolableConnection.java index 26ee29d2..2b812210 100644 --- a/src/com/landawn/abacus/dataSource/PoolableConnection.java +++ b/src/com/landawn/abacus/dataSource/PoolableConnection.java @@ -78,7 +78,7 @@ void cachePreparedStatement(PoolablePreparedStatement stmt) { CachedStatmentKey id = stmt.getId(); try { - stmt.clearParameters(); + stmt.reset(); synchronized (cachedStatementPool) { if (cachedStatementPool.containsKey(id)) { diff --git a/src/com/landawn/abacus/dataSource/PoolablePreparedStatement.java b/src/com/landawn/abacus/dataSource/PoolablePreparedStatement.java index 8cd4cbb0..a1843cdc 100644 --- a/src/com/landawn/abacus/dataSource/PoolablePreparedStatement.java +++ b/src/com/landawn/abacus/dataSource/PoolablePreparedStatement.java @@ -1358,6 +1358,7 @@ public void setEscapeProcessing(boolean enable) throws SQLException { */ @Override public void setFetchDirection(int direction) throws SQLException { + this.fetchDirection = internalStmt.getFetchDirection(); internalStmt.setFetchDirection(direction); } @@ -1370,6 +1371,7 @@ public void setFetchDirection(int direction) throws SQLException { */ @Override public void setFetchSize(int rows) throws SQLException { + this.fetchSize = internalStmt.getFetchSize(); internalStmt.setFetchSize(rows); } @@ -1382,6 +1384,7 @@ public void setFetchSize(int rows) throws SQLException { */ @Override public void setMaxFieldSize(int max) throws SQLException { + this.maxFieldSize = internalStmt.getMaxFieldSize(); internalStmt.setMaxFieldSize(max); } @@ -1394,31 +1397,33 @@ public void setMaxFieldSize(int max) throws SQLException { */ @Override public void setMaxRows(int max) throws SQLException { + this.maxRows = internalStmt.getMaxRows(); internalStmt.setMaxRows(max); } /** - * Method setPoolable. + * Method setQueryTimeout. * - * @param poolable + * @param seconds * @throws SQLException - * @see java.sql.Statement#setPoolable(boolean) + * @see java.sql.Statement#setQueryTimeout(int) */ @Override - public void setPoolable(boolean poolable) throws SQLException { - internalStmt.setPoolable(poolable); + public void setQueryTimeout(int seconds) throws SQLException { + this.queryTimeout = internalStmt.getQueryTimeout(); + internalStmt.setQueryTimeout(seconds); } /** - * Method setQueryTimeout. + * Method setPoolable. * - * @param seconds + * @param poolable * @throws SQLException - * @see java.sql.Statement#setQueryTimeout(int) + * @see java.sql.Statement#setPoolable(boolean) */ @Override - public void setQueryTimeout(int seconds) throws SQLException { - internalStmt.setQueryTimeout(seconds); + public void setPoolable(boolean poolable) throws SQLException { + internalStmt.setPoolable(poolable); } /** @@ -1488,6 +1493,38 @@ public boolean isCloseOnCompletion() throws SQLException { return internalStmt.isCloseOnCompletion(); } + private int fetchSize = -1; + private int fetchDirection = -1; + private int maxRows = -1; + private int maxFieldSize = -1; + private int queryTimeout = -1; + + protected void reset() throws SQLException { + // internalStmt.clearParameters(); + // internalStmt.clearBatch(); + // internalStmt.clearWarnings(); + + if (fetchSize != -1) { + internalStmt.setFetchSize(fetchSize); + } + + if (fetchDirection != -1) { + internalStmt.setFetchDirection(fetchDirection); + } + + if (maxRows != -1) { + internalStmt.setMaxRows(maxRows); + } + + if (maxFieldSize != -1) { + internalStmt.setMaxFieldSize(maxFieldSize); + } + + if (queryTimeout != -1) { + internalStmt.setQueryTimeout(queryTimeout); + } + } + static class ResultSetProxy implements ResultSet { private final ResultSet internalRS; private final PoolablePreparedStatement poolableStmt; diff --git a/src/com/landawn/abacus/dataSource/SQLConnectionManager.java b/src/com/landawn/abacus/dataSource/SQLConnectionManager.java index b4569092..fee23bf4 100644 --- a/src/com/landawn/abacus/dataSource/SQLConnectionManager.java +++ b/src/com/landawn/abacus/dataSource/SQLConnectionManager.java @@ -46,6 +46,7 @@ import com.landawn.abacus.util.ClassUtil; import com.landawn.abacus.util.Configuration; import com.landawn.abacus.util.JdbcUtil; +import com.landawn.abacus.util.N; /** * @@ -184,9 +185,7 @@ public Connection getConnection() { } if (conn == null) { - String msg = "Can not get connection. Max active connection is " + maxActive + ". Current active connection: " + xpool.size(); - logger.warn(msg); - throw new RuntimeException(msg); + throw new RuntimeException("Can not get connection. Max active connection is " + maxActive + ". Current active connection: " + xpool.size()); } } @@ -376,7 +375,6 @@ private synchronized PoolableConnection newConnection() { } catch (SQLException e) { String msg = "Faied to create new connection for data source '" + url + "'." + " [Active connection number]: " + (xpool.size() + 1) + ". " + AbacusException.getErrorMsg(e); - logger.error(msg, e); throw new UncheckedSQLException(msg, e); } } @@ -476,9 +474,7 @@ class DriverManagerDataSource extends AbstractDataSource { try { DriverManager.registerDriver((Driver) ClassUtil.forClass(driver).newInstance()); } catch (Exception e) { - String msg = AbacusException.getErrorMsg(e); - logger.warn(msg); - throw new RuntimeException(msg, e); + throw N.toRuntimeException(e); } } diff --git a/src/com/landawn/abacus/dataSource/SQLDataSource.java b/src/com/landawn/abacus/dataSource/SQLDataSource.java index 547cfa8b..9706d987 100644 --- a/src/com/landawn/abacus/dataSource/SQLDataSource.java +++ b/src/com/landawn/abacus/dataSource/SQLDataSource.java @@ -96,7 +96,6 @@ public SQLDataSource(DataSourceConfiguration dsConfig) { databaseProductVersion = metaData.getDatabaseProductVersion(); defaultConnectionIsolation = conn.getTransactionIsolation(); } catch (SQLException e) { - logger.warn(AbacusException.getErrorMsg(e)); throw new UncheckedSQLException(e); } finally { close(conn); @@ -148,7 +147,6 @@ public SQLDataSource(Map props) { databaseProductVersion = metaData.getDatabaseProductVersion(); defaultConnectionIsolation = conn.getTransactionIsolation(); } catch (SQLException e) { - logger.warn(AbacusException.getErrorMsg(e)); throw new UncheckedSQLException(e); } finally { close(conn); @@ -216,9 +214,7 @@ private ConnectionManager createConnectionManager(String provider, Map ContinuableFuture insert(final String sql, final Object... parameters) { - return asyncExecutor.execute(new Callable() { + public final ContinuableFuture insert(final String sql, final Object... parameters) { + return asyncExecutor.execute(new Callable() { @Override - public T call() throws Exception { + public ID call() throws Exception { return sqlExecutor.insert(sql, parameters); } }); } @SafeVarargs - public final ContinuableFuture insert(final String sql, final StatementSetter statementSetter, final Object... parameters) { - return asyncExecutor.execute(new Callable() { + public final ContinuableFuture insert(final String sql, final StatementSetter statementSetter, final Object... parameters) { + return asyncExecutor.execute(new Callable() { @Override - public T call() throws Exception { + public ID call() throws Exception { return sqlExecutor.insert(sql, statementSetter, parameters); } }); } @SafeVarargs - public final ContinuableFuture insert(final String sql, final JdbcSettings jdbcSettings, final Object... parameters) { - return asyncExecutor.execute(new Callable() { + public final ContinuableFuture insert(final String sql, final JdbcSettings jdbcSettings, final Object... parameters) { + return asyncExecutor.execute(new Callable() { @Override - public T call() throws Exception { + public ID call() throws Exception { return sqlExecutor.insert(sql, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture insert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, + public final ContinuableFuture insert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) { - return asyncExecutor.execute(new Callable() { + return asyncExecutor.execute(new Callable() { @Override - public T call() throws Exception { + public ID call() throws Exception { return sqlExecutor.insert(sql, statementSetter, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture insert(final Connection conn, final String sql, final Object... parameters) { - return asyncExecutor.execute(new Callable() { + public final ContinuableFuture insert(final Connection conn, final String sql, final Object... parameters) { + return asyncExecutor.execute(new Callable() { @Override - public T call() throws Exception { + public ID call() throws Exception { return sqlExecutor.insert(conn, sql, parameters); } }); } @SafeVarargs - public final ContinuableFuture insert(final Connection conn, final String sql, final StatementSetter statementSetter, final Object... parameters) { - return asyncExecutor.execute(new Callable() { + public final ContinuableFuture insert(final Connection conn, final String sql, final StatementSetter statementSetter, final Object... parameters) { + return asyncExecutor.execute(new Callable() { @Override - public T call() throws Exception { + public ID call() throws Exception { return sqlExecutor.insert(conn, sql, statementSetter, parameters); } }); } @SafeVarargs - public final ContinuableFuture insert(final Connection conn, final String sql, final JdbcSettings jdbcSettings, final Object... parameters) { - return asyncExecutor.execute(new Callable() { + public final ContinuableFuture insert(final Connection conn, final String sql, final JdbcSettings jdbcSettings, final Object... parameters) { + return asyncExecutor.execute(new Callable() { @Override - public T call() throws Exception { + public ID call() throws Exception { return sqlExecutor.insert(conn, sql, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture insert(final Connection conn, final String sql, final StatementSetter statementSetter, + public final ContinuableFuture insert(final Connection conn, final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) { - return asyncExecutor.execute(new Callable() { + return asyncExecutor.execute(new Callable() { @Override - public T call() throws Exception { + public ID call() throws Exception { return sqlExecutor.insert(conn, sql, statementSetter, jdbcSettings, parameters); } }); } - public ContinuableFuture> batchInsert(final String sql, final List parametersList) { - return asyncExecutor.execute(new Callable>() { + public ContinuableFuture> batchInsert(final String sql, final List parametersList) { + return asyncExecutor.execute(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return sqlExecutor.batchInsert(sql, parametersList); } }); } - public ContinuableFuture> batchInsert(final String sql, final StatementSetter statementSetter, final List parametersList) { - return asyncExecutor.execute(new Callable>() { + public ContinuableFuture> batchInsert(final String sql, final StatementSetter statementSetter, final List parametersList) { + return asyncExecutor.execute(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return sqlExecutor.batchInsert(sql, statementSetter, parametersList); } }); } - public ContinuableFuture> batchInsert(final String sql, final JdbcSettings jdbcSettings, final List parametersList) { - return asyncExecutor.execute(new Callable>() { + public ContinuableFuture> batchInsert(final String sql, final JdbcSettings jdbcSettings, final List parametersList) { + return asyncExecutor.execute(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return sqlExecutor.batchInsert(sql, jdbcSettings, parametersList); } }); } - public ContinuableFuture> batchInsert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, + public ContinuableFuture> batchInsert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final List parametersList) { - return asyncExecutor.execute(new Callable>() { + return asyncExecutor.execute(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return sqlExecutor.batchInsert(sql, statementSetter, jdbcSettings, parametersList); } }); } - public ContinuableFuture> batchInsert(final Connection conn, final String sql, final List parametersList) { - return asyncExecutor.execute(new Callable>() { + public ContinuableFuture> batchInsert(final Connection conn, final String sql, final List parametersList) { + return asyncExecutor.execute(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return sqlExecutor.batchInsert(conn, sql, parametersList); } }); } - public ContinuableFuture> batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter, + public ContinuableFuture> batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter, final List parametersList) { - return asyncExecutor.execute(new Callable>() { + return asyncExecutor.execute(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return sqlExecutor.batchInsert(conn, sql, statementSetter, parametersList); } }); } - public ContinuableFuture> batchInsert(final Connection conn, final String sql, final JdbcSettings jdbcSettings, final List parametersList) { - return asyncExecutor.execute(new Callable>() { + public ContinuableFuture> batchInsert(final Connection conn, final String sql, final JdbcSettings jdbcSettings, + final List parametersList) { + return asyncExecutor.execute(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return sqlExecutor.batchInsert(conn, sql, jdbcSettings, parametersList); } }); } - public ContinuableFuture> batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter, + public ContinuableFuture> batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final List parametersList) { - return asyncExecutor.execute(new Callable>() { + return asyncExecutor.execute(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return sqlExecutor.batchInsert(conn, sql, statementSetter, jdbcSettings, parametersList); } }); @@ -521,89 +522,88 @@ public Optional call() throws Exception { } @SafeVarargs - public final ContinuableFuture> get(final String sql, final JdbcUtil.RecordGetter recordGetter, - final Object... parameters) { + public final ContinuableFuture> get(final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.get(sql, recordGetter, parameters); + return sqlExecutor.get(sql, rowMapper, parameters); } }); } @SafeVarargs public final ContinuableFuture> get(final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.get(sql, statementSetter, recordGetter, parameters); + return sqlExecutor.get(sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture> get(final String sql, final JdbcUtil.RecordGetter recordGetter, + public final ContinuableFuture> get(final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.get(sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.get(sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> get(final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.get(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.get(sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture> get(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, + public final ContinuableFuture> get(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.get(conn, sql, recordGetter, parameters); + return sqlExecutor.get(conn, sql, rowMapper, parameters); } }); } @SafeVarargs public final ContinuableFuture> get(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.get(conn, sql, statementSetter, recordGetter, parameters); + return sqlExecutor.get(conn, sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture> get(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, + public final ContinuableFuture> get(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.get(conn, sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.get(conn, sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> get(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.get(conn, sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.get(conn, sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @@ -694,88 +694,88 @@ public T call() throws Exception { } @SafeVarargs - public final ContinuableFuture gett(final String sql, final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { + public final ContinuableFuture gett(final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable() { @Override public T call() throws Exception { - return sqlExecutor.gett(sql, recordGetter, parameters); + return sqlExecutor.gett(sql, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture gett(final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { + public final ContinuableFuture gett(final String sql, final StatementSetter statementSetter, final JdbcUtil.RowMapper rowMapper, + final Object... parameters) { return asyncExecutor.execute(new Callable() { @Override public T call() throws Exception { - return sqlExecutor.gett(sql, statementSetter, recordGetter, parameters); + return sqlExecutor.gett(sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture gett(final String sql, final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final ContinuableFuture gett(final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable() { @Override public T call() throws Exception { - return sqlExecutor.gett(sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.gett(sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture gett(final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + public final ContinuableFuture gett(final String sql, final StatementSetter statementSetter, final JdbcUtil.RowMapper rowMapper, + final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable() { @Override public T call() throws Exception { - return sqlExecutor.gett(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.gett(sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture gett(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, + public final ContinuableFuture gett(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable() { @Override public T call() throws Exception { - return sqlExecutor.gett(conn, sql, recordGetter, parameters); + return sqlExecutor.gett(conn, sql, rowMapper, parameters); } }); } @SafeVarargs public final ContinuableFuture gett(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable() { @Override public T call() throws Exception { - return sqlExecutor.gett(conn, sql, statementSetter, recordGetter, parameters); + return sqlExecutor.gett(conn, sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture gett(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, + public final ContinuableFuture gett(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable() { @Override public T call() throws Exception { - return sqlExecutor.gett(conn, sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.gett(conn, sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture gett(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable() { @Override public T call() throws Exception { - return sqlExecutor.gett(conn, sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.gett(conn, sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @@ -867,89 +867,89 @@ public Optional call() throws Exception { } @SafeVarargs - public final ContinuableFuture> findFirst(final String sql, final JdbcUtil.RecordGetter recordGetter, + public final ContinuableFuture> findFirst(final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.findFirst(sql, recordGetter, parameters); + return sqlExecutor.findFirst(sql, rowMapper, parameters); } }); } @SafeVarargs public final ContinuableFuture> findFirst(final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.findFirst(sql, statementSetter, recordGetter, parameters); + return sqlExecutor.findFirst(sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture> findFirst(final String sql, final JdbcUtil.RecordGetter recordGetter, + public final ContinuableFuture> findFirst(final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.findFirst(sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.findFirst(sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> findFirst(final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.findFirst(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.findFirst(sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture> findFirst(final Connection conn, final String sql, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { + public final ContinuableFuture> findFirst(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, + final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.findFirst(conn, sql, recordGetter, parameters); + return sqlExecutor.findFirst(conn, sql, rowMapper, parameters); } }); } @SafeVarargs public final ContinuableFuture> findFirst(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.findFirst(conn, sql, statementSetter, recordGetter, parameters); + return sqlExecutor.findFirst(conn, sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture> findFirst(final Connection conn, final String sql, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + public final ContinuableFuture> findFirst(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, + final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.findFirst(conn, sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.findFirst(conn, sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> findFirst(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return sqlExecutor.findFirst(conn, sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.findFirst(conn, sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @@ -1041,89 +1041,88 @@ public List call() throws Exception { } @SafeVarargs - public final ContinuableFuture> list(final String sql, final JdbcUtil.BiRecordGetter recordGetter, - final Object... parameters) { + public final ContinuableFuture> list(final String sql, final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.list(sql, recordGetter, parameters); + return sqlExecutor.list(sql, rowMapper, parameters); } }); } @SafeVarargs public final ContinuableFuture> list(final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.list(sql, statementSetter, recordGetter, parameters); + return sqlExecutor.list(sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture> list(final String sql, final JdbcUtil.BiRecordGetter recordGetter, + public final ContinuableFuture> list(final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.list(sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.list(sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> list(final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.list(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.list(sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture> list(final Connection conn, final String sql, final JdbcUtil.BiRecordGetter recordGetter, + public final ContinuableFuture> list(final Connection conn, final String sql, final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.list(conn, sql, recordGetter, parameters); + return sqlExecutor.list(conn, sql, rowMapper, parameters); } }); } @SafeVarargs public final ContinuableFuture> list(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.list(conn, sql, statementSetter, recordGetter, parameters); + return sqlExecutor.list(conn, sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture> list(final Connection conn, final String sql, final JdbcUtil.BiRecordGetter recordGetter, + public final ContinuableFuture> list(final Connection conn, final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.list(conn, sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.list(conn, sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> list(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.list(conn, sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.list(conn, sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @@ -1173,45 +1172,45 @@ public List call() throws Exception { } @SafeVarargs - public final ContinuableFuture> listAll(final String sql, final JdbcUtil.BiRecordGetter recordGetter, + public final ContinuableFuture> listAll(final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.listAll(sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.listAll(sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> listAll(final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.listAll(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.listAll(sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs - public final ContinuableFuture> listAll(final List sqls, final JdbcUtil.BiRecordGetter recordGetter, + public final ContinuableFuture> listAll(final List sqls, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.listAll(sqls, recordGetter, jdbcSettings, parameters); + return sqlExecutor.listAll(sqls, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> listAll(final List sqls, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return sqlExecutor.listAll(sqls, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.listAll(sqls, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @@ -1774,45 +1773,45 @@ public Stream call() throws Exception { } @SafeVarargs - public final ContinuableFuture> stream(final String sql, final JdbcUtil.BiRecordGetter recordGetter, + public final ContinuableFuture> stream(final String sql, final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return sqlExecutor.stream(sql, recordGetter, parameters); + return sqlExecutor.stream(sql, rowMapper, parameters); } }); } @SafeVarargs public final ContinuableFuture> stream(final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return sqlExecutor.stream(sql, statementSetter, recordGetter, parameters); + return sqlExecutor.stream(sql, statementSetter, rowMapper, parameters); } }); } @SafeVarargs - public final ContinuableFuture> stream(final String sql, final JdbcUtil.BiRecordGetter recordGetter, + public final ContinuableFuture> stream(final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return sqlExecutor.stream(sql, recordGetter, jdbcSettings, parameters); + return sqlExecutor.stream(sql, rowMapper, jdbcSettings, parameters); } }); } @SafeVarargs public final ContinuableFuture> stream(final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return sqlExecutor.stream(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return sqlExecutor.stream(sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } diff --git a/src/com/landawn/abacus/util/ExceptionalStream.java b/src/com/landawn/abacus/util/ExceptionalStream.java index 115c63fb..77d1ac92 100644 --- a/src/com/landawn/abacus/util/ExceptionalStream.java +++ b/src/com/landawn/abacus/util/ExceptionalStream.java @@ -42,7 +42,7 @@ import com.landawn.abacus.logging.LoggerFactory; import com.landawn.abacus.util.Fn.Factory; import com.landawn.abacus.util.Fn.Suppliers; -import com.landawn.abacus.util.JdbcUtil.BiRecordGetter; +import com.landawn.abacus.util.JdbcUtil.BiRowMapper; import com.landawn.abacus.util.StringUtil.Strings; import com.landawn.abacus.util.u.Optional; import com.landawn.abacus.util.u.OptionalDouble; @@ -55,6 +55,7 @@ import com.landawn.abacus.util.stream.Collector; import com.landawn.abacus.util.stream.Collectors; import com.landawn.abacus.util.stream.ObjIteratorEx; +import com.landawn.abacus.util.stream.SequentialOnly; import com.landawn.abacus.util.stream.Stream; /** @@ -64,6 +65,7 @@ * * @author Haiyang Li */ +@SequentialOnly public class ExceptionalStream implements AutoCloseable { static final Logger logger = LoggerFactory.getLogger(ExceptionalStream.class); @@ -537,16 +539,16 @@ public static ExceptionalStream rows(final Class targetC N.checkArgNotNull(targetClass, "targetClass"); N.checkArgNotNull(resultSet, "resultSet"); - final Try.BiFunction, T, SQLException> recordGetter = new Try.BiFunction, T, SQLException>() { - private final BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final Try.BiFunction, T, SQLException> rowMapper = new Try.BiFunction, T, SQLException>() { + private final BiRowMapper biRowMapper = BiRowMapper.to(targetClass); @Override public T apply(ResultSet resultSet, List columnLabels) throws SQLException { - return biRecordGetter.apply(resultSet, columnLabels); + return biRowMapper.apply(resultSet, columnLabels); } }; - return rows(resultSet, recordGetter); + return rows(resultSet, rowMapper); } /** @@ -578,14 +580,14 @@ public void run() throws SQLException { * It's user's responsibility to close the input resultSet after the stream is finished. * * @param resultSet - * @param recordGetter + * @param rowMapper * @return * @throws UncheckedSQLException */ - public static ExceptionalStream rows(final ResultSet resultSet, final Try.Function recordGetter) + public static ExceptionalStream rows(final ResultSet resultSet, final Try.Function rowMapper) throws UncheckedSQLException { N.checkArgNotNull(resultSet, "resultSet"); - N.checkArgNotNull(recordGetter, "recordGetter"); + N.checkArgNotNull(rowMapper, "rowMapper"); final ExceptionalIterator iter = new ExceptionalIterator() { private boolean hasNext; @@ -607,7 +609,7 @@ public T next() throws SQLException { hasNext = false; - return recordGetter.apply(resultSet); + return rowMapper.apply(resultSet); } @Override @@ -629,14 +631,14 @@ public void skip(long n) throws SQLException { * It's user's responsibility to close the input resultSet after the stream is finished. * * @param resultSet - * @param recordGetter + * @param rowMapper * @return * @throws UncheckedSQLException */ public static ExceptionalStream rows(final ResultSet resultSet, - final Try.BiFunction, T, SQLException> recordGetter) throws UncheckedSQLException { + final Try.BiFunction, T, SQLException> rowMapper) throws UncheckedSQLException { N.checkArgNotNull(resultSet, "resultSet"); - N.checkArgNotNull(recordGetter, "recordGetter"); + N.checkArgNotNull(rowMapper, "rowMapper"); final ExceptionalIterator iter = new ExceptionalIterator() { private List columnLabels = null; @@ -663,7 +665,7 @@ public T next() throws SQLException { columnLabels = JdbcUtil.getColumnLabelList(resultSet); } - return recordGetter.apply(resultSet, columnLabels); + return rowMapper.apply(resultSet, columnLabels); } @Override @@ -1412,14 +1414,14 @@ public T next() throws E { }, closeHandlers); } - public ExceptionalStream collapse(final Try.BiPredicate collapsible, final R init, - final Try.BiFunction op) { + public ExceptionalStream collapse(final Try.BiPredicate collapsible, final U init, + final Try.BiFunction op) { checkArgNotNull(collapsible, "collapsible"); checkArgNotNull(op, "accumulator"); final ExceptionalIterator iter = elements; - return newStream(new ExceptionalIterator() { + return newStream(new ExceptionalIterator() { private boolean hasNext = false; private T next = null; @@ -1429,8 +1431,8 @@ public boolean hasNext() throws E { } @Override - public R next() throws E { - R res = op.apply(init, hasNext ? next : (next = iter.next())); + public U next() throws E { + U res = op.apply(init, hasNext ? next : (next = iter.next())); while ((hasNext = iter.hasNext())) { if (collapsible.test(next, (next = iter.next()))) { @@ -1518,6 +1520,76 @@ public R next() throws E { }, closeHandlers); } + public ExceptionalStream scan(final Try.BiFunction accumulator) { + final ExceptionalIterator iter = elements; + + return newStream(new ExceptionalIterator() { + private T res = null; + private boolean isFirst = true; + + @Override + public boolean hasNext() throws E { + return iter.hasNext(); + } + + @Override + public T next() throws E { + if (isFirst) { + isFirst = false; + return (res = iter.next()); + } else { + return (res = accumulator.apply(res, iter.next())); + } + } + }, closeHandlers); + } + + public ExceptionalStream scan(final U init, final Try.BiFunction accumulator) { + final ExceptionalIterator iter = elements; + + return newStream(new ExceptionalIterator() { + private U res = init; + + @Override + public boolean hasNext() throws E { + return iter.hasNext(); + } + + @Override + public U next() throws E { + return (res = accumulator.apply(res, iter.next())); + } + }, closeHandlers); + } + + public ExceptionalStream scan(final U init, final Try.BiFunction accumulator, final boolean initIncluded) { + if (initIncluded == false) { + return scan(init, accumulator); + } + + final ExceptionalIterator iter = elements; + + return newStream(new ExceptionalIterator() { + private boolean isFirst = true; + private U res = init; + + @Override + public boolean hasNext() throws E { + return isFirst || iter.hasNext(); + } + + @Override + public U next() throws E { + if (isFirst) { + isFirst = false; + return init; + } + + return (res = accumulator.apply(res, iter.next())); + } + }, closeHandlers); + } + public ExceptionalStream prepend(ExceptionalStream s) { return concat(s, this); } @@ -2872,39 +2944,39 @@ public OptionalDouble averageDouble(Try.ToDoubleFunction func) thr } } - public T reduce(T identity, Try.BinaryOperator accumulator) throws E { + public Optional reduce(Try.BinaryOperator accumulator) throws E { checkArgNotNull(accumulator, "accumulator"); assertNotClosed(); try { - T result = identity; + if (elements.hasNext() == false) { + return Optional.empty(); + } + + T result = elements.next(); while (elements.hasNext()) { result = accumulator.apply(result, elements.next()); } - return result; + return Optional.of(result); } finally { close(); } } - public Optional reduce(Try.BinaryOperator accumulator) throws E { + public U reduce(final U identity, final Try.BiFunction accumulator) throws E { checkArgNotNull(accumulator, "accumulator"); assertNotClosed(); try { - if (elements.hasNext() == false) { - return Optional.empty(); - } - - T result = elements.next(); + U result = identity; while (elements.hasNext()) { result = accumulator.apply(result, elements.next()); } - return Optional.of(result); + return result; } finally { close(); } diff --git a/src/com/landawn/abacus/util/JdbcUtil.java b/src/com/landawn/abacus/util/JdbcUtil.java index 93a002a0..19cdd08e 100644 --- a/src/com/landawn/abacus/util/JdbcUtil.java +++ b/src/com/landawn/abacus/util/JdbcUtil.java @@ -1716,16 +1716,16 @@ public static boolean dropTableIfExists(final Connection conn, final String tabl } /** - * Don't cache or reuse the returned {@code BiRecordGetter} instance. + * Don't cache or reuse the returned {@code BiRowMapper} instance. * * @param targetType Array/List/Map or Entity with getter/setter methods. * @return - * @deprecated replaced by {@code BiRecordGetter#to(Class)} in JDK 1.8 or above. + * @deprecated replaced by {@code BiRowMapper#to(Class)} in JDK 1.8 or above. */ @Deprecated - public static BiRecordGetter createBiRecordGetterByTargetClass(final Class targetClass) { + public static BiRowMapper createBiRowMapperByTargetClass(final Class targetClass) { if (Object[].class.isAssignableFrom(targetClass)) { - return new BiRecordGetter() { + return new BiRowMapper() { @Override public T apply(ResultSet rs, List columnLabelList) throws SQLException { final int columnCount = columnLabelList.size(); @@ -1739,7 +1739,7 @@ public T apply(ResultSet rs, List columnLabelList) throws SQLException { } }; } else if (List.class.isAssignableFrom(targetClass)) { - return new BiRecordGetter() { + return new BiRowMapper() { private final boolean isListOrArrayList = targetClass.equals(List.class) || targetClass.equals(ArrayList.class); @@ -1756,7 +1756,7 @@ public T apply(ResultSet rs, List columnLabelList) throws SQLException { } }; } else if (Map.class.isAssignableFrom(targetClass)) { - return new BiRecordGetter() { + return new BiRowMapper() { private final boolean isMapOrHashMap = targetClass.equals(Map.class) || targetClass.equals(HashMap.class); private final boolean isLinkedHashMap = targetClass.equals(LinkedHashMap.class); @@ -1774,7 +1774,7 @@ public T apply(ResultSet rs, List columnLabelList) throws SQLException { } }; } else if (N.isEntity(targetClass)) { - return new BiRecordGetter() { + return new BiRowMapper() { private final boolean isDirtyMarker = N.isDirtyMarker(targetClass); private volatile String[] columnLabels = null; private volatile Method[] propSetters; @@ -1795,7 +1795,7 @@ public T apply(ResultSet rs, List columnLabelList) throws SQLException { if (columnTypes == null || propSetters == null) { final EntityInfo entityInfo = ParserUtil.getEntityInfo(targetClass); - final Map column2FieldNameMap = getField2ColumnNameMap(targetClass); + final Map column2FieldNameMap = getColumn2FieldNameMap(targetClass); propSetters = new Method[columnCount]; columnTypes = new Type[columnCount]; @@ -1846,7 +1846,7 @@ public T apply(ResultSet rs, List columnLabelList) throws SQLException { } }; } else { - return new BiRecordGetter() { + return new BiRowMapper() { private final Type targetType = N.typeOf(targetClass); private int columnCount = 0; @@ -1854,7 +1854,7 @@ public T apply(ResultSet rs, List columnLabelList) throws SQLException { public T apply(ResultSet rs, List columnLabelList) throws SQLException { if (columnCount != 1 && (columnCount = columnLabelList.size()) != 1) { throw new IllegalArgumentException( - "Type: " + targetClass + " doesn't support retrieving value from multiple columns: " + columnLabelList); + "It's not supported to retrieve value from multiple columns: " + columnLabelList + " for type: " + targetClass); } return targetType.get(rs, 1); @@ -3058,7 +3058,7 @@ public static void parse(final Resul final int queueSize, final Try.Consumer rowParser, final Try.Runnable onComplete) throws UncheckedSQLException, E, E2 { final Iterator iter = new ObjIterator() { - private final JdbcUtil.BiRecordGetter biFunc = BiRecordGetter.TO_ARRAY; + private final JdbcUtil.BiRowMapper biFunc = BiRowMapper.TO_ARRAY; private List columnLabels = null; private boolean hasNext; @@ -3242,7 +3242,7 @@ static boolean isTableNotExistsException(final Throwable e) { private static final Map, Map> column2FieldNameMapPool = new ConcurrentHashMap<>(); - static Map getField2ColumnNameMap(Class entityClass) { + static Map getColumn2FieldNameMap(Class entityClass) { Map result = column2FieldNameMapPool.get(entityClass); if (result == null) { @@ -3563,6 +3563,32 @@ public Q setString(int parameterIndex, String x) throws SQLException { return (Q) this; } + /** + * + * @param parameterIndex starts from 1, not 0. + * @param x + * @return + * @throws SQLException + */ + public Q setDate(int parameterIndex, java.sql.Date x) throws SQLException { + stmt.setDate(parameterIndex, x); + + return (Q) this; + } + + /** + * + * @param parameterIndex starts from 1, not 0. + * @param x + * @return + * @throws SQLException + */ + public Q setDate(int parameterIndex, java.util.Date x) throws SQLException { + stmt.setDate(parameterIndex, x == null ? null : x instanceof java.sql.Date ? (java.sql.Date) x : new java.sql.Date(x.getTime())); + + return (Q) this; + } + /** * * @param parameterIndex starts from 1, not 0. @@ -3583,8 +3609,8 @@ public Q setTime(int parameterIndex, java.sql.Time x) throws SQLException { * @return * @throws SQLException */ - public Q setDate(int parameterIndex, java.sql.Date x) throws SQLException { - stmt.setDate(parameterIndex, x); + public Q setTime(int parameterIndex, java.util.Date x) throws SQLException { + stmt.setTime(parameterIndex, x == null ? null : x instanceof java.sql.Time ? (java.sql.Time) x : new java.sql.Time(x.getTime())); return (Q) this; } @@ -3602,6 +3628,20 @@ public Q setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLExcept return (Q) this; } + /** + * + * @param parameterIndex starts from 1, not 0. + * @param x + * @return + * @throws SQLException + */ + public Q setTimestamp(int parameterIndex, java.util.Date x) throws SQLException { + stmt.setTimestamp(parameterIndex, + x == null ? null : x instanceof java.sql.Timestamp ? (java.sql.Timestamp) x : new java.sql.Timestamp(x.getTime())); + + return (Q) this; + } + public Q setBytes(int parameterIndex, byte[] x) throws SQLException { stmt.setBytes(parameterIndex, x); @@ -4560,7 +4600,7 @@ public Optional queryForUniqueNonNull(Class targetClass) throws Duplic private T get(Class targetClass, ResultSet rs) throws SQLException { final List columnLabels = JdbcUtil.getColumnLabelList(rs); - return BiRecordGetter.to(targetClass).apply(rs, columnLabels); + return BiRowMapper.to(targetClass).apply(rs, columnLabels); } public DataSet query() throws SQLException { @@ -4602,26 +4642,26 @@ public Optional get(final Class targetClass) throws DuplicatedResultEx /** * - * @param recordGetter + * @param rowMapper * @return * @throws DuplicatedResultException If there are more than one record found by the query * @throws SQLException * @throws E */ - public Optional get(RecordGetter recordGetter) throws DuplicatedResultException, SQLException, E { - return Optional.ofNullable(gett(recordGetter)); + public Optional get(RowMapper rowMapper) throws DuplicatedResultException, SQLException, E { + return Optional.ofNullable(gett(rowMapper)); } /** * - * @param recordGetter + * @param rowMapper * @return * @throws DuplicatedResultException If there are more than one record found by the query * @throws SQLException * @throws E */ - public Optional get(BiRecordGetter recordGetter) throws DuplicatedResultException, SQLException, E { - return Optional.ofNullable(gett(recordGetter)); + public Optional get(BiRowMapper rowMapper) throws DuplicatedResultException, SQLException, E { + return Optional.ofNullable(gett(rowMapper)); } /** @@ -4654,19 +4694,19 @@ public T gett(final Class targetClass) throws DuplicatedResultException, /** * - * @param recordGetter + * @param rowMapper * @return * @throws DuplicatedResultException If there are more than one record found by the query * @throws SQLException * @throws E */ - public T gett(RecordGetter recordGetter) throws DuplicatedResultException, SQLException, E { - checkArgNotNull(recordGetter, "recordGetter"); + public T gett(RowMapper rowMapper) throws DuplicatedResultException, SQLException, E { + checkArgNotNull(rowMapper, "rowMapper"); assertNotClosed(); try (ResultSet rs = executeQuery()) { if (rs.next()) { - final T result = Objects.requireNonNull(recordGetter.apply(rs)); + final T result = Objects.requireNonNull(rowMapper.apply(rs)); if (rs.next()) { throw new DuplicatedResultException("There are more than one record found by the query"); @@ -4684,19 +4724,19 @@ public T gett(RecordGetter recordGetter) throws D /** * - * @param recordGetter + * @param rowMapper * @return * @throws DuplicatedResultException If there are more than one record found by the query * @throws SQLException * @throws E */ - public T gett(BiRecordGetter recordGetter) throws DuplicatedResultException, SQLException, E { - checkArgNotNull(recordGetter, "recordGetter"); + public T gett(BiRowMapper rowMapper) throws DuplicatedResultException, SQLException, E { + checkArgNotNull(rowMapper, "rowMapper"); assertNotClosed(); try (ResultSet rs = executeQuery()) { if (rs.next()) { - final T result = Objects.requireNonNull(recordGetter.apply(rs, JdbcUtil.getColumnLabelList(rs))); + final T result = Objects.requireNonNull(rowMapper.apply(rs, JdbcUtil.getColumnLabelList(rs))); if (rs.next()) { throw new DuplicatedResultException("There are more than one record found by the query"); @@ -4733,27 +4773,27 @@ public Optional findFirst(final Class targetClass) throws SQLException } } - public Optional findFirst(RecordGetter recordGetter) throws SQLException, E { - checkArgNotNull(recordGetter, "recordGetter"); + public Optional findFirst(RowMapper rowMapper) throws SQLException, E { + checkArgNotNull(rowMapper, "rowMapper"); assertNotClosed(); try (ResultSet rs = executeQuery()) { - return rs.next() ? Optional.of(recordGetter.apply(rs)) : Optional. empty(); + return rs.next() ? Optional.of(rowMapper.apply(rs)) : Optional. empty(); } finally { closeAfterExecutionIfAllowed(); } } - public Optional findFirst(final RecordPredicate recordFilter, RecordGetter recordGetter) + public Optional findFirst(final RowFilter recordFilter, RowMapper rowMapper) throws SQLException, E, E2 { checkArgNotNull(recordFilter, "recordFilter"); - checkArgNotNull(recordGetter, "recordGetter"); + checkArgNotNull(rowMapper, "rowMapper"); assertNotClosed(); try (ResultSet rs = executeQuery()) { while (rs.next()) { if (recordFilter.test(rs)) { - return Optional.of(recordGetter.apply(rs)); + return Optional.of(rowMapper.apply(rs)); } } @@ -4763,21 +4803,21 @@ public Optional findFirst(fina } } - public Optional findFirst(BiRecordGetter recordGetter) throws SQLException, E { - checkArgNotNull(recordGetter, "recordGetter"); + public Optional findFirst(BiRowMapper rowMapper) throws SQLException, E { + checkArgNotNull(rowMapper, "rowMapper"); assertNotClosed(); try (ResultSet rs = executeQuery()) { - return rs.next() ? Optional.of(recordGetter.apply(rs, JdbcUtil.getColumnLabelList(rs))) : Optional. empty(); + return rs.next() ? Optional.of(rowMapper.apply(rs, JdbcUtil.getColumnLabelList(rs))) : Optional. empty(); } finally { closeAfterExecutionIfAllowed(); } } - public Optional findFirst(final BiRecordPredicate recordFilter, BiRecordGetter recordGetter) + public Optional findFirst(final BiRowFilter recordFilter, BiRowMapper rowMapper) throws SQLException, E, E2 { checkArgNotNull(recordFilter, "recordFilter"); - checkArgNotNull(recordGetter, "recordGetter"); + checkArgNotNull(rowMapper, "rowMapper"); assertNotClosed(); try (ResultSet rs = executeQuery()) { @@ -4785,7 +4825,7 @@ public Optional findFirst(fina while (rs.next()) { if (recordFilter.test(rs, columnLabels)) { - return Optional.of(recordGetter.apply(rs, columnLabels)); + return Optional.of(rowMapper.apply(rs, columnLabels)); } } @@ -4796,30 +4836,30 @@ public Optional findFirst(fina } public List list(final Class targetClass) throws SQLException { - return list(BiRecordGetter.to(targetClass)); + return list(BiRowMapper.to(targetClass)); } public List list(final Class targetClass, int maxResult) throws SQLException { - return list(BiRecordGetter.to(targetClass), maxResult); + return list(BiRowMapper.to(targetClass), maxResult); } - public List list(RecordGetter recordGetter) throws SQLException, E { - return list(recordGetter, Integer.MAX_VALUE); + public List list(RowMapper rowMapper) throws SQLException, E { + return list(rowMapper, Integer.MAX_VALUE); } - public List list(RecordGetter recordGetter, int maxResult) throws SQLException, E { - return list(RecordPredicate.ALWAYS_TRUE, recordGetter, maxResult); + public List list(RowMapper rowMapper, int maxResult) throws SQLException, E { + return list(RowFilter.ALWAYS_TRUE, rowMapper, maxResult); } - public List list(final RecordPredicate recordFilter, RecordGetter recordGetter) + public List list(final RowFilter recordFilter, RowMapper rowMapper) throws SQLException, E, E2 { - return list(recordFilter, recordGetter, Integer.MAX_VALUE); + return list(recordFilter, rowMapper, Integer.MAX_VALUE); } - public List list(final RecordPredicate recordFilter, RecordGetter recordGetter, - int maxResult) throws SQLException, E, E2 { + public List list(final RowFilter recordFilter, RowMapper rowMapper, int maxResult) + throws SQLException, E, E2 { checkArgNotNull(recordFilter, "recordFilter"); - checkArgNotNull(recordGetter, "recordGetter"); + checkArgNotNull(rowMapper, "rowMapper"); checkArg(maxResult >= 0, "'maxResult' can' be negative: " + maxResult); assertNotClosed(); @@ -4828,7 +4868,7 @@ public List list(final RecordP while (maxResult > 0 && rs.next()) { if (recordFilter.test(rs)) { - result.add(recordGetter.apply(rs)); + result.add(rowMapper.apply(rs)); maxResult--; } } @@ -4839,23 +4879,23 @@ public List list(final RecordP } } - public List list(BiRecordGetter recordGetter) throws SQLException, E { - return list(recordGetter, Integer.MAX_VALUE); + public List list(BiRowMapper rowMapper) throws SQLException, E { + return list(rowMapper, Integer.MAX_VALUE); } - public List list(BiRecordGetter recordGetter, int maxResult) throws SQLException, E { - return list(BiRecordPredicate.ALWAYS_TRUE, recordGetter, maxResult); + public List list(BiRowMapper rowMapper, int maxResult) throws SQLException, E { + return list(BiRowFilter.ALWAYS_TRUE, rowMapper, maxResult); } - public List list(final BiRecordPredicate recordFilter, BiRecordGetter recordGetter) + public List list(final BiRowFilter recordFilter, BiRowMapper rowMapper) throws SQLException, E, E2 { - return list(recordFilter, recordGetter, Integer.MAX_VALUE); + return list(recordFilter, rowMapper, Integer.MAX_VALUE); } - public List list(final BiRecordPredicate recordFilter, BiRecordGetter recordGetter, - int maxResult) throws SQLException, E, E2 { + public List list(final BiRowFilter recordFilter, BiRowMapper rowMapper, int maxResult) + throws SQLException, E, E2 { checkArgNotNull(recordFilter, "recordFilter"); - checkArgNotNull(recordGetter, "recordGetter"); + checkArgNotNull(rowMapper, "rowMapper"); checkArg(maxResult >= 0, "'maxResult' can' be negative: " + maxResult); assertNotClosed(); @@ -4865,7 +4905,7 @@ public List list(final BiRecor while (maxResult > 0 && rs.next()) { if (recordFilter.test(rs, columnLabels)) { - result.add(recordGetter.apply(rs, columnLabels)); + result.add(rowMapper.apply(rs, columnLabels)); maxResult--; } } @@ -4877,11 +4917,11 @@ public List list(final BiRecor } public ExceptionalStream stream(final Class targetClass) throws SQLException { - return stream(BiRecordGetter.to(targetClass)); + return stream(BiRowMapper.to(targetClass)); } - public ExceptionalStream stream(final RecordGetter recordGetter) throws SQLException { - checkArgNotNull(recordGetter, "recordGetter"); + public ExceptionalStream stream(final RowMapper rowMapper) throws SQLException { + checkArgNotNull(rowMapper, "rowMapper"); assertNotClosed(); final ExceptionalIterator lazyIter = ExceptionalIterator @@ -4917,7 +4957,7 @@ public T next() throws SQLException { hasNext = false; - return recordGetter.apply(resultSet); + return rowMapper.apply(resultSet); } @Override @@ -4974,8 +5014,8 @@ public void run() throws SQLException { }); } - public ExceptionalStream stream(final BiRecordGetter recordGetter) throws SQLException { - checkArgNotNull(recordGetter, "recordGetter"); + public ExceptionalStream stream(final BiRowMapper rowMapper) throws SQLException { + checkArgNotNull(rowMapper, "rowMapper"); assertNotClosed(); final ExceptionalIterator lazyIter = ExceptionalIterator @@ -5016,7 +5056,7 @@ public T next() throws SQLException { columnLabels = JdbcUtil.getColumnLabelList(resultSet); } - return recordGetter.apply(resultSet, columnLabels); + return rowMapper.apply(resultSet, columnLabels); } @Override @@ -5089,26 +5129,26 @@ public boolean exists() throws SQLException { } } - public void ifExists(final RecordConsumer recordConsumer) throws SQLException, E { - checkArgNotNull(recordConsumer, "recordConsumer"); + public void ifExists(final RowConsumer rowConsumer) throws SQLException, E { + checkArgNotNull(rowConsumer, "rowConsumer"); assertNotClosed(); try (ResultSet rs = executeQuery()) { if (rs.next()) { - recordConsumer.accept(rs); + rowConsumer.accept(rs); } } finally { closeAfterExecutionIfAllowed(); } } - public void ifExists(final BiRecordConsumer recordConsumer) throws SQLException, E { - checkArgNotNull(recordConsumer, "recordConsumer"); + public void ifExists(final BiRowConsumer rowConsumer) throws SQLException, E { + checkArgNotNull(rowConsumer, "rowConsumer"); assertNotClosed(); try (ResultSet rs = executeQuery()) { if (rs.next()) { - recordConsumer.accept(rs, JdbcUtil.getColumnLabelList(rs)); + rowConsumer.accept(rs, JdbcUtil.getColumnLabelList(rs)); } } finally { closeAfterExecutionIfAllowed(); @@ -5117,21 +5157,21 @@ public void ifExists(final BiRecordConsumer recordConsu /** * - * @param recordConsumer + * @param rowConsumer * @param orElseAction * @throws SQLException * @throws E * @throws E2 */ - public void ifExistsOrElse(final RecordConsumer recordConsumer, Try.Runnable orElseAction) + public void ifExistsOrElse(final RowConsumer rowConsumer, Try.Runnable orElseAction) throws SQLException, E, E2 { - checkArgNotNull(recordConsumer, "recordConsumer"); + checkArgNotNull(rowConsumer, "rowConsumer"); checkArgNotNull(orElseAction, "orElseAction"); assertNotClosed(); try (ResultSet rs = executeQuery()) { if (rs.next()) { - recordConsumer.accept(rs); + rowConsumer.accept(rs); } else { orElseAction.run(); } @@ -5142,21 +5182,21 @@ public void ifExistsOrElse(final Rec /** * - * @param recordConsumer + * @param rowConsumer * @param orElseAction * @throws SQLException * @throws E * @throws E2 */ - public void ifExistsOrElse(final BiRecordConsumer recordConsumer, Try.Runnable orElseAction) + public void ifExistsOrElse(final BiRowConsumer rowConsumer, Try.Runnable orElseAction) throws SQLException, E, E2 { - checkArgNotNull(recordConsumer, "recordConsumer"); + checkArgNotNull(rowConsumer, "rowConsumer"); checkArgNotNull(orElseAction, "orElseAction"); assertNotClosed(); try (ResultSet rs = executeQuery()) { if (rs.next()) { - recordConsumer.accept(rs, JdbcUtil.getColumnLabelList(rs)); + rowConsumer.accept(rs, JdbcUtil.getColumnLabelList(rs)); } else { orElseAction.run(); } @@ -5189,7 +5229,7 @@ public int count() throws SQLException { } } - public int count(final RecordPredicate recordFilter) throws SQLException, E { + public int count(final RowFilter recordFilter) throws SQLException, E { checkArgNotNull(recordFilter, "recordFilter"); assertNotClosed(); @@ -5208,7 +5248,7 @@ public int count(final RecordPredicate recordFilter) th } } - public int count(final BiRecordPredicate recordFilter) throws SQLException, E { + public int count(final BiRowFilter recordFilter) throws SQLException, E { checkArgNotNull(recordFilter, "recordFilter"); assertNotClosed(); @@ -5228,7 +5268,7 @@ public int count(final BiRecordPredicate recordFilter) } } - public boolean anyMatch(final RecordPredicate recordFilter) throws SQLException, E { + public boolean anyMatch(final RowFilter recordFilter) throws SQLException, E { checkArgNotNull(recordFilter, "recordFilter"); assertNotClosed(); @@ -5245,7 +5285,7 @@ public boolean anyMatch(final RecordPredicate recordFil } } - public boolean anyMatch(final BiRecordPredicate recordFilter) throws SQLException, E { + public boolean anyMatch(final BiRowFilter recordFilter) throws SQLException, E { checkArgNotNull(recordFilter, "recordFilter"); assertNotClosed(); @@ -5264,7 +5304,7 @@ public boolean anyMatch(final BiRecordPredicate recordF } } - public boolean allMatch(final RecordPredicate recordFilter) throws SQLException, E { + public boolean allMatch(final RowFilter recordFilter) throws SQLException, E { checkArgNotNull(recordFilter, "recordFilter"); assertNotClosed(); @@ -5281,7 +5321,7 @@ public boolean allMatch(final RecordPredicate recordFil } } - public boolean allMatch(final BiRecordPredicate recordFilter) throws SQLException, E { + public boolean allMatch(final BiRowFilter recordFilter) throws SQLException, E { checkArgNotNull(recordFilter, "recordFilter"); assertNotClosed(); @@ -5300,22 +5340,22 @@ public boolean allMatch(final BiRecordPredicate recordF } } - public boolean noneMatch(final RecordPredicate recordFilter) throws SQLException, E { + public boolean noneMatch(final RowFilter recordFilter) throws SQLException, E { return anyMatch(recordFilter) == false; } - public boolean noneMatch(final BiRecordPredicate recordFilter) throws SQLException, E { + public boolean noneMatch(final BiRowFilter recordFilter) throws SQLException, E { return anyMatch(recordFilter) == false; } - public void forEach(final RecordConsumer recordConsumer) throws SQLException, E { - checkArgNotNull(recordConsumer, "recordConsumer"); + public void forEach(final RowConsumer rowConsumer) throws SQLException, E { + checkArgNotNull(rowConsumer, "rowConsumer"); assertNotClosed(); try (ResultSet rs = executeQuery()) { while (rs.next()) { - recordConsumer.accept(rs); + rowConsumer.accept(rs); } } finally { @@ -5323,17 +5363,17 @@ public void forEach(final RecordConsumer recordConsumer } } - public void forEach(final RecordPredicate recordFilter, final RecordConsumer recordConsumer) + public void forEach(final RowFilter recordFilter, final RowConsumer rowConsumer) throws SQLException, E, E2 { checkArgNotNull(recordFilter, "recordFilter"); - checkArgNotNull(recordConsumer, "recordConsumer"); + checkArgNotNull(rowConsumer, "rowConsumer"); assertNotClosed(); try (ResultSet rs = executeQuery()) { while (rs.next()) { if (recordFilter.test(rs)) { - recordConsumer.accept(rs); + rowConsumer.accept(rs); } } } finally { @@ -5341,15 +5381,15 @@ public void forEach(final RecordPred } } - public void forEach(final BiRecordConsumer recordConsumer) throws SQLException, E { - checkArgNotNull(recordConsumer, "recordConsumer"); + public void forEach(final BiRowConsumer rowConsumer) throws SQLException, E { + checkArgNotNull(rowConsumer, "rowConsumer"); assertNotClosed(); try (ResultSet rs = executeQuery()) { final List columnLabels = JdbcUtil.getColumnLabelList(rs); while (rs.next()) { - recordConsumer.accept(rs, columnLabels); + rowConsumer.accept(rs, columnLabels); } } finally { @@ -5357,10 +5397,10 @@ public void forEach(final BiRecordConsumer recordConsum } } - public void forEach(final BiRecordPredicate recordFilter, final BiRecordConsumer recordConsumer) + public void forEach(final BiRowFilter recordFilter, final BiRowConsumer rowConsumer) throws SQLException, E, E2 { checkArgNotNull(recordFilter, "recordFilter"); - checkArgNotNull(recordConsumer, "recordConsumer"); + checkArgNotNull(rowConsumer, "rowConsumer"); assertNotClosed(); try (ResultSet rs = executeQuery()) { @@ -5368,7 +5408,7 @@ public void forEach(final BiRecordPr while (rs.next()) { if (recordFilter.test(rs, columnLabels)) { - recordConsumer.accept(rs, columnLabels); + rowConsumer.accept(rs, columnLabels); } } @@ -5390,14 +5430,14 @@ private ResultSet executeQuery() throws SQLException { * * @return */ - public Optional insert() throws SQLException { + public Optional insert() throws SQLException { assertNotClosed(); try { stmt.executeUpdate(); try (ResultSet rs = stmt.getGeneratedKeys()) { - return rs.next() ? Optional.of((T) JdbcUtil.getColumnValue(rs, 1)) : Optional. empty(); + return rs.next() ? Optional.of((ID) JdbcUtil.getColumnValue(rs, 1)) : Optional. empty(); } } finally { closeAfterExecutionIfAllowed(); @@ -5409,7 +5449,7 @@ public Optional insert() throws SQLException { * * @return */ - public List batchInsert() throws SQLException { + public List batchInsert() throws SQLException { assertNotClosed(); try { @@ -5419,14 +5459,69 @@ public List batchInsert() throws SQLException { } } - private List executeBatchInsert() throws SQLException { + /** + * 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, + BiParametersSetter 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, + BiParametersSetter 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; + } + + private List executeBatchInsert() throws SQLException { stmt.executeBatch(); try (ResultSet rs = stmt.getGeneratedKeys()) { - final List result = new ArrayList<>(); + final List result = new ArrayList<>(); while (rs.next()) { - result.add((T) JdbcUtil.getColumnValue(rs, 1)); + result.add((ID) JdbcUtil.getColumnValue(rs, 1)); } return result; @@ -5455,14 +5550,6 @@ public int[] batchUpdate() throws SQLException { } } - private int[] executeBatchUpdate() throws SQLException { - try { - return stmt.executeBatch(); - } finally { - stmt.clearBatch(); - } - } - public long largeUpate() throws SQLException { assertNotClosed(); @@ -5541,59 +5628,12 @@ public int batchUpdate(final int batchSize, final Itera 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, - BiParametersSetter 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, - BiParametersSetter 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<>(); - + private int[] executeBatchUpdate() throws SQLException { 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()); - } + return stmt.executeBatch(); } finally { - closeAfterExecutionIfAllowed(); + stmt.clearBatch(); } - - return result; } public boolean execute() throws SQLException { @@ -5963,14 +6003,26 @@ public Q setString(String parameterName, String x) throws SQLException { return (Q) this; } + public Q setDate(String parameterName, java.sql.Date x) throws SQLException { + stmt.setDate(parameterName, x); + + return (Q) this; + } + + public Q setDate(String parameterName, java.util.Date x) throws SQLException { + stmt.setDate(parameterName, x == null ? null : x instanceof java.sql.Date ? (java.sql.Date) x : new java.sql.Date(x.getTime())); + + return (Q) this; + } + public Q setTime(String parameterName, java.sql.Time x) throws SQLException { stmt.setTime(parameterName, x); return (Q) this; } - public Q setDate(String parameterName, java.sql.Date x) throws SQLException { - stmt.setDate(parameterName, x); + public Q setTime(String parameterName, java.util.Date x) throws SQLException { + stmt.setTime(parameterName, x == null ? null : x instanceof java.sql.Time ? (java.sql.Time) x : new java.sql.Time(x.getTime())); return (Q) this; } @@ -5981,6 +6033,12 @@ public Q setTimestamp(String parameterName, java.sql.Timestamp x) throws SQLExce return (Q) this; } + public Q setTimestamp(String parameterName, java.util.Date x) throws SQLException { + stmt.setTimestamp(parameterName, x == null ? null : x instanceof java.sql.Timestamp ? (java.sql.Timestamp) x : new java.sql.Timestamp(x.getTime())); + + return (Q) this; + } + public Q setBytes(String parameterName, byte[] x) throws SQLException { stmt.setBytes(parameterName, x); @@ -7285,94 +7343,94 @@ public M apply(final ResultSet rs, List columnLabels) throws SQLExceptio } /** - * Don't use {@code RecordGetter} in {@link PreparedQuery#list(RecordGetter)} or any place where multiple records will be retrieved by it, if column labels/count are used in {@link RecordGetter#apply(ResultSet)}. - * Consider using {@code BiRecordGetter} instead because it's more efficient to retrieve multiple records when column labels/count are used. + * Don't use {@code RowMapper} in {@link PreparedQuery#list(RowMapper)} or any place where multiple records will be retrieved by it, if column labels/count are used in {@link RowMapper#apply(ResultSet)}. + * Consider using {@code BiRowMapper} instead because it's more efficient to retrieve multiple records when column labels/count are used. * * @author haiyangl * * @param * @param */ - public static interface RecordGetter { + public static interface RowMapper { - public static final RecordGetter GET_BOOLEAN = new RecordGetter() { + public static final RowMapper GET_BOOLEAN = new RowMapper() { @Override public Boolean apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getBoolean(1); } }; - public static final RecordGetter GET_BYTE = new RecordGetter() { + public static final RowMapper GET_BYTE = new RowMapper() { @Override public Byte apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getByte(1); } }; - public static final RecordGetter GET_SHORT = new RecordGetter() { + public static final RowMapper GET_SHORT = new RowMapper() { @Override public Short apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getShort(1); } }; - public static final RecordGetter GET_INT = new RecordGetter() { + public static final RowMapper GET_INT = new RowMapper() { @Override public Integer apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getInt(1); } }; - public static final RecordGetter GET_LONG = new RecordGetter() { + public static final RowMapper GET_LONG = new RowMapper() { @Override public Long apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getLong(1); } }; - public static final RecordGetter GET_FLOAT = new RecordGetter() { + public static final RowMapper GET_FLOAT = new RowMapper() { @Override public Float apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getFloat(1); } }; - public static final RecordGetter GET_DOUBLE = new RecordGetter() { + public static final RowMapper GET_DOUBLE = new RowMapper() { @Override public Double apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getDouble(1); } }; - public static final RecordGetter GET_BIG_DECIMAL = new RecordGetter() { + public static final RowMapper GET_BIG_DECIMAL = new RowMapper() { @Override public BigDecimal apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getBigDecimal(1); } }; - public static final RecordGetter GET_STRING = new RecordGetter() { + public static final RowMapper GET_STRING = new RowMapper() { @Override public String apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getString(1); } }; - public static final RecordGetter GET_DATE = new RecordGetter() { + public static final RowMapper GET_DATE = new RowMapper() { @Override public Date apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getDate(1); } }; - public static final RecordGetter GET_TIME = new RecordGetter() { + public static final RowMapper GET_TIME = new RowMapper() { @Override public Time apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getTime(1); } }; - public static final RecordGetter GET_TIMESTAMP = new RecordGetter() { + public static final RowMapper GET_TIMESTAMP = new RowMapper() { @Override public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException { return rs.getTimestamp(1); @@ -7390,11 +7448,11 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // * @deprecated // */ //@Deprecated - //public static RecordGetter, RuntimeException> toPair(final Class leftType, final Class rightType) { + //public static RowMapper, RuntimeException> toPair(final Class leftType, final Class rightType) { // N.checkArgNotNull(leftType, "leftType"); // N.checkArgNotNull(rightType, "rightType"); // - // return new RecordGetter, RuntimeException>() { + // return new RowMapper, RuntimeException>() { // private final Type leftT = N.typeOf(leftType); // private final Type rightT = N.typeOf(rightType); // @@ -7415,13 +7473,13 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // * @deprecated // */ //@Deprecated - //public static RecordGetter, RuntimeException> toTriple(final Class leftType, final Class middleType, + //public static RowMapper, RuntimeException> toTriple(final Class leftType, final Class middleType, // final Class rightType) { // N.checkArgNotNull(leftType, "leftType"); // N.checkArgNotNull(middleType, "middleType"); // N.checkArgNotNull(rightType, "rightType"); // - // return new RecordGetter, RuntimeException>() { + // return new RowMapper, RuntimeException>() { // private final Type leftT = N.typeOf(leftType); // private final Type middleT = N.typeOf(middleType); // private final Type rightT = N.typeOf(rightType); @@ -7442,11 +7500,11 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // * @deprecated // */ //@Deprecated - //public static RecordGetter, RuntimeException> toTuple(final Class type1, final Class type2) { + //public static RowMapper, RuntimeException> toTuple(final Class type1, final Class type2) { // N.checkArgNotNull(type1, "type1"); // N.checkArgNotNull(type2, "type2"); // - // return new RecordGetter, RuntimeException>() { + // return new RowMapper, RuntimeException>() { // private final Type t1 = N.typeOf(type1); // private final Type t2 = N.typeOf(type2); // @@ -7467,13 +7525,13 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // * @deprecated // */ //@Deprecated - //public static RecordGetter, RuntimeException> toTuple(final Class type1, final Class type2, + //public static RowMapper, RuntimeException> toTuple(final Class type1, final Class type2, // final Class type3) { // N.checkArgNotNull(type1, "type1"); // N.checkArgNotNull(type2, "type2"); // N.checkArgNotNull(type3, "type3"); // - // return new RecordGetter, RuntimeException>() { + // return new RowMapper, RuntimeException>() { // private final Type t1 = N.typeOf(type1); // private final Type t2 = N.typeOf(type2); // private final Type t3 = N.typeOf(type3); @@ -7496,14 +7554,14 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // * @deprecated // */ //@Deprecated - //public static RecordGetter, RuntimeException> toTuple(final Class type1, final Class type2, + //public static RowMapper, RuntimeException> toTuple(final Class type1, final Class type2, // final Class type3, final Class type4) { // N.checkArgNotNull(type1, "type1"); // N.checkArgNotNull(type2, "type2"); // N.checkArgNotNull(type3, "type3"); // N.checkArgNotNull(type4, "type4"); // - // return new RecordGetter, RuntimeException>() { + // return new RowMapper, RuntimeException>() { // private final Type t1 = N.typeOf(type1); // private final Type t2 = N.typeOf(type2); // private final Type t3 = N.typeOf(type3); @@ -7528,7 +7586,7 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // * @deprecated // */ //@Deprecated - //public static RecordGetter, RuntimeException> toTuple(final Class type1, final Class type2, + //public static RowMapper, RuntimeException> toTuple(final Class type1, final Class type2, // final Class type3, final Class type4, final Class type5) { // N.checkArgNotNull(type1, "type1"); // N.checkArgNotNull(type2, "type2"); @@ -7536,7 +7594,7 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // N.checkArgNotNull(type4, "type4"); // N.checkArgNotNull(type5, "type5"); // - // return new RecordGetter, RuntimeException>() { + // return new RowMapper, RuntimeException>() { // private final Type t1 = N.typeOf(type1); // private final Type t2 = N.typeOf(type2); // private final Type t3 = N.typeOf(type3); @@ -7563,7 +7621,7 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // * @deprecated // */ //@Deprecated - //public static RecordGetter, RuntimeException> toTuple(final Class type1, + //public static RowMapper, RuntimeException> toTuple(final Class type1, // final Class type2, final Class type3, final Class type4, final Class type5, final Class type6) { // N.checkArgNotNull(type1, "type1"); // N.checkArgNotNull(type2, "type2"); @@ -7572,7 +7630,7 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // N.checkArgNotNull(type5, "type5"); // N.checkArgNotNull(type6, "type6"); // - // return new RecordGetter, RuntimeException>() { + // return new RowMapper, RuntimeException>() { // private final Type t1 = N.typeOf(type1); // private final Type t2 = N.typeOf(type2); // private final Type t3 = N.typeOf(type3); @@ -7601,7 +7659,7 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // * @deprecated // */ //@Deprecated - //public static RecordGetter, RuntimeException> toTuple(final Class type1, + //public static RowMapper, RuntimeException> toTuple(final Class type1, // final Class type2, final Class type3, final Class type4, final Class type5, final Class type6, final Class type7) { // N.checkArgNotNull(type1, "type1"); // N.checkArgNotNull(type2, "type2"); @@ -7611,7 +7669,7 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException // N.checkArgNotNull(type6, "type6"); // N.checkArgNotNull(type7, "type7"); // - // return new RecordGetter, RuntimeException>() { + // return new RowMapper, RuntimeException>() { // private final Type t1 = N.typeOf(type1); // private final Type t2 = N.typeOf(type2); // private final Type t3 = N.typeOf(type3); @@ -7628,92 +7686,92 @@ public Timestamp apply(final ResultSet rs) throws SQLException, RuntimeException //} } - public static interface BiRecordGetter { + public static interface BiRowMapper { - public static final BiRecordGetter GET_BOOLEAN = new BiRecordGetter() { + public static final BiRowMapper GET_BOOLEAN = new BiRowMapper() { @Override public Boolean apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getBoolean(1); } }; - public static final BiRecordGetter GET_BYTE = new BiRecordGetter() { + public static final BiRowMapper GET_BYTE = new BiRowMapper() { @Override public Byte apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getByte(1); } }; - public static final BiRecordGetter GET_SHORT = new BiRecordGetter() { + public static final BiRowMapper GET_SHORT = new BiRowMapper() { @Override public Short apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getShort(1); } }; - public static final BiRecordGetter GET_INT = new BiRecordGetter() { + public static final BiRowMapper GET_INT = new BiRowMapper() { @Override public Integer apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getInt(1); } }; - public static final BiRecordGetter GET_LONG = new BiRecordGetter() { + public static final BiRowMapper GET_LONG = new BiRowMapper() { @Override public Long apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getLong(1); } }; - public static final BiRecordGetter GET_FLOAT = new BiRecordGetter() { + public static final BiRowMapper GET_FLOAT = new BiRowMapper() { @Override public Float apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getFloat(1); } }; - public static final BiRecordGetter GET_DOUBLE = new BiRecordGetter() { + public static final BiRowMapper GET_DOUBLE = new BiRowMapper() { @Override public Double apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getDouble(1); } }; - public static final BiRecordGetter GET_BIG_DECIMAL = new BiRecordGetter() { + public static final BiRowMapper GET_BIG_DECIMAL = new BiRowMapper() { @Override public BigDecimal apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getBigDecimal(1); } }; - public static final BiRecordGetter GET_STRING = new BiRecordGetter() { + public static final BiRowMapper GET_STRING = new BiRowMapper() { @Override public String apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getString(1); } }; - public static final BiRecordGetter GET_DATE = new BiRecordGetter() { + public static final BiRowMapper GET_DATE = new BiRowMapper() { @Override public Date apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getDate(1); } }; - public static final BiRecordGetter GET_TIME = new BiRecordGetter() { + public static final BiRowMapper GET_TIME = new BiRowMapper() { @Override public Time apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getTime(1); } }; - public static final BiRecordGetter GET_TIMESTAMP = new BiRecordGetter() { + public static final BiRowMapper GET_TIMESTAMP = new BiRowMapper() { @Override public Timestamp apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { return rs.getTimestamp(1); } }; - public static final BiRecordGetter TO_ARRAY = new BiRecordGetter() { + public static final BiRowMapper TO_ARRAY = new BiRowMapper() { @Override public Object[] apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { final int columnCount = columnLabels.size(); @@ -7727,7 +7785,7 @@ public Object[] apply(final ResultSet rs, final List columnLabels) throw } }; - public static final BiRecordGetter, RuntimeException> TO_LIST = new BiRecordGetter, RuntimeException>() { + public static final BiRowMapper, RuntimeException> TO_LIST = new BiRowMapper, RuntimeException>() { @Override public List apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { final int columnCount = columnLabels.size(); @@ -7741,7 +7799,7 @@ public List apply(final ResultSet rs, final List columnLabels) t } }; - public static final BiRecordGetter, RuntimeException> TO_MAP = new BiRecordGetter, RuntimeException>() { + public static final BiRowMapper, RuntimeException> TO_MAP = new BiRowMapper, RuntimeException>() { @Override public Map apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { final int columnCount = columnLabels.size(); @@ -7755,7 +7813,7 @@ public Map apply(final ResultSet rs, final List columnLa } }; - public static final BiRecordGetter, RuntimeException> TO_LINKED_HASH_MAP = new BiRecordGetter, RuntimeException>() { + public static final BiRowMapper, RuntimeException> TO_LINKED_HASH_MAP = new BiRowMapper, RuntimeException>() { @Override public Map apply(final ResultSet rs, final List columnLabels) throws SQLException, RuntimeException { final int columnCount = columnLabels.size(); @@ -7772,50 +7830,50 @@ public Map apply(final ResultSet rs, final List columnLa T apply(ResultSet rs, List columnLabels) throws SQLException, E; /** - * Don't cache or reuse the returned {@code BiRecordGetter} instance. + * Don't cache or reuse the returned {@code BiRowMapper} instance. * * @param targetType Array/List/Map or Entity with getter/setter methods. * @return */ - public static BiRecordGetter to(Class targetClass) { - return JdbcUtil.createBiRecordGetterByTargetClass(targetClass); + public static BiRowMapper to(Class targetClass) { + return JdbcUtil.createBiRowMapperByTargetClass(targetClass); } } /** - * Don't use {@code RecordConsumer} in {@link PreparedQuery#forEach(RecordConsumer)} or any place where multiple records will be consumed by it, if column labels/count are used in {@link RecordConsumer#accept(ResultSet)}. - * Consider using {@code BiRecordConsumer} instead because it's more efficient to consume multiple records when column labels/count are used. + * Don't use {@code RowConsumer} in {@link PreparedQuery#forEach(RowConsumer)} or any place where multiple records will be consumed by it, if column labels/count are used in {@link RowConsumer#accept(ResultSet)}. + * Consider using {@code BiRowConsumer} instead because it's more efficient to consume multiple records when column labels/count are used. * * @author haiyangl * * @param */ - public static interface RecordConsumer { + public static interface RowConsumer { void accept(ResultSet rs) throws SQLException, E; } - public static interface BiRecordConsumer { + public static interface BiRowConsumer { void accept(ResultSet rs, List columnLabels) throws SQLException, E; } /** - * Don't use {@code RecordPredicate} in {@link PreparedQuery#list(RecordPredicate, RecordGetter)}, {@link PreparedQuery#forEach(RecordPredicate, RecordConsumer)} or any place where multiple records will be tested by it, if column labels/count are used in {@link RecordPredicate#test(ResultSet)}. - * Consider using {@code BiRecordConsumer} instead because it's more efficient to test multiple records when column labels/count are used. + * Don't use {@code RowFilter} in {@link PreparedQuery#list(RowFilter, RowMapper)}, {@link PreparedQuery#forEach(RowFilter, RowConsumer)} or any place where multiple records will be tested by it, if column labels/count are used in {@link RowFilter#test(ResultSet)}. + * Consider using {@code BiRowConsumer} instead because it's more efficient to test multiple records when column labels/count are used. * * * @author haiyangl * * @param */ - public static interface RecordPredicate { - public static final RecordPredicate ALWAYS_TRUE = new RecordPredicate() { + public static interface RowFilter { + public static final RowFilter ALWAYS_TRUE = new RowFilter() { @Override public boolean test(ResultSet rs) throws SQLException, RuntimeException { return true; } }; - public static final RecordPredicate ALWAYS_FALSE = new RecordPredicate() { + public static final RowFilter ALWAYS_FALSE = new RowFilter() { @Override public boolean test(ResultSet rs) throws SQLException, RuntimeException { return false; @@ -7825,15 +7883,15 @@ public boolean test(ResultSet rs) throws SQLException, RuntimeException { boolean test(ResultSet rs) throws SQLException, E; } - public static interface BiRecordPredicate { - public static final BiRecordPredicate ALWAYS_TRUE = new BiRecordPredicate() { + public static interface BiRowFilter { + public static final BiRowFilter ALWAYS_TRUE = new BiRowFilter() { @Override public boolean test(ResultSet rs, List columnLabels) throws SQLException, RuntimeException { return true; } }; - public static final BiRecordPredicate ALWAYS_FALSE = new BiRecordPredicate() { + public static final BiRowFilter ALWAYS_FALSE = new BiRowFilter() { @Override public boolean test(ResultSet rs, List columnLabels) throws SQLException, RuntimeException { return false; @@ -7848,7 +7906,7 @@ public boolean test(ResultSet rs, List columnLabels) throws SQLException * It's a gift from nature and created by thoughts. * *
- * Note: Setting parameters by 'ParametersSetter' or Retrieving result/record by 'ResultExtractor/BiResultExtractor/RecordGetter/BiRecordGetter' is disabled. + * Note: Setting parameters by 'ParametersSetter' or Retrieving result/record by 'ResultExtractor/BiResultExtractor/RowMapper/BiRowMapper' is disabled. * *
* @@ -7860,7 +7918,7 @@ public boolean test(ResultSet rs, List columnLabels) throws SQLException * *
  • SQL parameters can be set through input method parameters(by multiple parameters or a {@code Collection}), or by {@code JdbcUtil.ParametersSetter}.
  • * - *
  • {@code ResultExtractor/BiResultExtractor/RecordGetter/BiRecordGetter} can be specified by the last parameter of the method.
  • + *
  • {@code ResultExtractor/BiResultExtractor/RowMapper/BiRowMapper} can be specified by the last parameter of the method.
  • * *
  • The return type of the method must be same as the return type of {@code ResultExtractor/BiResultExtractor} if it's specified by the last parameter of the method.
  • * @@ -7872,27 +7930,27 @@ public boolean test(ResultSet rs, List columnLabels) throws SQLException *
  • Which underline {@code PreparedQuery/PreparedCallableQuery} method to call for SQL methods/operations annotated with {@code @Select/@NamedSelect}: *
      *
    • If {@code ResultExtractor/BiResultExtractor} is specified by the last parameter of the method, {@code PreparedQuery#query(ResultExtractor/BiResultExtractor)} will be called.
    • - *
    • Or else if {@code RecordGetter/BiRecordGetter} is specified by the last parameter of the method:
    • + *
    • Or else if {@code RowMapper/BiRowMapper} is specified by the last parameter of the method:
    • *
        - *
      • If the return type of the method is {@code List} and one of below conditions is matched, {@code PreparedQuery#list(RecordGetter/BiRecordGetter)} will be called:
      • + *
      • If the return type of the method is {@code List} and one of below conditions is matched, {@code PreparedQuery#list(RowMapper/BiRowMapper)} will be called:
      • *
          *
        • The return type of the method is raw {@code List} without parameterized type, and the method name doesn't start with {@code "get"/"findFirst"/"findOne"}.
        • *
        *
          - *
        • The last parameter type is raw {@code RecordGetter/BiRecordGetter} without parameterized type, and the method name doesn't start with {@code "get"/"findFirst"/"findOne"}.
        • + *
        • The last parameter type is raw {@code RowMapper/BiRowMapper} without parameterized type, and the method name doesn't start with {@code "get"/"findFirst"/"findOne"}.
        • *
        *
          - *
        • The return type of the method is generic {@code List} with parameterized type and The last parameter type is generic {@code RecordGetter/BiRecordGetter} with parameterized types, but They're not same.
        • + *
        • The return type of the method is generic {@code List} with parameterized type and The last parameter type is generic {@code RowMapper/BiRowMapper} with parameterized types, but They're not same.
        • *
        *
      *
        - *
      • Or else if the return type of the method is {@code ExceptionalStream/Stream}, {@code PreparedQuery#stream(RecordGetter/BiRecordGetter)} will be called.
      • + *
      • Or else if the return type of the method is {@code ExceptionalStream/Stream}, {@code PreparedQuery#stream(RowMapper/BiRowMapper)} will be called.
      • *
      *
        - *
      • Or else if the return type of the method is {@code Optional}, {@code PreparedQuery#findFirst(RecordGetter/BiRecordGetter)} will be called.
      • + *
      • Or else if the return type of the method is {@code Optional}, {@code PreparedQuery#findFirst(RowMapper/BiRowMapper)} will be called.
      • *
      *
        - *
      • Or else, {@code PreparedQuery#findFirst(RecordGetter/BiRecordGetter).orNull()} will be called.
      • + *
      • Or else, {@code PreparedQuery#findFirst(RowMapper/BiRowMapper).orNull()} will be called.
      • *
      *
    • Or else:
    • *
        @@ -7948,17 +8006,17 @@ public boolean test(ResultSet rs, List columnLabels) throws SQLException * @see PreparedQuery#queryForSingleResult(Class) * @see PreparedQuery#queryForSingleNonNull(Class) * @see PreparedQuery#findFirst(Class) - * @see PreparedQuery#findFirst(RecordGetter) - * @see PreparedQuery#findFirst(BiRecordGetter) + * @see PreparedQuery#findFirst(RowMapper) + * @see PreparedQuery#findFirst(BiRowMapper) * @see PreparedQuery#list(Class) - * @see PreparedQuery#list(RecordGetter) - * @see PreparedQuery#list(BiRecordGetter) + * @see PreparedQuery#list(RowMapper) + * @see PreparedQuery#list(BiRowMapper) * @see PreparedQuery#query() * @see PreparedQuery#query(ResultExtractor) * @see PreparedQuery#query(BiResultExtractor) * @see PreparedQuery#stream(Class) - * @see PreparedQuery#stream(RecordGetter) - * @see PreparedQuery#stream(BiRecordGetter) + * @see PreparedQuery#stream(RowMapper) + * @see PreparedQuery#stream(BiRowMapper) * * @since 1.8 */ @@ -8088,9 +8146,9 @@ public static R newInstance(final Class daoInterface, final j if (paramLen > 0 && (ResultExtractor.class.isAssignableFrom(lastParamType) || BiResultExtractor.class.isAssignableFrom(lastParamType) - || RecordGetter.class.isAssignableFrom(lastParamType) || BiRecordGetter.class.isAssignableFrom(lastParamType))) { + || RowMapper.class.isAssignableFrom(lastParamType) || BiRowMapper.class.isAssignableFrom(lastParamType))) { throw new UnsupportedOperationException( - "Retrieving result/record by 'ResultExtractor/BiResultExtractor/RecordGetter/BiRecordGetter' is disabled. Can't use it in method: " + "Retrieving result/record by 'ResultExtractor/BiResultExtractor/RowMapper/BiRowMapper' is disabled. Can't use it in method: " + m.getName()); } @@ -8147,9 +8205,9 @@ public Object apply(Dao proxy, Object[] args, javax.sql.DataSource ds) throws Ex (Collection) args[0]), args); } }; - } else if (paramLen > 0 && (ResultExtractor.class.isAssignableFrom(lastParamType) - || BiResultExtractor.class.isAssignableFrom(lastParamType) || RecordGetter.class.isAssignableFrom(lastParamType) - || BiRecordGetter.class.isAssignableFrom(lastParamType))) { + } else if (paramLen > 0 + && (ResultExtractor.class.isAssignableFrom(lastParamType) || BiResultExtractor.class.isAssignableFrom(lastParamType) + || RowMapper.class.isAssignableFrom(lastParamType) || BiRowMapper.class.isAssignableFrom(lastParamType))) { if (paramLen == 1) { // Getting ClassCastException. Not sure why query result is being casted Dao. It seems there is a bug in JDk compiler. // call = (proxy, args, ds) -> queryFunc.apply(JdbcUtil.prepareQuery(proxy, ds, query, isNamedQuery, returnGeneratedKeys), @@ -8424,40 +8482,40 @@ static BiFunction createQuery final boolean isListQuery = isListQuery(method); if (paramLen > 0 && (ResultExtractor.class.isAssignableFrom(lastParamType) || BiResultExtractor.class.isAssignableFrom(lastParamType) - || RecordGetter.class.isAssignableFrom(lastParamType) || BiRecordGetter.class.isAssignableFrom(lastParamType))) { - if (RecordGetter.class.isAssignableFrom(lastParamType)) { + || RowMapper.class.isAssignableFrom(lastParamType) || BiRowMapper.class.isAssignableFrom(lastParamType))) { + if (RowMapper.class.isAssignableFrom(lastParamType)) { if (isListQuery) { - return (preparedQuery, args) -> (R) preparedQuery.list((RecordGetter) args[paramLen - 1]); + return (preparedQuery, args) -> (R) preparedQuery.list((RowMapper) args[paramLen - 1]); } else if (Optional.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.findFirst((RecordGetter) args[paramLen - 1]); + return (preparedQuery, args) -> (R) preparedQuery.findFirst((RowMapper) args[paramLen - 1]); } else if (ExceptionalStream.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.stream((RecordGetter) args[paramLen - 1]); + return (preparedQuery, args) -> (R) preparedQuery.stream((RowMapper) args[paramLen - 1]); } else if (Stream.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.stream((RecordGetter) args[paramLen - 1]).unchecked(); + return (preparedQuery, args) -> (R) preparedQuery.stream((RowMapper) args[paramLen - 1]).unchecked(); } else { if (Nullable.class.isAssignableFrom(returnType)) { - throw new UnsupportedOperationException("The return type of method: " + method.getName() + " can't be: " + returnType - + " when RecordGetter/BiRecordGetter is specified"); + throw new UnsupportedOperationException( + "The return type of method: " + method.getName() + " can't be: " + returnType + " when RowMapper/BiRowMapper is specified"); } - return (preparedQuery, args) -> (R) preparedQuery.findFirst((RecordGetter) args[paramLen - 1]).orNull(); + return (preparedQuery, args) -> (R) preparedQuery.findFirst((RowMapper) args[paramLen - 1]).orNull(); } - } else if (BiRecordGetter.class.isAssignableFrom(lastParamType)) { + } else if (BiRowMapper.class.isAssignableFrom(lastParamType)) { if (isListQuery) { - return (preparedQuery, args) -> (R) preparedQuery.list((BiRecordGetter) args[paramLen - 1]); + return (preparedQuery, args) -> (R) preparedQuery.list((BiRowMapper) args[paramLen - 1]); } else if (Optional.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.findFirst((BiRecordGetter) args[paramLen - 1]); + return (preparedQuery, args) -> (R) preparedQuery.findFirst((BiRowMapper) args[paramLen - 1]); } else if (ExceptionalStream.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.stream((BiRecordGetter) args[paramLen - 1]); + return (preparedQuery, args) -> (R) preparedQuery.stream((BiRowMapper) args[paramLen - 1]); } else if (Stream.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.stream((BiRecordGetter) args[paramLen - 1]).unchecked(); + return (preparedQuery, args) -> (R) preparedQuery.stream((BiRowMapper) args[paramLen - 1]).unchecked(); } else { if (Nullable.class.isAssignableFrom(returnType)) { - throw new UnsupportedOperationException("The return type of method: " + method.getName() + " can't be: " + returnType - + " when RecordGetter/BiRecordGetter is specified"); + throw new UnsupportedOperationException( + "The return type of method: " + method.getName() + " can't be: " + returnType + " when RowMapper/BiRowMapper is specified"); } - return (preparedQuery, args) -> (R) preparedQuery.findFirst((BiRecordGetter) args[paramLen - 1]).orNull(); + return (preparedQuery, args) -> (R) preparedQuery.findFirst((BiRowMapper) args[paramLen - 1]).orNull(); } } else { if (method.getGenericParameterTypes()[paramLen - 1] instanceof ParameterizedType) { @@ -8481,9 +8539,9 @@ static BiFunction createQuery } else if (DataSet.class.isAssignableFrom(returnType)) { return (preparedQuery, args) -> (R) preparedQuery.query(); } else if (N.isEntity(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.findFirst(BiRecordGetter.to(returnType)).orNull(); + return (preparedQuery, args) -> (R) preparedQuery.findFirst(BiRowMapper.to(returnType)).orNull(); } else if (Map.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.findFirst(BiRecordGetter.to(returnType)).orNull(); + return (preparedQuery, args) -> (R) preparedQuery.findFirst(BiRowMapper.to(returnType)).orNull(); } else if (isListQuery) { final ParameterizedType parameterizedReturnType = (ParameterizedType) method.getGenericReturnType(); final Class eleType = parameterizedReturnType.getActualTypeArguments()[0] instanceof Class @@ -8492,9 +8550,9 @@ static BiFunction createQuery if (N.isEntity(eleType) || Map.class.isAssignableFrom(eleType) || List.class.isAssignableFrom(eleType) || Object[].class.isAssignableFrom(eleType)) { - return (preparedQuery, args) -> (R) preparedQuery.list(BiRecordGetter.to(eleType)); + return (preparedQuery, args) -> (R) preparedQuery.list(BiRowMapper.to(eleType)); } else { - final RecordGetter recardGetter = rs -> N.typeOf(eleType).get(rs, 1); + final RowMapper recardGetter = rs -> N.typeOf(eleType).get(rs, 1); return (preparedQuery, args) -> (R) preparedQuery.list(recardGetter); } } else if (Optional.class.isAssignableFrom(returnType) || Nullable.class.isAssignableFrom(returnType)) { @@ -8507,9 +8565,9 @@ static BiFunction createQuery if (N.isEntity(eleType) || Map.class.isAssignableFrom(eleType) || List.class.isAssignableFrom(eleType) || Object[].class.isAssignableFrom(eleType)) { if (Nullable.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) Nullable.from(preparedQuery.findFirst(BiRecordGetter.to(eleType))); + return (preparedQuery, args) -> (R) Nullable.from(preparedQuery.findFirst(BiRowMapper.to(eleType))); } else { - return (preparedQuery, args) -> (R) preparedQuery.findFirst(BiRecordGetter.to(eleType)); + return (preparedQuery, args) -> (R) preparedQuery.findFirst(BiRowMapper.to(eleType)); } } else { if (Nullable.class.isAssignableFrom(returnType)) { @@ -8544,9 +8602,9 @@ static BiFunction createQuery if (N.isEntity(eleType) || Map.class.isAssignableFrom(eleType) || List.class.isAssignableFrom(eleType) || Object[].class.isAssignableFrom(eleType)) { if (ExceptionalStream.class.isAssignableFrom(returnType)) { - return (preparedQuery, args) -> (R) preparedQuery.stream(BiRecordGetter.to(eleType)); + return (preparedQuery, args) -> (R) preparedQuery.stream(BiRowMapper.to(eleType)); } else { - return (preparedQuery, args) -> (R) preparedQuery.stream(BiRecordGetter.to(eleType)).unchecked(); + return (preparedQuery, args) -> (R) preparedQuery.stream(BiRowMapper.to(eleType)).unchecked(); } } else { if (ExceptionalStream.class.isAssignableFrom(returnType)) { @@ -8581,11 +8639,10 @@ static boolean isListQuery(final Method method) { if (method.getGenericReturnType() instanceof ParameterizedType) { final ParameterizedType parameterizedReturnType = (ParameterizedType) method.getGenericReturnType(); - if (paramLen > 0 - && (RecordGetter.class.isAssignableFrom(paramTypes[paramLen - 1]) || BiRecordGetter.class.isAssignableFrom(paramTypes[paramLen - 1])) + if (paramLen > 0 && (RowMapper.class.isAssignableFrom(paramTypes[paramLen - 1]) || BiRowMapper.class.isAssignableFrom(paramTypes[paramLen - 1])) && method.getGenericParameterTypes()[paramLen - 1] instanceof ParameterizedType) { - // if the return type of the method is same as the return type of RecordGetter/BiRecordGetter parameter, return false; + // if the return type of the method is same as the return type of RowMapper/BiRowMapper parameter, return false; return !parameterizedReturnType.equals(((ParameterizedType) method.getGenericParameterTypes()[paramLen - 1]).getActualTypeArguments()[0]); } } diff --git a/src/com/landawn/abacus/util/MemcachedLock.java b/src/com/landawn/abacus/util/MemcachedLock.java index 537962f2..49faf559 100644 --- a/src/com/landawn/abacus/util/MemcachedLock.java +++ b/src/com/landawn/abacus/util/MemcachedLock.java @@ -28,7 +28,7 @@ * @author Haiyang Li */ public final class MemcachedLock { - private static final Logger logger = LoggerFactory.getLogger(MemcachedLock.class); + static final Logger logger = LoggerFactory.getLogger(MemcachedLock.class); private final SpyMemcached mc; @@ -54,9 +54,7 @@ public boolean lock(K target, V value, long liveTime) { try { return mc.add(key, value, liveTime); } catch (Exception e) { - String msg = "Failed to lock target with key: " + key; - logger.warn(msg, e); - throw new AbacusException(msg, e); + throw new AbacusException("Failed to lock target with key: " + key, e); } } @@ -74,9 +72,7 @@ public boolean unlock(K target) { try { return mc.delete(toKey(target)); } catch (Exception e) { - String msg = "Failed to unlock with key: " + target; - logger.warn(msg, e); - throw new AbacusException(msg, e); + throw new AbacusException("Failed to unlock with key: " + target, e); } } diff --git a/src/com/landawn/abacus/util/N.java b/src/com/landawn/abacus/util/N.java index 1c013476..1a3ab7df 100644 --- a/src/com/landawn/abacus/util/N.java +++ b/src/com/landawn/abacus/util/N.java @@ -743,6 +743,21 @@ public static T newInstance(final Class cls) { } } + public static boolean mayCausedBy(Throwable e, final Class exceptionClass) { + N.checkArgNotNull(e, "e"); + N.checkArgNotNull(exceptionClass, "exceptionClass"); + + while (e != null) { + if (exceptionClass.isAssignableFrom(e.getClass())) { + return true; + } + + e = e.getCause(); + } + + return false; + } + @SuppressWarnings("unchecked") private static T invoke(final Constructor c, final Object... args) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { diff --git a/src/com/landawn/abacus/util/SQLExecutor.java b/src/com/landawn/abacus/util/SQLExecutor.java index 8c8f7719..e6930e73 100644 --- a/src/com/landawn/abacus/util/SQLExecutor.java +++ b/src/com/landawn/abacus/util/SQLExecutor.java @@ -60,7 +60,7 @@ import com.landawn.abacus.type.Type; import com.landawn.abacus.util.Fn.FN; import com.landawn.abacus.util.Fn.Suppliers; -import com.landawn.abacus.util.JdbcUtil.BiRecordGetter; +import com.landawn.abacus.util.JdbcUtil.BiRowMapper; import com.landawn.abacus.util.JdbcUtil.PreparedQuery; import com.landawn.abacus.util.SQLBuilder.NAC; import com.landawn.abacus.util.SQLBuilder.NLC; @@ -707,38 +707,38 @@ public DBVersion dbVersion() { } @SafeVarargs - public final T insert(final String sql, final Object... parameters) throws UncheckedSQLException { + public final ID insert(final String sql, final Object... parameters) throws UncheckedSQLException { return insert(sql, StatementSetter.DEFAULT, parameters); } @SafeVarargs - public final T insert(final String sql, final StatementSetter statementSetter, final Object... parameters) throws UncheckedSQLException { + public final ID insert(final String sql, final StatementSetter statementSetter, final Object... parameters) throws UncheckedSQLException { return insert(sql, statementSetter, null, parameters); } @SafeVarargs - public final T insert(final String sql, final JdbcSettings jdbcSettings, final Object... parameters) throws UncheckedSQLException { + public final ID insert(final String sql, final JdbcSettings jdbcSettings, final Object... parameters) throws UncheckedSQLException { return insert(sql, StatementSetter.DEFAULT, jdbcSettings, parameters); } @SafeVarargs - public final T insert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) + public final ID insert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) throws UncheckedSQLException { return insert(null, sql, statementSetter, jdbcSettings, parameters); } @SafeVarargs - public final T insert(final Connection conn, final String sql, final Object... parameters) throws UncheckedSQLException { + public final ID insert(final Connection conn, final String sql, final Object... parameters) throws UncheckedSQLException { return insert(conn, sql, StatementSetter.DEFAULT, parameters); } @SafeVarargs - public final T insert(final Connection conn, final String sql, final StatementSetter statementSetter, final Object... parameters) + public final ID insert(final Connection conn, final String sql, final StatementSetter statementSetter, final Object... parameters) throws UncheckedSQLException { return insert(conn, sql, statementSetter, null, parameters); } - public final T insert(final Connection conn, final String sql, final JdbcSettings jdbcSettings, final Object... parameters) + public final ID insert(final Connection conn, final String sql, final JdbcSettings jdbcSettings, final Object... parameters) throws UncheckedSQLException { return insert(conn, sql, StatementSetter.DEFAULT, jdbcSettings, parameters); } @@ -748,7 +748,7 @@ public final T insert(final Connection conn, final String sql, final JdbcSet */ @SuppressWarnings({ "unchecked", "deprecation" }) @SafeVarargs - public final T insert(final Connection conn, final String sql, StatementSetter statementSetter, JdbcSettings jdbcSettings, final Object... parameters) + public final ID insert(final Connection conn, final String sql, StatementSetter statementSetter, JdbcSettings jdbcSettings, final Object... parameters) throws UncheckedSQLException { final NamedSQL namedSQL = getNamedSQL(sql); statementSetter = checkStatementSetter(namedSQL, statementSetter); @@ -770,7 +770,6 @@ public final T insert(final Connection conn, final String sql, StatementSett result = executeInsert(namedSQL, stmt); } catch (SQLException e) { String msg = AbacusException.getErrorMsg(e) + ". [SQL] " + namedSQL.getNamedSQL(); - logger.error(msg); throw new UncheckedSQLException(msg, e); } finally { closeQuietly(stmt); @@ -818,7 +817,7 @@ public final T insert(final Connection conn, final String sql, StatementSett } } - return (T) result; + return (ID) result; } protected Object executeInsert(final NamedSQL namedSQL, final PreparedStatement stmt) throws SQLException { @@ -846,33 +845,33 @@ protected Object executeInsert(final NamedSQL namedSQL, final PreparedStatement return id; } - public List batchInsert(final String sql, final List parametersList) throws UncheckedSQLException { + public List batchInsert(final String sql, final List parametersList) throws UncheckedSQLException { return batchInsert(sql, StatementSetter.DEFAULT, parametersList); } - public List batchInsert(final String sql, final StatementSetter statementSetter, final List parametersList) throws UncheckedSQLException { + public List batchInsert(final String sql, final StatementSetter statementSetter, final List parametersList) throws UncheckedSQLException { return batchInsert(sql, statementSetter, null, parametersList); } - public List batchInsert(final String sql, final JdbcSettings jdbcSettings, final List parametersList) throws UncheckedSQLException { + public List batchInsert(final String sql, final JdbcSettings jdbcSettings, final List parametersList) throws UncheckedSQLException { return batchInsert(sql, StatementSetter.DEFAULT, jdbcSettings, parametersList); } - public List batchInsert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final List parametersList) + public List batchInsert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final List parametersList) throws UncheckedSQLException { return batchInsert(null, sql, statementSetter, jdbcSettings, parametersList); } - public List batchInsert(final Connection conn, final String sql, final List parametersList) throws UncheckedSQLException { + public List batchInsert(final Connection conn, final String sql, final List parametersList) throws UncheckedSQLException { return batchInsert(conn, sql, StatementSetter.DEFAULT, parametersList); } - public List batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter, final List parametersList) + public List batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter, final List parametersList) throws UncheckedSQLException { return batchInsert(conn, sql, statementSetter, null, parametersList); } - public List batchInsert(final Connection conn, final String sql, final JdbcSettings jdbcSettings, final List parametersList) + public List batchInsert(final Connection conn, final String sql, final JdbcSettings jdbcSettings, final List parametersList) throws UncheckedSQLException { return batchInsert(conn, sql, StatementSetter.DEFAULT, jdbcSettings, parametersList); } @@ -882,7 +881,7 @@ public List batchInsert(final Connection conn, final String sql, final Jd * @see #batchInsert(Connection, String, StatementSetter, JdbcSettings, Object[]) */ @SuppressWarnings("deprecation") - public List batchInsert(final Connection conn, final String sql, StatementSetter statementSetter, JdbcSettings jdbcSettings, + public List batchInsert(final Connection conn, final String sql, StatementSetter statementSetter, JdbcSettings jdbcSettings, final List parametersList) throws UncheckedSQLException { final NamedSQL namedSQL = getNamedSQL(sql); statementSetter = checkStatementSetter(namedSQL, statementSetter); @@ -893,7 +892,7 @@ public List batchInsert(final Connection conn, final String sql, Statemen final int len = parametersList.size(); final int batchSize = getBatchSize(jdbcSettings); - List resultIdList = new ArrayList<>(len); + List resultIdList = new ArrayList<>(len); DataSource ds = null; Connection localConn = null; @@ -968,7 +967,6 @@ public List batchInsert(final Connection conn, final String sql, Statemen } String msg = AbacusException.getErrorMsg(e) + ". [SQL] " + namedSQL.getNamedSQL(); - logger.error(msg); throw new UncheckedSQLException(msg, e); } finally { if ((conn == null) && (len > batchSize)) { @@ -1060,7 +1058,7 @@ private void setIsolationLevel(JdbcSettings jdbcSettings, Connection localConn) } } - protected void executeBatchInsert(final List resultIdList, final NamedSQL namedSQL, final PreparedStatement stmt) throws SQLException { + protected void executeBatchInsert(final List resultIdList, final NamedSQL namedSQL, final PreparedStatement stmt) throws SQLException { if (_isReadOnly) { throw new AbacusException("This SQL Executor is configured for read-only"); } @@ -1073,7 +1071,7 @@ protected void executeBatchInsert(final List resultIdList, final NamedSQL rs = stmt.getGeneratedKeys(); while (rs.next()) { - resultIdList.add((T) JdbcUtil.getColumnValue(rs, 1)); + resultIdList.add((ID) JdbcUtil.getColumnValue(rs, 1)); } } catch (SQLException e) { logger.error("Failed to retrieve the auto-generated Ids", e); @@ -1145,7 +1143,6 @@ public final int update(final Connection conn, final String sql, StatementSetter return executeUpdate(namedSQL, stmt); } catch (SQLException e) { String msg = AbacusException.getErrorMsg(e) + ". [SQL] " + namedSQL.getNamedSQL(); - logger.error(msg); throw new UncheckedSQLException(msg, e); } finally { closeQuietly(stmt); @@ -1281,7 +1278,6 @@ public int batchUpdate(final Connection conn, final String sql, StatementSetter } String msg = AbacusException.getErrorMsg(e) + ". [SQL] " + namedSQL.getNamedSQL(); - logger.error(msg); throw new UncheckedSQLException(msg, e); } finally { if ((conn == null) && (len > batchSize)) { @@ -1529,67 +1525,67 @@ public final Optional get(final Class targetClass, final Connection co /** * v * @param sql - * @param recordGetter + * @param rowMapper * @param parameters * @return * @throws DuplicatedResultException if two or more records are found. */ @SafeVarargs - public final Optional get(final String sql, final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { - return Optional.ofNullable(gett(sql, recordGetter, parameters)); + public final Optional get(final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { + return Optional.ofNullable(gett(sql, rowMapper, parameters)); } - public final Optional get(final String sql, final StatementSetter statementSetter, final JdbcUtil.RecordGetter recordGetter, + public final Optional get(final String sql, final StatementSetter statementSetter, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { - return Optional.ofNullable(gett(sql, statementSetter, recordGetter, parameters)); + return Optional.ofNullable(gett(sql, statementSetter, rowMapper, parameters)); } - public final Optional get(final String sql, final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final Optional get(final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return Optional.ofNullable(gett(sql, recordGetter, jdbcSettings, parameters)); + return Optional.ofNullable(gett(sql, rowMapper, jdbcSettings, parameters)); } /** * * @param sql * @param statementSetter - * @param recordGetter + * @param rowMapper * @param jdbcSettings * @param parameters * @return * @throws DuplicatedResultException if two or more records are found. */ @SafeVarargs - public final Optional get(final String sql, final StatementSetter statementSetter, final JdbcUtil.RecordGetter recordGetter, + public final Optional get(final String sql, final StatementSetter statementSetter, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return Optional.ofNullable(gett(sql, statementSetter, recordGetter, jdbcSettings, parameters)); + return Optional.ofNullable(gett(sql, statementSetter, rowMapper, jdbcSettings, parameters)); } /** * * @param conn * @param sql - * @param recordGetter + * @param rowMapper * @param parameters * @return * @throws DuplicatedResultException if two or more records are found. */ @SafeVarargs - public final Optional get(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, + public final Optional get(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { - return Optional.ofNullable(gett(conn, sql, recordGetter, parameters)); + return Optional.ofNullable(gett(conn, sql, rowMapper, parameters)); } @SafeVarargs public final Optional get(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { - return Optional.ofNullable(gett(conn, sql, statementSetter, recordGetter, parameters)); + final JdbcUtil.RowMapper rowMapper, final Object... parameters) { + return Optional.ofNullable(gett(conn, sql, statementSetter, rowMapper, parameters)); } @SafeVarargs - public final Optional get(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, + public final Optional get(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, JdbcSettings jdbcSettings, final Object... parameters) { - return Optional.ofNullable(gett(conn, sql, recordGetter, jdbcSettings, parameters)); + return Optional.ofNullable(gett(conn, sql, rowMapper, jdbcSettings, parameters)); } /** @@ -1597,7 +1593,7 @@ public final Optional get(final Connection conn, final String sql, final * @param conn * @param sql * @param statementSetter - * @param recordGetter + * @param rowMapper * @param jdbcSettings * @param parameters * @return @@ -1605,8 +1601,8 @@ public final Optional get(final Connection conn, final String sql, final */ @SafeVarargs public final Optional get(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { - return Optional.ofNullable(gett(conn, sql, statementSetter, recordGetter, jdbcSettings, parameters)); + final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { + return Optional.ofNullable(gett(conn, sql, statementSetter, rowMapper, jdbcSettings, parameters)); } @SafeVarargs @@ -1663,55 +1659,54 @@ public final T gett(final Class targetClass, final Connection conn, final JdbcSettings jdbcSettings, final Object... parameters) { N.checkArgNotNull(targetClass, "targetClass"); - final JdbcUtil.RecordGetter recordGetter = new JdbcUtil.RecordGetter() { - private final BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final JdbcUtil.RowMapper rowMapper = new JdbcUtil.RowMapper() { + private final BiRowMapper biRowMapper = BiRowMapper.to(targetClass); @Override public T apply(ResultSet rs) throws SQLException { - return biRecordGetter.apply(rs, JdbcUtil.getColumnLabelList(rs)); + return biRowMapper.apply(rs, JdbcUtil.getColumnLabelList(rs)); } }; - return gett(conn, sql, statementSetter, recordGetter, jdbcSettings, parameters); + return gett(conn, sql, statementSetter, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final T gett(final String sql, final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { - return gett(sql, StatementSetter.DEFAULT, recordGetter, parameters); + public final T gett(final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { + return gett(sql, StatementSetter.DEFAULT, rowMapper, parameters); } @SafeVarargs - public final T gett(final String sql, final StatementSetter statementSetter, final JdbcUtil.RecordGetter recordGetter, + public final T gett(final String sql, final StatementSetter statementSetter, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { - return gett(sql, statementSetter, recordGetter, null, parameters); + return gett(sql, statementSetter, rowMapper, null, parameters); } @SafeVarargs - public final T gett(final String sql, final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final T gett(final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return gett(sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return gett(sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final T gett(final String sql, final StatementSetter statementSetter, final JdbcUtil.RecordGetter recordGetter, + public final T gett(final String sql, final StatementSetter statementSetter, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return gett(null, sql, statementSetter, recordGetter, jdbcSettings, parameters); + return gett(null, sql, statementSetter, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final T gett(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, - final Object... parameters) { - return gett(conn, sql, StatementSetter.DEFAULT, recordGetter, parameters); + public final T gett(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { + return gett(conn, sql, StatementSetter.DEFAULT, rowMapper, parameters); } public final T gett(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { - return gett(conn, sql, statementSetter, recordGetter, null, parameters); + final JdbcUtil.RowMapper rowMapper, final Object... parameters) { + return gett(conn, sql, statementSetter, rowMapper, null, parameters); } - public final T gett(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, JdbcSettings jdbcSettings, + public final T gett(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, JdbcSettings jdbcSettings, final Object... parameters) { - return gett(conn, sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return gett(conn, sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } /** @@ -1719,7 +1714,7 @@ public final T gett(final Connection conn, final String sql, final JdbcUtil. * @param conn * @param sql * @param statementSetter - * @param recordGetter + * @param rowMapper * @param jdbcSettings * @param parameters * @return @@ -1728,8 +1723,8 @@ public final T gett(final Connection conn, final String sql, final JdbcUtil. @SuppressWarnings("unchecked") @SafeVarargs public final T gett(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, JdbcSettings jdbcSettings, final Object... parameters) { - N.checkArgNotNull(recordGetter, "recordGetter"); + final JdbcUtil.RowMapper rowMapper, JdbcSettings jdbcSettings, final Object... parameters) { + N.checkArgNotNull(rowMapper, "rowMapper"); final ResultExtractor resultExtractor = new ResultExtractor() { @Override @@ -1743,7 +1738,7 @@ public T extractData(ResultSet rs, final JdbcSettings jdbcSettings) throws SQLEx T result = null; if (rs.next()) { - result = Objects.requireNonNull(recordGetter.apply(rs)); + result = Objects.requireNonNull(rowMapper.apply(rs)); if (rs.next()) { throw new DuplicatedResultException("More than one records found by sql: " + sql); @@ -1814,55 +1809,55 @@ public final Optional findFirst(final Class targetClass, final Connect final JdbcSettings jdbcSettings, final Object... parameters) { N.checkArgNotNull(targetClass, "targetClass"); - final JdbcUtil.RecordGetter recordGetter = new JdbcUtil.RecordGetter() { - private final BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final JdbcUtil.RowMapper rowMapper = new JdbcUtil.RowMapper() { + private final BiRowMapper biRowMapper = BiRowMapper.to(targetClass); @Override public T apply(ResultSet rs) throws SQLException { - return biRecordGetter.apply(rs, JdbcUtil.getColumnLabelList(rs)); + return biRowMapper.apply(rs, JdbcUtil.getColumnLabelList(rs)); } }; - return findFirst(conn, sql, statementSetter, recordGetter, jdbcSettings, parameters); + return findFirst(conn, sql, statementSetter, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final Optional findFirst(final String sql, final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { - return findFirst(sql, StatementSetter.DEFAULT, recordGetter, parameters); + public final Optional findFirst(final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { + return findFirst(sql, StatementSetter.DEFAULT, rowMapper, parameters); } @SafeVarargs - public final Optional findFirst(final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { - return findFirst(sql, statementSetter, recordGetter, null, parameters); + public final Optional findFirst(final String sql, final StatementSetter statementSetter, final JdbcUtil.RowMapper rowMapper, + final Object... parameters) { + return findFirst(sql, statementSetter, rowMapper, null, parameters); } @SafeVarargs - public final Optional findFirst(final String sql, final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final Optional findFirst(final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return findFirst(sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return findFirst(sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final Optional findFirst(final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { - return findFirst(null, sql, statementSetter, recordGetter, jdbcSettings, parameters); + public final Optional findFirst(final String sql, final StatementSetter statementSetter, final JdbcUtil.RowMapper rowMapper, + final JdbcSettings jdbcSettings, final Object... parameters) { + return findFirst(null, sql, statementSetter, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final Optional findFirst(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, + public final Optional findFirst(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, final Object... parameters) { - return findFirst(conn, sql, StatementSetter.DEFAULT, recordGetter, parameters); + return findFirst(conn, sql, StatementSetter.DEFAULT, rowMapper, parameters); } public final Optional findFirst(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final Object... parameters) { - return findFirst(conn, sql, statementSetter, recordGetter, null, parameters); + final JdbcUtil.RowMapper rowMapper, final Object... parameters) { + return findFirst(conn, sql, statementSetter, rowMapper, null, parameters); } - public final Optional findFirst(final Connection conn, final String sql, final JdbcUtil.RecordGetter recordGetter, + public final Optional findFirst(final Connection conn, final String sql, final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return findFirst(conn, sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return findFirst(conn, sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } /** @@ -1872,7 +1867,7 @@ public final Optional findFirst(final Connection conn, final String sql, * @param conn * @param sql * @param statementSetter - * @param recordGetter + * @param rowMapper * @param jdbcSettings * @param parameters * @return @@ -1880,8 +1875,8 @@ public final Optional findFirst(final Connection conn, final String sql, @SuppressWarnings("unchecked") @SafeVarargs public final Optional findFirst(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.RecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { - N.checkArgNotNull(recordGetter, "recordGetter"); + final JdbcUtil.RowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { + N.checkArgNotNull(rowMapper, "rowMapper"); final ResultExtractor resultExtractor = new ResultExtractor() { @Override @@ -1892,7 +1887,7 @@ public T extractData(ResultSet rs, final JdbcSettings jdbcSettings) throws SQLEx JdbcUtil.skip(rs, offset); } - return rs.next() ? Objects.requireNonNull(recordGetter.apply(rs)) : null; + return rs.next() ? Objects.requireNonNull(rowMapper.apply(rs)) : null; } }; @@ -1949,48 +1944,48 @@ public final List list(final Class targetClass, final Connection conn, @SafeVarargs public final List list(final Class targetClass, final Connection conn, final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) { - final JdbcUtil.BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final JdbcUtil.BiRowMapper biRowMapper = BiRowMapper.to(targetClass); - return list(conn, sql, statementSetter, biRecordGetter, jdbcSettings, parameters); + return list(conn, sql, statementSetter, biRowMapper, jdbcSettings, parameters); } @SafeVarargs - public final List list(final String sql, final JdbcUtil.BiRecordGetter recordGetter, final Object... parameters) { - return list(sql, StatementSetter.DEFAULT, recordGetter, parameters); + public final List list(final String sql, final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { + return list(sql, StatementSetter.DEFAULT, rowMapper, parameters); } @SafeVarargs - public final List list(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRecordGetter recordGetter, + public final List list(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { - return list(sql, statementSetter, recordGetter, null, parameters); + return list(sql, statementSetter, rowMapper, null, parameters); } @SafeVarargs - public final List list(final String sql, final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final List list(final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return list(sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return list(sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final List list(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRecordGetter recordGetter, + public final List list(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return list(null, sql, statementSetter, recordGetter, jdbcSettings, parameters); + return list(null, sql, statementSetter, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final List list(final Connection conn, final String sql, final JdbcUtil.BiRecordGetter recordGetter, + public final List list(final Connection conn, final String sql, final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { - return list(conn, sql, StatementSetter.DEFAULT, recordGetter, parameters); + return list(conn, sql, StatementSetter.DEFAULT, rowMapper, parameters); } public final List list(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final Object... parameters) { - return list(conn, sql, statementSetter, recordGetter, null, parameters); + final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { + return list(conn, sql, statementSetter, rowMapper, null, parameters); } - public final List list(final Connection conn, final String sql, final JdbcUtil.BiRecordGetter recordGetter, + public final List list(final Connection conn, final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return list(conn, sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return list(conn, sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } /** @@ -1998,7 +1993,7 @@ public final List list(final Connection conn, final String sql, final Jdb * @param conn * @param sql * @param statementSetter - * @param recordGetter + * @param rowMapper * @param jdbcSettings * @param parameters * @return @@ -2006,8 +2001,8 @@ public final List list(final Connection conn, final String sql, final Jdb @SuppressWarnings("unchecked") @SafeVarargs public final List list(final Connection conn, final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { - N.checkArgNotNull(recordGetter); + final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { + N.checkArgNotNull(rowMapper); final ResultExtractor> resultExtractor = new ResultExtractor>() { @Override @@ -2023,7 +2018,7 @@ public List extractData(ResultSet rs, final JdbcSettings jdbcSettings) throws final List columnLabels = JdbcUtil.getColumnLabelList(rs); while (count-- > 0 && rs.next()) { - result.add(recordGetter.apply(rs, columnLabels)); + result.add(rowMapper.apply(rs, columnLabels)); } return result; @@ -2041,9 +2036,9 @@ public final List listAll(final Class targetClass, final String sql, f @SafeVarargs public final List listAll(final Class targetClass, final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) { - final JdbcUtil.BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final JdbcUtil.BiRowMapper biRowMapper = BiRowMapper.to(targetClass); - return listAll(sql, statementSetter, biRecordGetter, jdbcSettings, parameters); + return listAll(sql, statementSetter, biRowMapper, jdbcSettings, parameters); } @SafeVarargs @@ -2054,24 +2049,24 @@ public final List listAll(final Class targetClass, final List @SafeVarargs public final List listAll(final Class targetClass, final List sqls, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) { - final JdbcUtil.BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final JdbcUtil.BiRowMapper biRowMapper = BiRowMapper.to(targetClass); - return listAll(sqls, statementSetter, biRecordGetter, jdbcSettings, parameters); + return listAll(sqls, statementSetter, biRowMapper, jdbcSettings, parameters); } @SafeVarargs - public final List listAll(final String sql, final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final List listAll(final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return listAll(sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return listAll(sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final List listAll(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRecordGetter recordGetter, + public final List listAll(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { checkJdbcSettingsForAllQuery(jdbcSettings); if (jdbcSettings == null || N.isNullOrEmpty(jdbcSettings.getQueryWithDataSources())) { - return list(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return list(sql, statementSetter, rowMapper, jdbcSettings, parameters); } final Collection dss = jdbcSettings.getQueryWithDataSources(); @@ -2089,7 +2084,7 @@ public JdbcSettings apply(String ds) { }).parallel(dss.size()).map(new Function>() { @Override public List apply(JdbcSettings newJdbcSettings) { - return list(sql, statementSetter, recordGetter, newJdbcSettings, parameters); + return list(sql, statementSetter, rowMapper, newJdbcSettings, parameters); } }).toList(); } else { @@ -2099,7 +2094,7 @@ public List apply(JdbcSettings newJdbcSettings) { for (String ds : dss) { newJdbcSettings.setQueryWithDataSource(ds); - resultList.add(list(sql, statementSetter, recordGetter, newJdbcSettings, parameters)); + resultList.add(list(sql, statementSetter, rowMapper, newJdbcSettings, parameters)); } } @@ -2113,16 +2108,16 @@ private void checkJdbcSettingsForAllQuery(JdbcSettings jdbcSettings) { } @SafeVarargs - public final List listAll(final List sqls, final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final List listAll(final List sqls, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return listAll(sqls, null, recordGetter, jdbcSettings, parameters); + return listAll(sqls, null, rowMapper, jdbcSettings, parameters); } @SafeVarargs - public final List listAll(final List sqls, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + public final List listAll(final List sqls, final StatementSetter statementSetter, final JdbcUtil.BiRowMapper rowMapper, + final JdbcSettings jdbcSettings, final Object... parameters) { if (sqls.size() == 1) { - return listAll(sqls.get(0), statementSetter, recordGetter, jdbcSettings, parameters); + return listAll(sqls.get(0), statementSetter, rowMapper, jdbcSettings, parameters); } List> resultList = null; @@ -2131,14 +2126,14 @@ public final List listAll(final List sqls, final StatementSetter resultList = Stream.of(sqls).parallel(sqls.size()).map(new Function>() { @Override public List apply(String sql) { - return listAll(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return listAll(sql, statementSetter, rowMapper, jdbcSettings, parameters); } }).toList(); } else { resultList = new ArrayList<>(sqls.size()); for (String sql : sqls) { - resultList.add(listAll(sql, statementSetter, recordGetter, jdbcSettings, parameters)); + resultList.add(listAll(sql, statementSetter, rowMapper, jdbcSettings, parameters)); } } @@ -2614,14 +2609,15 @@ protected T query(final Class targetClass, final Connection conn, final S stmt = prepareStatement(ds, localConn, namedSQL, statementSetter, jdbcSettings, false, false, parameters); - stmt.setFetchDirection(ResultSet.FETCH_FORWARD); + if (jdbcSettings == null || jdbcSettings.getFetchDirection() == -1) { + stmt.setFetchDirection(ResultSet.FETCH_FORWARD); + } rs = stmt.executeQuery(); result = resultExtractor.extractData(targetClass, namedSQL, rs, jdbcSettings); } catch (SQLException e) { String msg = AbacusException.getErrorMsg(e) + ". [SQL] " + namedSQL.getNamedSQL(); - logger.error(msg); throw new UncheckedSQLException(msg, e); } finally { if (result instanceof ResultSet) { @@ -2740,26 +2736,26 @@ public final Stream stream(final Class targetClass, final String sql, @SafeVarargs public final Stream stream(final Class targetClass, final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) { - final JdbcUtil.BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final JdbcUtil.BiRowMapper biRowMapper = BiRowMapper.to(targetClass); - return stream(sql, statementSetter, biRecordGetter, jdbcSettings, parameters); + return stream(sql, statementSetter, biRowMapper, jdbcSettings, parameters); } @SafeVarargs - public final Stream stream(final String sql, final JdbcUtil.BiRecordGetter recordGetter, final Object... parameters) { - return stream(sql, StatementSetter.DEFAULT, recordGetter, parameters); + public final Stream stream(final String sql, final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { + return stream(sql, StatementSetter.DEFAULT, rowMapper, parameters); } @SafeVarargs - public final Stream stream(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRecordGetter recordGetter, + public final Stream stream(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRowMapper rowMapper, final Object... parameters) { - return stream(sql, statementSetter, recordGetter, null, parameters); + return stream(sql, statementSetter, rowMapper, null, parameters); } @SafeVarargs - public final Stream stream(final String sql, final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final Stream stream(final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return stream(sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return stream(sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } /** @@ -2768,13 +2764,13 @@ public final Stream stream(final String sql, final JdbcUtil.BiRecordGette * * @param sql * @param statementSetter - * @param recordGetter + * @param rowMapper * @param jdbcSettings * @param parameters * @return */ @SafeVarargs - public final Stream stream(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRecordGetter recordGetter, + public final Stream stream(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { final ObjIteratorEx lazyIter = ObjIteratorEx.of(new Supplier>() { @@ -2823,7 +2819,7 @@ public T next() { } try { - final T result = recordGetter.apply(rs, columnLabels); + final T result = rowMapper.apply(rs, columnLabels); hasNext = false; return result; } catch (SQLException e) { @@ -2922,15 +2918,15 @@ public final Stream streamAll(final Class targetClass, final String sq @SafeVarargs public final Stream streamAll(final Class targetClass, final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) { - final JdbcUtil.BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final JdbcUtil.BiRowMapper biRowMapper = BiRowMapper.to(targetClass); - return streamAll(sql, statementSetter, biRecordGetter, jdbcSettings, parameters); + return streamAll(sql, statementSetter, biRowMapper, jdbcSettings, parameters); } @SafeVarargs - public final Stream streamAll(final String sql, final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, + public final Stream streamAll(final String sql, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { - return streamAll(sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, parameters); + return streamAll(sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, parameters); } /** @@ -2944,12 +2940,12 @@ public final Stream streamAll(final String sql, final JdbcUtil.BiRecordGe * @return */ @SafeVarargs - public final Stream streamAll(final String sql, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + public final Stream streamAll(final String sql, final StatementSetter statementSetter, final JdbcUtil.BiRowMapper rowMapper, + final JdbcSettings jdbcSettings, final Object... parameters) { checkJdbcSettingsForAllQuery(jdbcSettings); if (jdbcSettings == null || N.isNullOrEmpty(jdbcSettings.getQueryWithDataSources())) { - return stream(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return stream(sql, statementSetter, rowMapper, jdbcSettings, parameters); } final Collection dss = jdbcSettings.getQueryWithDataSources(); @@ -2967,7 +2963,7 @@ public Stream apply(Stream s) { }).flatMap(new Function>() { @Override public Stream apply(JdbcSettings newJdbcSettings) { - return stream(sql, statementSetter, recordGetter, newJdbcSettings, parameters); + return stream(sql, statementSetter, rowMapper, newJdbcSettings, parameters); } }); } @@ -2990,15 +2986,15 @@ public final Stream streamAll(final Class targetClass, final List Stream streamAll(final Class targetClass, final List sqls, final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) { - final JdbcUtil.BiRecordGetter biRecordGetter = BiRecordGetter.to(targetClass); + final JdbcUtil.BiRowMapper biRowMapper = BiRowMapper.to(targetClass); - return streamAll(sqls, statementSetter, biRecordGetter, jdbcSettings, parameters); + return streamAll(sqls, statementSetter, biRowMapper, jdbcSettings, parameters); } @SafeVarargs - public final Stream streamAll(final List sqls, final JdbcUtil.BiRecordGetter recordGetter, - final JdbcSettings jdbcSettings, final Object... parameters) { - return streamAll(sqls, null, recordGetter, jdbcSettings, parameters); + public final Stream streamAll(final List sqls, final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, + final Object... parameters) { + return streamAll(sqls, null, rowMapper, jdbcSettings, parameters); } /** @@ -3007,16 +3003,16 @@ public final Stream streamAll(final List sqls, final JdbcUtil.BiR * * @param sqls * @param statementSetter - * @param recordGetter + * @param rowMapper * @param jdbcSettings * @param parameters * @return */ @SafeVarargs public final Stream streamAll(final List sqls, final StatementSetter statementSetter, - final JdbcUtil.BiRecordGetter recordGetter, final JdbcSettings jdbcSettings, final Object... parameters) { + final JdbcUtil.BiRowMapper rowMapper, final JdbcSettings jdbcSettings, final Object... parameters) { if (sqls.size() == 1) { - return streamAll(sqls.get(0), statementSetter, recordGetter, jdbcSettings, parameters); + return streamAll(sqls.get(0), statementSetter, rowMapper, jdbcSettings, parameters); } final boolean isQueryInParallel = jdbcSettings != null && jdbcSettings.isQueryInParallel(); @@ -3029,7 +3025,7 @@ public Stream apply(Stream s) { }).flatMap(new Function>() { @Override public Stream apply(String sql) { - return streamAll(sql, statementSetter, recordGetter, jdbcSettings, parameters); + return streamAll(sql, statementSetter, rowMapper, jdbcSettings, parameters); } }); } @@ -3167,7 +3163,6 @@ public final void execute(final Connection conn, final String sql, final Object. stmt.execute(); } catch (SQLException e) { String msg = AbacusException.getErrorMsg(e) + ". [SQL] " + namedSQL.getNamedSQL(); - logger.error(msg); throw new UncheckedSQLException(msg, e); } finally { closeQuietly(stmt); @@ -4177,83 +4172,83 @@ public Optional findFirst(final Connection conn, final Collection sel return sqlExecutor.findFirst(targetClass, conn, sp.sql, StatementSetter.DEFAULT, jdbcSettings, sp.parameters.toArray()); } - public Optional findFirst(String selectPropName, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { - return findFirst(selectPropName, recordGetter, whereCause, null); + public Optional findFirst(String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { + return findFirst(selectPropName, rowMapper, whereCause, null); } - public Optional findFirst(String selectPropName, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, + public Optional findFirst(String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return findFirst(null, selectPropName, recordGetter, whereCause, jdbcSettings); + return findFirst(null, selectPropName, rowMapper, whereCause, jdbcSettings); } - public Optional findFirst(final Connection conn, String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public Optional findFirst(final Connection conn, String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { - return findFirst(conn, selectPropName, recordGetter, whereCause, null); + return findFirst(conn, selectPropName, rowMapper, whereCause, null); } - public Optional findFirst(final Connection conn, String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public Optional findFirst(final Connection conn, String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return findFirst(conn, Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return findFirst(conn, Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } - public Optional findFirst(String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { - return findFirst(selectPropName, recordGetter, whereCause, null); + public Optional findFirst(String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { + return findFirst(selectPropName, rowMapper, whereCause, null); } - public Optional findFirst(String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, + public Optional findFirst(String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return findFirst(null, selectPropName, recordGetter, whereCause, jdbcSettings); + return findFirst(null, selectPropName, rowMapper, whereCause, jdbcSettings); } - public Optional findFirst(final Connection conn, String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public Optional findFirst(final Connection conn, String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { - return findFirst(conn, selectPropName, recordGetter, whereCause, null); + return findFirst(conn, selectPropName, rowMapper, whereCause, null); } - public Optional findFirst(final Connection conn, String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public Optional findFirst(final Connection conn, String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return findFirst(conn, Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return findFirst(conn, Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } - public Optional findFirst(Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public Optional findFirst(Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { - return findFirst(selectPropNames, recordGetter, whereCause, null); + return findFirst(selectPropNames, rowMapper, whereCause, null); } - public Optional findFirst(Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public Optional findFirst(Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return findFirst(null, selectPropNames, recordGetter, whereCause, jdbcSettings); + return findFirst(null, selectPropNames, rowMapper, whereCause, jdbcSettings); } - public Optional findFirst(final Connection conn, Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { - return findFirst(conn, selectPropNames, recordGetter, whereCause, null); + public Optional findFirst(final Connection conn, Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, + final Condition whereCause) { + return findFirst(conn, selectPropNames, rowMapper, whereCause, null); } - public Optional findFirst(final Connection conn, Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + public Optional findFirst(final Connection conn, Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, + final Condition whereCause, final JdbcSettings jdbcSettings) { final SP sp = prepareQuery(selectPropNames, whereCause); - return sqlExecutor.findFirst(conn, sp.sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, sp.parameters.toArray()); + return sqlExecutor.findFirst(conn, sp.sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, sp.parameters.toArray()); } - public Optional findFirst(Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, + public Optional findFirst(Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { - return findFirst(selectPropNames, recordGetter, whereCause, null); + return findFirst(selectPropNames, rowMapper, whereCause, null); } - public Optional findFirst(Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, + public Optional findFirst(Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return findFirst(null, selectPropNames, recordGetter, whereCause, jdbcSettings); + return findFirst(null, selectPropNames, rowMapper, whereCause, jdbcSettings); } - public Optional findFirst(final Connection conn, Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { - return findFirst(conn, selectPropNames, recordGetter, whereCause, null); + public Optional findFirst(final Connection conn, Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, + final Condition whereCause) { + return findFirst(conn, selectPropNames, rowMapper, whereCause, null); } - public Optional findFirst(final Connection conn, Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + public Optional findFirst(final Connection conn, Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, + final Condition whereCause, final JdbcSettings jdbcSettings) { final SP sp = prepareQuery(selectPropNames, whereCause); final ResultExtractor resultExtractor = new ResultExtractor() { @@ -4265,7 +4260,7 @@ public R extractData(ResultSet rs, final JdbcSettings jdbcSettings) throws SQLEx JdbcUtil.skip(rs, offset); } - return rs.next() ? Objects.requireNonNull(recordGetter.apply(rs, JdbcUtil.getColumnLabelList(rs))) : null; + return rs.next() ? Objects.requireNonNull(rowMapper.apply(rs, JdbcUtil.getColumnLabelList(rs))) : null; } }; @@ -4298,92 +4293,91 @@ public List list(final Connection conn, final Collection selectPropNa return sqlExecutor.list(targetClass, conn, sp.sql, StatementSetter.DEFAULT, jdbcSettings, sp.parameters.toArray()); } - public List list(String selectPropName, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { - return list(selectPropName, recordGetter, whereCause, null); + public List list(String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { + return list(selectPropName, rowMapper, whereCause, null); } - public List list(String selectPropName, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, + public List list(String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return list(null, selectPropName, recordGetter, whereCause, jdbcSettings); + return list(null, selectPropName, rowMapper, whereCause, jdbcSettings); } - public List list(final Connection conn, String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public List list(final Connection conn, String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { - return list(conn, selectPropName, recordGetter, whereCause, null); + return list(conn, selectPropName, rowMapper, whereCause, null); } - public List list(final Connection conn, String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public List list(final Connection conn, String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return list(conn, Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return list(conn, Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } - public List list(String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { - return list(selectPropName, recordGetter, whereCause, null); + public List list(String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { + return list(selectPropName, rowMapper, whereCause, null); } - public List list(String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, + public List list(String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return list(null, selectPropName, recordGetter, whereCause, jdbcSettings); + return list(null, selectPropName, rowMapper, whereCause, jdbcSettings); } - public List list(final Connection conn, String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public List list(final Connection conn, String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { - return list(conn, selectPropName, recordGetter, whereCause, null); + return list(conn, selectPropName, rowMapper, whereCause, null); } - public List list(final Connection conn, String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public List list(final Connection conn, String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return list(conn, Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return list(conn, Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } - public List list(Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { - return list(selectPropNames, recordGetter, whereCause, null); + public List list(Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { + return list(selectPropNames, rowMapper, whereCause, null); } - public List list(Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, + public List list(Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return list(null, selectPropNames, recordGetter, whereCause, jdbcSettings); + return list(null, selectPropNames, rowMapper, whereCause, jdbcSettings); } - public List list(final Connection conn, Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public List list(final Connection conn, Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { - return list(conn, selectPropNames, recordGetter, whereCause, null); + return list(conn, selectPropNames, rowMapper, whereCause, null); } - public List list(final Connection conn, Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public List list(final Connection conn, Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - N.checkArgNotNull(recordGetter); + N.checkArgNotNull(rowMapper); - final JdbcUtil.BiRecordGetter biRecordGetter = new JdbcUtil.BiRecordGetter() { + final JdbcUtil.BiRowMapper biRowMapper = new JdbcUtil.BiRowMapper() { @Override public R apply(final ResultSet rs, final List columnLabels) throws SQLException { - return recordGetter.apply(rs); + return rowMapper.apply(rs); } }; - return list(conn, selectPropNames, biRecordGetter, whereCause, jdbcSettings); + return list(conn, selectPropNames, biRowMapper, whereCause, jdbcSettings); } - public List list(Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, - final Condition whereCause) { - return list(selectPropNames, recordGetter, whereCause, null); + public List list(Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { + return list(selectPropNames, rowMapper, whereCause, null); } - public List list(Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, + public List list(Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return list(null, selectPropNames, recordGetter, whereCause, jdbcSettings); + return list(null, selectPropNames, rowMapper, whereCause, jdbcSettings); } - public List list(final Connection conn, Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, + public List list(final Connection conn, Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { - return list(conn, selectPropNames, recordGetter, whereCause, null); + return list(conn, selectPropNames, rowMapper, whereCause, null); } - public List list(final Connection conn, Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, + public List list(final Connection conn, Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { final SP sp = prepareQuery(selectPropNames, whereCause); - return sqlExecutor.list(conn, sp.sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, sp.parameters.toArray()); + return sqlExecutor.list(conn, sp.sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, sp.parameters.toArray()); } /** @@ -4413,35 +4407,35 @@ public List listAll(final Collection selectPropNames, final Condition return sqlExecutor.listAll(targetClass, sp.sql, StatementSetter.DEFAULT, jdbcSettings, sp.parameters.toArray()); } - public List listAll(String selectPropName, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, + public List listAll(String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return listAll(Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return listAll(Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } - public List listAll(String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, + public List listAll(String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return listAll(Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return listAll(Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } - public List listAll(Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, - final Condition whereCause, final JdbcSettings jdbcSettings) { - N.checkArgNotNull(recordGetter); + public List listAll(Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, + final JdbcSettings jdbcSettings) { + N.checkArgNotNull(rowMapper); - final JdbcUtil.BiRecordGetter biRecordGetter = new JdbcUtil.BiRecordGetter() { + final JdbcUtil.BiRowMapper biRowMapper = new JdbcUtil.BiRowMapper() { @Override public R apply(final ResultSet rs, final List columnLabels) throws SQLException { - return recordGetter.apply(rs); + return rowMapper.apply(rs); } }; - return listAll(selectPropNames, biRecordGetter, whereCause, jdbcSettings); + return listAll(selectPropNames, biRowMapper, whereCause, jdbcSettings); } - public List listAll(Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, - final Condition whereCause, final JdbcSettings jdbcSettings) { + public List listAll(Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, + final JdbcSettings jdbcSettings) { final SP sp = prepareQuery(selectPropNames, whereCause); - return sqlExecutor.listAll(sp.sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, sp.parameters.toArray()); + return sqlExecutor.listAll(sp.sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, sp.parameters.toArray()); } /** @@ -4491,12 +4485,12 @@ public Stream stream(final Collection selectPropNames, final Conditio * * * @param selectPropName - * @param recordGetter + * @param rowMapper * @param whereCause * @return */ - public Stream stream(String selectPropName, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { - return stream(selectPropName, recordGetter, whereCause, null); + public Stream stream(String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { + return stream(selectPropName, rowMapper, whereCause, null); } /** @@ -4505,14 +4499,14 @@ public Stream stream(String selectPropName, final JdbcUtil.RecordGetter Stream stream(String selectPropName, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, + public Stream stream(String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return stream(Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return stream(Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } /** @@ -4521,12 +4515,12 @@ public Stream stream(String selectPropName, final JdbcUtil.RecordGetter Stream stream(String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { - return stream(selectPropName, recordGetter, whereCause, null); + public Stream stream(String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { + return stream(selectPropName, rowMapper, whereCause, null); } /** @@ -4535,14 +4529,14 @@ public Stream stream(String selectPropName, final JdbcUtil.BiRecordGetter * * * @param selectPropName - * @param recordGetter + * @param rowMapper * @param whereCause * @param jdbcSettings * @return */ - public Stream stream(String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, + public Stream stream(String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return stream(Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return stream(Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } /** @@ -4551,13 +4545,12 @@ public Stream stream(String selectPropName, final JdbcUtil.BiRecordGetter * * * @param selectPropNames - * @param recordGetter + * @param rowMapper * @param whereCause * @return */ - public Stream stream(Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, - final Condition whereCause) { - return stream(selectPropNames, recordGetter, whereCause, null); + public Stream stream(Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { + return stream(selectPropNames, rowMapper, whereCause, null); } /** @@ -4566,23 +4559,23 @@ public Stream stream(Collection selectPropNames, final JdbcUtil.R * * * @param selectPropNames - * @param recordGetter + * @param rowMapper * @param whereCause * @param jdbcSettings * @return */ - public Stream stream(Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, - final Condition whereCause, final JdbcSettings jdbcSettings) { - N.checkArgNotNull(recordGetter); + public Stream stream(Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, + final JdbcSettings jdbcSettings) { + N.checkArgNotNull(rowMapper); - final JdbcUtil.BiRecordGetter biRecordGetter = new JdbcUtil.BiRecordGetter() { + final JdbcUtil.BiRowMapper biRowMapper = new JdbcUtil.BiRowMapper() { @Override public R apply(final ResultSet rs, final List columnLabels) throws SQLException { - return recordGetter.apply(rs); + return rowMapper.apply(rs); } }; - return stream(selectPropNames, biRecordGetter, whereCause, jdbcSettings); + return stream(selectPropNames, biRowMapper, whereCause, jdbcSettings); } /** @@ -4591,13 +4584,12 @@ public R apply(final ResultSet rs, final List columnLabels) throws SQLEx * * * @param selectPropNames - * @param recordGetter + * @param rowMapper * @param whereCause * @return */ - public Stream stream(Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, - final Condition whereCause) { - return stream(selectPropNames, recordGetter, whereCause, null); + public Stream stream(Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { + return stream(selectPropNames, rowMapper, whereCause, null); } /** @@ -4606,16 +4598,16 @@ public Stream stream(Collection selectPropNames, final JdbcUtil.B * * * @param selectPropNames - * @param recordGetter + * @param rowMapper * @param whereCause * @param jdbcSettings * @return */ - public Stream stream(Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, - final Condition whereCause, final JdbcSettings jdbcSettings) { + public Stream stream(Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, + final JdbcSettings jdbcSettings) { final SP sp = prepareQuery(selectPropNames, whereCause); - return sqlExecutor.stream(sp.sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, sp.parameters.toArray()); + return sqlExecutor.stream(sp.sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, sp.parameters.toArray()); } /** @@ -4658,14 +4650,14 @@ public Stream streamAll(final Collection selectPropNames, final Condi * * * @param selectPropName - * @param recordGetter + * @param rowMapper * @param whereCause * @param jdbcSettings * @return */ - public Stream streamAll(String selectPropName, final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, + public Stream streamAll(String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return streamAll(Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return streamAll(Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } /** @@ -4675,14 +4667,14 @@ public Stream streamAll(String selectPropName, final JdbcUtil.RecordGette * * * @param selectPropName - * @param recordGetter + * @param rowMapper * @param whereCause * @param jdbcSettings * @return */ - public Stream streamAll(String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, + public Stream streamAll(String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { - return streamAll(Arrays.asList(selectPropName), recordGetter, whereCause, jdbcSettings); + return streamAll(Arrays.asList(selectPropName), rowMapper, whereCause, jdbcSettings); } /** @@ -4692,23 +4684,23 @@ public Stream streamAll(String selectPropName, final JdbcUtil.BiRecordGet * * * @param selectPropNames - * @param recordGetter + * @param rowMapper * @param whereCause * @param jdbcSettings * @return */ - public Stream streamAll(Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, - final Condition whereCause, final JdbcSettings jdbcSettings) { - N.checkArgNotNull(recordGetter); + public Stream streamAll(Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, + final JdbcSettings jdbcSettings) { + N.checkArgNotNull(rowMapper); - final JdbcUtil.BiRecordGetter biRecordGetter = new JdbcUtil.BiRecordGetter() { + final JdbcUtil.BiRowMapper biRowMapper = new JdbcUtil.BiRowMapper() { @Override public R apply(final ResultSet rs, final List columnLabels) throws SQLException { - return recordGetter.apply(rs); + return rowMapper.apply(rs); } }; - return streamAll(selectPropNames, biRecordGetter, whereCause, jdbcSettings); + return streamAll(selectPropNames, biRowMapper, whereCause, jdbcSettings); } /** @@ -4718,16 +4710,16 @@ public R apply(final ResultSet rs, final List columnLabels) throws SQLEx * * * @param selectPropNames - * @param recordGetter + * @param rowMapper * @param whereCause * @param jdbcSettings * @return */ - public Stream streamAll(Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, + public Stream streamAll(Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { final SP sp = prepareQuery(selectPropNames, whereCause); - return sqlExecutor.streamAll(sp.sql, StatementSetter.DEFAULT, recordGetter, jdbcSettings, sp.parameters.toArray()); + return sqlExecutor.streamAll(sp.sql, StatementSetter.DEFAULT, rowMapper, jdbcSettings, sp.parameters.toArray()); } public DataSet query(final Condition whereCause) { @@ -6267,162 +6259,162 @@ public Optional call() throws Exception { }); } - public ContinuableFuture> findFirst(final String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> findFirst(final String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(selectPropName, recordGetter, whereCause); + return mapper.findFirst(selectPropName, rowMapper, whereCause); } }); } - public ContinuableFuture> findFirst(final String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> findFirst(final String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.findFirst(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } public ContinuableFuture> findFirst(final Connection conn, final String selectPropName, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { + final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(conn, selectPropName, recordGetter, whereCause); + return mapper.findFirst(conn, selectPropName, rowMapper, whereCause); } }); } public ContinuableFuture> findFirst(final Connection conn, final String selectPropName, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(conn, selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.findFirst(conn, selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> findFirst(final Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { + public ContinuableFuture> findFirst(final Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, + final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(selectPropNames, recordGetter, whereCause); + return mapper.findFirst(selectPropNames, rowMapper, whereCause); } }); } - public ContinuableFuture> findFirst(final Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + public ContinuableFuture> findFirst(final Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, + final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.findFirst(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } public ContinuableFuture> findFirst(final Connection conn, final Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { + final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(conn, selectPropNames, recordGetter, whereCause); + return mapper.findFirst(conn, selectPropNames, rowMapper, whereCause); } }); } public ContinuableFuture> findFirst(final Connection conn, final Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(conn, selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.findFirst(conn, selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> findFirst(final String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> findFirst(final String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(selectPropName, recordGetter, whereCause); + return mapper.findFirst(selectPropName, rowMapper, whereCause); } }); } - public ContinuableFuture> findFirst(final String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> findFirst(final String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.findFirst(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } public ContinuableFuture> findFirst(final Connection conn, final String selectPropName, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { + final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(conn, selectPropName, recordGetter, whereCause); + return mapper.findFirst(conn, selectPropName, rowMapper, whereCause); } }); } public ContinuableFuture> findFirst(final Connection conn, final String selectPropName, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(conn, selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.findFirst(conn, selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> findFirst(final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { + public ContinuableFuture> findFirst(final Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, + final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(selectPropNames, recordGetter, whereCause); + return mapper.findFirst(selectPropNames, rowMapper, whereCause); } }); } - public ContinuableFuture> findFirst(final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + public ContinuableFuture> findFirst(final Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, + final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.findFirst(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } public ContinuableFuture> findFirst(final Connection conn, final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { + final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(conn, selectPropNames, recordGetter, whereCause); + return mapper.findFirst(conn, selectPropNames, rowMapper, whereCause); } }); } public ContinuableFuture> findFirst(final Connection conn, final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Optional call() throws Exception { - return mapper.findFirst(conn, selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.findFirst(conn, selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } @@ -6482,162 +6474,162 @@ public List call() throws Exception { }); } - public ContinuableFuture> list(final String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> list(final String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(selectPropName, recordGetter, whereCause); + return mapper.list(selectPropName, rowMapper, whereCause); } }); } - public ContinuableFuture> list(final String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> list(final String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.list(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> list(final Connection conn, final String selectPropName, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { + public ContinuableFuture> list(final Connection conn, final String selectPropName, final JdbcUtil.RowMapper rowMapper, + final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(conn, selectPropName, recordGetter, whereCause); + return mapper.list(conn, selectPropName, rowMapper, whereCause); } }); } - public ContinuableFuture> list(final Connection conn, final String selectPropName, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + public ContinuableFuture> list(final Connection conn, final String selectPropName, final JdbcUtil.RowMapper rowMapper, + final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(conn, selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.list(conn, selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> list(final Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> list(final Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(selectPropNames, recordGetter, whereCause); + return mapper.list(selectPropNames, rowMapper, whereCause); } }); } - public ContinuableFuture> list(final Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> list(final Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.list(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } public ContinuableFuture> list(final Connection conn, final Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause) { + final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(conn, selectPropNames, recordGetter, whereCause); + return mapper.list(conn, selectPropNames, rowMapper, whereCause); } }); } public ContinuableFuture> list(final Connection conn, final Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(conn, selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.list(conn, selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> list(final String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> list(final String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(selectPropName, recordGetter, whereCause); + return mapper.list(selectPropName, rowMapper, whereCause); } }); } - public ContinuableFuture> list(final String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> list(final String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.list(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } public ContinuableFuture> list(final Connection conn, final String selectPropName, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { + final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(conn, selectPropName, recordGetter, whereCause); + return mapper.list(conn, selectPropName, rowMapper, whereCause); } }); } public ContinuableFuture> list(final Connection conn, final String selectPropName, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(conn, selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.list(conn, selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> list(final Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> list(final Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(selectPropNames, recordGetter, whereCause); + return mapper.list(selectPropNames, rowMapper, whereCause); } }); } - public ContinuableFuture> list(final Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> list(final Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.list(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } public ContinuableFuture> list(final Connection conn, final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { + final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(conn, selectPropNames, recordGetter, whereCause); + return mapper.list(conn, selectPropNames, rowMapper, whereCause); } }); } public ContinuableFuture> list(final Connection conn, final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.list(conn, selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.list(conn, selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } @@ -6660,42 +6652,42 @@ public List call() throws Exception { }); } - public ContinuableFuture> listAll(final String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> listAll(final String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.listAll(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.listAll(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> listAll(final String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> listAll(final String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.listAll(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.listAll(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> listAll(final Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> listAll(final Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.listAll(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.listAll(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> listAll(final Collection selectPropNames, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> listAll(final Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public List call() throws Exception { - return mapper.listAll(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.listAll(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } @@ -6727,82 +6719,82 @@ public Stream call() throws Exception { }); } - public ContinuableFuture> stream(final String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> stream(final String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.stream(selectPropName, recordGetter, whereCause); + return mapper.stream(selectPropName, rowMapper, whereCause); } }); } - public ContinuableFuture> stream(final String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> stream(final String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.stream(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.stream(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> stream(final Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> stream(final Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.stream(selectPropNames, recordGetter, whereCause); + return mapper.stream(selectPropNames, rowMapper, whereCause); } }); } - public ContinuableFuture> stream(final Collection selectPropNames, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> stream(final Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.stream(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.stream(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> stream(final String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> stream(final String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.stream(selectPropName, recordGetter, whereCause); + return mapper.stream(selectPropName, rowMapper, whereCause); } }); } - public ContinuableFuture> stream(final String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> stream(final String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.stream(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.stream(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> stream(final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause) { + public ContinuableFuture> stream(final Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, + final Condition whereCause) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.stream(selectPropNames, recordGetter, whereCause); + return mapper.stream(selectPropNames, rowMapper, whereCause); } }); } - public ContinuableFuture> stream(final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + public ContinuableFuture> stream(final Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, + final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.stream(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.stream(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } @@ -6825,42 +6817,42 @@ public Stream call() throws Exception { }); } - public ContinuableFuture> streamAll(final String selectPropName, final JdbcUtil.RecordGetter recordGetter, + public ContinuableFuture> streamAll(final String selectPropName, final JdbcUtil.RowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.streamAll(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.streamAll(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> streamAll(final String selectPropName, final JdbcUtil.BiRecordGetter recordGetter, + public ContinuableFuture> streamAll(final String selectPropName, final JdbcUtil.BiRowMapper rowMapper, final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.streamAll(selectPropName, recordGetter, whereCause, jdbcSettings); + return mapper.streamAll(selectPropName, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> streamAll(final Collection selectPropNames, - final JdbcUtil.RecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + public ContinuableFuture> streamAll(final Collection selectPropNames, final JdbcUtil.RowMapper rowMapper, + final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.streamAll(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.streamAll(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } - public ContinuableFuture> streamAll(final Collection selectPropNames, - final JdbcUtil.BiRecordGetter recordGetter, final Condition whereCause, final JdbcSettings jdbcSettings) { + public ContinuableFuture> streamAll(final Collection selectPropNames, final JdbcUtil.BiRowMapper rowMapper, + final Condition whereCause, final JdbcSettings jdbcSettings) { return asyncExecutor.execute(new Callable>() { @Override public Stream call() throws Exception { - return mapper.streamAll(selectPropNames, recordGetter, whereCause, jdbcSettings); + return mapper.streamAll(selectPropNames, rowMapper, whereCause, jdbcSettings); } }); } @@ -7802,7 +7794,8 @@ public static ResultExtractor> toMap(final Try.Function> ResultExtractor toMap(final Try.Function keyExtractor, - final Try.Function valueExtractor, final Collector downstream, final Supplier supplier) { + final Try.Function valueExtractor, final Collector downstream, + final Supplier supplier) { N.checkArgNotNull(keyExtractor, "keyExtractor"); N.checkArgNotNull(valueExtractor, "valueExtractor"); N.checkArgNotNull(downstream, "downstream"); diff --git a/src/com/landawn/abacus/util/Seq.java b/src/com/landawn/abacus/util/Seq.java index 540d073f..efd31fd3 100644 --- a/src/com/landawn/abacus/util/Seq.java +++ b/src/com/landawn/abacus/util/Seq.java @@ -1376,18 +1376,18 @@ public List collapse(final Try.Bi return result; } - public List collapse(final Try.BiPredicate collapsible, final R init, - final Try.BiFunction op) throws E, E2 { + public List collapse(final Try.BiPredicate collapsible, final U init, + final Try.BiFunction op) throws E, E2 { N.checkArgNotNull(collapsible); N.checkArgNotNull(op); - final List result = new ArrayList<>(); + final List result = new ArrayList<>(); final Iterator iter = iterator(); boolean hasNext = false; T next = null; while (hasNext || iter.hasNext()) { - R res = op.apply(init, hasNext ? next : (next = iter.next())); + U res = op.apply(init, hasNext ? next : (next = iter.next())); while ((hasNext = iter.hasNext())) { if (collapsible.test(next, (next = iter.next()))) { @@ -1545,7 +1545,7 @@ public List scan(final Try.BiFunction List scan(final R init, final Try.BiFunction accumulator) throws E { + public List scan(final U init, final Try.BiFunction accumulator) throws E { return scan(init, accumulator, false); } @@ -1557,17 +1557,17 @@ public List scan(final R init, final Try.BiFunction< * @return * @throws E */ - public List scan(final R init, final Try.BiFunction accumulator, boolean initIncluded) throws E { + public List scan(final U init, final Try.BiFunction accumulator, boolean initIncluded) throws E { N.checkArgNotNull(accumulator); - final List result = new ArrayList<>(); + final List result = new ArrayList<>(); if (initIncluded) { result.add(init); } final Iterator iter = iterator(); - R next = init; + U next = init; while (iter.hasNext()) { result.add((next = accumulator.apply(next, iter.next()))); @@ -1638,7 +1638,7 @@ public Nullable reduce(Try.BinaryOperator accumul * @param accumulator * @return */ - public T reduce(T identity, Try.BinaryOperator accumulator) throws E { + public U reduce(final U identity, final Try.BiFunction accumulator) throws E { N.checkArgNotNull(accumulator); if (isEmpty()) { @@ -1646,7 +1646,7 @@ public T reduce(T identity, Try.BinaryOperator accum } final Iterator iter = iterator(); - T result = identity; + U result = identity; while (iter.hasNext()) { result = accumulator.apply(result, iter.next()); @@ -1696,15 +1696,38 @@ public R collect(final Collector collector) { return collector.finisher().apply(result); } + public R collect(final java.util.stream.Collector collector) { + N.checkArgNotNull(collector); + + final java.util.function.BiConsumer accumulator = collector.accumulator(); + final A result = collector.supplier().get(); + + for (T e : coll) { + accumulator.accept(result, e); + } + + return collector.finisher().apply(result); + } + public RR collectThenApply(final Collector downstream, final Try.Function mapper) throws E { return mapper.apply(collect(downstream)); } + public RR collectThenApply(final java.util.stream.Collector downstream, + final Try.Function mapper) throws E { + return mapper.apply(collect(downstream)); + } + public void collectThenAccept(final Collector downstream, final Try.Consumer consumer) throws E { consumer.accept(collect(downstream)); } + public void collectThenAccept(final java.util.stream.Collector downstream, final Try.Consumer consumer) + throws E { + consumer.accept(collect(downstream)); + } + @SafeVarargs public final List append(T... a) { if (N.isNullOrEmpty(a)) { diff --git a/src/com/landawn/abacus/util/stream/AbstractStream.java b/src/com/landawn/abacus/util/stream/AbstractStream.java index 1800e42f..7e12ea3f 100644 --- a/src/com/landawn/abacus/util/stream/AbstractStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractStream.java @@ -538,10 +538,10 @@ public T next() { } @Override - public Stream collapse(final BiPredicate collapsible, final R init, final BiFunction op) { + public Stream collapse(final BiPredicate collapsible, final U init, final BiFunction op) { final ObjIteratorEx iter = iteratorEx(); - return newStream(new ObjIteratorEx() { + return newStream(new ObjIteratorEx() { private boolean hasNext = false; private T next = null; @@ -551,8 +551,8 @@ public boolean hasNext() { } @Override - public R next() { - R res = op.apply(init, hasNext ? next : (next = iter.next())); + public U next() { + U res = op.apply(init, hasNext ? next : (next = iter.next())); while ((hasNext = iter.hasNext())) { if (collapsible.test(next, (next = iter.next()))) { @@ -659,11 +659,11 @@ public T next() { } @Override - public Stream scan(final R init, final BiFunction accumulator) { + public Stream scan(final U init, final BiFunction accumulator) { final ObjIteratorEx iter = iteratorEx(); - return newStream(new ObjIteratorEx() { - private R res = init; + return newStream(new ObjIteratorEx() { + private U res = init; @Override public boolean hasNext() { @@ -671,23 +671,23 @@ public boolean hasNext() { } @Override - public R next() { + public U next() { return (res = accumulator.apply(res, iter.next())); } }, false, null); } @Override - public Stream scan(final R init, final BiFunction accumulator, boolean initIncluded) { + public Stream scan(final U init, final BiFunction accumulator, boolean initIncluded) { if (initIncluded == false) { return scan(init, accumulator); } final ObjIteratorEx iter = iteratorEx(); - return newStream(new ObjIteratorEx() { + return newStream(new ObjIteratorEx() { private boolean isFirst = true; - private R res = init; + private U res = init; @Override public boolean hasNext() { @@ -695,7 +695,7 @@ public boolean hasNext() { } @Override - public R next() { + public U next() { if (isFirst) { isFirst = false; return init; diff --git a/src/com/landawn/abacus/util/stream/ArrayStream.java b/src/com/landawn/abacus/util/stream/ArrayStream.java index 4cf05967..cbbb69b6 100644 --- a/src/com/landawn/abacus/util/stream/ArrayStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayStream.java @@ -2971,6 +2971,23 @@ public Optional reduce(BinaryOperator accumulator) { } } + @Override + public U reduce(final U identity, final BiFunction accumulator, final BinaryOperator combiner) { + assertNotClosed(); + + try { + U result = identity; + + for (int i = fromIndex; i < toIndex; i++) { + result = accumulator.apply(result, elements[i]); + } + + return result; + } finally { + close(); + } + } + @Override public R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { assertNotClosed(); diff --git a/src/com/landawn/abacus/util/stream/IteratorStream.java b/src/com/landawn/abacus/util/stream/IteratorStream.java index 48a5aeca..edc89094 100644 --- a/src/com/landawn/abacus/util/stream/IteratorStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorStream.java @@ -2898,6 +2898,23 @@ public Optional reduce(BinaryOperator accumulator) { } } + @Override + public U reduce(final U identity, final BiFunction accumulator, final BinaryOperator combiner) { + assertNotClosed(); + + try { + U result = identity; + + while (elements.hasNext()) { + result = accumulator.apply(result, elements.next()); + } + + return result; + } finally { + close(); + } + } + @Override public R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { assertNotClosed(); diff --git a/src/com/landawn/abacus/util/stream/ParallelArrayStream.java b/src/com/landawn/abacus/util/stream/ParallelArrayStream.java index 476cf929..0244f051 100644 --- a/src/com/landawn/abacus/util/stream/ParallelArrayStream.java +++ b/src/com/landawn/abacus/util/stream/ParallelArrayStream.java @@ -3894,6 +3894,101 @@ public T call() { return result == NONE ? (Optional) Optional.empty() : Optional.of(result); } + @Override + public U reduce(final U identity, final BiFunction accumulator, final BinaryOperator combiner) { + assertNotClosed(); + + if (maxThreadNum <= 1 || toIndex - fromIndex <= 1) { + return super.reduce(identity, accumulator, combiner); + } + + final int threadNum = N.min(maxThreadNum, (toIndex - fromIndex)); + final List> futureList = new ArrayList<>(threadNum); + final Holder eHolder = new Holder<>(); + + if (splitor == Splitor.ARRAY) { + final int sliceSize = (toIndex - fromIndex) / threadNum + ((toIndex - fromIndex) % threadNum == 0 ? 0 : 1); + + for (int i = 0; i < threadNum; i++) { + final int sliceIndex = i; + + futureList.add(asyncExecutor.execute(new Callable() { + @Override + public U call() { + int cursor = fromIndex + sliceIndex * sliceSize; + final int to = toIndex - cursor > sliceSize ? cursor + sliceSize : toIndex; + + U result = identity; + + try { + while (cursor < to && eHolder.value() == null) { + result = accumulator.apply(result, elements[cursor++]); + } + } catch (Exception e) { + setError(eHolder, e); + } + + return result; + } + })); + } + } else { + final MutableInt cursor = MutableInt.of(fromIndex); + + for (int i = 0; i < threadNum; i++) { + futureList.add(asyncExecutor.execute(new Callable() { + + @Override + public U call() { + U result = identity; + T next = null; + + try { + while (eHolder.value() == null) { + synchronized (elements) { + if (cursor.intValue() < toIndex) { + next = elements[cursor.getAndIncrement()]; + } else { + break; + } + } + + result = accumulator.apply(result, next); + } + } catch (Exception e) { + setError(eHolder, e); + } + + return result; + } + })); + } + } + + if (eHolder.value() != null) { + close(); + throw N.toRuntimeException(eHolder.value()); + } + + U result = (U) NONE; + + try { + for (ContinuableFuture future : futureList) { + if (result == NONE) { + result = future.get(); + } else { + result = combiner.apply(result, future.get()); + } + } + } catch (InterruptedException | ExecutionException e) { + throw N.toRuntimeException(e); + } finally { + close(); + } + + return result == NONE ? identity : result; + } + @Override public R collect(final Supplier supplier, final BiConsumer accumulator, final BiConsumer combiner) { assertNotClosed(); diff --git a/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java b/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java index 4fb344c1..365a703e 100644 --- a/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java +++ b/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java @@ -2816,6 +2816,69 @@ public T call() { return result == NONE ? (Optional) Optional.empty() : Optional.of(result); } + @Override + public U reduce(final U identity, final BiFunction accumulator, final BinaryOperator combiner) { + assertNotClosed(); + + if (maxThreadNum <= 1) { + return super.reduce(identity, accumulator, combiner); + } + + final List> futureList = new ArrayList<>(maxThreadNum); + final Holder eHolder = new Holder<>(); + + for (int i = 0; i < maxThreadNum; i++) { + futureList.add(asyncExecutor.execute(new Callable() { + @Override + public U call() { + U result = identity; + T next = null; + + try { + while (eHolder.value() == null) { + synchronized (elements) { + if (elements.hasNext()) { + next = elements.next(); + } else { + break; + } + } + + result = accumulator.apply(result, next); + } + } catch (Exception e) { + setError(eHolder, e); + } + + return result; + } + })); + } + + if (eHolder.value() != null) { + close(); + throw N.toRuntimeException(eHolder.value()); + } + + U result = (U) NONE; + + try { + for (ContinuableFuture future : futureList) { + if (result == NONE) { + result = future.get(); + } else { + result = combiner.apply(result, future.get()); + } + } + } catch (InterruptedException | ExecutionException e) { + throw N.toRuntimeException(e); + } finally { + close(); + } + + return result == NONE ? identity : result; + } + @Override public R collect(final Supplier supplier, final BiConsumer accumulator, final BiConsumer combiner) { assertNotClosed(); diff --git a/src/com/landawn/abacus/util/stream/ParallelSupported.java b/src/com/landawn/abacus/util/stream/ParallelSupported.java index 15b303fa..a6ce397e 100644 --- a/src/com/landawn/abacus/util/stream/ParallelSupported.java +++ b/src/com/landawn/abacus/util/stream/ParallelSupported.java @@ -23,10 +23,6 @@ @Documented @Retention(value = RetentionPolicy.CLASS) @Target(value = { ElementType.METHOD, ElementType.TYPE }) - -/** - * - */ public @interface ParallelSupported { } diff --git a/src/com/landawn/abacus/util/stream/SequentialOnly.java b/src/com/landawn/abacus/util/stream/SequentialOnly.java index 89d1bcc3..f5d24891 100644 --- a/src/com/landawn/abacus/util/stream/SequentialOnly.java +++ b/src/com/landawn/abacus/util/stream/SequentialOnly.java @@ -23,10 +23,6 @@ @Documented @Retention(value = RetentionPolicy.CLASS) @Target(value = { ElementType.METHOD, ElementType.TYPE }) - -/** - * - */ public @interface SequentialOnly { } diff --git a/src/com/landawn/abacus/util/stream/Stream.java b/src/com/landawn/abacus/util/stream/Stream.java index 88d0a4ec..e4ec64e0 100644 --- a/src/com/landawn/abacus/util/stream/Stream.java +++ b/src/com/landawn/abacus/util/stream/Stream.java @@ -657,7 +657,7 @@ public EntryStream countByToEntry(final Function collapse(final BiPredicate collapsible, final BiFunction mergeFunction); @SequentialOnly - public abstract Stream collapse(final BiPredicate collapsible, final R init, final BiFunction op); + public abstract Stream collapse(final BiPredicate collapsible, final U init, final BiFunction op); @SequentialOnly public abstract Stream collapse(final BiPredicate collapsible, final Supplier supplier, @@ -745,7 +745,7 @@ public abstract Stream collapse(final BiPredicate c * @return the new stream which has the extract same size as this stream. */ @SequentialOnly - public abstract Stream scan(final R init, final BiFunction accumulator); + public abstract Stream scan(final U init, final BiFunction accumulator); /** * @@ -755,7 +755,7 @@ public abstract Stream collapse(final BiPredicate c * @return */ @SequentialOnly - public abstract Stream scan(final R init, final BiFunction accumulator, final boolean initIncluded); + public abstract Stream scan(final U init, final BiFunction accumulator, final boolean initIncluded); /** * Returns Stream of Stream with consecutive sub sequences of the elements, each of the same size (the final sequence may be smaller). @@ -1878,6 +1878,9 @@ public abstract , M extends Multimap> M f @ParallelSupported public abstract Optional reduce(BinaryOperator accumulator); + @ParallelSupported + public abstract U reduce(U identity, BiFunction accumulator, BinaryOperator combiner); + @ParallelSupported public abstract R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner); @@ -2353,6 +2356,11 @@ public abstract long persist(final PreparedStatement stmt, final int batchSize, @SequentialOnly public abstract java.util.stream.Stream toJdkStream(); + /** + * Remember to close this Stream after the iteration is done, if required. + * + * @return + */ @SequentialOnly @Override public ObjIterator iterator() {