/** * Get Country (cached) * * @param ctx context * @param C_Region_ID ID * @return Country */ public static MRegion get(Ctx ctx, int C_Region_ID) { if (s_regions.isEmpty()) loadAllRegions(ctx); String key = String.valueOf(C_Region_ID); MRegion r = s_regions.get(ctx, key); if (r != null) return r; r = new MRegion(ctx, C_Region_ID, null); if (r.getC_Region_ID() == C_Region_ID) { s_regions.put(key, r); return r; } return null; } // get
/** * Load Regions (cached) * * @param ctx context */ private static void loadAllRegions(Ctx ctx) { String sql = "SELECT * FROM C_Region WHERE IsActive='Y'"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, (Trx) null); rs = pstmt.executeQuery(); while (rs.next()) { MRegion r = new MRegion(ctx, rs, null); s_regions.put(String.valueOf(r.getC_Region_ID()), r); if (r.isDefault()) s_default = r; } } catch (SQLException e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } s_log.fine(s_regions.size() + " - default=" + s_default); } // loadAllRegions