Class StoreUtil
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addEventHandler
(PersistentEventHandler<? extends Persistent> handler, 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 boolean
canBeUsedForSelect
(String objectname) Returns true if the passed objectname exists in the database schema and can be used as select target.static void
Check the content of the fields of a persistent against the length constraint of the columns in the database.static void
static String
Create a unique key for the object.static Persistent
Create a persistent object from a json object.static int
dbAttrPos
(Persistent o, String fieldname) static String
static String
dbAttrs
(Persistent o, String prefix) static int
Returns the fields of the object which have corresponding fields in the database.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
executeScript
(String content, PrintWriter res, boolean tryAvoid) static void
executeSQLFile
(String commands, PrintWriter res) static int
executeSQLFile
(String commands, PrintWriter res, boolean tryAvoid) static boolean
existsColumn
(String tablename, 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
existsConstraint
(String tablename, String constraintname) static boolean
existsIndex
(String tablename, String indexname) Returns true if the passed index exists in the current db-schema for the passed table.static boolean
existsObject
(Set<String> objectNameSet, String name) static boolean
existsSchemaObject
(String objectname, String objectType) Returns true if the passed object exists in the current db-schema.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 BigInteger
getBigInteger
(ResultSet rs, int columnIndex) Get a BigInteger from a column of the current row of a ResultSet.static BigInteger
getBigInteger
(ResultSet rs, String columnName) Get a BigInteger from a column of the current row of a ResultSet.static byte[]
Get a byte array from a Blob column of the current row of a ResultSet.static InputStream
getBlobStream
(ResultSet rs, int columnIndex) Get a String from a Blob column of the current row of a ResultSet.static String
getBlobString
(ResultSet rs, int columnIndex) Get a String from a Blob column of the current row of a ResultSet.static String
Get a String from a Clob column of the current row of a ResultSet.static byte[]
getClobBytes
(ResultSet rs, int columnIndex) Get a byte array from a Clob column of the current row of a ResultSet.static ResultSetMetaData
getColumnDefinitions
(Class<? extends Persistent> c, String selectList) Determine the ResultSetMetaData for columns of a Persistent class.static DatabaseMetaData
Retrieves a DatabaseMetaData object that contains metadata about the database to which the store is connected.static Date
Get a Date from a column of the current row of a ResultSet.static Date
Get a Date from a column of the current row of a ResultSet.static Store
Deprecated, for removal: This API element is subject to removal in a future version.static <T extends Persistent>
List<PersistentEventHandler<T>>Get a List ofPersistentEventHandler
for a specified class c.getExportedKeys
(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
static Field
getField
(Persistent o, String fieldname) static Object
static Object
getFromRS
(ResultSet rs, ResultSetMetaData metaData, int i) getImportedKeys
(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).getIndexInfo
(String tablename) static String
getIndexNameForColumns
(String tablename, String columns, boolean uniqueOnly) Returns the name of the index, if one exists for the passed columns of the passed table.static int
static int
static Persistent
getNewInstance
(Class<?> c) Create a new instance of c. c can be an interface, thenmapInterface(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>
TReturns thePersistent
, if obj is a string like: <classname>:<oid>getObjectNames
(String namePattern, String objectType) Returns a set of names of database objects (VIEWs/TABLEs/...) conforming to the name pattern in the current db-schema.getTableNames
(String tableNamePattern) Returns a set of names of tables conforming to the name pattern in the current db-schema.Get the table types of the database. c.f.getViewNames
(String viewNamePattern) Returns a set of names of views conforming to the name pattern in the current db-schema.static boolean
hasClassAttribute
(Class<?> c) static boolean
hasDbField
(Class<?> c, 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
(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 String
mapInterfaceToClassName
(String className) Get the name of the Persistent class which is implemented by a class with the given classname.static boolean
mayBeReferenced
(String className) Check, if for this class a foreign key can be defined.static double
noNaN
(double d) static float
noNaN
(float f) Creates a list of strings of oids from a list of objects.static PreparedStatement
prepareStatement
(String stmtText) Prepare a statement against the current connection The statement is also visible in the DBConnections overview.static void
removeEventHandler
(PersistentEventHandler<?> handler) Remove aPersistentEventHandler
.static void
setBigDecimal
(PreparedStatement stmt, int pos, BigDecimal value) Get a parameter in a PreparedStatement from a BigDecimal.static void
setBigInteger
(PreparedStatement stmt, int pos, BigInteger 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
setFetchsize
(int rows) static void
setFieldToValue
(Persistent o, Field ff, Object val, Map<String, ? extends Object> req) Set a field of an objectstatic boolean
setFieldToValue
(Persistent o, Field ff, Object value, Map<String, ? extends Object> req, boolean dontLocalizeNumbers) Set a field of an objectstatic 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
static boolean
setValues2
(Persistent o, Map<String, ? extends Object> req, Map<String, Short> fieldmodes, boolean dontLocalizeNumbers) static void
Mark a statement (generated withprepareStatement(java.lang.String)
) as finished.static <T extends Enum<T>>
TMaps a value to an instance of an Enum classstatic JSONObject
toJson
(Persistent pers) Convert a persistent to JSONstatic JSONObject
toJsonAsReference
(Persistent pers) toMap
(Persistent pers) Convert a persistent to a MaptoMapAsReference
(Persistent pers) static String
Translate SQL Statements in to native form.static String
toString
(Persistent obj) Generates a String representation to identify a persistent object.static String
toString
(Class<?> referencingClass, Persistent obj) Generates a String representation to identify a persistent object.static String
transformCase
(String id) static String
transformCase
(DatabaseMetaData dbmd, String id) static ApplicationException
wrapSQLException
(int errNum, Throwable e) Wraps an exception ; tries to discriminate between sql constraint violations and other exceptions
-
Field Details
-
MISSING_VALUE
- See Also:
-
PASSWORD_PLACEHOLDER
- See Also:
-
PASSWORDFIELD_PREFIX
- See Also:
-
-
Method Details
-
getNewInstance
Create a new instance of c. c can be an interface, thenmapInterface(Class)
is used to determine the appropriate implementation class.- Parameters:
c
- the class or interface- Returns:
- an instance of c
-
getNewInstance
Create a new instance of a class c specified via the className . c can be an interface, thenmapInterface(String)
is used to determine the appropriate implementation class.- Parameters:
className
- the name of the class or interface- Returns:
- an instance of c
-
base
Return the base object of a Persistent o. If o ist an instance ofView
, its base object is returned, otherwise, o is returned.- Parameters:
o
- the View Object- Returns:
- the base object of o.
-
dbFields
Returns the fields of the object which have corresponding fields in the database.- Returns:
- a List containing the persistent fields of the class.
-
hasDbField
Returns true, if the Class has a field with the given name which corresponds to a column in the database.- Returns:
- true, if there is such a field
-
dbMultiValuedFields
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
-
dbAttrsCount
-
dbAttrs
-
hasClassAttribute
-
dbAttrPos
-
setValues
-
setValues
-
setValues2
-
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 objectff
- the field which reveices the valueval
- the valuedontLocalizeNumbers
- 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 ExceptionSet 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 ExceptionSet a field of an object- Parameters:
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 format- Throws:
Exception
-
setFromRSByName
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 objectrs
- the ResultSet- Throws:
Exception
-
setFromRSByName
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 objectrs
- the ResultSetaddToCache
- if true, the object is added to the Thread-Cache.- Throws:
Exception
-
setFromRS
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 objectrs
- the ResultSet- Throws:
Exception
-
setFromRS
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 objectrs
- the ResultSetaddToCache
- if true, the object is added to the Thread-Cache.- Throws:
Exception
-
getFromRS
- Throws:
Exception
-
getFromRS
- Throws:
Exception
-
getField
-
toNative
Translate SQL Statements in to native form. Can also be used instead of the (removed)toNativeScript()
method.- Parameters:
statements
- the statement(s) in SQL, containing special tags for DBMS-dependent things- Returns:
- the statements in native SQL
-
addEventHandler
public static void addEventHandler(PersistentEventHandler<? extends Persistent> handler, Class<?>... classes) Add an event handler for the passed persistent classes. Each class must implementPersistent
otherwise no registration for that class will be performed and an error will be logged (but no Exception will be thrown).The determination of applicable event handlers during read, insert, update and delete operations is done via the runtime class
o.getClass()
of the object o.In general, registrations for interfaces, abstract classes or superclasses will not work; there will be a log entry at level ERROR of the form "PersistentEventHandler <classname> is NOT being registered ..." in such a case.
One exception from this general rule is if the interface can be mapped to a well defined single implementation class (i.e. if
isSingleInterface(Class)
returns true like for interface com.groiss.org.User).Another exception is the
Persistent
interface itself. Handlers registered forPersistent
will be called for all objects implementing Persistent. Such handlers must decide themselves if they are applicable or not, e.g. by usingif (o instanceof class/interface) {...}
.- Parameters:
handler
- thePersistentEventHandler
to be called when instances of the classes are manipulated via the store.classes
- the runtime classes for which the handler will be invoked.
-
removeEventHandler
Remove aPersistentEventHandler
. All handlers with the same class as handler get removed.- Parameters:
handler
- an instance of the handlers to be removed
-
getEventHandlers
public static <T extends Persistent> List<PersistentEventHandler<T>> getEventHandlers(Class<Persistent> c) Get a List ofPersistentEventHandler
for a specified class c.- Parameters:
c
- the class- Returns:
- a list of PersistentEventHandlers for c
-
getDate
Get a Date from a column of the current row of a ResultSet. Deals with DATE and TIMESTAMP SQL datatypes.- Parameters:
rs
- the ResultSetcolumnName
- the name of the column- Returns:
- the date
- Throws:
SQLException
-
getDate
Get a Date from a column of the current row of a ResultSet. Deals with DATE and TIMESTAMP SQL datatypes.- Parameters:
rs
- the ResultSetcolumnIndex
- the index of the column- Returns:
- the date
- Throws:
SQLException
-
getBigDecimal
Get a BigDecimal from a column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnName
- the name of the column- Returns:
- the BigDecimal
- Throws:
SQLException
-
getBigDecimal
Get a BigDecimal from a column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnIndex
- 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 PreparedStatementpos
- the number of the parameter in the stmtvalue
- the BigDecimal- Throws:
SQLException
-
getBigInteger
Get a BigInteger from a column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnName
- the name of the column- Returns:
- the BigInteger
- Throws:
SQLException
-
getBigInteger
Get a BigInteger from a column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnIndex
- the index of the column- Returns:
- the BigInteger
- Throws:
SQLException
-
setBigInteger
public static void setBigInteger(PreparedStatement stmt, int pos, BigInteger value) throws SQLException Get a parameter in a PreparedStatement from a BigDecimal. Masks differences in RDBMS implementations.- Parameters:
stmt
- the PreparedStatementpos
- the number of the parameter in the stmtvalue
- the BigDecimal- Throws:
SQLException
-
getClobBytes
Get a byte array from a Clob column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnIndex
- the index of the column- Returns:
- the byte[]
- Throws:
SQLException
Exception
-
getBlob
Get a byte array from a Blob column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnIndex
- the index of the column- Returns:
- the byte[]
- Throws:
SQLException
Exception
-
getClob
Get a String from a Clob column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnIndex
- the index of the column- Returns:
- the String
- Throws:
SQLException
Exception
-
getBlobString
Get a String from a Blob column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnIndex
- the index of the column- Returns:
- the String
- Throws:
SQLException
Exception
-
getBlobStream
Get a String from a Blob column of the current row of a ResultSet. Masks differences in RDBMS implementations.- Parameters:
rs
- the ResultSetcolumnIndex
- the index of the column- Returns:
- the String
- Throws:
SQLException
Exception
-
prepareStatement
Prepare a statement against the current connection The statement is also visible in the DBConnections overview. After finishing the statement, usestmtFinished()
to let is disappear from this overview.- Parameters:
stmtText
- the text of the SQL statement- Returns:
- the PreparedStatement
- Throws:
SQLException
-
stmtFinished
public static void stmtFinished()Mark a statement (generated withprepareStatement(java.lang.String)
) as finished. -
setBindVars
Set the bind variables of a prepared statement based on an object array.- Parameters:
stmt
- the prepared statementbindVars
- the list of bind variables, may containNil
NullExpression
and wrappers.
-
existsTable
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).Only ordinary tables (objects with type 'TABLE') are considered; objects with other types like 'SYNONYM' or 'SYSTEM TABLE' will not be found.
- Parameters:
tablename
- the name of the table to be checked.- Returns:
true
if a table with the given name exists, elsefalse
- Throws:
Exception
-
canBeUsedForSelect
Returns true if the passed objectname exists in the database schema and can be used as select target. The object name will be transformed into proper case for the check (can be avoided by enclosing it in double quotes). Usually true for TABLEs, VIEWs, SYNONYMs, etc.- Parameters:
objectname
- the name of the object- Returns:
true
if the object can be used in a "select ... from objectname" statement, elsefalse
-
existsView
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).Only ordinary views (objects with type 'VIEW') are considered; objects with other types like 'SYNONYM' or 'MATERIALIZED VIEW' will not be found.
- Parameters:
viewname
- the name of the view to be checked.- Returns:
true
if a view with the given name exists, elsefalse
- Throws:
Exception
-
existsSchemaObject
Returns true if the passed object exists in the current db-schema. The object name will be transformed into proper case for the check (can be avoided by enclosing it in double quotes).- Parameters:
objectType
- type of object (e.g "VIEW" or "TABLE") like returned fromDatabaseMetaData.getTableTypes()
,null
returns all types of objects- Returns:
true
if an object with the given name (and type) exists, elsefalse
- Throws:
Exception
-
existsColumn
Returns true if the passed table/view exists in the current db-schema and the passed column exists in this table/view. The names will be transformed into proper case for the check (can be avoided by enclosing them in double quotes).- Parameters:
tablename
- the name of the table/view to be checked.columnname
- the name of the column to be checked.- Returns:
true
if a the specified column exists in the specified table, elsefalse
- Throws:
Exception
-
getTableNames
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).Only ordinary tables (objects with type 'TABLE') are considered; objects with other types like 'SYNONYM' or 'SYSTEM TABLE' will not be found.
- Parameters:
tableNamePattern
- the pattern for the table names to match against.- Returns:
- a set of names of tables
- Throws:
Exception
-
getViewNames
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).Only ordinary views (objects with type 'VIEW') are considered; objects with other types like 'SYNONYM' or 'MATERIALIZED VIEW' will not be found.
- Parameters:
viewNamePattern
- the pattern for the view names to match against.- Returns:
- a set of names of views
- Throws:
Exception
-
existsObject
-
getObjectNames
Returns a set of names of database objects (VIEWs/TABLEs/...) conforming to the name pattern in the current db-schema. The name pattern will be transformed into proper case for the check (can be avoided by enclosing it in double quotes).- Parameters:
namePattern
- the pattern for the object names to match against.objectType
- type of object (e.g "VIEW" or "TABLE") like returned fromDatabaseMetaData.getTableTypes()
,null
returns all types of objects- Returns:
- a set of names of objects
- Throws:
Exception
-
getTableTypes
Get the table types of the database. c.f.DatabaseMetaData.getTableTypes()
- Returns:
- the table types
- Throws:
Exception
-
getExportedKeys
Retrieves a description of the foreign key columns that reference the given table's primary key columns (the foreign keys exported by a table).- Parameters:
tablename
- the name of the table- Returns:
- a list of rows. each row is a list of FK_NAME, FK_TABLENAME and FKCOLUMN_NAME
- Throws:
Exception
-
existsConstraint
- Throws:
Exception
-
getImportedKeys
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).- Parameters:
tablename
- the name of the table- Returns:
- a list of rows. each row is a list of FK_NAME, FKCOLUMN_NAME, PKTABLE_NAME and PKCOLUMN_NAME
- Throws:
Exception
-
existsIndex
Returns true if the passed index exists in the current db-schema for the passed table. The names will be transformed into proper case for the check (can be avoided by enclosing them in double quotes).- Parameters:
indexname
- the name of the index to be checked.tablename
- the name of the table to be checked.- Returns:
true
if a the specified index exists in the specified table, elsefalse
- Throws:
Exception
-
getIndexNameForColumns
public static String getIndexNameForColumns(String tablename, String columns, boolean uniqueOnly) throws Exception Returns the name of the index, if one exists for the passed columns of the passed table. The names will be transformed into proper case for the check (can be avoided by enclosing them in double quotes).- Parameters:
columns
- comma separated list of column names.tablename
- the name of the table to be checked.uniqueOnly
- when true, return only indices for unique values; when false, return indices regardless of whether unique or not- Returns:
- the name of the index, if an index for the columns exists in the specified table, else null
- Throws:
Exception
-
getIndexInfo
- Throws:
Exception
-
transformCase
- Throws:
Exception
-
transformCase
-
getMaxTableNameLength
public static int getMaxTableNameLength() -
getMaxConstraintIndexNameLength
public static int getMaxConstraintIndexNameLength() -
mapInterface
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
Get the Persistent class which is implemented by a class with the given classname. e.g. mapsUser
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
-
mapInterfaceToClassName
Get the name of the Persistent class which is implemented by a class with the given classname. e.g. mapsUser
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
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
-
mayBeReferenced
Check, if for this class a foreign key can be defined.- Parameters:
className
- name of a class- Returns:
- Throws:
ClassNotFoundException
-
executeScript
- Throws:
Exception
-
executeScript
public static void executeScript(String content, PrintWriter res, boolean tryAvoid) throws Exception - Throws:
Exception
-
executeSQLFile
- Throws:
Exception
-
executeSQLFile
public static int executeSQLFile(String commands, PrintWriter res, boolean tryAvoid) throws Exception - Throws:
Exception
-
getObject
Returns thePersistent
, if obj is a string like: <classname>:<oid>- Parameters:
obj
- A string like <classname>:<oid>.- Returns:
- The matching
Persistent
-
toString
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, separated by a colon
-
toString
Generates a String representation to identify a persistent object. The result depends on the class of the reference. If a call tohasClassAttribute(Class)
of the referencing evaluates to true, or if the class implements com.groiss.Form, then the oid is prefixed by the class name and a colon, else only the oid is returned.- Parameters:
referencingClass
- the class by which the object is referencedobj
- the persistent object- Returns:
- a String containing the class name of obj and its oid, separated by a colon; or just the 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) -
toEnum
Maps a value to an instance of an Enum class- Type Parameters:
T
- The resulting Enum Type- Parameters:
clazz
- the enum Classvalue
- the value to Map- Returns:
- en Enum of the specified type with the corresponding value, or null
When T extends
DefinedEnum
, the definedValue() is matched against, if not, Enum.name() is matched against (so then it is basically the same asEnum.valueOf(Class, String)
.
-
setFetchsize
public static void setFetchsize(int rows) -
getFetchSize
public static int getFetchSize() -
getDefaultStore
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- a
Store
instance
-
getColumnDefinitions
public static ResultSetMetaData getColumnDefinitions(Class<? extends Persistent> c, String selectList) Determine the ResultSetMetaData for columns of a Persistent class. Might not work for specific databases and / or JDBC drivers. In such a case, null will be returned.- Parameters:
c
- the Persistent classselectList
- the select list. If it is null or empty, then thedbAttrs(Persistent)
is used to determine the select list. By using "*" for the select list, even transient attributes will be considered.- Returns:
- the table definition as ResultSetMetaData
-
toJson
Convert a persistent to JSON. - Null values are written (JSONObect.NULL), - persistents are written as [toString(), classname:oid] - dates are written using getTime() as long- Throws:
Exception
-
createObjectFromJson
Create a persistent object from a json object. -
toMap
Convert a persistent to a Map. - Null values are written (JSONObect.NULL), - persistents are written as JSONObject [toString(), classname:oid] - dates are written using getTime() as long- Throws:
Exception
-
toJsonAsReference
-
toMapAsReference
-
wrapSQLException
Wraps an exception ; tries to discriminate between sql constraint violations and other exceptionswhen sqlexception && sqlstate==23* ==> integrity constraint, (appex 478,e)
when sqlexception && sqlstate!=23* ==> appex(errNum,e)
when appex ==> appex
otherwise: ==> new Appex(errNum,e)
- Parameters:
errNum
-e
-- Returns:
-
getDatabaseMetaData
Retrieves a DatabaseMetaData object that contains metadata about the database to which the store is connected.- Returns:
- a DatabaseMetaData object for this store (for the current connection)
- Throws:
SQLException
- if a database access error occurs
-
oidList
Creates a list of strings of oids from a list of objects. If the objects are of type Persistent, indeed the oid will be used (as string) for the result, otherwise the toString() method will be used.- Parameters:
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.- Returns:
- a list of Strings, each element of the list consists of maximal splitsize elements, separated by a comma
-
createExportKey
Create a unique key for the object. If the class has a key defined, use it, otherwise use oid.- Throws:
Exception
-
checkDataLength
Check the content of the fields of a persistent against the length constraint of the columns in the database. Only columns of type CHAR, VARCHAR and DECIMAL are taken in to account. Will throw an ApplicationException with number 1135 if violations would occur.- Parameters:
o
- the persistent object to check
-
Store.getInstance()