From: Jorg J. <jj...@us...> - 2003-08-26 19:35:27
|
Update of /cvsroot/compiere/base/src/org/compiere/model In directory sc8-pr-cvs1:/tmp/cvs-serv29401/src/org/compiere/model Added Files: MAttribute.java MAttributeInstance.java MAttributeSet.java MAttributeSetInstance.java MAttributeValue.java MLot.java Removed Files: MPAttributeSetInstance.java Log Message: . --- NEW FILE: MAttribute.java --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Smart Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.model; import java.util.*; import java.sql.*; import org.compiere.util.*; /** * Product Attribute * * @author Jorg Janke * @version $Id: MAttribute.java,v 1.1 2003/08/26 17:30:35 jjanke Exp $ */ public class MAttribute extends X_M_Attribute { /** * Standard Constructor * @param ctx context * @param M_Attribute_ID id */ public MAttribute (Properties ctx, int M_Attribute_ID) { super (ctx, M_Attribute_ID); /** if (M_Attribute_ID == 0) { setIsInstanceAttribute (false); setIsMandatory (false); setM_Attribute_ID (0); setName (null); } **/ } // MAttribute /** * Load Constructor * @param ctx context * @param rs result set */ public MAttribute (Properties ctx, ResultSet rs) { super (ctx, rs); } // MAttribute /** Values */ private MAttributeValue[] m_values = null; /** * Get Values if List * @return Values or null if not list */ public MAttributeValue[] getMAttributeValues() { if (m_values == null && isList()) { ArrayList list = new ArrayList(); if (!isMandatory()) list.add (null); // String sql = "SELECT * FROM M_AttributeValue " + "WHERE M_Attribute_ID=? " + "ORDER BY Value"; PreparedStatement pstmt = null; try { pstmt = DB.prepareStatement(sql); pstmt.setInt(1, getM_Attribute_ID()); ResultSet rs = pstmt.executeQuery(); while (rs.next()) list.add(new MAttributeValue (getCtx(), rs)); rs.close(); pstmt.close(); pstmt = null; } catch (SQLException ex) { log.error("getValues", ex); } try { if (pstmt != null) pstmt.close(); } catch (SQLException ex1) { } pstmt = null; m_values = new MAttributeValue[list.size()]; list.toArray(m_values); } return m_values; } // getValues /*************************************************************************/ /** * Get Attribute Instance * @param M_AttributeSetInstance_ID attribute set instance * @return Attribute Instance or null */ public MAttributeInstance getMAttributeInstance (int M_AttributeSetInstance_ID) { MAttributeInstance retValue = null; String sql = "SELECT * " + "FROM M_AttributeInstance " + "WHERE M_Attribute_ID=? AND M_AttributeSetInstance_ID=?"; PreparedStatement pstmt = null; try { pstmt = DB.prepareStatement (sql); pstmt.setInt (1, getM_Attribute_ID()); pstmt.setInt(2, M_AttributeSetInstance_ID); ResultSet rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MAttributeInstance (getCtx(), rs); rs.close (); pstmt.close (); pstmt = null; } catch (SQLException ex) { log.error ("getAttributeInstance", ex); } try { if (pstmt != null) pstmt.close (); } catch (SQLException ex1) { } pstmt = null; return retValue; } // getAttributeInstance /** * Set Attribute Instance * @param value value * @param M_AttributeSetInstance_ID id */ public void setMAttributeInstance (int M_AttributeSetInstance_ID, MAttributeValue value) { MAttributeInstance instance = getMAttributeInstance(M_AttributeSetInstance_ID); if (instance == null) { if (value != null) instance = new MAttributeInstance (getCtx (), getM_Attribute_ID (), M_AttributeSetInstance_ID, value.getM_AttributeValue_ID (), value.getName ()); // Cached !! else instance = new MAttributeInstance (getCtx(), getM_Attribute_ID(), M_AttributeSetInstance_ID, 0, null); } else { if (value != null) { instance.setM_AttributeValue_ID (value.getM_AttributeValue_ID ()); instance.setValue (value.getName()); // Cached !! } else { instance.setM_AttributeValue_ID (0); instance.setValue (null); } } instance.save(); } // setAttributeInstance /** * Set Attribute Instance * @param value value * @param M_AttributeSetInstance_ID id */ public void setMAttributeInstance (int M_AttributeSetInstance_ID, String value) { MAttributeInstance instance = getMAttributeInstance(M_AttributeSetInstance_ID); if (instance == null) instance = new MAttributeInstance (getCtx(), getM_Attribute_ID(), M_AttributeSetInstance_ID, value); else instance.setValue(value); instance.save(); } // setAttributeInstance } // MAttribute --- NEW FILE: MAttributeInstance.java --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Smart Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.model; import java.util.*; import java.sql.*; /** * Product Attribute Set * * @author Jorg Janke * @version $Id: MAttributeInstance.java,v 1.1 2003/08/26 17:30:35 jjanke Exp $ */ public class MAttributeInstance extends X_M_AttributeInstance { /** * Standard Constructor * @param ctx context * @param M_AttributeInstance_ID id */ public MAttributeInstance (Properties ctx, int M_AttributeInstance_ID) { super (ctx, M_AttributeInstance_ID); /** if (M_AttributeInstance_ID == 0) { setM_AttributeSetInstance_ID (0); setM_Attribute_ID (0); } **/ } // MAttributeInstance /** * Load Cosntructor * @param ctx context * @param rs result set */ public MAttributeInstance (Properties ctx, ResultSet rs) { super (ctx, rs); } // MAttributeInstance /** * String Value Constructior * @param ctx context * @param M_Attribute_ID attribute * @param M_AttributeSetInstance_ID instance * @param Value string value */ public MAttributeInstance (Properties ctx, int M_Attribute_ID, int M_AttributeSetInstance_ID, String Value) { super (ctx, 0); setM_Attribute_ID (M_Attribute_ID); setM_AttributeSetInstance_ID (M_AttributeSetInstance_ID); setValue (Value); } // MAttributeInstance /** * Selection Value Constructior * @param ctx context * @param M_Attribute_ID attribute * @param M_AttributeSetInstance_ID instance * @param M_AttributeValue_ID selection * @param Value String representation for fast display */ public MAttributeInstance (Properties ctx, int M_Attribute_ID, int M_AttributeSetInstance_ID, int M_AttributeValue_ID, String Value) { super (ctx, 0); setM_Attribute_ID (M_Attribute_ID); setM_AttributeSetInstance_ID (M_AttributeSetInstance_ID); setM_AttributeValue_ID (M_AttributeValue_ID); setValue (Value); } // MAttributeInstance /** * String Representation * @return info */ public String toString() { return getValue(); } // toString } // MAttributeInstance --- NEW FILE: MAttributeSet.java --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Smart Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.model; import java.util.*; import java.sql.*; import org.compiere.util.*; /** * Product Attribute Set * * @author Jorg Janke * @version $Id: MAttributeSet.java,v 1.1 2003/08/26 17:30:35 jjanke Exp $ */ public class MAttributeSet extends X_M_AttributeSet { /** * Standard constructor * @param ctx context * @param M_AttributeSet_ID id */ public MAttributeSet (Properties ctx, int M_AttributeSet_ID) { super (ctx, M_AttributeSet_ID); if (M_AttributeSet_ID == 0) { setIsGuaranteeDate (false); setIsLot (false); setIsSerNo (false); setM_AttributeSet_ID (0); setName (null); } } // MAttributeSet /** * Load constructor * @param ctx context * @param rs result set */ public MAttributeSet (Properties ctx, ResultSet rs) { super (ctx, rs); } // MAttributeSet /** Instance Attributes */ private MAttribute[] m_instanceAttributes = null; /** Instance Attributes */ private MAttribute[] m_productAttributes = null; /** * Get Attribute Array * @param instanceAttributes true if for instance * @return instance or product attribute array */ public MAttribute[] getMAttributes (boolean instanceAttributes) { if ((m_instanceAttributes == null && instanceAttributes) || m_productAttributes == null && !instanceAttributes) { String sql = "SELECT mau.M_Attribute_ID " + "FROM M_AttributeUse mau" + " INNER JOIN M_Attribute ma ON (mau.M_Attribute_ID=ma.M_Attribute_ID) " + "WHERE mau.IsActive='Y' AND ma.IsActive='Y'" + " AND mau.M_AttributeSet_ID=? AND ma.IsInstanceAttribute=? " // #1,2 + "ORDER BY mau.SeqNo"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; try { pstmt = DB.prepareStatement(sql); pstmt.setInt(1, getM_AttributeSet_ID()); pstmt.setString(2, instanceAttributes ? "Y" : "N"); ResultSet rs = pstmt.executeQuery(); while (rs.next()) list.add (new MAttribute (getCtx(), rs.getInt(1))); rs.close(); pstmt.close(); pstmt = null; } catch (SQLException ex) { log.error("getMAttributes", ex); } try { if (pstmt != null) pstmt.close(); } catch (SQLException ex1) { } pstmt = null; // if (instanceAttributes) { m_instanceAttributes = new MAttribute[list.size()]; list.toArray (m_instanceAttributes); } else { m_productAttributes = new MAttribute[list.size()]; list.toArray (m_productAttributes); } } // if (instanceAttributes) return m_instanceAttributes; return m_productAttributes; } // getMAttributes } // MAttributeSet --- NEW FILE: MAttributeSetInstance.java --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Smart Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.model; import java.util.*; import java.sql.*; import java.text.DateFormat; import org.apache.log4j.Logger; import org.compiere.util.*; /** * Product Attribute Set Instance * * @author Jorg Janke * @version $Id: MAttributeSetInstance.java,v 1.1 2003/08/26 17:30:35 jjanke Exp $ */ public class MAttributeSetInstance extends X_M_AttributeSetInstance { /** * Get Attribute Set Instance from ID or Product * @param ctx context * @param M_AttributeSetInstance_ID id or 0 * @param M_Product_ID required if id is 0 * @return Attribute Set Instance or null */ public static MAttributeSetInstance get (Properties ctx, int M_AttributeSetInstance_ID, int M_Product_ID) { MAttributeSetInstance retValue = null; if (M_AttributeSetInstance_ID != 0) { s_log.debug("get - M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID); return new MAttributeSetInstance (ctx, M_AttributeSetInstance_ID); } // Get it from Product s_log.debug("get - M_Product_ID=" + M_Product_ID); if (M_Product_ID == 0) return null; String sql = "SELECT M_AttributeSet_ID, M_AttributeSetInstance_ID " + "FROM M_Product " + "WHERE M_Product_ID=?"; PreparedStatement pstmt = null; try { pstmt = DB.prepareStatement(sql); pstmt.setInt(1, M_Product_ID); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { M_AttributeSetInstance_ID = rs.getInt(2); if (M_AttributeSetInstance_ID != 0) retValue = new MAttributeSetInstance (ctx, M_AttributeSetInstance_ID); else retValue = new MAttributeSetInstance (ctx, 0, rs.getInt(1)); } rs.close(); pstmt.close(); pstmt = null; } catch (SQLException ex) { s_log.error("get", ex); } try { if (pstmt != null) pstmt.close(); } catch (SQLException ex1) { } pstmt = null; // return retValue; } // get private static Logger s_log = Logger.getLogger (MAttributeSetInstance.class); /*************************************************************************/ /** * Standard Constructor * @param ctx context * @param M_AttributeSetInstance_ID id */ public MAttributeSetInstance (Properties ctx, int M_AttributeSetInstance_ID) { super (ctx, M_AttributeSetInstance_ID); } // MAttributeSetInstance /** * Load Constructor * @param ctx context * @param rs result set */ public MAttributeSetInstance (Properties ctx, ResultSet rs) { super (ctx, rs); } // MAttributeSetInstance /** * Standard Constructor * @param ctx context * @param M_AttributeSetInstance_ID id * @param M_AttributeSet_ID attribute set */ public MAttributeSetInstance (Properties ctx, int M_AttributeSetInstance_ID, int M_AttributeSet_ID) { super (ctx, M_AttributeSetInstance_ID); setM_AttributeSet_ID(M_AttributeSet_ID); } // MAttributeSetInstance /** Attribute Set */ private MAttributeSet m_mas = null; /** Date Format */ private DateFormat m_dateFormat = DisplayType.getDateFormat(DisplayType.Date); /** * Set Attribute Set * @param mas attribute set */ public void setMAttributeSet (MAttributeSet mas) { m_mas = mas; setM_AttributeSet_ID(mas.getM_AttributeSet_ID()); } // setAttributeSet /** * Get Attribute Set * @return Attrbute Set or null */ public MAttributeSet getMAttributeSet() { if (m_mas == null && getM_AttributeSet_ID() != 0) m_mas = new MAttributeSet (getCtx(), getM_AttributeSet_ID()); return m_mas; } // getMAttributeSet /** * Set Description */ public void setDescription() { // Make sure we have a Attribute Set getMAttributeSet(); if (m_mas == null) { setDescription ("??"); return; } StringBuffer sb = new StringBuffer(); // SerNo if (m_mas.isSerNo() && getSerNo() != null) sb.append(getSerNo()); // Lot if (m_mas.isLot() && getLot() != null) { if (sb.length() > 0) sb.append("_"); sb.append (getLot ()); } // GuaranteeDate if (m_mas.isGuaranteeDate() && getGuaranteeDate() != null) { if (sb.length() > 0) sb.append("_"); sb.append (m_dateFormat.format (getGuaranteeDate())); } // Instance Attribute Values MAttribute[] attributes = m_mas.getMAttributes(false); for (int i = 0; i < attributes.length; i++) { if (sb.length() > 0 && i == 0) sb.append("_"); if (i != 0) sb.append("-"); MAttributeInstance mai = attributes[i].getMAttributeInstance(getM_AttributeSetInstance_ID()); if (mai != null && mai.getValue() != null) sb.append(mai.getValue()); } // Product Attribute Values attributes = m_mas.getMAttributes(true); for (int i = 0; i < attributes.length; i++) { if (sb.length() > 0 && i == 0) sb.append("_"); if (i != 0) sb.append("-"); MAttributeInstance mai = attributes[i].getMAttributeInstance(getM_AttributeSetInstance_ID()); if (mai != null && mai.getValue() != null) sb.append(mai.getValue()); } // // log.debug("setDescription - " + sb.toString()); setDescription (sb.toString()); } // setDescription } // MAttributeSetInstance --- NEW FILE: MAttributeValue.java --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Smart Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.model; import java.util.*; import java.sql.*; /** * Product Attribute Value * * @author Jorg Janke * @version $Id: MAttributeValue.java,v 1.1 2003/08/26 17:30:35 jjanke Exp $ */ public class MAttributeValue extends X_M_AttributeValue { public MAttributeValue (Properties ctx, int M_AttributeValue_ID) { super (ctx, M_AttributeValue_ID); /** if (M_AttributeValue_ID == 0) { setM_AttributeValue_ID (0); setM_Attribute_ID (0); setName (null); setValue (null); } **/ } // MAttributeValue public MAttributeValue (Properties ctx, ResultSet rs) { super (ctx, rs); } // MAttributeValue /** * String Representation * @return info */ public String toString() { return getName(); } // toString } // MAttributeValue --- NEW FILE: MLot.java --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Smart Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.model; import java.util.*; import java.sql.*; import org.apache.log4j.Logger; import org.compiere.util.*; /** * Product Lot * * @author Jorg Janke * @version $Id: MLot.java,v 1.1 2003/08/26 17:30:35 jjanke Exp $ */ public class MLot extends X_M_Lot { /** * Get Lots for Product * @param ctx context * @param M_Product_ID product * @return Array of Lots for Product */ public static MLot[] getProductLots (Properties ctx, int M_Product_ID) { String sql = "SELECT * FROM M_Lot WHERE M_Product_ID=?"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; try { pstmt = DB.prepareStatement (sql); pstmt.setInt (1, M_Product_ID); ResultSet rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MLot (ctx, rs)); rs.close (); pstmt.close (); pstmt = null; } catch (SQLException ex) { s_log.error ("getProductLots (MLot)", ex); } try { if (pstmt != null) pstmt.close (); } catch (SQLException ex1) { } pstmt = null; // MLot[] retValue = new MLot[list.size()]; list.toArray(retValue); return retValue; } // getProductLots /** * Get Lot Key Name Pairs for Product * @param M_Product_ID product * @return Array of Lot Key Name Pairs for Product */ public static KeyNamePair[] getProductLots (int M_Product_ID) { String sql = "SELECT M_Lot_ID, Name FROM M_Lot WHERE M_Product_ID=?"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; try { pstmt = DB.prepareStatement (sql); pstmt.setInt (1, M_Product_ID); ResultSet rs = pstmt.executeQuery (); while (rs.next ()) list.add (new KeyNamePair (rs.getInt(1), rs.getString(2))); rs.close (); pstmt.close (); pstmt = null; } catch (SQLException ex) { s_log.error ("getProductLots (KeyNamePair)", ex); } try { if (pstmt != null) pstmt.close (); } catch (SQLException ex1) { } pstmt = null; // KeyNamePair[] retValue = new KeyNamePair[list.size()]; list.toArray(retValue); return retValue; } // getProductLots private static Logger s_log = Logger.getLogger(MLot.class); /*************************************************************************/ /** * Standard Constructor * @param ctx context * @param M_Lot_ID ID */ public MLot (Properties ctx, int M_Lot_ID) { super (ctx, M_Lot_ID); /** if (M_Lot_ID == 0) { setM_Lot_ID (0); setM_Product_ID (0); setName (null); } **/ } // MLot /** * Load Constructor * @param ctx context * @param rs result set */ public MLot (Properties ctx, ResultSet rs) { super (ctx, rs); } // MLot /** * String Representation * @return info */ public String toString() { return getName(); } // toString } // MLot --- MPAttributeSetInstance.java DELETED --- |