Package org.compiere.model
Class SetGetUtil
java.lang.Object
org.compiere.model.SetGetUtil
Static utility methods for working with
SetGetModel
interface-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendValue
(SetGetModel model, String columnName, String value) Append value to column (with " | " as separator between existing value and "value")static int
copyChangedValues
(PO to, PO from) Copy all values from "from" to "to"static boolean
copyValues
(PO to, PO from, String[] includeFields, String[] excludeFields) Copy from the fields to.
The second object is not required to be in the same table.
The following fields are not copied: AD_Client_ID, AD_Org_ID, Created% Updated% IsActive.
If excludeFields includeFields and are null, then it will copy all the fields (which can be copied).static boolean
copyValues
(SetGetModel to, String from_tableName, int from_id, String[] includeFields) Update "to" with values from querystatic BigDecimal
get_AttrValueAsBigDecimal
(SetGetModel model, String name) Get Value as BigDecimalstatic boolean
get_AttrValueAsBoolean
(SetGetModel model, String name) Get Value as Booleanstatic Timestamp
get_AttrValueAsDate
(SetGetModel model, String name) Get Value as Timestampstatic int
get_AttrValueAsInt
(SetGetModel model, String name) Get Value as integerstatic String
get_AttrValueAsString
(SetGetModel model, String name, String valueIfNull) Get Value as Stringstatic Properties
Get Context from given object.static String
getInfoString
(Properties ctx, String tableName, int id, String trxName) Get Info text for given table and ID.static String
getTableName
(Class<? extends PO> clazz) Get Table_Name for given PO classstatic String
getTrxName
(Object o) Get TrxName for given object.static boolean
is_ValueChanged
(SetGetModel model, String... propertyNames) Is any of the column changestatic final boolean
Check if given object is persistent objectstatic boolean
Check if given object was produced by used entry (i.e. created from a window)static <T> T
newInstance
(Properties ctx, Class<T> clazz, String trxName) Create new instance of "clazz" with the (ctx, 0, trxName) constructor.static void
set_AttrValueEx
(SetGetModel model, String name, Object value) Set Attribute Valuestatic void
setLineNo
(SetGetModel model, String parentColumnName, String lineColumnName) Set model's Line#static void
updateColumns
(SetGetModel[] models, String[] columnNames, String sql, Object[] params, String trxName) Update columns from the result of the given query.static void
updateColumns
(SetGetModel[] models, String[] columnNames, ResultSet rs) Update columns from result setstatic void
updateColumns
(SetGetModel model, String[] columnNames, String sql, Object[] params, String trxName) Update columns from the result of the given query.static void
updateColumns
(SetGetModel model, String[] columnNames, String sql, String trxName) Update columns from the result of the given query.static void
updateColumns
(SetGetModel model, String[] columnNames, ResultSet rs) Update columns from first row of result setstatic SetGetModel
Wrap given object (if possible) to SetGetModel
-
Constructor Details
-
SetGetUtil
public SetGetUtil()
-
-
Method Details
-
updateColumns
public static void updateColumns(SetGetModel model, String[] columnNames, String sql, Object[] params, String trxName) Update columns from the result of the given query.If the query returns more than one row, only the first row will be used.
This is a simplified version of
updateColumns(SetGetModel[], String[], String, Object[], String)
which calls:updateColumns(new SetGetModel[]{model}, columnNames, query, trxName);
- Parameters:
model
-columnNames
- column names; if null, all columns from given query are used; if a columnName from array is null it will be ignoredsql
- sql queryparams
- sql parameterstrxName
-- See Also:
-
updateColumns
public static void updateColumns(SetGetModel model, String[] columnNames, String sql, String trxName) Update columns from the result of the given query.- Parameters:
model
-columnNames
-sql
-trxName
-
-
updateColumns
public static void updateColumns(SetGetModel[] models, String[] columnNames, String sql, Object[] params, String trxName) Update columns from the result of the given query.- Parameters:
models
-columnNames
-sql
-params
-trxName
-- See Also:
-
updateColumns
public static void updateColumns(SetGetModel[] models, String[] columnNames, ResultSet rs) throws SQLException Update columns from result set- Parameters:
models
-columnNames
- column names; if null, all columns from given query are used; if a columnName from array is null it will be ignoredrs
-- Throws:
SQLException
-
updateColumns
public static void updateColumns(SetGetModel model, String[] columnNames, ResultSet rs) throws SQLException Update columns from first row of result set- Parameters:
model
-columnNames
-rs
-- Throws:
SQLException
-
copyValues
Copy from the fields to.
The second object is not required to be in the same table.
The following fields are not copied: AD_Client_ID, AD_Org_ID, Created% Updated% IsActive.
If excludeFields includeFields and are null, then it will copy all the fields (which can be copied).- Parameters:
to
- destination objectfrom
- sourceincludeFields
- name fields to be excluded; null will be interpreted as String [0]; excludeFields includeFields and mutually exclusive, priority being includeFields; If includeFields excludeFields are null and then copy all fieldsexcludeFields
- name fields to be excluded, null will be interpreted as String [0]- Returns:
- false if "to" or "from" is null, true otherwise
-
copyChangedValues
Copy all values from "from" to "to"- Returns:
- number of columns that were copied and were also changed in object "from"
- See Also:
-
copyValues
public static boolean copyValues(SetGetModel to, String from_tableName, int from_id, String[] includeFields) Update "to" with values from query- Parameters:
to
- destination objectfrom_tableName
- source table to query fromfrom_id
- source record IDincludeFields
- name fields to be excluded, null will be interpreted as String[0];- See Also:
-
get_AttrValueAsInt
Get Value as integer- Parameters:
model
-name
- column name- Returns:
- int value
-
get_AttrValueAsDate
Get Value as Timestamp- Parameters:
model
-name
- column name- Returns:
- Timestamp value
-
get_AttrValueAsBigDecimal
Get Value as BigDecimal- Parameters:
model
-name
- column name- Returns:
- BigDecimal or
BigDecimal.ZERO
-
get_AttrValueAsBoolean
Get Value as Boolean- Parameters:
model
-name
- column name- Returns:
- boolean value
-
get_AttrValueAsString
Get Value as String- Parameters:
model
-name
- column namevalueIfNull
- value that will be returned if the value is null- Returns:
- String value
-
set_AttrValueEx
Set Attribute Value- Parameters:
model
-name
- column namevalue
-- Throws:
AdempiereException
- if it can not be set (error setting, attribute/column name not found).
-
is_ValueChanged
Is any of the column change- Parameters:
model
-propertyNames
-- Returns:
- true if ANY of given columns had changed
-
getTrxName
Get TrxName for given object.- Parameters:
o
-- Returns:
- trxName or null
-
isUserEntry
Check if given object was produced by used entry (i.e. created from a window)- Parameters:
o
- object- Returns:
- If object is instanceof PO then ... If object is null then false will be returned. Else true will be returned.
-
setLineNo
Set model's Line#- Parameters:
model
-parentColumnName
- parent column name; if null then it won't be usedlineColumnName
- line column name; if null "Line" will be used
-
getTableName
Get Table_Name for given PO class- Parameters:
clazz
-- Returns:
- tableName
- Throws:
AdempiereException
- if no table name found or any other exception occurs
-
isPersistent
Check if given object is persistent object- Parameters:
o
- object- Returns:
- true if is persistent (i.e. instanceof PO)
-
getCtx
Get Context from given object. If object is null, null will be returned. If object does not have getCtx() support then Env.getCtx() will be returned.- Parameters:
o
- object- Returns:
- context or null(if object is null)
-
wrap
Wrap given object (if possible) to SetGetModel- Parameters:
o
- object- Returns:
- object wrapped to SetGetModel
-
newInstance
Create new instance of "clazz" with the (ctx, 0, trxName) constructor.- Type Parameters:
T
-- Parameters:
ctx
-clazz
-trxName
-- Returns:
- new instance of "clazz"
-
appendValue
Append value to column (with " | " as separator between existing value and "value")- Parameters:
model
-columnName
-value
-
-
getInfoString
Get Info text for given table and ID.
This method callsMLookupFactory.getLookup_TableDirEmbed(Language, String, String, String)
to generate the info text.- Parameters:
ctx
- contexttableName
- tablenameid
- record idtrxName
-- Returns:
- record description
-