Package org.reldb.wrapd.sqldb
Class ResultSetToTuple
java.lang.Object
org.reldb.wrapd.sqldb.ResultSetToTuple
public class ResultSetToTuple
extends java.lang.Object
Tools for creating Tuple-derived classes from ResultSetS and for turning ResultSetS into Tuple-derived instances for processing directly or as a List or Stream.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ResultSetToTuple.AttributeReceiver
A functional interface for defining lambda expressions that do something with an attribute name and an attribute type.static interface
ResultSetToTuple.TupleProcessor<T extends Tuple>
FunctionalInterface to define lambdas for processing each Tuple in a ResultSet. -
Constructor Summary
Constructors Constructor Description ResultSetToTuple()
-
Method Summary
Modifier and Type Method Description static TupleTypeGenerator.GenerateResult
createTuple(java.lang.String codeDir, java.lang.String packageSpec, java.lang.String tupleName, java.sql.ResultSet results, Customisations customisations)
Given a target code directory and a desired Tuple class name, and a ResultSet, generate a Tuple class to host the ResultSet.static TupleTypeGenerator.GenerateResult
createTupleForUpdate(java.lang.String codeDir, java.lang.String packageSpec, java.lang.String tupleName, java.sql.ResultSet results, Customisations customisations, java.lang.String tableName)
Given a target code directory and a desired UpdatableTuple class name, and a ResultSet, generate an UpdatableTuple class to host the ResultSet.static boolean
destroyTuple(java.lang.String codeDir, java.lang.String packageSpec, java.lang.String tupleName)
Eliminate the tuple with a given name.static Response<java.lang.Class<?>>
obtainTypeOfFirstColumnOfResultSet(java.sql.ResultSet results, Customisations customisations)
Obtain the type of the first column of a ResultSet.static <T extends Tuple>
voidprocess(java.sql.ResultSet resultSet, java.lang.Class<T> tupleType, ResultSetToTuple.TupleProcessor<T> tupleProcessor)
Iterate a ResultSet, unmarshall each row into a Tuple, and pass it to a TupleProcessor for processing.static <T extends UpdatableTuple>
voidprocessForUpdate(Database database, java.sql.ResultSet resultSet, java.lang.Class<T> tupleType, ResultSetToTuple.TupleProcessor<T> tupleProcessor)
Iterate a ResultSet, unmarshall each row into a Tuple, and pass it to a TupleProcessor for processing.static void
processResultSetAttributes(java.sql.ResultSet results, Customisations customisations, ResultSetToTuple.AttributeReceiver receiver)
Do something with each attribute (i.e., name/class pair) of a ResultSet.static <T extends Tuple>
java.util.List<T>toList(java.sql.ResultSet resultSet, java.lang.Class<T> tupleType)
Convert a ResultSet to a List of TupleS.static <T extends UpdatableTuple>
java.util.List<T>toListForUpdate(Database database, java.sql.ResultSet resultSet, java.lang.Class<T> tupleType)
Convert a ResultSet to a List of UpdatableTupleS, each configured for a possible future update.static <T extends Tuple>
java.util.stream.Stream<T>toStream(java.sql.ResultSet resultSet, java.lang.Class<T> tupleType)
Convert a ResultSet to a Stream of TupleS.static <T extends UpdatableTuple>
java.util.stream.Stream<T>toStreamForUpdate(Database database, java.sql.ResultSet resultSet, java.lang.Class<T> tupleType)
Convert a ResultSet to a Stream of UpdatableTupleS, each configured for a possible future update.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
ResultSetToTuple
public ResultSetToTuple()
-
-
Method Details
-
processResultSetAttributes
public static void processResultSetAttributes(java.sql.ResultSet results, Customisations customisations, ResultSetToTuple.AttributeReceiver receiver) throws java.sql.SQLException, java.lang.ClassNotFoundExceptionDo something with each attribute (i.e., name/class pair) of a ResultSet.- Parameters:
results
- A ResultSet.customisations
- Customisations for specific DBMS types.receiver
- The lambda that will receive each attribute.- Throws:
java.sql.SQLException
- thrown if there is a problem retrieving ResultSet metadata.java.lang.ClassNotFoundException
- thrown if a column class specified in the ResultSet metadata can't be loaded.
-
obtainTypeOfFirstColumnOfResultSet
public static Response<java.lang.Class<?>> obtainTypeOfFirstColumnOfResultSet(java.sql.ResultSet results, Customisations customisations)Obtain the type of the first column of a ResultSet. Used in ValueOf.- Parameters:
results
- A ResultSet.customisations
- Customisations for specific DBMS types.- Returns:
- The type of the first column of the ResultSet, or an error, wrapped in a Response.
-
createTupleForUpdate
public static TupleTypeGenerator.GenerateResult createTupleForUpdate(java.lang.String codeDir, java.lang.String packageSpec, java.lang.String tupleName, java.sql.ResultSet results, Customisations customisations, java.lang.String tableName) throws java.sql.SQLException, java.lang.ClassNotFoundExceptionGiven a target code directory and a desired UpdatableTuple class name, and a ResultSet, generate an UpdatableTuple class to host the ResultSet. This will normally be invoked in a setup/build phase run.- Parameters:
codeDir
- Directory where source code will be stored.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleName
- Name of new UpdatableTuple class.results
- ResultSet to be used to create the new UpdatableTuple class.customisations
- Customisations for specific DBMS types.tableName
- Name of table this Tuple maps to. Null if not mapped to a table.- Returns:
- Result of Tuple generation.
- Throws:
java.sql.SQLException
- thrown if there is a problem retrieving ResultSet metadata.java.lang.ClassNotFoundException
- thrown if a column class specified in the ResultSet metadata can't be loaded.java.lang.IllegalArgumentException
- thrown if an argument is null
-
createTuple
public static TupleTypeGenerator.GenerateResult createTuple(java.lang.String codeDir, java.lang.String packageSpec, java.lang.String tupleName, java.sql.ResultSet results, Customisations customisations) throws java.sql.SQLException, java.lang.ClassNotFoundExceptionGiven a target code directory and a desired Tuple class name, and a ResultSet, generate a Tuple class to host the ResultSet. This will normally be invoked in a setup/build phase run.- Parameters:
codeDir
- Directory where source code will be stored.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleName
- Name of new Tuple class.results
- ResultSet to be used to create the new Tuple class.customisations
- Customisations for specific DBMS types.- Returns:
- Result of Tuple generation.
- Throws:
java.sql.SQLException
- thrown if there is a problem retrieving ResultSet metadata.java.lang.ClassNotFoundException
- thrown if a column class specified in the ResultSet metadata can't be loaded.java.lang.IllegalArgumentException
- thrown if an argument is null
-
process
public static <T extends Tuple> void process(java.sql.ResultSet resultSet, java.lang.Class<T> tupleType, ResultSetToTuple.TupleProcessor<T> tupleProcessor) throws java.lang.ThrowableIterate a ResultSet, unmarshall each row into a Tuple, and pass it to a TupleProcessor for processing.- Type Parameters:
T
- Tuple type.- Parameters:
resultSet
- ResultSet to iteratetupleType
- tuple typetupleProcessor
- tuple processor- Throws:
java.lang.SecurityException
- thrown if tuple constructor is not accessiblejava.lang.NoSuchMethodException
- thrown if tuple constructor doesn't existjava.lang.reflect.InvocationTargetException
- thrown if unable to instantiate tuple classjava.lang.IllegalArgumentException
- thrown if unable to instantiate tuple class, or if there is a type mismatch assigning tuple field values, or a null argumentjava.lang.IllegalAccessException
- thrown if unable to instantiate tuple classjava.lang.InstantiationException
- thrown if unable to instantiate tuple classjava.sql.SQLException
- thrown if accessing ResultSet failsjava.lang.NoSuchFieldException
- thrown if a given ResultSet field name cannot be found in the Tuplejava.lang.CloneNotSupportedException
- thrown af a Tuple cannot be cloned to create a backupjava.lang.Throwable
-
processForUpdate
public static <T extends UpdatableTuple> void processForUpdate(Database database, java.sql.ResultSet resultSet, java.lang.Class<T> tupleType, ResultSetToTuple.TupleProcessor<T> tupleProcessor) throws java.lang.ThrowableIterate a ResultSet, unmarshall each row into a Tuple, and pass it to a TupleProcessor for processing.- Type Parameters:
T
- UpdatableTuple type.- Parameters:
database
- The Database that issued the query that produced the ResultSet.resultSet
- ResultSet to iteratetupleType
- tuple typetupleProcessor
- tuple processor- Throws:
java.lang.SecurityException
- thrown if tuple constructor is not accessiblejava.lang.NoSuchMethodException
- thrown if tuple constructor doesn't existjava.lang.reflect.InvocationTargetException
- thrown if unable to instantiate tuple classjava.lang.IllegalArgumentException
- thrown if unable to instantiate tuple class, or if there is a type mismatch assigning tuple field values, or a null argumentjava.lang.IllegalAccessException
- thrown if unable to instantiate tuple classjava.lang.InstantiationException
- thrown if unable to instantiate tuple classjava.sql.SQLException
- thrown if accessing ResultSet failsjava.lang.NoSuchFieldException
- thrown if a given ResultSet field name cannot be found in the Tuplejava.lang.CloneNotSupportedException
- thrown af a Tuple cannot be cloned to create a backupjava.lang.Throwable
-
toList
public static <T extends Tuple> java.util.List<T> toList(java.sql.ResultSet resultSet, java.lang.Class<T> tupleType) throws java.lang.ThrowableConvert a ResultSet to a List of TupleS.- Type Parameters:
T
- Tuple type.- Parameters:
resultSet
- ResultSet to iteratetupleType
- tuple type- Returns:
- List<? extends Tuple> List of tuples returned
- Throws:
java.lang.SecurityException
- thrown if tuple constructor is not accessiblejava.lang.NoSuchMethodException
- thrown if tuple constructor doesn't existjava.lang.reflect.InvocationTargetException
- thrown if unable to instantiate tuple classjava.lang.IllegalArgumentException
- thrown if unable to instantiate tuple class, or if there is a type mismatch assigning tuple field values, or null argumentsjava.lang.IllegalAccessException
- thrown if unable to instantiate tuple classjava.lang.InstantiationException
- thrown if unable to instantiate tuple classjava.sql.SQLException
- thrown if accessing ResultSet failsjava.lang.NoSuchFieldException
- thrown if a given ResultSet field name cannot be found in the Tuplejava.lang.CloneNotSupportedException
- thrown af a Tuple cannot be cloned to create a backupjava.lang.Throwable
-
toListForUpdate
public static <T extends UpdatableTuple> java.util.List<T> toListForUpdate(Database database, java.sql.ResultSet resultSet, java.lang.Class<T> tupleType) throws java.lang.ThrowableConvert a ResultSet to a List of UpdatableTupleS, each configured for a possible future update.- Type Parameters:
T
- UpdatableTuple type.- Parameters:
database
- The Database that issued the query that produced the ResultSet.resultSet
- ResultSet to iteratetupleType
- tuple type- Returns:
- List<? extends UpdatableTuple> List of tuples returned
- Throws:
java.lang.SecurityException
- thrown if tuple constructor is not accessiblejava.lang.NoSuchMethodException
- thrown if tuple constructor doesn't existjava.lang.reflect.InvocationTargetException
- thrown if unable to instantiate tuple classjava.lang.IllegalArgumentException
- thrown if unable to instantiate tuple class, or if there is a type mismatch assigning tuple field values, or null argumentsjava.lang.IllegalAccessException
- thrown if unable to instantiate tuple classjava.lang.InstantiationException
- thrown if unable to instantiate tuple classjava.sql.SQLException
- thrown if accessing ResultSet failsjava.lang.NoSuchFieldException
- thrown if a given ResultSet field name cannot be found in the Tuplejava.lang.CloneNotSupportedException
- thrown af a Tuple cannot be cloned to create a backupjava.lang.Throwable
-
toStream
public static <T extends Tuple> java.util.stream.Stream<T> toStream(java.sql.ResultSet resultSet, java.lang.Class<T> tupleType) throws java.lang.ThrowableConvert a ResultSet to a Stream of TupleS.- Type Parameters:
T
- Tuple type.- Parameters:
resultSet
- source ResultSettupleType
- subclass of Tuple. Each row will be converted to a new instance of this class.- Returns:
- Stream<? extends Tuple>.
- Throws:
java.lang.SecurityException
- thrown if tuple constructor is not accessiblejava.lang.NoSuchMethodException
- thrown if tuple constructor doesn't existjava.lang.reflect.InvocationTargetException
- thrown if unable to instantiate tuple classjava.lang.IllegalArgumentException
- thrown if unable to instantiate tuple class, or if there is a type mismatch assigning tuple field values, or null argumentsjava.lang.IllegalAccessException
- thrown if unable to instantiate tuple classjava.lang.InstantiationException
- thrown if unable to instantiate tuple classjava.sql.SQLException
- thrown if accessing ResultSet failsjava.lang.NoSuchFieldException
- thrown if a given ResultSet field name cannot be found in the Tuplejava.lang.CloneNotSupportedException
- thrown af a Tuple cannot be cloned to create a backupjava.lang.Throwable
-
toStreamForUpdate
public static <T extends UpdatableTuple> java.util.stream.Stream<T> toStreamForUpdate(Database database, java.sql.ResultSet resultSet, java.lang.Class<T> tupleType) throws java.lang.ThrowableConvert a ResultSet to a Stream of UpdatableTupleS, each configured for a possible future update.- Type Parameters:
T
- UpdatableTuple type.- Parameters:
database
- The Database that issued the query that produced the ResultSet.resultSet
- source ResultSettupleType
- subclass of UpdatableTuple. Each row will be converted to a new instance of this class.- Returns:
- Stream<? extends UpdatableTuple>.
- Throws:
java.lang.SecurityException
- thrown if tuple constructor is not accessiblejava.lang.NoSuchMethodException
- thrown if tuple constructor doesn't existjava.lang.reflect.InvocationTargetException
- thrown if unable to instantiate tuple classjava.lang.IllegalArgumentException
- thrown if unable to instantiate tuple class, or if there is a type mismatch assigning tuple field values, or null argumentsjava.lang.IllegalAccessException
- thrown if unable to instantiate tuple classjava.lang.InstantiationException
- thrown if unable to instantiate tuple classjava.sql.SQLException
- thrown if accessing ResultSet failsjava.lang.NoSuchFieldException
- thrown if a given ResultSet field name cannot be found in the Tuplejava.lang.CloneNotSupportedException
- thrown af a Tuple cannot be cloned to create a backupjava.lang.Throwable
-
destroyTuple
public static boolean destroyTuple(java.lang.String codeDir, java.lang.String packageSpec, java.lang.String tupleName)Eliminate the tuple with a given name.- Parameters:
codeDir
- Directory where source code will be stored.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleName
- Name of tuple class.- Returns:
- True if source code and generated class have been deleted.
-