Package org.compiere.model
Class SetGetUtil
- java.lang.Object
-
- org.compiere.model.SetGetUtil
-
public class SetGetUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description SetGetUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
appendValue(SetGetModel model, String columnName, String 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.static boolean
copyValues(SetGetModel to, String from_tableName, int from_id, String[] includeFields)
Copy from the fields to the.static 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
getCtx(Object o)
Get Context from given object.static String
getInfoString(Properties ctx, String tableName, int id, String trxName)
Get Info 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)
static boolean
isPersistent(Object o)
Check if given object is persistent objectstatic boolean
isUserEntry(Object o)
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)
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 the result of the given query.static 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)
static void
updateColumns(SetGetModel model, String[] columnNames, ResultSet rs)
static SetGetModel
wrap(Object o)
Wrap given object (if possible) to SetGetModel
-
-
-
Method Detail
-
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(SetGetModel[], String[], String, Object[], String)
-
updateColumns
public static void updateColumns(SetGetModel model, String[] columnNames, String sql, String 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(SetGetModel[], String[], ResultSet)
-
updateColumns
public static void updateColumns(SetGetModel[] models, String[] columnNames, ResultSet rs) throws SQLException
Update columns from the result of the given query.- 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
- Throws:
SQLException
-
copyValues
public 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).- Returns:
- false if "to" or "from" is null, true otherwise
-
copyChangedValues
public static int copyChangedValues(PO to, PO from)
Copy all values from "from" to "to"- Returns:
- number of columns that were copied and were were also changed in object "from"
- See Also:
copyValues(PO, PO, String[], String[])
-
copyValues
public static boolean copyValues(SetGetModel to, String from_tableName, int from_id, String[] includeFields)
Copy from the fields to the. The two objects do not need to be in the same table.- Parameters:
to
- destination objectfrom_tableName
- source object tablefrom_id
- source object IDincludeFields
- name fields to be excluded, null will be interpreted as String[0];- See Also:
updateColumns(SetGetModel, String[], String, String)
-
get_AttrValueAsInt
public static int get_AttrValueAsInt(SetGetModel model, String name)
Get Value as integer- Parameters:
model
-name
-- Returns:
- int value
-
get_AttrValueAsDate
public static Timestamp get_AttrValueAsDate(SetGetModel model, String name)
Get Value as Timestamp- Parameters:
model
-name
-- Returns:
- Timestamp value
-
get_AttrValueAsBigDecimal
public static BigDecimal get_AttrValueAsBigDecimal(SetGetModel model, String name)
Get Value as BigDecimal- Parameters:
model
-name
-- Returns:
- BigDecimal or
BigDecimal.ZERO
-
get_AttrValueAsBoolean
public static boolean get_AttrValueAsBoolean(SetGetModel model, String name)
Get Value as Boolean- Parameters:
model
-name
-- Returns:
- boolean value
-
get_AttrValueAsString
public static String get_AttrValueAsString(SetGetModel model, String name, String valueIfNull)
Get Value as String- Parameters:
model
-name
-valueIfNull
- value that will be returned if the value is null- Returns:
- String value
-
set_AttrValueEx
public static void set_AttrValueEx(SetGetModel model, String name, Object value)
Set Attribute Value- Parameters:
model
-name
-value
-- Throws:
AdempiereException
- if it can not be set (error setting, attribute/column name not found).
-
is_ValueChanged
public static boolean is_ValueChanged(SetGetModel model, String... propertyNames)
- Parameters:
model
-propertyNames
-- Returns:
- true if ANY of given properties had changed
-
getTrxName
public static String getTrxName(Object o)
Get TrxName for given object.- Parameters:
o
-- Returns:
- trxName or null
-
isUserEntry
public static boolean isUserEntry(Object o)
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
public static void setLineNo(SetGetModel model, String parentColumnName, String lineColumnName)
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
public static String getTableName(Class<? extends PO> clazz)
Get Table_Name for given PO class- Parameters:
clazz
-- Returns:
- tableName
- Throws:
AdempiereException
- if no table name found or any other exception occurs
-
isPersistent
public static final boolean isPersistent(Object o)
Check if given object is persistent object- Parameters:
o
- object- Returns:
- true if is persistent (i.e. instanceof PO)
-
getCtx
public static Properties getCtx(Object o)
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
public static SetGetModel wrap(Object o)
Wrap given object (if possible) to SetGetModel- Parameters:
o
- object- Returns:
- object wrapped to SetGetModel
-
newInstance
public static <T> T newInstance(Properties ctx, Class<T> clazz, String trxName)
-
appendValue
public static void appendValue(SetGetModel model, String columnName, String value)
-
getInfoString
public static String getInfoString(Properties ctx, String tableName, int id, String trxName)
Get Info for given table and ID. This method callsto generate the info string.
- Parameters:
ctx
- contexttableName
- tablenameid
- record idtrxName
-- Returns:
- record description
-
-