public class StoreUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MISSING_VALUE |
Modifier and Type | Method and Description |
---|---|
static void |
addEventHandler(PersistentEventHandler<? extends Persistent> h,
java.lang.Class<?>... classes)
Add an event handler for the passed persistent 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 |
executeScript(java.lang.String content,
java.io.PrintWriter res,
boolean tryAvoid) |
static void |
executeSQLFile(java.lang.String commands,
java.io.PrintWriter res) |
static int |
executeSQLFile(java.lang.String commands,
java.io.PrintWriter res,
boolean tryAvoid) |
static boolean |
existsColumn(java.lang.String tablename,
java.lang.String columnname)
Returns true if the passed table/view exists in the current db-schema and the passed column exists in this table/view.
|
static boolean |
existsIndex(java.lang.String tablename,
java.lang.String indexname)
Returns true if the passed index exists in the current db-schema for the passed 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 byte[] |
getBlob(java.sql.ResultSet rs,
int columnIndex)
Get a byte array from a Blob column of the current row of a ResultSet.
|
static java.io.InputStream |
getBlobStream(java.sql.ResultSet rs,
int columnIndex)
Get a String from a Blob column of the current row of a ResultSet.
|
static java.lang.String |
getBlobString(java.sql.ResultSet rs,
int columnIndex)
Get a String from a Blob column of the current row of a ResultSet.
|
static java.lang.String |
getClob(java.sql.ResultSet rs,
int columnIndex)
Get a String from a Clob column of the current row of a ResultSet.
|
static byte[] |
getClobBytes(java.sql.ResultSet rs,
int columnIndex)
Get a byte array from a Clob 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 <T extends Persistent> |
getEventHandlers(java.lang.Class<T> c)
Get a List of
PersistentEventHandler for a specified class c. |
static java.util.List<java.util.List<java.lang.Object>> |
getExportedKeys(java.lang.String tablename)
Retrieves a description of the foreign key columns that reference the given table's
primary key columns (the foreign keys exported by a table).
|
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 java.util.List<java.util.List<java.lang.Object>> |
getImportedKeys(java.lang.String tablename)
Retrieves a description of the primary key columns that are referenced by the given table's
foreign key columns (the primary keys imported by a table).
|
static java.util.Map<java.lang.String,java.lang.String> |
getIndexInfo(java.lang.String tablename) |
static int |
getMaxConstraintIndexNameLength() |
static int |
getMaxTableNameLength() |
static Persistent |
getNewInstance(java.lang.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(java.lang.String className)
Create a new instance of a class c specified via the className .
|
static <T extends Persistent> |
getObject(java.lang.Object obj)
Returns the
Persistent , if obj is a string like: <classname>:<oid> |
static java.sql.ResultSetMetaData |
getTableDefinition(java.lang.Class<? extends Persistent> c) |
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 |
hasDbField(java.lang.Class<?> c,
java.lang.String fieldName)
Returns true, if the Class has a field with the given name which corresponds to a column in the database.
|
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)
|
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 java.util.List<java.lang.String> |
oidList(java.util.List<?> l,
int splitsize)
Creates a list of strings of oids from a list of objects.
|
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 |
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 <T extends java.lang.Enum<T>> |
toEnum(java.lang.Class<T> clazz,
java.lang.Object value)
Maps a value to an instance of an Enum class
|
static org.json.JSONObject |
toJson(Persistent pers)
Convert a persistent to JSON
|
static org.json.JSONObject |
toJsonAsReference(Persistent pers) |
static java.util.Map<java.lang.String,java.lang.Object> |
toMap(Persistent pers)
Convert a persistent to a Map
|
static java.util.Map<java.lang.String,java.lang.Object> |
toMapAsReference(Persistent pers) |
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) |
static ApplicationException |
wrapSQLException(int errNum,
java.lang.Throwable e)
Wraps an exception ; tries to discriminate between sql constraint violations and other exceptions
when sqlexception && sqlstate=23* ==> integrity coinstraint, (appex 478,e)
when sqlexception && sqlstate!
|
public static final java.lang.String MISSING_VALUE
public static Persistent getNewInstance(java.lang.Class<?> c) throws java.lang.Exception
mapInterface(Class)
is used to determine the appropriate implementation class.c
- the class or interfacejava.lang.Exception
public static Persistent getNewInstance(java.lang.String className) throws java.lang.Exception
mapInterface(String)
is used to determine the appropriate implementation class.className
- the name of the class or interfacejava.lang.Exception
public static Persistent base(Persistent o)
View
, its base object is returned, otherwise, o is returned.o
- the View Objectpublic static java.util.List<java.lang.reflect.Field> dbFields(Persistent o)
public static boolean hasDbField(java.lang.Class<?> c, java.lang.String fieldName)
public static java.util.List<java.lang.reflect.Field> dbMultiValuedFields(Persistent o)
public static void cleanDbFieldV()
public static java.lang.String dbAttrs(Persistent o, java.lang.String prefix)
public static int dbAttrsCount(Persistent o)
public static java.lang.String dbAttrs(Persistent o)
public static boolean hasClassAttribute(java.lang.Class<?> c)
public static int dbAttrPos(Persistent o, java.lang.String fieldname)
public static void setValues(Persistent o, java.util.Map<java.lang.String,? extends java.lang.Object> req)
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)
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)
public static boolean setNumber(Persistent o, java.lang.reflect.Field ff, java.lang.String val, boolean dontLocalizeNumbers) throws java.lang.Exception
o
- the target objectff
- the field which reveices the valueval
- the valuedontLocalizeNumbers
- if true, don't use the localized number formatterjava.lang.Exception
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
o
- ff
- val
- req
- java.lang.Exception
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
o
- the object to fillff
- the object's fieldvalue
- the value to assignreq
- all other valuesdontLocalizeNumbers
- false
if value may be in a locale-dependent formatjava.lang.Exception
public static void setFromRSByName(Persistent o, java.sql.ResultSet rs) throws java.lang.Exception
o
- The persistent objectrs
- the ResultSetjava.lang.Exception
public static void setFromRSByName(Persistent o, java.sql.ResultSet rs, boolean addToCache) throws java.lang.Exception
o
- The persistent objectrs
- the ResultSetaddToCache
- if true, the object is added to the Thread-Cache.java.lang.Exception
public static void setFromRS(Persistent o, java.sql.ResultSet rs) throws java.lang.Exception
o
- The persistent objectrs
- the ResultSetjava.lang.Exception
public static void setFromRS(Persistent o, java.sql.ResultSet rs, boolean addToCache) throws java.lang.Exception
o
- The persistent objectrs
- the ResultSetaddToCache
- if true, the object is added to the Thread-Cache.java.lang.Exception
public static java.lang.Object getFromRS(java.sql.ResultSet rs, java.sql.ResultSetMetaData metaData, int i) throws java.lang.Exception
java.lang.Exception
public static java.lang.Object getFromRS(java.sql.ResultSet rs, int sqlType, int i) throws java.lang.Exception
java.lang.Exception
public static java.lang.reflect.Field getField(Persistent o, java.lang.String fieldname)
public static java.lang.String toNativeScript(java.lang.String arg)
public static java.lang.String toNative(java.lang.String arg)
public static void addEventHandler(PersistentEventHandler<? extends Persistent> h, java.lang.Class<?>... classes)
Persistent
otherwise
no registration for that class will be performed and an error will be logged.h
- the PersistentEventHandler
to be called when instances of the classes are manipulated via the store.classes
- the classes for which the handler will be invoked.public static void removeEventHandler(PersistentEventHandler<?> peh)
PersistentEventHandler
. All handlers with the same class as peh get removed.peh
- an instance of the handler to be removedpublic static <T extends Persistent> java.util.List<PersistentEventHandler<T>> getEventHandlers(java.lang.Class<T> c)
PersistentEventHandler
for a specified class c.c
- the classpublic static java.util.Date getDate(java.sql.ResultSet rs, java.lang.String columnName) throws java.sql.SQLException
rs
- the ResultSetcolumnName
- the name of the columnjava.sql.SQLException
public static java.util.Date getDate(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
rs
- the ResultSetcolumnIndex
- the index of the columnjava.sql.SQLException
public static java.math.BigDecimal getBigDecimal(java.sql.ResultSet rs, java.lang.String columnName) throws java.sql.SQLException
rs
- the ResultSetcolumnName
- the name of the columnjava.sql.SQLException
public static java.math.BigDecimal getBigDecimal(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
rs
- the ResultSetcolumnIndex
- the index of the columnjava.sql.SQLException
public static void setBigDecimal(java.sql.PreparedStatement stmt, int pos, java.math.BigDecimal value) throws java.sql.SQLException
stmt
- the PreparedStatementpos
- the number of the parameter in the stmtvalue
- the BigDecimaljava.sql.SQLException
public static byte[] getClobBytes(java.sql.ResultSet rs, int columnIndex) throws java.lang.Exception
rs
- the ResultSetcolumnIndex
- the index of the columnjava.sql.SQLException
java.lang.Exception
public static byte[] getBlob(java.sql.ResultSet rs, int columnIndex) throws java.lang.Exception
rs
- the ResultSetcolumnIndex
- the index of the columnjava.sql.SQLException
java.lang.Exception
public static java.lang.String getClob(java.sql.ResultSet rs, int columnIndex) throws java.lang.Exception
rs
- the ResultSetcolumnIndex
- the index of the columnjava.sql.SQLException
java.lang.Exception
public static java.lang.String getBlobString(java.sql.ResultSet rs, int columnIndex) throws java.lang.Exception
rs
- the ResultSetcolumnIndex
- the index of the columnjava.sql.SQLException
java.lang.Exception
public static java.io.InputStream getBlobStream(java.sql.ResultSet rs, int columnIndex) throws java.lang.Exception
rs
- the ResultSetcolumnIndex
- the index of the columnjava.sql.SQLException
java.lang.Exception
public static void setBindVars(java.sql.PreparedStatement stmt, java.lang.Object[] bindVars)
stmt
- the prepared statementbindVars
- the array of bind variables, may contain Nil
NullExpression
and wrappers.public static boolean existsTable(java.lang.String tablename) throws java.lang.Exception
tablename
- the name of the table to be checked.true
if a table with the given name exists, else false
java.lang.Exception
public static boolean existsView(java.lang.String viewname) throws java.lang.Exception
viewname
- the name of the view to be checked.true
if a view with the given name exists, else false
java.lang.Exception
public static boolean existsColumn(java.lang.String tablename, java.lang.String columnname) throws java.lang.Exception
tablename
- the name of the table/view to be checked.columnname
- the name of the column to be checked.true
if a the specified column exists in the specified table, else false
java.lang.Exception
public static java.util.Set<java.lang.String> getTableNames(java.lang.String tableNamePattern) throws java.lang.Exception
tableNamePattern
- the pattern for the table names to match against.java.lang.Exception
public static java.util.Set<java.lang.String> getViewNames(java.lang.String viewNamePattern) throws java.lang.Exception
viewNamePattern
- the pattern for the view names to match against.java.lang.Exception
public static boolean existsObject(java.util.Set<java.lang.String> objectNameSet, java.lang.String name)
public static java.util.List<java.util.List<java.lang.Object>> getExportedKeys(java.lang.String tablename) throws java.lang.Exception
tablename
- the name of the tablejava.lang.Exception
public static java.util.List<java.util.List<java.lang.Object>> getImportedKeys(java.lang.String tablename) throws java.lang.Exception
tablename
- the name of the tablejava.lang.Exception
public static boolean existsIndex(java.lang.String tablename, java.lang.String indexname) throws java.lang.Exception
indexname
- the name of the index to be checked.tablename
- the name of the table to be checked.true
if a the specified index exists in the specified table, else false
java.lang.Exception
public static java.util.Map<java.lang.String,java.lang.String> getIndexInfo(java.lang.String tablename) throws java.lang.Exception
java.lang.Exception
public static java.lang.String transformCase(java.sql.DatabaseMetaData dbmd, java.lang.String id) throws java.lang.Exception
java.lang.Exception
public static java.lang.String transformCase(java.lang.String id)
public static int getMaxTableNameLength()
public static int getMaxConstraintIndexNameLength()
public static <P> java.lang.Class<Persistent> mapInterface(java.lang.Class<P> c)
P
- c
- interface to determine the underlying class forpublic static java.lang.Class<Persistent> mapInterface(java.lang.String className) throws java.lang.ClassNotFoundException
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)className
- the name of the interface to determine the underlying class forjava.lang.ClassNotFoundException
public static java.lang.String mapInterfaceToClassName(java.lang.String className)
User
interface to the com.dec.avw.core.User class.
If c is no such mappable interface, then className is returned.className
- the name of the interface to determine the underlying className forpublic static boolean isSingleInterface(java.lang.Class<?> c)
c
- the interface to checkpublic static void executeScript(java.lang.String content, java.io.PrintWriter res) throws java.lang.Exception
java.lang.Exception
public static void executeScript(java.lang.String content, java.io.PrintWriter res, boolean tryAvoid) throws java.lang.Exception
java.lang.Exception
public static void executeSQLFile(java.lang.String commands, java.io.PrintWriter res) throws java.lang.Exception
java.lang.Exception
public static int executeSQLFile(java.lang.String commands, java.io.PrintWriter res, boolean tryAvoid) throws java.lang.Exception
java.lang.Exception
public static <T extends Persistent> T getObject(java.lang.Object obj)
Persistent
, if obj is a string like: <classname>:<oid>obj
- A string like <classname>:<oid>.Persistent
public static java.lang.String toString(Persistent obj)
obj
- the persistent objectpublic static boolean isSystemOid(long oid)
oid
- public static double noNaN(double d)
public static float noNaN(float f)
public static <T extends java.lang.Enum<T>> T toEnum(java.lang.Class<T> clazz, java.lang.Object value)
T
- The resulting Enum Typeclazz
- the enum Classvalue
- the value to MapDefinedEnum
, the definedValue() is matched against,
if not, Enum.name() is matched against (so then it is basically the same as Enum.valueOf(Class, String)
.public static void setFetchsize(int rows)
public static int getFetchSize()
public static Store getDefaultStore()
public static java.sql.ResultSetMetaData getTableDefinition(java.lang.Class<? extends Persistent> c)
public static org.json.JSONObject toJson(Persistent pers) throws java.lang.Exception
java.lang.Exception
public static java.util.Map<java.lang.String,java.lang.Object> toMap(Persistent pers) throws java.lang.Exception
java.lang.Exception
public static org.json.JSONObject toJsonAsReference(Persistent pers)
public static java.util.Map<java.lang.String,java.lang.Object> toMapAsReference(Persistent pers)
public static ApplicationException wrapSQLException(int errNum, java.lang.Throwable e)
when sqlexception && sqlstate=23* ==> integrity coinstraint, (appex 478,e)
when sqlexception && sqlstate!=23* ==> appex(errNum,e) when appex ==> appex otherwise: ==> new Appex(errNum,e)errNum
- e
- public static java.util.List<java.lang.String> oidList(java.util.List<?> l, int splitsize)
l
- the list of objectssplitsize
- the maximum number of entries per list element (chunk size). If 0 is used, a suitable predefined size
is being used.@enterprise 9.0.33982 Copyright © 2001-2023 Groiss Informatics GmbH. All Rights Reserved.