com.groiss.store
Class StoreUtil

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

public class StoreUtil
extends Object

Utilities for store


Method Summary
static void addEventHandler(PersistentEventHandler h, 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, String fieldname)
           
static String dbAttrs(Persistent o)
           
static String dbAttrs(Persistent o, String prefix)
           
static int dbAttrsCount(Persistent o)
           
static List<Field> dbFields(Persistent o)
          Returns the fields of the object which have corresponding fields in the database.
static List<Field> dbMultiValuedFields(Persistent o)
          Returns the multivalued fields (Lists, Maps, Sets) of the object which have corresponding fields in the database.
static void executeScript(String content, PrintWriter res)
           
static void executeSQLFile(String commands, PrintWriter res)
           
static boolean existsColumn(String tablename, String columnname)
          Returns true if the passed table exists in the current db-schema and the passed column exists in this table.
static boolean existsTable(String tablename)
          Returns true if the passed table exists in the current db-schema.
static boolean existsView(String viewname)
          Returns true if the passed view exists in the current db-schema.
static BigDecimal getBigDecimal(ResultSet rs, int columnIndex)
          Get a BigDecimal from a column of the current row of a ResultSet.
static BigDecimal getBigDecimal(ResultSet rs, String columnName)
          Get a BigDecimal from a column of the current row of a ResultSet.
static Date getDate(ResultSet rs, int columnIndex)
          Get a Date from a column of the current row of a ResultSet.
static Date getDate(ResultSet rs, String columnName)
          Get a Date from a column of the current row of a ResultSet.
static List<PersistentEventHandler> getEventHandlers(Class<? extends Persistent> c)
          Get a List of PersistentEventHandler for a speciefied class c.
static Field getField(Persistent o, String fieldname)
           
static Object getFromRS(ResultSet rs, int sqlType, int i)
           
static Object getFromRS(ResultSet rs, ResultSetMetaData metaData, int i)
           
static Persistent getNewInstance(Class<?> c)
          Create a new instance of c. c can be an interface, then mapInterface(Class) is used to determine the appropriate implementation class.
static Persistent getNewInstance(String className)
          Create a new instance of a class c specified via the className .
static
<T extends Persistent>
T
getObject(Object obj)
           
static boolean hasClassAttribute(Class<?> c)
           
static boolean isSingleInterface(Class<?> c)
          Determines if an interface c hides a single implementation (e.g. com.groiss.org.User covers com.dec.avw.core.User)
static boolean isSystemOid(long oid)
          Returns true if the given oid is the oid of a system object (>0, <1000).
static
<P> Class<Persistent>
mapInterface(Class<P> c)
          Get the Persistent class which is implemented by the a Class c.
static Class<Persistent> mapInterface(String classname)
          Get 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(PreparedStatement stmt, int pos, BigDecimal value)
          Get a parameter in a PreparedStatement from a BigDecimal.
static void setBindVars(PreparedStatement stmt, Object[] bindVars)
          Set the bind variables of a prepared statement based on an object array.
static void setFieldToValue(Persistent o, Field ff, Object val, Map<String,? extends Object> req)
          Set a field of an object
static boolean setFieldToValue(Persistent o, Field ff, Object value, Map<String,? extends Object> req, boolean dontLocalizeNumbers)
          Set a field of an object
static void setFromDB(Persistent o, ResultSet rs)
          Deprecated.  
static void setFromDB(Persistent o, ResultSet rs, boolean addToCache)
          Deprecated.  
static void setFromRS(Persistent o, 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, 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, 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, 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, Field ff, String val, boolean dontLocalizeNumbers)
          Set a field to a numeric value, the value is given as String.
static void setValues(Persistent o, Map<String,? extends Object> req)
           
static void setValues(Persistent o, Map<String,? extends Object> req, Map<String,Short> fieldmodes)
           
static boolean setValues2(Persistent o, Map<String,? extends Object> req, Map<String,Short> fieldmodes, boolean dontLocalizeNumbers)
           
static String toNative(String arg)
           
static String toNativeScript(String arg)
           
static String toString(Persistent obj)
          Generates a String representation to identify a persistent object.
static String transformCase(DatabaseMetaData dbmd, 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(Class<?> c)
                                 throws 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:
Exception

getNewInstance

public static Persistent getNewInstance(String className)
                                 throws 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:
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 List<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 List<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 String dbAttrs(Persistent o,
                             String prefix)

dbAttrsCount

public static int dbAttrsCount(Persistent o)

dbAttrs

public static String dbAttrs(Persistent o)

hasClassAttribute

public static boolean hasClassAttribute(Class<?> c)

dbAttrPos

public static int dbAttrPos(Persistent o,
                            String fieldname)

setValues

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

setValues

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

setValues2

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

setNumber

public static boolean setNumber(Persistent o,
                                Field ff,
                                String val,
                                boolean dontLocalizeNumbers)
                         throws 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:
Exception

setFieldToValue

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

Parameters:
o -
ff -
val -
req -
Throws:
Exception

setFieldToValue

public static boolean setFieldToValue(Persistent o,
                                      Field ff,
                                      Object value,
                                      Map<String,? extends Object> req,
                                      boolean dontLocalizeNumbers)
                               throws 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:
Exception

setFromDB

@Deprecated
public static void setFromDB(Persistent o,
                                        ResultSet rs)
                      throws 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:
Exception

setFromDB

@Deprecated
public static void setFromDB(Persistent o,
                                        ResultSet rs,
                                        boolean addToCache)
                      throws 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:
Exception

setFromRSByName

public static void setFromRSByName(Persistent o,
                                   ResultSet rs)
                            throws 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:
Exception

setFromRSByName

public static void setFromRSByName(Persistent o,
                                   ResultSet rs,
                                   boolean addToCache)
                            throws 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:
Exception

setFromRS

public static void setFromRS(Persistent o,
                             ResultSet rs)
                      throws 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:
Exception

setFromRS

public static void setFromRS(Persistent o,
                             ResultSet rs,
                             boolean addToCache)
                      throws 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:
Exception

getFromRS

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

getFromRS

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

getField

public static Field getField(Persistent o,
                             String fieldname)

toNativeScript

public static String toNativeScript(String arg)

toNative

public static String toNative(String arg)

addEventHandler

public static void addEventHandler(PersistentEventHandler h,
                                   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 List<PersistentEventHandler> getEventHandlers(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 Date getDate(ResultSet rs,
                           String columnName)
                    throws 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:
SQLException

getDate

public static Date getDate(ResultSet rs,
                           int columnIndex)
                    throws 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:
SQLException

getBigDecimal

public static BigDecimal getBigDecimal(ResultSet rs,
                                       String columnName)
                                throws 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:
SQLException

getBigDecimal

public static BigDecimal getBigDecimal(ResultSet rs,
                                       int columnIndex)
                                throws 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:
SQLException

setBigDecimal

public static void setBigDecimal(PreparedStatement stmt,
                                 int pos,
                                 BigDecimal value)
                          throws 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:
SQLException

setBindVars

public static void setBindVars(PreparedStatement stmt,
                               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

existsTable

public static boolean existsTable(String tablename)
                           throws 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:
Exception

existsView

public static boolean existsView(String viewname)
                          throws 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:
Exception

existsColumn

public static boolean existsColumn(String tablename,
                                   String columnname)
                            throws 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:
Exception

transformCase

public static String transformCase(DatabaseMetaData dbmd,
                                   String id)
                            throws Exception
Throws:
Exception

mapInterface

public static <P> Class<Persistent> mapInterface(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 Class<Persistent> mapInterface(String classname)
                                      throws 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:
ClassNotFoundException

isSingleInterface

public static boolean isSingleInterface(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(String content,
                                 PrintWriter res)
                          throws Exception
Throws:
Exception

executeSQLFile

public static void executeSQLFile(String commands,
                                  PrintWriter res)
                           throws Exception
Throws:
Exception

getObject

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

toString

public static 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)


@enterprise 8.0.10809 Copyright © 2001-2012 Groiss Informatics GmbH. All Rights Reserved.