com.groiss.store
Class StoreUtil

java.lang.Object
  extended by com.groiss.store.StoreUtil

public class StoreUtil
extends java.lang.Object

Utilities for store


Method Summary
static void addEventHandler(PersistentEventHandler h, java.lang.Class<Persistent>[] classes)
          Add an event handler for some classes.
static Persistent base(Persistent o)
          Return the base object of a Persistent o.
static void cleanDbFieldV()
           
static int dbAttrPos(Persistent o, java.lang.String fieldname)
           
static java.lang.String dbAttrs(Persistent o)
           
static java.lang.String dbAttrs(Persistent o, java.lang.String prefix)
           
static int dbAttrsCount(Persistent o)
           
static java.util.List<java.lang.reflect.Field> dbFields(Persistent o)
          Returns the fields of the object which have corresponding fields in the database.
static java.util.List<java.lang.reflect.Field> dbMultiValuedFields(Persistent o)
          Returns the multivalued fields (Lists, Maps, Sets) of the object which have corresponding fields in the database.
static void executeScript(java.lang.String content, java.io.PrintWriter res)
           
static void executeSQLFile(java.lang.String commands, java.io.PrintWriter res)
           
static boolean existsColumn(java.lang.String tablename, java.lang.String columnname)
          Returns true if the passed table exists in the current db-schema and the passed column exists in this table.
static boolean existsObject(java.util.Set<java.lang.String> objectNameSet, java.lang.String name)
           
static boolean existsTable(java.lang.String tablename)
          Returns true if the passed table exists in the current db-schema.
static boolean existsView(java.lang.String viewname)
          Returns true if the passed view exists in the current db-schema.
static java.math.BigDecimal getBigDecimal(java.sql.ResultSet rs, int columnIndex)
          Get a BigDecimal from a column of the current row of a ResultSet.
static java.math.BigDecimal getBigDecimal(java.sql.ResultSet rs, java.lang.String columnName)
          Get a BigDecimal from a column of the current row of a ResultSet.
static java.util.Date getDate(java.sql.ResultSet rs, int columnIndex)
          Get a Date from a column of the current row of a ResultSet.
static java.util.Date getDate(java.sql.ResultSet rs, java.lang.String columnName)
          Get a Date from a column of the current row of a ResultSet.
static Store getDefaultStore()
           
static java.util.List<PersistentEventHandler> getEventHandlers(java.lang.Class<? extends Persistent> c)
          Get a List of PersistentEventHandler for a speciefied class c.
static int getFetchSize()
           
static java.lang.reflect.Field getField(Persistent o, java.lang.String fieldname)
           
static java.lang.Object getFromRS(java.sql.ResultSet rs, int sqlType, int i)
           
static java.lang.Object getFromRS(java.sql.ResultSet rs, java.sql.ResultSetMetaData metaData, int i)
           
static int getMaxTableNameLength()
           
static Persistent getNewInstance(java.lang.Class<?> c)
          Create a new instance of c.
static Persistent getNewInstance(java.lang.String className)
          Create a new instance of a class c specified via the className .
static
<T extends Persistent>
T
getObject(java.lang.Object obj)
           
static java.util.Set<java.lang.String> getTableNames(java.lang.String tableNamePattern)
          Returns a set of names of tables conforming to the name pattern in the current db-schema.
static java.util.Set<java.lang.String> getViewNames(java.lang.String viewNamePattern)
          Returns a set of names of views conforming to the name pattern in the current db-schema.
static boolean hasClassAttribute(java.lang.Class<?> c)
           
static boolean isSingleInterface(java.lang.Class<?> c)
          Determines if an interface c hides a single implementation (e.g.
static boolean isSystemOid(long oid)
          Returns true if the given oid is the oid of a system object (>0, <1000).
static
<P> java.lang.Class<Persistent>
mapInterface(java.lang.Class<P> c)
          Get the Persistent class which is implemented by the a Class c.
static java.lang.Class<Persistent> mapInterface(java.lang.String classname)
          Get the Persistent class which is implemented by a class with the given classname.
static java.lang.String mapInterfaceToClassName(java.lang.String classname)
          Get the name of the Persistent class which is implemented by a class with the given classname.
static double noNaN(double d)
           
static float noNaN(float f)
           
static void removeEventHandler(PersistentEventHandler peh)
          Remove a PersistentEventHandler.
static void setBigDecimal(java.sql.PreparedStatement stmt, int pos, java.math.BigDecimal value)
          Get a parameter in a PreparedStatement from a BigDecimal.
static void setBindVars(java.sql.PreparedStatement stmt, java.lang.Object[] bindVars)
          Set the bind variables of a prepared statement based on an object array.
static void setFetchsize(int rows)
           
static void setFieldToValue(Persistent o, java.lang.reflect.Field ff, java.lang.Object val, java.util.Map<java.lang.String,? extends java.lang.Object> req)
          Set a field of an object
static boolean setFieldToValue(Persistent o, java.lang.reflect.Field ff, java.lang.Object value, java.util.Map<java.lang.String,? extends java.lang.Object> req, boolean dontLocalizeNumbers)
          Set a field of an object
static void setFromDB(Persistent o, java.sql.ResultSet rs)
          Deprecated.  
static void setFromDB(Persistent o, java.sql.ResultSet rs, boolean addToCache)
          Deprecated.  
static void setFromRS(Persistent o, java.sql.ResultSet rs)
          Set the members of the persistent object to the corresponding values of the current row of the result set.
static void setFromRS(Persistent o, java.sql.ResultSet rs, boolean addToCache)
          Set the members of the persistent object to the corresponding values of the current row of the result set.
static void setFromRSByName(Persistent o, java.sql.ResultSet rs)
          Set the members of the persistent object to the corresponding values of the current row of the result set.
static void setFromRSByName(Persistent o, java.sql.ResultSet rs, boolean addToCache)
          Set the members of the persistent object to the corresponding values of the current row of the result set.
static boolean setNumber(Persistent o, java.lang.reflect.Field ff, java.lang.String val, boolean dontLocalizeNumbers)
          Set a field to a numeric value, the value is given as String.
static void setValues(Persistent o, java.util.Map<java.lang.String,? extends java.lang.Object> req)
           
static void setValues(Persistent o, java.util.Map<java.lang.String,? extends java.lang.Object> req, java.util.Map<java.lang.String,java.lang.Short> fieldmodes)
           
static boolean setValues2(Persistent o, java.util.Map<java.lang.String,? extends java.lang.Object> req, java.util.Map<java.lang.String,java.lang.Short> fieldmodes, boolean dontLocalizeNumbers)
           
static java.lang.String toNative(java.lang.String arg)
           
static java.lang.String toNativeScript(java.lang.String arg)
           
static java.lang.String toString(Persistent obj)
          Generates a String representation to identify a persistent object.
static java.lang.String transformCase(java.sql.DatabaseMetaData dbmd, java.lang.String id)
           
static java.lang.String transformCase(java.lang.String id)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNewInstance

public static Persistent getNewInstance(java.lang.Class<?> c)
                                 throws java.lang.Exception
Create a new instance of c. c can be an interface, then mapInterface(Class) is used to determine the appropriate implementation class.

Parameters:
c - the class or interface
Returns:
an instance of c
Throws:
java.lang.Exception

getNewInstance

public static Persistent getNewInstance(java.lang.String className)
                                 throws java.lang.Exception
Create a new instance of a class c specified via the className . c can be an interface, then mapInterface(String) is used to determine the appropriate implementation class.

Parameters:
className - the name of the class or interface
Returns:
an instance of c
Throws:
java.lang.Exception

base

public static Persistent base(Persistent o)
Return the base object of a Persistent o. If o ist an instance of View, its base object is returned, otherwise, o is returned.

Parameters:
o - the View Object
Returns:
the base object of o.

dbFields

public static java.util.List<java.lang.reflect.Field> dbFields(Persistent o)
Returns the fields of the object which have corresponding fields in the database.

Returns:
a List containing the persistent fields of the class.

dbMultiValuedFields

public static java.util.List<java.lang.reflect.Field> dbMultiValuedFields(Persistent o)
Returns the multivalued fields (Lists, Maps, Sets) of the object which have corresponding fields in the database.

Returns:
a List containing the persistent multivalued fields of the class.

cleanDbFieldV

public static void cleanDbFieldV()

dbAttrs

public static java.lang.String dbAttrs(Persistent o,
                                       java.lang.String prefix)

dbAttrsCount

public static int dbAttrsCount(Persistent o)

dbAttrs

public static java.lang.String dbAttrs(Persistent o)

hasClassAttribute

public static boolean hasClassAttribute(java.lang.Class<?> c)

dbAttrPos

public static int dbAttrPos(Persistent o,
                            java.lang.String fieldname)

setValues

public static void setValues(Persistent o,
                             java.util.Map<java.lang.String,? extends java.lang.Object> req)

setValues

public static void setValues(Persistent o,
                             java.util.Map<java.lang.String,? extends java.lang.Object> req,
                             java.util.Map<java.lang.String,java.lang.Short> fieldmodes)

setValues2

public static boolean setValues2(Persistent o,
                                 java.util.Map<java.lang.String,? extends java.lang.Object> req,
                                 java.util.Map<java.lang.String,java.lang.Short> fieldmodes,
                                 boolean dontLocalizeNumbers)

setNumber

public static boolean setNumber(Persistent o,
                                java.lang.reflect.Field ff,
                                java.lang.String val,
                                boolean dontLocalizeNumbers)
                         throws java.lang.Exception
Set a field to a numeric value, the value is given as String.

Parameters:
o - the target object
ff - the field which reveices the value
val - the value
dontLocalizeNumbers - if true, don't use the localized number formatter
Returns:
true if the field is numeric
Throws:
java.lang.Exception

setFieldToValue

public static void setFieldToValue(Persistent o,
                                   java.lang.reflect.Field ff,
                                   java.lang.Object val,
                                   java.util.Map<java.lang.String,? extends java.lang.Object> req)
                            throws java.lang.Exception
Set a field of an object

Parameters:
o -
ff -
val -
req -
Throws:
java.lang.Exception

setFieldToValue

public static boolean setFieldToValue(Persistent o,
                                      java.lang.reflect.Field ff,
                                      java.lang.Object value,
                                      java.util.Map<java.lang.String,? extends java.lang.Object> req,
                                      boolean dontLocalizeNumbers)
                               throws java.lang.Exception
Set a field of an object

Parameters:
o - the object to fill
ff - the object's field
value - the value to assign
req - all other values
dontLocalizeNumbers - false if value may be in a locale-dependent format
Throws:
java.lang.Exception

setFromDB

@Deprecated
public static void setFromDB(Persistent o,
                                        java.sql.ResultSet rs)
                      throws java.lang.Exception
Deprecated. 

Set the members of the persistent object to the corresponding values of the current row of the result set. The object is added to the Thread-Cache. This method normally uses setFromRS. When the property database.setfromdb.compatibility is set in the configuration, setFromRSByName is used.

Parameters:
o - The persistent object
rs - the ResultSet
Throws:
java.lang.Exception

setFromDB

@Deprecated
public static void setFromDB(Persistent o,
                                        java.sql.ResultSet rs,
                                        boolean addToCache)
                      throws java.lang.Exception
Deprecated. 

Set the members of the persistent object to the corresponding values of the current row of the result set. This method normally uses setFromRS. When the property database.setfromdb.compatibility is set in the configuration, setFromRSByName is used.

Parameters:
o - The persistent object
rs - the ResultSet
addToCache - if true, the object is added to the Thread-Cache.
Throws:
java.lang.Exception

setFromRSByName

public static void setFromRSByName(Persistent o,
                                   java.sql.ResultSet rs)
                            throws java.lang.Exception
Set the members of the persistent object to the corresponding values of the current row of the result set. The object is added to the Thread-Cache. The method uses a conventional metadata based approach to determine the position and data types of the fields of the ResultSet and is somewhat slower than setFromRS.

Parameters:
o - The persistent object
rs - the ResultSet
Throws:
java.lang.Exception

setFromRSByName

public static void setFromRSByName(Persistent o,
                                   java.sql.ResultSet rs,
                                   boolean addToCache)
                            throws java.lang.Exception
Set the members of the persistent object to the corresponding values of the current row of the result set. The method uses a conventional metadata based approach to determine the position and data types of the fields of the ResultSet and is somewhat slower than setFromRS.

Parameters:
o - The persistent object
rs - the ResultSet
addToCache - if true, the object is added to the Thread-Cache.
Throws:
java.lang.Exception

setFromRS

public static void setFromRS(Persistent o,
                             java.sql.ResultSet rs)
                      throws java.lang.Exception
Set the members of the persistent object to the corresponding values of the current row of the result set. The object is added to the Thread-Cache. The method uses a fast approach to determine the position and data types of the fields of the ResultSet.

Parameters:
o - The persistent object
rs - the ResultSet
Throws:
java.lang.Exception

setFromRS

public static void setFromRS(Persistent o,
                             java.sql.ResultSet rs,
                             boolean addToCache)
                      throws java.lang.Exception
Set the members of the persistent object to the corresponding values of the current row of the result set. The method uses a fast approach to determine the position and data types of the fields of the ResultSet.

Parameters:
o - The persistent object
rs - the ResultSet
addToCache - if true, the object is added to the Thread-Cache.
Throws:
java.lang.Exception

getFromRS

public static java.lang.Object getFromRS(java.sql.ResultSet rs,
                                         java.sql.ResultSetMetaData metaData,
                                         int i)
                                  throws java.sql.SQLException
Throws:
java.sql.SQLException

getFromRS

public static java.lang.Object getFromRS(java.sql.ResultSet rs,
                                         int sqlType,
                                         int i)
                                  throws java.sql.SQLException
Throws:
java.sql.SQLException

getField

public static java.lang.reflect.Field getField(Persistent o,
                                               java.lang.String fieldname)

toNativeScript

public static java.lang.String toNativeScript(java.lang.String arg)

toNative

public static java.lang.String toNative(java.lang.String arg)

addEventHandler

public static void addEventHandler(PersistentEventHandler h,
                                   java.lang.Class<Persistent>[] classes)
Add an event handler for some classes.

Parameters:
h - the PersistentEventHandler to be called when instances of the classes are manipulated via the store.
classes - an array of classes

removeEventHandler

public static void removeEventHandler(PersistentEventHandler peh)
Remove a PersistentEventHandler. All handlers with the same class as peh get removed.

Parameters:
peh - an instance of the handler to be removed

getEventHandlers

public static java.util.List<PersistentEventHandler> getEventHandlers(java.lang.Class<? extends Persistent> c)
Get a List of PersistentEventHandler for a speciefied class c.

Parameters:
c - the class
Returns:
a list of PersistentEventHandlers for c

getDate

public static java.util.Date getDate(java.sql.ResultSet rs,
                                     java.lang.String columnName)
                              throws java.sql.SQLException
Get a Date from a column of the current row of a ResultSet. Deals with DATE and TIMESTAMP SQL datatypes.

Parameters:
rs - the ResultSet
columnName - the name of the column
Returns:
the date
Throws:
java.sql.SQLException

getDate

public static java.util.Date getDate(java.sql.ResultSet rs,
                                     int columnIndex)
                              throws java.sql.SQLException
Get a Date from a column of the current row of a ResultSet. Deals with DATE and TIMESTAMP SQL datatypes.

Parameters:
rs - the ResultSet
columnIndex - the index of the column
Returns:
the date
Throws:
java.sql.SQLException

getBigDecimal

public static java.math.BigDecimal getBigDecimal(java.sql.ResultSet rs,
                                                 java.lang.String columnName)
                                          throws java.sql.SQLException
Get a BigDecimal from a column of the current row of a ResultSet. Masks differences in RDBMS implementations.

Parameters:
rs - the ResultSet
columnName - the name of the column
Returns:
the BigDecimal
Throws:
java.sql.SQLException

getBigDecimal

public static java.math.BigDecimal getBigDecimal(java.sql.ResultSet rs,
                                                 int columnIndex)
                                          throws java.sql.SQLException
Get a BigDecimal from a column of the current row of a ResultSet. Masks differences in RDBMS implementations.

Parameters:
rs - the ResultSet
columnIndex - the index of the column
Returns:
the BigDecimal
Throws:
java.sql.SQLException

setBigDecimal

public static void setBigDecimal(java.sql.PreparedStatement stmt,
                                 int pos,
                                 java.math.BigDecimal value)
                          throws java.sql.SQLException
Get a parameter in a PreparedStatement from a BigDecimal. Masks differences in RDBMS implementations.

Parameters:
stmt - the PreparedStatement
pos - the number of the parameter in the stmt
value - the BigDecimal
Throws:
java.sql.SQLException

setBindVars

public static void setBindVars(java.sql.PreparedStatement stmt,
                               java.lang.Object[] bindVars)
Set the bind variables of a prepared statement based on an object array.

Parameters:
stmt - the prepared statement
bindVars - the array of bind variables, may contain Nil wrappers.

existsTable

public static boolean existsTable(java.lang.String tablename)
                           throws java.lang.Exception
Returns true if the passed table exists in the current db-schema. The table name will be transformed into proper case for the check (can be avoided by enclosing it in double quotes).

Parameters:
tablename - the name of the table to be checked.
Returns:
true if a table with the given name exists, else false
Throws:
java.lang.Exception

existsView

public static boolean existsView(java.lang.String viewname)
                          throws java.lang.Exception
Returns true if the passed view exists in the current db-schema. The view name will be transformed into proper case for the check (can be avoided by enclosing it in double quotes).

Parameters:
viewname - the name of the view to be checked.
Returns:
true if a view with the given name exists, else false
Throws:
java.lang.Exception

getTableNames

public static java.util.Set<java.lang.String> getTableNames(java.lang.String tableNamePattern)
                                                     throws java.lang.Exception
Returns a set of names of tables conforming to the name pattern in the current db-schema. The table name pattern will be transformed into proper case for the check (can be avoided by enclosing it in double quotes).

Parameters:
tableNamePattern - the pattern for the table names to match against.
Returns:
a set of names of tables
Throws:
java.lang.Exception

getViewNames

public static java.util.Set<java.lang.String> getViewNames(java.lang.String viewNamePattern)
                                                    throws java.lang.Exception
Returns a set of names of views conforming to the name pattern in the current db-schema. The view name pattern will be transformed into proper case for the check (can be avoided by enclosing it in double quotes).

Parameters:
viewNamePattern - the pattern for the view names to match against.
Returns:
a set of names of views
Throws:
java.lang.Exception

existsObject

public static boolean existsObject(java.util.Set<java.lang.String> objectNameSet,
                                   java.lang.String name)

existsColumn

public static boolean existsColumn(java.lang.String tablename,
                                   java.lang.String columnname)
                            throws java.lang.Exception
Returns true if the passed table exists in the current db-schema and the passed column exists in this table. The names will be transformed into upper case for the check.

Parameters:
tablename - the name of the table to be checked.
columnname - the name of the column to be checked.
Returns:
true if a table with the given name exists else instead
Throws:
java.lang.Exception

transformCase

public static java.lang.String transformCase(java.sql.DatabaseMetaData dbmd,
                                             java.lang.String id)
                                      throws java.lang.Exception
Throws:
java.lang.Exception

transformCase

public static java.lang.String transformCase(java.lang.String id)

getMaxTableNameLength

public static int getMaxTableNameLength()

mapInterface

public static <P> java.lang.Class<Persistent> mapInterface(java.lang.Class<P> c)
Get the Persistent class which is implemented by the a Class c. e.g. maps com.groiss.org.User interface to the com.dec.avw.core.User class. If c is no such mappable interface, then c is returned (cast to a Persistent)

Type Parameters:
P -
Parameters:
c - interface to determine the underlying class for
Returns:
the mapped Persistent class

mapInterface

public static java.lang.Class<Persistent> mapInterface(java.lang.String classname)
                                                throws java.lang.ClassNotFoundException
Get the Persistent class which is implemented by a class with the given classname. e.g. maps User interface to the com.dec.avw.core.User class. If c is no such mappable interface, then an instance of the class named classname is returned (cast to a Persistent)

Parameters:
classname - the name of the interface to determine the underlying class for
Returns:
the mapped Persistent class
Throws:
java.lang.ClassNotFoundException

mapInterfaceToClassName

public static java.lang.String mapInterfaceToClassName(java.lang.String classname)
Get the name of the Persistent class which is implemented by a class with the given classname. e.g. maps User interface to the com.dec.avw.core.User class. If c is no such mappable interface, then className is returned.

Parameters:
className - the name of the interface to determine the underlying className for
Returns:
the mapped class name

isSingleInterface

public static boolean isSingleInterface(java.lang.Class<?> c)
Determines if an interface c hides a single implementation (e.g. com.groiss.org.User covers com.dec.avw.core.User)

Parameters:
c - the interface to check
Returns:
true, if the is a single known implementation of c

executeScript

public static void executeScript(java.lang.String content,
                                 java.io.PrintWriter res)
                          throws java.lang.Exception
Throws:
java.lang.Exception

executeSQLFile

public static void executeSQLFile(java.lang.String commands,
                                  java.io.PrintWriter res)
                           throws java.lang.Exception
Throws:
java.lang.Exception

getObject

public static <T extends Persistent> T getObject(java.lang.Object obj)

toString

public static java.lang.String toString(Persistent obj)
Generates a String representation to identify a persistent object.

Parameters:
obj - the persistent object
Returns:
a String containing the class name of obj and its oid

isSystemOid

public static boolean isSystemOid(long oid)
Returns true if the given oid is the oid of a system object (>0, <1000).

Parameters:
oid -

noNaN

public static double noNaN(double d)

noNaN

public static float noNaN(float f)

setFetchsize

public static void setFetchsize(int rows)

getFetchSize

public static int getFetchSize()

getDefaultStore

public static Store getDefaultStore()


@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.