1 14 package org.compiere.model; 15 16 import java.util.*; 17 import java.sql.*; 18 import java.math.*; 19 import java.io.Serializable ; 20 21 import org.compiere.util.*; 22 23 29 public class MRef_List extends X_AD_Ref_List 30 { 31 38 public static MRef_List get (Properties ctx, int AD_Reference_ID, String Value) 39 { 40 MRef_List retValue = null; 41 String sql = "SELECT * FROM AD_Ref_List " 42 + "WHERE AD_Reference_ID=? AND Value=?"; 43 PreparedStatement pstmt = null; 44 try 45 { 46 pstmt = DB.prepareStatement (sql); 47 pstmt.setInt (1, AD_Reference_ID); 48 pstmt.setString (2, Value); 49 ResultSet rs = pstmt.executeQuery (); 50 if (rs.next ()) 51 retValue = new MRef_List (ctx, rs); 52 rs.close (); 53 pstmt.close (); 54 pstmt = null; 55 } 56 catch (SQLException ex) 57 { 58 s_log.error ("get", ex); 59 } 60 try 61 { 62 if (pstmt != null) 63 pstmt.close (); 64 } 65 catch (SQLException ex1) 66 { 67 } 68 pstmt = null; 69 70 return retValue; 71 } 73 80 public static String getListName (Properties ctx, int AD_Reference_ID, String Value) 81 { 82 String AD_Language = Env.getAD_Language(ctx); 83 String key = AD_Language + "_" + AD_Reference_ID + "_" + Value; 84 String retValue = (String )s_cache.get(key); 85 if (retValue != null) 86 return retValue; 87 88 boolean isBaseLanguage = Env.isBaseLanguage(AD_Language, "AD_Ref_List"); 89 String sql = isBaseLanguage ? 90 "SELECT Name FROM AD_Ref_List " 91 + "WHERE AD_Reference_ID=? AND Value=?" : 92 "SELECT t.Name FROM AD_Ref_List_Trl t" 93 + " INNER JOIN AD_Ref_List r ON (r.AD_Ref_List_ID=t.AD_Ref_List_ID) " 94 + "WHERE r.AD_Reference_ID=? AND r.Value=? AND t.AD_Language=?"; 95 PreparedStatement pstmt = null; 96 try 97 { 98 pstmt = DB.prepareStatement (sql); 99 pstmt.setInt (1, AD_Reference_ID); 100 pstmt.setString(2, Value); 101 if (!isBaseLanguage) 102 pstmt.setString(3, AD_Language); 103 ResultSet rs = pstmt.executeQuery (); 104 if (rs.next ()) 105 retValue = rs.getString(1); 106 rs.close (); 107 pstmt.close (); 108 pstmt = null; 109 } 110 catch (SQLException ex) 111 { 112 s_log.error ("getListName - " + sql + " - " + key, ex); 113 } 114 try 115 { 116 if (pstmt != null) 117 pstmt.close (); 118 } 119 catch (SQLException ex1) 120 { 121 } 122 pstmt = null; 123 124 if (retValue == null) 126 { 127 retValue = ""; 128 s_log.warn("getListName - Not found " + key); 129 } 130 s_cache.put(key, retValue); 131 return retValue; 133 } 135 136 137 private static Logger s_log = Logger.getCLogger (MRef_List.class); 138 139 private static CCache s_cache = new CCache("MRef_List", 20); 140 141 142 143 148 public MRef_List (Properties ctx, ResultSet rs) 149 { 150 super (ctx, rs); 151 } 153 157 public String toString() 158 { 159 return getName(); 160 } 162 163 } | Popular Tags |