/org.adempiere.base/src/org/compiere/model/PO.java
Java | 4737 lines | 3385 code | 295 blank | 1057 comment | 1081 complexity | a1e28fef5a408d013f14412b0a13ea0f MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /******************************************************************************
- * Product: Adempiere ERP & CRM Smart Business Solution *
- * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
- * This program is free software; you can redistribute it and/or modify it *
- * under the terms version 2 of the GNU General Public License as published *
- * by the Free Software Foundation. This program is distributed in the hope *
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- * See the GNU General Public License for more details. *
- * You should have received a copy of the GNU General Public License along *
- * with this program; if not, write to the Free Software Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
- * For the text or an alternative of this public license, you may reach us *
- * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
- * or via info@compiere.org or http://www.compiere.org/license.html *
- *****************************************************************************/
- package org.compiere.model;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.Serializable;
- import java.io.StringWriter;
- import java.math.BigDecimal;
- import java.sql.Blob;
- import java.sql.Clob;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Savepoint;
- import java.sql.Timestamp;
- import java.text.Collator;
- import java.util.ArrayList;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Properties;
- import java.util.UUID;
- import java.util.logging.Level;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javax.xml.transform.Transformer;
- import javax.xml.transform.TransformerFactory;
- import javax.xml.transform.dom.DOMSource;
- import javax.xml.transform.stream.StreamResult;
- import org.adempiere.base.event.EventManager;
- import org.adempiere.base.event.IEventTopics;
- import org.adempiere.exceptions.AdempiereException;
- import org.adempiere.exceptions.DBException;
- import org.adempiere.process.UUIDGenerator;
- import org.compiere.Adempiere;
- import org.compiere.acct.Doc;
- import org.compiere.util.CCache;
- import org.compiere.util.CLogMgt;
- import org.compiere.util.CLogger;
- import org.compiere.util.CacheMgt;
- import org.compiere.util.DB;
- import org.compiere.util.DisplayType;
- import org.compiere.util.Env;
- import org.compiere.util.Evaluatee;
- import org.compiere.util.Ini;
- import org.compiere.util.Language;
- import org.compiere.util.Msg;
- import org.compiere.util.SecureEngine;
- import org.compiere.util.Trace;
- import org.compiere.util.Trx;
- import org.compiere.util.ValueNamePair;
- import org.osgi.service.event.Event;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- /**
- * Persistent Object.
- * Superclass for actual implementations
- *
- * @author Jorg Janke
- * @version $Id: PO.java,v 1.12 2006/08/09 16:38:47 jjanke Exp $
- *
- * @author Teo Sarca, SC ARHIPAC SERVICE SRL
- * <li>FR [ 1675490 ] ModelValidator on modelChange after events
- * <li>BF [ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent
- * <li>FR [ 1720995 ] Add PO.saveEx() and PO.deleteEx() methods
- * <li>BF [ 1990856 ] PO.set_Value* : truncate string more than needed
- * <li>FR [ 2042844 ] PO.get_Translation improvements
- * <li>FR [ 2818369 ] Implement PO.get_ValueAs*(columnName)
- * https://sourceforge.net/tracker/?func=detail&aid=2818369&group_id=176962&atid=879335
- * <li>BF [ 2849122 ] PO.AfterSave is not rollback on error
- * https://sourceforge.net/tracker/?func=detail&aid=2849122&group_id=176962&atid=879332
- * <li>BF [ 2859125 ] Can't set AD_OrgBP_ID
- * https://sourceforge.net/tracker/index.php?func=detail&aid=2859125&group_id=176962&atid=879332
- * <li>BF [ 2866493 ] VTreePanel is not saving who did the node move
- * https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2866493&group_id=176962
- * @author Teo Sarca, teo.sarca@gmail.com
- * <li>BF [ 2876259 ] PO.insertTranslation query is not correct
- * https://sourceforge.net/tracker/?func=detail&aid=2876259&group_id=176962&atid=879332
- * @author Victor Perez, e-Evolution SC
- * <li>[ 2195894 ] Improve performance in PO engine
- * <li>http://sourceforge.net/tracker/index.php?func=detail&aid=2195894&group_id=176962&atid=879335
- * <li>BF [2947622] The replication ID (Primary Key) is not working
- * <li>https://sourceforge.net/tracker/?func=detail&aid=2947622&group_id=176962&atid=879332
- */
- public abstract class PO
- implements Serializable, Comparator<Object>, Evaluatee, Cloneable
- {
- /**
- *
- */
- private static final long serialVersionUID = -2997116608353367498L;
- public static final String LOCAL_TRX_PREFIX = "POSave";
- private static final String USE_TIMEOUT_FOR_UPDATE = "org.adempiere.po.useTimeoutForUpdate";
- /** default timeout, 300 seconds **/
- private static final int QUERY_TIME_OUT = 300;
- /**
- * Set Document Value Workflow Manager
- * @param docWFMgr mgr
- */
- public static void setDocWorkflowMgr (DocWorkflowMgr docWFMgr)
- {
- s_docWFMgr = docWFMgr;
- s_log.config (s_docWFMgr.toString());
- } // setDocWorkflowMgr
- /** Document Value Workflow Manager */
- private static DocWorkflowMgr s_docWFMgr = null;
- /** User Maintained Entity Type */
- static public final String ENTITYTYPE_UserMaintained = "U";
- /** Dictionary Maintained Entity Type */
- static public final String ENTITYTYPE_Dictionary = "D";
- /**************************************************************************
- * Create New Persistent Object
- * @param ctx context
- */
- public PO (Properties ctx)
- {
- this (ctx, 0, null, null);
- } // PO
- /**
- * Create & Load existing Persistent Object
- * @param ID The unique ID of the object
- * @param ctx context
- * @param trxName transaction name
- */
- public PO (Properties ctx, int ID, String trxName)
- {
- this (ctx, ID, trxName, null);
- } // PO
- /**
- * Create & Load existing Persistent Object.
- * @param ctx context
- * @param rs optional - load from current result set position (no navigation, not closed)
- * if null, a new record is created.
- * @param trxName transaction name
- */
- public PO (Properties ctx, ResultSet rs, String trxName)
- {
- this (ctx, 0, trxName, rs);
- } // PO
- /**
- * Create & Load existing Persistent Object.
- * <pre>
- * You load
- * - an existing single key record with new PO (ctx, Record_ID)
- * or new PO (ctx, Record_ID, trxName)
- * or new PO (ctx, rs, get_TrxName())
- * - a new single key record with new PO (ctx, 0)
- * - an existing multi key record with new PO (ctx, rs, get_TrxName())
- * - a new multi key record with new PO (ctx, null)
- * The ID for new single key records is created automatically,
- * you need to set the IDs for multi-key records explicitly.
- * </pre>
- * @param ctx context
- * @param ID the ID if 0, the record defaults are applied - ignored if re exists
- * @param trxName transaction name
- * @param rs optional - load from current result set position (no navigation, not closed)
- */
- public PO (Properties ctx, int ID, String trxName, ResultSet rs)
- {
- p_ctx = ctx != null ? ctx : Env.getCtx();
- m_trxName = trxName;
- p_info = initPO(ctx);
- if (p_info == null || p_info.getTableName() == null)
- throw new IllegalArgumentException ("Invalid PO Info - " + p_info);
- //
- int size = p_info.getColumnCount();
- m_oldValues = new Object[size];
- m_newValues = new Object[size];
- m_setErrors = new ValueNamePair[size];
- if (rs != null)
- load(rs); // will not have virtual columns
- else
- load(ID, trxName);
- } // PO
- /**
- * Create New PO by Copying existing (key not copied).
- * @param ctx context
- * @param source source object
- * @param AD_Client_ID client
- * @param AD_Org_ID org
- */
- public PO (Properties ctx, PO source, int AD_Client_ID, int AD_Org_ID)
- {
- this (ctx, 0, null, null); // create new
- //
- if (source != null)
- copyValues (source, this);
- setAD_Client_ID(AD_Client_ID);
- setAD_Org_ID(AD_Org_ID);
- } // PO
- /** Logger */
- protected transient CLogger log = CLogger.getCLogger (getClass());
- /** Static Logger */
- private static CLogger s_log = CLogger.getCLogger (PO.class);
- /** Context */
- protected Properties p_ctx;
- /** Model Info */
- protected volatile POInfo p_info = null;
- /** Original Values */
- private Object[] m_oldValues = null;
- /** New Values */
- private Object[] m_newValues = null;
- /** Errors when setting */
- private ValueNamePair[] m_setErrors = null;
- /** Record_IDs */
- private Object[] m_IDs = new Object[] {I_ZERO};
- /** Key Columns */
- private String[] m_KeyColumns = null;
- /** Create New for Multi Key */
- private boolean m_createNew = false;
- /** Attachment with entries */
- private MAttachment m_attachment = null;
- /** Deleted ID */
- private int m_idOld = 0;
- /** Custom Columns */
- private HashMap<String,String> m_custom = null;
- /** Attributes */
- private HashMap<String,Object> m_attributes = null;
- /** Zero Integer */
- protected static final Integer I_ZERO = new Integer(0);
- /** Accounting Columns */
- private ArrayList <String> s_acctColumns = null;
- /** Trifon - Indicates that this record is created by replication functionality.*/
- private boolean m_isReplication = false;
- /** Access Level S__ 100 4 System info */
- public static final int ACCESSLEVEL_SYSTEM = 4;
- /** Access Level _C_ 010 2 Client info */
- public static final int ACCESSLEVEL_CLIENT = 2;
- /** Access Level __O 001 1 Organization info */
- public static final int ACCESSLEVEL_ORG = 1;
- /** Access Level SCO 111 7 System shared info */
- public static final int ACCESSLEVEL_ALL = 7;
- /** Access Level SC_ 110 6 System/Client info */
- public static final int ACCESSLEVEL_SYSTEMCLIENT = 6;
- /** Access Level _CO 011 3 Client shared info */
- public static final int ACCESSLEVEL_CLIENTORG = 3;
- /**
- * Initialize and return PO_Info
- * @param ctx context
- * @return POInfo
- */
- abstract protected POInfo initPO (Properties ctx);
- /**
- * Get Table Access Level
- * @return Access Level
- */
- abstract protected int get_AccessLevel();
- /**
- * String representation
- * @return String representation
- */
- public String toString()
- {
- StringBuilder sb = new StringBuilder("PO[")
- .append(get_WhereClause(true)).append("]");
- return sb.toString();
- } // toString
- /**
- * Equals based on ID
- * @param cmp comparator
- * @return true if ID the same
- */
- public boolean equals (Object cmp)
- {
- if (cmp == null)
- return false;
- if (!(cmp instanceof PO))
- return false;
- if (cmp.getClass().equals(this.getClass()))
- // if both ID's are zero they can't be compared by ID
- if (((PO)cmp).get_ID() == 0 && get_ID() == 0)
- return super.equals(cmp);
- else
- return ((PO)cmp).get_ID() == get_ID();
- return super.equals(cmp);
- } // equals
-
- public int hashCode()
- {
- assert false : "hashCode not designed";
- return 42; // any arbitrary constant will do
- }
- /**
- * Compare based on DocumentNo, Value, Name, Description
- * @param o1 Object 1
- * @param o2 Object 2
- * @return -1 if o1 < o2
- */
- public int compare (Object o1, Object o2)
- {
- if (o1 == null)
- return -1;
- else if (o2 == null)
- return 1;
- if (!(o1 instanceof PO))
- throw new ClassCastException ("Not PO -1- " + o1);
- if (!(o2 instanceof PO))
- throw new ClassCastException ("Not PO -2- " + o2);
- // same class
- Collator collator = Collator.getInstance();
- if (o1.getClass().equals(o2.getClass()))
- {
- int index = get_ColumnIndex("DocumentNo");
- if (index == -1)
- index = get_ColumnIndex("Value");
- if (index == -1)
- index = get_ColumnIndex("Name");
- if (index == -1)
- index = get_ColumnIndex("Description");
- if (index != -1)
- {
- PO po1 = (PO)o1;
- Object comp1 = po1.get_Value(index);
- PO po2 = (PO)o2;
- Object comp2 = po2.get_Value(index);
- if (comp1 == null)
- return -1;
- else if (comp2 == null)
- return 1;
- return collator.compare(comp1.toString(), comp2.toString());
- }
- }
- return collator.compare(o1.toString(), o2.toString());
- } // compare
- /**
- * Get TableName.
- * @return table name
- */
- public String get_TableName()
- {
- return p_info.getTableName();
- } // get_TableName
- /**
- * Get Key Columns.
- * @return table name
- */
- public String[] get_KeyColumns()
- {
- return m_KeyColumns;
- } // get_KeyColumns
- /**
- * Get Table ID.
- * @return table id
- */
- public int get_Table_ID()
- {
- return p_info.getAD_Table_ID();
- } // get_TableID
- /**
- * Return Single Key Record ID
- * @return ID or 0
- */
- public int get_ID()
- {
- Object oo = m_IDs[0];
- if (oo != null && oo instanceof Integer)
- return ((Integer)oo).intValue();
- return 0;
- } // getID
- /**
- * Return Deleted Single Key Record ID
- * @return ID or 0
- */
- public int get_IDOld()
- {
- return m_idOld;
- } // getID
- /**
- * Get Context
- * @return context
- */
- public Properties getCtx()
- {
- return p_ctx;
- } // getCtx
- /**
- * Get Logger
- * @return logger
- */
- public CLogger get_Logger()
- {
- return log;
- } // getLogger
- /**************************************************************************
- * Get Value
- * @param index index
- * @return value
- */
- public final Object get_Value (int index)
- {
- if (index < 0 || index >= get_ColumnCount())
- {
- log.log(Level.WARNING, "Index invalid - " + index);
- return null;
- }
- if (m_newValues[index] != null)
- {
- if (m_newValues[index].equals(Null.NULL))
- return null;
- return m_newValues[index];
- }
- return m_oldValues[index];
- } // get_Value
- /**
- * Get Value as int
- * @param index index
- * @return int value or 0
- */
- public int get_ValueAsInt (int index)
- {
- Object value = get_Value(index);
- if (value == null)
- return 0;
- if (value instanceof Integer)
- return ((Integer)value).intValue();
- try
- {
- return Integer.parseInt(value.toString());
- }
- catch (NumberFormatException ex)
- {
- log.warning(p_info.getColumnName(index) + " - " + ex.getMessage());
- return 0;
- }
- } // get_ValueAsInt
- /**
- * Get Value
- * @param columnName column name
- * @return value or null
- */
- public final Object get_Value (String columnName)
- {
- int index = get_ColumnIndex(columnName);
- if (index < 0)
- {
- log.log(Level.WARNING, "Column not found - " + columnName);
- Trace.printStack();
- return null;
- }
- return get_Value (index);
- } // get_Value
- /**
- * Get Encrypted Value
- * @param columnName column name
- * @return value or null
- */
- protected final Object get_ValueE (String columnName)
- {
- return get_Value (columnName);
- } // get_ValueE
- /**
- * Get Column Value
- * @param variableName name
- * @return value or ""
- */
- public String get_ValueAsString (String variableName)
- {
- Object value = get_Value (variableName);
- if (value == null)
- return "";
- return value.toString();
- } // get_ValueAsString
- /**
- * Get Value of Column
- * @param AD_Column_ID column
- * @return value or null
- */
- public final Object get_ValueOfColumn (int AD_Column_ID)
- {
- int index = p_info.getColumnIndex(AD_Column_ID);
- if (index < 0)
- {
- log.log(Level.WARNING, "Not found - AD_Column_ID=" + AD_Column_ID);
- return null;
- }
- return get_Value (index);
- } // get_ValueOfColumn
- /**
- * Get Old Value
- * @param index index
- * @return value
- */
- public final Object get_ValueOld (int index)
- {
- if (index < 0 || index >= get_ColumnCount())
- {
- log.log(Level.WARNING, "Index invalid - " + index);
- return null;
- }
- return m_oldValues[index];
- } // get_ValueOld
- /**
- * Get Old Value
- * @param columnName column name
- * @return value or null
- */
- public final Object get_ValueOld (String columnName)
- {
- int index = get_ColumnIndex(columnName);
- if (index < 0)
- {
- log.log(Level.WARNING, "Column not found - " + columnName);
- return null;
- }
- return get_ValueOld (index);
- } // get_ValueOld
- /**
- * Get Old Value as int
- * @param columnName column name
- * @return int value or 0
- */
- public int get_ValueOldAsInt (String columnName)
- {
- Object value = get_ValueOld(columnName);
- if (value == null)
- return 0;
- if (value instanceof Integer)
- return ((Integer)value).intValue();
- try
- {
- return Integer.parseInt(value.toString());
- }
- catch (NumberFormatException ex)
- {
- log.warning(columnName + " - " + ex.getMessage());
- return 0;
- }
- } // get_ValueOldAsInt
- /**
- * Is Value Changed
- * @param index index
- * @return true if changed
- */
- public final boolean is_ValueChanged (int index)
- {
- if (index < 0 || index >= get_ColumnCount())
- {
- log.log(Level.WARNING, "Index invalid - " + index);
- return false;
- }
- if (m_newValues[index] == null)
- return false;
- if (m_newValues[index] == Null.NULL && m_oldValues[index] == null)
- return false;
- return !m_newValues[index].equals(m_oldValues[index]);
- } // is_ValueChanged
- /**
- * Is Value Changed
- * @param columnName column name
- * @return true if changed
- */
- public final boolean is_ValueChanged (String columnName)
- {
- int index = get_ColumnIndex(columnName);
- if (index < 0)
- {
- log.log(Level.WARNING, "Column not found - " + columnName);
- return false;
- }
- return is_ValueChanged (index);
- } // is_ValueChanged
- /**
- * Return new - old.
- * - New Value if Old Value is null
- * - New Value - Old Value if Number
- * - otherwise null
- * @param index index
- * @return new - old or null if not appropriate or not changed
- */
- public final Object get_ValueDifference (int index)
- {
- if (index < 0 || index >= get_ColumnCount())
- {
- log.log(Level.WARNING, "Index invalid - " + index);
- return null;
- }
- Object nValue = m_newValues[index];
- // No new Value or NULL
- if (nValue == null || nValue == Null.NULL)
- return null;
- //
- Object oValue = m_oldValues[index];
- if (oValue == null || oValue == Null.NULL)
- return nValue;
- if (nValue instanceof BigDecimal)
- {
- BigDecimal obd = (BigDecimal)oValue;
- return ((BigDecimal)nValue).subtract(obd);
- }
- else if (nValue instanceof Integer)
- {
- int result = ((Integer)nValue).intValue();
- result -= ((Integer)oValue).intValue();
- return new Integer(result);
- }
- //
- log.warning("Invalid type - New=" + nValue);
- return null;
- } // get_ValueDifference
- /**
- * Return new - old.
- * - New Value if Old Value is null
- * - New Value - Old Value if Number
- * - otherwise null
- * @param columnName column name
- * @return new - old or null if not appropriate or not changed
- */
- public final Object get_ValueDifference (String columnName)
- {
- int index = get_ColumnIndex(columnName);
- if (index < 0)
- {
- log.log(Level.WARNING, "Column not found - " + columnName);
- return null;
- }
- return get_ValueDifference (index);
- } // get_ValueDifference
- /**************************************************************************
- * Set Value
- * @param ColumnName column name
- * @param value value
- * @return true if value set
- */
- protected final boolean set_Value (String ColumnName, Object value)
- {
- return set_Value(ColumnName, value, true);
- }
-
- /**************************************************************************
- * Set Value
- * @param ColumnName column name
- * @param value value
- * @param checkWritable
- * @return true if value set
- */
- protected final boolean set_Value (String ColumnName, Object value, boolean checkWritable)
- {
- if (value instanceof String && ColumnName.equals("WhereClause")
- && value.toString().toUpperCase().indexOf("=NULL") != -1)
- log.warning("Invalid Null Value - " + ColumnName + "=" + value);
- int index = get_ColumnIndex(ColumnName);
- if (index < 0)
- {
- log.log(Level.SEVERE, "Column not found - " + ColumnName);
- log.saveError("ColumnNotFound", "Column not found - " + ColumnName);
- return false;
- }
- if (ColumnName.endsWith("_ID") && value instanceof String )
- {
- // Convert to Integer only if info class is Integer - teo_sarca [ 2859125 ]
- Class<?> clazz = p_info.getColumnClass(p_info.getColumnIndex(ColumnName));
- if (Integer.class == clazz)
- {
- log.severe("Invalid Data Type for " + ColumnName + "=" + value);
- value = Integer.parseInt((String)value);
- }
- }
- return set_Value (index, value, checkWritable);
- } // setValue
- /**
- * Set Encrypted Value
- * @param ColumnName column name
- * @param value value
- * @return true if value set
- */
- protected final boolean set_ValueE (String ColumnName, Object value)
- {
- return set_Value (ColumnName, value);
- } // setValueE
- /**
- * Set Value if updateable and correct class.
- * (and to NULL if not mandatory)
- * @param index index
- * @param value value
- * @return true if value set
- */
- protected final boolean set_Value (int index, Object value)
- {
- return set_Value(index, value, true);
- }
-
- /**
- * Set Value if updateable and correct class.
- * (and to NULL if not mandatory)
- * @param index index
- * @param value value
- * @param checkWritable
- * @return true if value set
- */
- protected final boolean set_Value (int index, Object value, boolean checkWritable)
- {
- if (index < 0 || index >= get_ColumnCount())
- {
- log.log(Level.WARNING, "Index invalid - " + index);
- return false;
- }
- String ColumnName = p_info.getColumnName(index);
- String colInfo = " - " + ColumnName;
- //
- m_setErrors[index] = null;
- if (checkWritable)
- {
- if (p_info.isVirtualColumn(index))
- {
- log.log(Level.WARNING, "Virtual Column" + colInfo);
- log.saveError("VirtualColumn", "Virtual Column" + colInfo);
- m_setErrors[index] = new ValueNamePair("VirtualColumn", "Virtual Column" + colInfo);
- return false;
- }
-
- //
- // globalqss -- Bug 1618469 - is throwing not updateable even on new records
- // if (!p_info.isColumnUpdateable(index))
- if ( ( ! p_info.isColumnUpdateable(index) ) && ( ! is_new() ) )
- {
- colInfo += " - NewValue=" + value + " - OldValue=" + get_Value(index);
- log.log(Level.WARNING, "Column not updateable" + colInfo);
- log.saveError("ColumnReadonly", "Column not updateable" + colInfo);
- m_setErrors[index] = new ValueNamePair("ColumnReadonly", "Column not updateable" + colInfo);
- return false;
- }
- }
- //
- if (value == null)
- {
- if (checkWritable && p_info.isColumnMandatory(index))
- {
- log.saveError("FillMandatory", ColumnName + " is mandatory.");
- m_setErrors[index] = new ValueNamePair("FillMandatory", ColumnName + " is mandatory.");
- return false;
- }
- m_newValues[index] = Null.NULL; // correct
- if (log.isLoggable(Level.FINER)) log.finer(ColumnName + " = null");
- }
- else
- {
- // matching class or generic object
- if (value.getClass().equals(p_info.getColumnClass(index))
- || p_info.getColumnClass(index) == Object.class)
- m_newValues[index] = value; // correct
- // Integer can be set as BigDecimal
- else if (value.getClass() == BigDecimal.class
- && p_info.getColumnClass(index) == Integer.class)
- m_newValues[index] = new Integer (((BigDecimal)value).intValue());
- // Set Boolean
- else if (p_info.getColumnClass(index) == Boolean.class
- && ("Y".equals(value) || "N".equals(value)) )
- m_newValues[index] = new Boolean("Y".equals(value));
- // added by vpj-cd
- // To solve BUG [ 1618423 ] Set Project Type button in Project window throws warning
- // generated because C_Project.C_Project_Type_ID is defined as button in dictionary
- // although is ID (integer) in database
- else if (value.getClass() == Integer.class
- && p_info.getColumnClass(index) == String.class)
- m_newValues[index] = value;
- else if (value.getClass() == String.class
- && p_info.getColumnClass(index) == Integer.class)
- try
- {
- m_newValues[index] = new Integer((String)value);
- }
- catch (NumberFormatException e)
- {
- String errmsg = ColumnName
- + " - Class invalid: " + value.getClass().toString()
- + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value;
- log.log(Level.SEVERE, errmsg);
- log.saveError("WrongDataType", errmsg);
- m_setErrors[index] = new ValueNamePair("WrongDataType", errmsg);
- return false;
- }
- else
- {
- String errmsg = ColumnName
- + " - Class invalid: " + value.getClass().toString()
- + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value;
- log.log(Level.SEVERE, errmsg);
- log.saveError("WrongDataType", errmsg);
- m_setErrors[index] = new ValueNamePair("WrongDataType", errmsg);
- return false;
- }
- // Validate (Min/Max)
- String error = p_info.validate(index, value);
- if (error != null)
- {
- log.log(Level.WARNING, ColumnName + "=" + value + " - " + error);
- int separatorIndex = error.indexOf(";");
- if (separatorIndex > 0) {
- log.saveError(error.substring(0,separatorIndex), error.substring(separatorIndex+1));
- m_setErrors[index] = new ValueNamePair(error.substring(0,separatorIndex), error.substring(separatorIndex+1));
- } else {
- log.saveError(error, ColumnName);
- m_setErrors[index] = new ValueNamePair(error, ColumnName);
- }
- return false;
- }
- // Length for String
- if (p_info.getColumnClass(index) == String.class)
- {
- String stringValue = value.toString();
- int length = p_info.getFieldLength(index);
- if (stringValue.length() > length && length > 0)
- {
- log.warning(ColumnName + " - Value too long - truncated to length=" + length);
- m_newValues[index] = stringValue.substring(0,length);
- }
- }
- // Validate reference list [1762461]
- if (p_info.getColumn(index).DisplayType == DisplayType.List &&
- p_info.getColumn(index).AD_Reference_Value_ID > 0 &&
- value instanceof String) {
- if (MRefList.get(getCtx(), p_info.getColumn(index).AD_Reference_Value_ID,
- (String) value, get_TrxName()) != null)
- ;
- else {
- StringBuilder validValues = new StringBuilder();
- for (ValueNamePair vp : MRefList.getList(getCtx(), p_info.getColumn(index).AD_Reference_Value_ID, false))
- validValues.append(" - ").append(vp.getValue());
- String errmsg = ColumnName + " Invalid value - "
- + value + " - Reference_ID=" + p_info.getColumn(index).AD_Reference_Value_ID + validValues.toString();
- log.saveError("Validate", errmsg);
- m_setErrors[index] = new ValueNamePair("Validate", errmsg);
- return false;
- }
- }
- if (log.isLoggable(Level.FINEST)) log.finest(ColumnName + " = " + m_newValues[index] + " (OldValue="+m_oldValues[index]+")");
- }
- set_Keys (ColumnName, m_newValues[index]);
- // FR 2962094 Fill ProcessedOn when the Processed column is changing from N to Y
- setProcessedOn(ColumnName, value, m_oldValues[index]);
- return true;
- } // setValue
- /* FR 2962094 - Finish implementation of weighted average costing
- Fill the column ProcessedOn (if it exists) with a bigdecimal representation of current timestamp (with nanoseconds)
- */
- public void setProcessedOn(String ColumnName, Object value, Object oldValue) {
- if ("Processed".equals(ColumnName)
- && value instanceof Boolean
- && ((Boolean)value).booleanValue() == true
- && (oldValue == null
- || (oldValue instanceof Boolean
- && ((Boolean)oldValue).booleanValue() == false))) {
- if (get_ColumnIndex("ProcessedOn") > 0) {
- // fill processed on column
- //get current time from db
- Timestamp ts = DB.getSQLValueTS(null, "SELECT CURRENT_TIMESTAMP FROM DUAL");
- long mili = ts.getTime();
- int nano = ts.getNanos();
- double doublets = Double.parseDouble(Long.toString(mili) + "." + Integer.toString(nano));
- BigDecimal bdtimestamp = BigDecimal.valueOf(doublets);
- set_Value("ProcessedOn", bdtimestamp);
- }
- }
- }
- /**
- * Set Value w/o check (update, r/o, ..).
- * Used when Column is R/O
- * Required for key and parent values
- * @param ColumnName column name
- * @param value value
- * @return true if value set
- */
- public final boolean set_ValueNoCheck (String ColumnName, Object value)
- {
- return set_Value(ColumnName, value, false);
- } // set_ValueNoCheck
- /**
- * Set Encrypted Value w/o check (update, r/o, ..).
- * Used when Column is R/O
- * Required for key and parent values
- * @param ColumnName column name
- * @param value value
- * @return true if value set
- */
- protected final boolean set_ValueNoCheckE (String ColumnName, Object value)
- {
- return set_ValueNoCheck (ColumnName, value);
- } // set_ValueNoCheckE
- /**
- * Set value of Column
- * @param columnName
- * @param value
- */
- public final void set_ValueOfColumn(String columnName, Object value)
- {
- set_ValueOfColumnReturningBoolean(columnName, value);
- }
- /**
- * Set value of Column returning boolean
- * @param columnName
- * @param value
- * @returns boolean indicating success or failure
- */
- public final boolean set_ValueOfColumnReturningBoolean(String columnName, Object value)
- {
- int AD_Column_ID = p_info.getAD_Column_ID(columnName);
- if (AD_Column_ID > 0)
- return set_ValueOfColumnReturningBoolean(AD_Column_ID, value);
- else
- return false;
- }
- /**
- * Set Value of Column
- * @param AD_Column_ID column
- * @param value value
- */
- public final void set_ValueOfColumn (int AD_Column_ID, Object value)
- {
- set_ValueOfColumnReturningBoolean (AD_Column_ID, value);
- } // setValueOfColumn
- /**
- * Set Value of Column
- * @param AD_Column_ID column
- * @param value value
- * @returns boolean indicating success or failure
- */
- public final boolean set_ValueOfColumnReturningBoolean (int AD_Column_ID, Object value)
- {
- int index = p_info.getColumnIndex(AD_Column_ID);
- if (index < 0)
- log.log(Level.SEVERE, "Not found - AD_Column_ID=" + AD_Column_ID);
- String ColumnName = p_info.getColumnName(index);
- if (ColumnName.equals("IsApproved"))
- return set_ValueNoCheck(ColumnName, value);
- else
- return set_Value (index, value);
- } // setValueOfColumn
- /**
- * Set Custom Column
- * @param columnName column
- * @param value value
- */
- public final void set_CustomColumn (String columnName, Object value)
- {
- set_CustomColumnReturningBoolean (columnName, value);
- } // set_CustomColumn
- /**
- * Set Custom Column returning boolean
- * @param columnName column
- * @param value value
- * @returns boolean indicating success or failure
- */
- public final boolean set_CustomColumnReturningBoolean (String columnName, Object value)
- {
- // [ 1845793 ] PO.set_CustomColumn not updating correctly m_newValues
- // this is for columns not in PO - verify and call proper method if exists
- int poIndex = get_ColumnIndex(columnName);
- if (poIndex > 0) {
- // is not custom column - it exists in the PO
- return set_Value(columnName, value);
- }
- if (m_custom == null)
- m_custom = new HashMap<String,String>();
- String valueString = "NULL";
- if (value == null)
- ;
- else if (value instanceof Number)
- valueString = value.toString();
- else if (value instanceof Boolean)
- valueString = ((Boolean)value).booleanValue() ? "'Y'" : "'N'";
- else if (value instanceof Timestamp)
- valueString = DB.TO_DATE((Timestamp)value, false);
- else // if (value instanceof String)
- valueString = DB.TO_STRING(value.toString());
- // Save it
- if (log.isLoggable(Level.INFO))log.log(Level.INFO, columnName + "=" + valueString);
- m_custom.put(columnName, valueString);
- return true;
- } // set_CustomColumn
- /**
- * Set (numeric) Key Value
- * @param ColumnName column name
- * @param value value
- */
- private void set_Keys (String ColumnName, Object value)
- {
- // Update if KeyColumn
- for (int i = 0; i < m_IDs.length; i++)
- {
- if (ColumnName.equals (m_KeyColumns[i]))
- {
- m_IDs[i] = value;
- }
- } // for all key columns
- } // setKeys
- /**************************************************************************
- * Get Column Count
- * @return column count
- */
- public int get_ColumnCount()
- {
- return p_info.getColumnCount();
- } // getColumnCount
- /**
- * Get Column Name
- * @param index index
- * @return ColumnName
- */
- public String get_ColumnName (int index)
- {
- return p_info.getColumnName (index);
- } // getColumnName
- /**
- * Get Column Label
- * @param index index
- * @return Column Label
- */
- protected String get_ColumnLabel (int index)
- {
- return p_info.getColumnLabel (index);
- } // getColumnLabel
- /**
- * Get Column Description
- * @param index index
- * @return column description
- */
- protected String get_ColumnDescription (int index)
- {
- return p_info.getColumnDescription (index);
- } // getColumnDescription
- /**
- * Is Column Mandatory
- * @param index index
- * @return true if column mandatory
- */
- protected boolean isColumnMandatory (int index)
- {
- return p_info.isColumnMandatory(index);
- } // isColumnNandatory
- /**
- * Is Column Updateable
- * @param index index
- * @return true if column updateable
- */
- protected boolean isColumnUpdateable (int index)
- {
- return p_info.isColumnUpdateable(index);
- } // isColumnUpdateable
- /**
- * Set Column Updateable
- * @param index index
- * @param updateable column updateable
- */
- protected void set_ColumnUpdateable (int index, boolean updateable)
- {
- p_info.setColumnUpdateable(index, updateable);
- } // setColumnUpdateable
- /**
- * Set all columns updateable
- * @param updateable updateable
- */
- protected void setUpdateable (boolean updateable)
- {
- p_info.setUpdateable (updateable);
- } // setUpdateable
- /**
- * Get Column DisplayType
- * @param index index
- * @return display type
- */
- protected int get_ColumnDisplayType (int index)
- {
- return p_info.getColumnDisplayType(index);
- } // getColumnDisplayType
- /**
- * Get Lookup
- * @param index index
- * @return Lookup or null
- */
- protected Lookup get_ColumnLookup(int index)
- {
- return p_info.getColumnLookup(index);
- } // getColumnLookup
- /**
- * Get Column Index
- * @param columnName column name
- * @return index of column with ColumnName or -1 if not found
- */
- public final int get_ColumnIndex (String columnName)
- {
- return p_info.getColumnIndex(columnName);
- } // getColumnIndex
- /**
- * Get Display Value of value
- * @param columnName columnName
- * @param currentValue current value
- * @return String value with "./." as null
- */
- public String get_DisplayValue(String columnName, boolean currentValue)
- {
- Object value = currentValue ? get_Value(columnName) : get_ValueOld(columnName);
- if (value == null)
- return "./.";
- String retValue = value.toString();
- int index = get_ColumnIndex(columnName);
- if (index < 0)
- return retValue;
- int dt = get_ColumnDisplayType(index);
- if (DisplayType.isText(dt) || DisplayType.YesNo == dt)
- return retValue;
- // Lookup
- Lookup lookup = get_ColumnLookup(index);
- if (lookup != null)
- return lookup.getDisplay(value);
- // Other
- return retValue;
- } // get_DisplayValue
- /**
- * Copy old values of From to new values of To.
- * Does not copy Keys
- * @param from old, existing & unchanged PO
- * @param to new, not saved PO
- * @param AD_Client_ID client
- * @param AD_Org_ID org
- */
- protected static void copyValues (PO from, PO to, int AD_Client_ID, int AD_Org_ID)
- {
- copyValues (from, to);
- to.setAD_Client_ID(AD_Client_ID);
- to.setAD_Org_ID(AD_Org_ID);
- } // copyValues
- /**
- * Copy old values of From to new values of To.
- * Does not copy Keys and AD_Client_ID/AD_Org_ID
- * @param from old, existing & unchanged PO
- * @param to new, not saved PO
- */
- public static void copyValues (PO from, PO to)
- {
- if (s_log.isLoggable(Level.FINE)) s_log.fine("From ID=" + from.get_ID() + " - To ID=" + to.get_ID());
- // Different Classes
- if (from.getClass() != to.getClass())
- {
- for (int i1 = 0; i1 < from.m_oldValues.length; i1++)
- {
- String colName = from.p_info.getColumnName(i1);
- MColumn column = MColumn.get(from.getCtx(), from.p_info.getAD_Column_ID(colName));
- if ( column.isVirtualColumn()
- || column.isKey() // KeyColumn
- || column.isUUIDColumn() // IDEMPIERE-67
- || column.isStandardColumn()
- || ! column.isAllowCopy())
- continue;
- for (int i2 = 0; i2 < to.m_oldValues.length; i2++)
- {
- if (to.p_info.getColumnName(i2).equals(colName))
- {
- to.m_newValues[i2] = from.m_oldValues[i1];
- break;
- }
- }
- } // from loop
- }
- else // same class
- {
- for (int i = 0; i < from.m_oldValues.length; i++)
- {
- String colName = from.p_info.getColumnName(i);
- MColumn column = MColumn.get(from.getCtx(), from.p_info.getAD_Column_ID(colName));
- if ( column.isVirtualColumn()
- || column.isKey() // KeyColumn
- || column.isUUIDColumn()
- || column.isStandardColumn()
- || ! column.isAllowCopy())
- continue;
- to.m_newValues[i] = from.m_oldValues[i];
- }
- } // same class
- } // copy
- /**************************************************************************
- * Load record with ID
- * @param ID ID
- * @param trxName transaction name
- */
- protected void load (int ID, String trxName)
- {
- if (log.isLoggable(Level.FINEST)) log.finest("ID=" + ID);
- if (ID > 0)
- {
- setKeyInfo();
- m_IDs = new Object[] {new Integer(ID)};
- //m_KeyColumns = new String[] {p_info.getTableName() + "_ID"};
- load(trxName);
- }
- else // new
- {
- loadDefaults();
- m_createNew = true;
- setKeyInfo(); // sets m_IDs
- loadComplete(true);
- }
- } // load
- /**
- * (re)Load record with m_ID[*]
- * @param trxName transaction
- * @return true if loaded
- */
- public boolean load (String trxName)
- {
- m_trxName = trxName;
- boolean success = true;
- StringBuilder sql = new StringBuilder("SELECT ");
- int size = get_ColumnCount();
- for (int i = 0; i < size; i++)
- {
- if (i != 0)
- sql.append(",");
- sql.append(p_info.getColumnSQL(i)); // Normal and Virtual Column
- }
- sql.append(" FROM ").append(p_info.getTableName())
- .append(" WHERE ")
- .append(get_WhereClause(false));
- //
- // int index = -1;
- if (log.isLoggable(Level.FINEST)) log.finest(get_WhereClause(true));
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- try
- {
- pstmt = DB.prepareStatement(sql.toString(), m_trxName); // local trx only
- for (int i = 0; i < m_IDs.length; i++)
- {
- Object oo = m_IDs[i];
- if (oo instanceof Integer)
- pstmt.setInt(i+1, ((Integer)m_IDs[i]).intValue());
- else if (oo instanceof Boolean)
- pstmt.setString(i+1, ((Boolean) m_IDs[i] ? "Y" : "N"));
- else if (oo instanceof Timestamp)
- pstmt.setTimestamp(i+1, (Timestamp)m_IDs[i]);
- else
- pstmt.setString(i+1, m_IDs[i].toString());
- }
- rs = pstmt.executeQuery();
- if (rs.next())
- {
- success = load(rs);
- }
- else
- {
- log.log(Level.SEVERE, "NO Data found for " + get_WhereClause(true), new Exception());
- m_IDs = new Object[] {I_ZERO};
- success = false;
- // throw new DBException("NO Data found for " + get_WhereClause(true));
- }
- m_createNew = false;
- // reset new values
- m_newValues = new Object[size];
- }
- catch (Exception e)
- {
- String msg = "";
- if (m_trxName != null)
- msg = "[" + m_trxName + "] - ";
- msg += get_WhereClause(true)
- // + ", Index=" + index
- // + ", Column=" + get_ColumnName(index)
- // + ", " + p_info.toString(index)
- + ", SQL=" + sql.toString();
- success = false;
- m_IDs = new Object[] {I_ZERO};
- log.log(Level.SEVERE, msg, e);
- // throw new DBException(e);
- }
- // Finish
- finally {
- DB.close(rs, pstmt);
- rs = null; pstmt = null;
- }
- loadComplete(success);
- return success;
- } // load
- /**
- * Load from the current position of a ResultSet
- * @param rs result set
- * @return true if loaded
- */
- protected boolean load (ResultSet rs)
- {
- int size = get_ColumnCount();
- boolean success = true;
- int index = 0;
- log.finest("(rs)");
- // load column values
- for (index = 0; index < size; index++)
- {
- String columnName = p_info.getColumnName(index);
- Class<?> clazz = p_info.getColumnClass(index);
- int dt = p_info.getColumnDisplayType(index);
- try
- {
- if (clazz == Integer.class)
- m_oldValues[index] = decrypt(index, new Integer(rs.getInt(columnName)));
- else if (clazz == BigDecimal.class)
- m_oldValues[index] = decrypt(index, rs.getBigDecimal(columnName));
- else if (clazz == Boolean.class)
- m_oldValues[index] = new Boolean ("Y".equals(decrypt(index, rs.getString(columnName))));
- else if (clazz == Timestamp.class)
- m_oldValues[index] = decrypt(index, rs.getTimestamp(columnName));
- else if (DisplayType.isLOB(dt))
- m_oldValues[index] = get_LOB (rs.getObject(columnName));
- else if (clazz == String.class)
- {
- String value = (String)decrypt(index, rs.getString(columnName));
- if (value != null)
- {
- if (get_Table_ID() == I_AD_Column.Table_ID || get_Table_ID() == I_AD_Element.Table_ID
- || get_Table_ID() == I_AD_Field.Table_ID)
- {
- if ("Description".equals(columnName) || "Help".equals(columnName))
- {
- value = value.intern();
- }
- }
- }
- m_oldValues[index] = value;
- }
- else
- m_oldValues[index] = loadSpecial(rs, index);
- // NULL
- if (rs.wasNull() && m_oldValues[index] != null)
- m_oldValues[index] = null;
- //
- if (CLogMgt.isLevelAll())
- log.finest(String.valueOf(index) + ": " + p_info.getColumnName(index)
- + "(" + p_info.getColumnClass(index) + ") = " + m_oldValues[index]);
- }
- catch (SQLException e)
- {
- if (p_info.isVirtualColumn(index)) { // if rs constructor used
- if (log.isLoggable(Level.FINER))log.log(Level.FINER, "Virtual Column not loaded: " + columnName);
- } else {
- log.log(Level.SEVERE, "(rs) - " + String.valueOf(index)
- + ": " + p_info.getTableName() + "." + p_info.getColumnName(index)
- + " (" + p_info.getColumnClass(index) + ") - " + e);
- success = false;
- }
- }
- }
- m_createNew = false;
- setKeyInfo();
- loadComplete(success);
- return success;
- } // load
- /**
- * Load from HashMap
- * @param hmIn hash map
- * @return true if loaded
- */
- protected boolean load (HashMap<String,String> hmIn)
- {
- int size = get_ColumnCount();
- boolean success = true;
- int index = 0;
- log.finest("(hm)");
- // load column values
- for (index = 0; index < size; index++)
- {
- String columnName = p_info.getColumnName(index);
- String value = (String)hmIn.get(columnName);
- if (value == null)
- continue;
- Class<?> clazz = p_info.getColumnClass(index);
- int dt = p_info.getColumnDisplayType(index);
- try
- {
- if (clazz == Integer.class)
- m_oldValues[index] = new Integer(value);
- else if (clazz == BigDecimal.class)
- m_oldValues[index] = new BigDecimal(value);
- else if (clazz == Boolean.class)
- m_oldValues[index] = new Boolean ("Y".equals(value));
- else if (clazz == Timestamp.class)
- m_oldValues[index] = Timestamp.valueOf(value);
- else if (DisplayType.isLOB(dt))
- m_oldValues[index] = null; // get_LOB (rs.getObject(columnName));
- else if (clazz == String.class)
- m_oldValues[index] = value;
- else
- m_oldValues[index] = null; // loadSpecial(rs, index);
- //
- if (CLogMgt.isLevelAll())
- log.finest(String.valueOf(index) + ": " + p_info.getColumnName(index)
- + "(" + p_info.getColumnClass(index) + ") = " + m_oldValues[index]);
- }
- catch (Exception e)
- {
- if (p_info.isVirtualColumn(index)) { // if rs constructor used
- if (log.isLoggable(Level.FINER))log.log(Level.FINER, "Virtual Column not loaded: " + columnName);
- } else {
- log.log(Level.SEVERE, "(ht) - " + String.valueOf(index)
- + ": " + p_info.getTableName() + "." + p_info.getColumnName(index)
- + " (" + p_info.getColumnClass(index) + ") - " + e);
- success = false;
- }
- }
- }
- m_createNew = false;
- // Overwrite
- setStandardDefaults();
- setKeyInfo();
- loadComplete(success);
- return success;
- } // load
- /**
- * Create Hashmap with data as Strings
- * @return HashMap
- */
- protected HashMap<String,String> get_HashMap()
- {
- HashMap<String,String> hmOut = new HashMap<String,String>();
- int size = get_ColumnCount();
- for (int i = 0; i < size; i++)
- {
- Object value = get_Value(i);
- // Don't insert NULL values (allows Database defaults)
- if (value == null
- || p_info.isVirtualColumn(i))
- continue;
- // Display Type
- int dt = p_info.getColumnDisplayType(i);
- // Based on class of definition, not class of value
- Class<?> c = p_info.getColumnClass(i);
- String stringValue = null;
- if (c == Object.class)
- ; // saveNewSpecial (value, i));
- else if (value == null || value.equals (Null.NULL))
- ;
- else if (value instanceof Integer || value instanceof BigDecimal)
- stringValue = value.toString();
- else if (c == Boolean.class)
- {
- boolean bValue = false;
- if (value instanceof Boolean)
- bValue = ((Boolean)value).booleanValue();
- else
- bValue = "Y".equals(value);
- stringValue = bValue ? "Y" : "N";
- }
- else if (value instanceof Timestamp)
- stringValue = value.toString();
- else if (c == String.class)
- stringValue = (String)value;
- else if (DisplayType.isLOB(dt))
- ;
- else
- ; // saveNewSpecial (value, i));
- //
- if (stringValue != null)
- hmOut.put(p_info.getColumnName(i), stringValue);
- }
- // Custom Columns
- if (m_custom != null)
- {
- Iterator<String> it = m_custom.keySet().iterator();
- while (it.hasNext())
- {
- String column = (String)it.next();
- // int index = p_info.getColumnIndex(column);
- String value = (String)m_custom.get(column);
- if (value != null)
- hmOut.put(column, value);
- }
- m_custom = null;
- }
- return hmOut;
- } // get_HashMap
- /**
- * Load Special data (images, ..).
- * To be extended by sub-classes
- * @param rs result set
- * @param index zero based index
- * @return value value
- * @throws SQLException
- */
- protected Object loadSpecial (ResultSet rs, int index) throws SQLException
- {
- if (log.isLoggable(Level.FINEST)) log.finest("(NOP) - " + p_info.getColumnName(index));
- return null;
- } // loadSpecial
- /**
- * Load is complete
- * @param success success
- * To be extended by sub-classes
- */
- protected void loadComplete (boolean success)
- {
- } // loadComplete
- /**
- * Load Defaults
- */
- protected void loadDefaults()
- {
- setStandardDefaults();
- //
- /** @todo defaults from Field */
- // MField.getDefault(p_info.getDefaultLogic(i));
- } // loadDefaults
- /**
- * Set Default values.
- * Client, Org, Created/Updated, *By, IsActive
- */
- protected void setStandardDefaults()
- {
- int size = get_ColumnCount();
- for (int i = 0; i < size; i++)
- {
- if (p_info.isVirtualColumn(i))
- continue;
- String colName = p_info.getColumnName(i);
- // Set Standard Values
- if (colName.endsWith("tedBy"))
- m_newValues[i] = new Integer (Env.getContextAsInt(p_ctx, "#AD_User_ID"));
- else if (colName.equals("Created") || colName.equals("Updated"))
- m_newValues[i] = new Timestamp (System.currentTimeMillis());
- else if (colName.equals(p_info.getTableName() + "_ID")) // KeyColumn
- m_newValues[i] = I_ZERO;
- else if (colName.equals("IsActive"))
- m_newValues[i] = new Boolean(true);
- else if (colName.equals("AD_Client_ID"))
- m_newValues[i] = new Integer(Env.getAD_Client_ID(p_ctx));
- else if (colName.equals("AD_Org_ID"))
- m_newValues[i] = new Integer(Env.getAD_Org_ID(p_ctx));
- else if (colName.equals("Processed"))
- m_newValues[i] = new Boolean(false);
- else if (colName.equals("Processing"))
- m_newValues[i] = new Boolean(false);
- else if (colName.equals("Posted"))
- m_newValues[i] = new Boolean(false);
- }
- } // setDefaults
- /**
- * Set Key Info (IDs and KeyColumns).
- */
- private void setKeyInfo()
- {
- // Search for Primary Key
- for (int i = 0; i < p_info.getColumnCount(); i++)
- {
- if (p_info.isKey(i))
- {
- String ColumnName = p_info.getColumnName(i);
- m_KeyColumns = new String[] {ColumnName};
- if (p_info.getColumnName(i).endsWith("_ID"))
- {
- Integer ii = (Integer)get_Value(i);
- if (ii == null)
- m_IDs = new Object[] {I_ZERO};
- else
- m_IDs = new Object[] {ii};
- if (log.isLoggable(Level.FINEST)) log.finest("(PK) " + ColumnName + "=" + ii);
- }
- else
- {
- Object oo = get_Value(i);
- if (oo == null)
- m_IDs = new Object[] {null};
- else
- m_IDs = new Object[] {oo};
- if (log.isLoggable(Level.FINEST)) log.finest("(PK) " + ColumnName + "=" + oo);
- }
- return;
- }
- } // primary key search
- // Search for Parents
- ArrayList<String> columnNames = new ArrayList<String>();
- for (int i = 0; i < p_info.getColumnCount(); i++)
- {
- if (p_info.isColumnParent(i))
- columnNames.add(p_info.getColumnName(i));
- }
- // Set FKs
- int size = columnNames.size();
- if (size == 0)
- throw new IllegalStateException("No PK nor FK - " + p_info.getTableName());
- m_IDs = new Object[size];
- m_KeyColumns = new String[size];
- for (int i = 0; i < size; i++)
- {
- m_KeyColumns[i] = (String)columnNames.get(i);
- if (m_KeyColumns[i].endsWith("_ID"))
- {
- Integer ii = null;
- try
- {
- ii = (Integer)get_Value(m_KeyColumns[i]);
- }
- catch (Exception e)
- {
- log.log(Level.SEVERE, "", e);
- }
- if (ii != null)
- m_IDs[i] = ii;
- }
- else
- m_IDs[i] = get_Value(m_KeyColumns[i]);
- if (log.isLoggable(Level.FINEST)) log.finest("(FK) " + m_KeyColumns[i] + "=" + m_IDs[i]);
- }
- } // setKeyInfo
- /**************************************************************************
- * Are all mandatory Fields filled (i.e. can we save)?.
- * Stops at first null mandatory field
- * @return true if all mandatory fields are ok
- */
- protected boolean isMandatoryOK()
- {
- int size = get_ColumnCo…
Large files files are truncated, but you can click here to view the full file