1 14 package org.compiere.model; 15 16 import java.sql.*; 17 import java.util.*; 18 import java.io.Serializable ; 19 20 import oracle.net.TNSAddress.Description; 21 22 import org.compiere.util.DB; 23 import org.compiere.util.Env; 24 import org.compiere.util.CCache; 25 import org.compiere.util.NamePair; 26 import org.compiere.util.KeyNamePair; 27 28 34 public class MPAttribute extends Lookup 35 implements Serializable 36 { 37 38 43 public MPAttribute(Properties ctx, int WindowNo) 44 { 45 super(); 46 m_ctx = ctx; 47 m_WindowNo = WindowNo; 48 } 50 private int m_WindowNo; 51 private Properties m_ctx; 52 53 private PreparedStatement m_pstmt = null; 54 55 60 public String getDisplay (Object value) 61 { 62 if (value == null) 63 return ""; 64 NamePair pp = get (value); 65 if (pp == null) 66 return "<" + value.toString() + ">"; 67 return pp.getName(); 68 } 70 75 public boolean containsKey (Object key) 76 { 77 return get(key) != null; 78 } 80 85 public NamePair get (Object value) 86 { 87 if (value == null) 88 return null; 89 int M_AttributeSetInstance_ID = 0; 90 if (value instanceof Integer ) 91 M_AttributeSetInstance_ID = ((Integer )value).intValue(); 92 else 93 { 94 try 95 { 96 M_AttributeSetInstance_ID = Integer.parseInt(value.toString()); 97 } 98 catch (Exception e) 99 { 100 log.error("get - " + value, e); 101 } 102 } 103 if (M_AttributeSetInstance_ID == 0) 104 return null; 105 if (m_pstmt == null) 108 m_pstmt = DB.prepareStatement("SELECT Description " 109 + "FROM M_AttributeSetInstance " 110 + "WHERE M_AttributeSetInstance_ID=?"); 111 String Description = null; 113 try 114 { 115 m_pstmt.setInt(1, M_AttributeSetInstance_ID); 116 ResultSet rs = m_pstmt.executeQuery(); 117 if (rs.next()) 118 Description = rs.getString(1); rs.close(); 120 } 121 catch (Exception e) 122 { 123 log.error("get", e); 124 } 125 if (Description == null) 126 return null; 127 return new KeyNamePair (M_AttributeSetInstance_ID, Description); 128 } 130 134 public void dispose() 135 { 136 try 137 { 138 if (m_pstmt != null) 139 m_pstmt.close(); 140 } 141 catch (SQLException e) 142 { 143 log.error("dispose", e); 144 } 145 log.debug("dispose"); 146 super.dispose(); 147 } 149 157 public ArrayList getData (boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary) 158 { 159 log.error("getData - not implemented"); 160 return null; 161 } 163 168 public String getColumnName() 169 { 170 return "M_AttributeSetInstance_ID"; 171 } 173 } | Popular Tags |