1 14 package org.compiere.model; 15 16 import java.util.*; 17 import java.sql.*; 18 import java.io.*; 19 20 import org.compiere.util.*; 21 22 28 public final class MLocator extends X_M_Locator implements Serializable 29 { 30 35 public MLocator (Properties ctx, int M_Locator_ID) 36 { 37 super (ctx, M_Locator_ID); 38 if (M_Locator_ID == 0) 39 { 40 setIsDefault (false); 43 setPriorityNo (50); 44 } 49 } 51 60 public MLocator (Properties ctx, int M_Warehouse_ID, String Value, 61 String X, String Y, String Z) 62 { 63 this (ctx, 0); 64 setM_Warehouse_ID (M_Warehouse_ID); setValue (Value); 66 setX (X); 67 setY (Y); 68 setZ (Z); 69 } 71 76 public MLocator (Properties ctx, ResultSet rs) 77 { 78 super (ctx, rs); 79 } 81 private static Logger s_log = Logger.getCLogger (MLocator.class); 82 83 84 94 public static MLocator get (Properties ctx, int M_Warehouse_ID, String Value, 95 String X, String Y, String Z) 96 { 97 MLocator retValue = null; 98 String sql = "SELECT * FROM M_Locator WHERE M_Warehouse_ID=? AND X=? AND Y=? AND Z=?"; 99 PreparedStatement pstmt = null; 100 try 101 { 102 pstmt = DB.prepareStatement(sql); 103 pstmt.setInt(1, M_Warehouse_ID); 104 pstmt.setString(2, X); 105 pstmt.setString(3, Y); 106 pstmt.setString(4, Z); 107 ResultSet rs = pstmt.executeQuery(); 108 if (rs.next()) 109 retValue = new MLocator (ctx, rs); 110 rs.close(); 111 pstmt.close(); 112 pstmt = null; 113 } 114 catch (SQLException ex) 115 { 116 s_log.error("get", ex); 117 } 118 try 119 { 120 if (pstmt != null) 121 pstmt.close(); 122 } 123 catch (SQLException ex1) 124 { 125 } 126 pstmt = null; 127 if (retValue == null) 129 { 130 retValue = new MLocator (ctx, M_Warehouse_ID, Value, X, Y, Z); 131 retValue.save(); 132 } 133 return retValue; 134 } 136 140 public String toString() 141 { 142 return getValue(); 143 } 145 146 147 private static CCache s_warehouseName = new CCache("MLocatorWarehouseName", 5); 148 149 153 public String getWarehouseName() 154 { 155 int M_Warehouse_ID = getM_Warehouse_ID(); 156 if (M_Warehouse_ID == 0) 157 return ""; 158 Integer key = new Integer (M_Warehouse_ID); 159 String Name = (String )s_warehouseName.get(key); 160 if (Name == null) 161 { 162 String sql = "SELECT Value, Name FROM M_Warehouse WHERE M_Warehouse_ID=?"; 163 PreparedStatement pstmt = null; 164 try 165 { 166 pstmt = DB.prepareStatement(sql); 167 pstmt.setInt(1, M_Warehouse_ID); 168 ResultSet rs = pstmt.executeQuery(); 169 if (rs.next()) 170 Name = rs.getString(2); 171 rs.close(); 172 pstmt.close(); 173 pstmt = null; 174 } 175 catch (SQLException ex) 176 { 177 log.error("getWarehouseName", ex); 178 } 179 try 180 { 181 if (pstmt != null) 182 pstmt.close(); 183 } 184 catch (SQLException ex1) 185 { 186 } 187 pstmt = null; 188 if (Name != null) 189 s_warehouseName.put(key, Name); 190 } 191 if (Name == null) 192 return "<" + M_Warehouse_ID + ">"; 193 return Name; 194 } 196 } | Popular Tags |