From: Marek M. <mar...@us...> - 2005-01-21 15:37:33
|
Update of /cvsroot/compiere/webStore/src/java/org/compiere/ifm/app/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10217/src/java/org/compiere/ifm/app/query Modified Files: Tag: pbs_payment ContactSearch.java SelectionSearch.java Log Message: Index: ContactSearch.java =================================================================== RCS file: /cvsroot/compiere/webStore/src/java/org/compiere/ifm/app/query/Attic/ContactSearch.java,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -C2 -d -r1.1.2.8 -r1.1.2.9 *** ContactSearch.java 18 Jan 2005 00:01:22 -0000 1.1.2.8 --- ContactSearch.java 21 Jan 2005 15:37:24 -0000 1.1.2.9 *************** *** 48,51 **** --- 48,52 ---- List contacts = new ArrayList(); PreparedStatement stmt = null; + ResultSet result = null; try { StringBuffer sqlQuery = new StringBuffer( *************** *** 118,122 **** ! ResultSet result = stmt.executeQuery(); int count = 0; while (result.next()) { --- 119,123 ---- ! result = stmt.executeQuery(); int count = 0; while (result.next()) { *************** *** 133,137 **** throw new RuntimeException("Could not execute search query", e); } finally { ! closeStatement(stmt); } return contacts; --- 134,138 ---- throw new RuntimeException("Could not execute search query", e); } finally { ! close(result,stmt); } return contacts; *************** *** 173,177 **** con.addLocation(lok); } ! closeStatement(pstmt); pstmt = DB .prepareStatement(" SELECT * from IFM_Keyword WHERE IFM_Contacts_ID IN " --- 174,178 ---- con.addLocation(lok); } ! close(res,pstmt); pstmt = DB .prepareStatement(" SELECT * from IFM_Keyword WHERE IFM_Contacts_ID IN " *************** *** 188,192 **** con.addKeyword(keyword); } ! closeStatement(pstmt); pstmt = DB .prepareStatement(" SELECT * from IFM_Extraction WHERE IFM_Contacts_ID IN " --- 189,193 ---- con.addKeyword(keyword); } ! close(res,pstmt); pstmt = DB .prepareStatement(" SELECT * from IFM_Extraction WHERE IFM_Contacts_ID IN " *************** *** 203,207 **** con.addExtraction(extraction); } ! closeStatement(pstmt); pstmt = DB .prepareStatement(" SELECT * from IFM_Contact_Phone WHERE IFM_Contacts_ID IN " --- 204,208 ---- con.addExtraction(extraction); } ! close(res,pstmt); pstmt = DB .prepareStatement(" SELECT * from IFM_Contact_Phone WHERE IFM_Contacts_ID IN " *************** *** 218,222 **** con.addPhone(phone); } ! closeStatement(pstmt); } catch (SQLException e) { throw new RuntimeException(e); --- 219,223 ---- con.addPhone(phone); } ! close(res,pstmt); } catch (SQLException e) { throw new RuntimeException(e); *************** *** 239,248 **** contact.addLetter(letter); } ! closeStatement(pstmt); } catch (SQLException e) { throw new RuntimeException(e); } } ! private static void closeStatement(PreparedStatement s) { if (s != null) { try { --- 240,255 ---- contact.addLetter(letter); } ! close(res,pstmt); } catch (SQLException e) { throw new RuntimeException(e); } } ! private static void close(ResultSet rs,PreparedStatement s) { ! if (rs != null) { ! try { ! rs.close(); ! } catch (SQLException e) { ! } ! } if (s != null) { try { *************** *** 271,275 **** list.setWriteAccess("Y".equals(res.getString(2))); } ! closeStatement(pstmt); } catch (SQLException e) { throw new RuntimeException(e); --- 278,282 ---- list.setWriteAccess("Y".equals(res.getString(2))); } ! close(res,pstmt); } catch (SQLException e) { throw new RuntimeException(e); *************** *** 277,279 **** --- 284,325 ---- } + + /** + * Load contacts and its relations by ID lists + * @param contactIds list of Integer contact ids + * @return list of M_IFM_Contacts + */ + public static List loadContacts(List contactIds) { + List contacts = new ArrayList(contactIds.size()); + if(contactIds.isEmpty()){ + return contacts; + } + try { + StringBuffer inClause = new StringBuffer("("); + for (Iterator cont = contactIds.iterator(); cont.hasNext();) { + cont.next(); + inClause.append("?"); + if (cont.hasNext()) inClause.append(","); + } + inClause.append(")"); + + PreparedStatement pstmt = DB + .prepareStatement("SELECT * from IFM_Contacts WHERE IFM_Contacts_ID IN " + + inClause); + int pos =1; + for(int i = 0;i<contactIds.size();i++){ + pstmt.setInt(pos++, ((Integer)contactIds.get(i)).intValue()); + } + ResultSet res = pstmt.executeQuery(); + while(res.next()){ + M_IFM_Contacts contact = new M_IFM_Contacts(Env.getCtx(),res); + contacts.add(contact); + } + close(res,pstmt); + loadRelations(contacts); + return contacts; + }catch(SQLException e){ + throw new RuntimeException(e); + } + } } \ No newline at end of file Index: SelectionSearch.java =================================================================== RCS file: /cvsroot/compiere/webStore/src/java/org/compiere/ifm/app/query/Attic/SelectionSearch.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** SelectionSearch.java 20 Jan 2005 13:02:34 -0000 1.1.2.3 --- SelectionSearch.java 21 Jan 2005 15:37:24 -0000 1.1.2.4 *************** *** 27,30 **** --- 27,33 ---- import org.compiere.model.M_IFM_Keyword; import org.compiere.model.M_IFM_Letter; + import org.compiere.model.M_IFM_Selection; + import org.compiere.model.M_IFM_Selection_Detail; + import org.compiere.model.M_IFM_Selection_Letter; import org.compiere.model.X_IFM_Selection; import org.compiere.util.DB; *************** *** 47,114 **** * @return */ ! public static List search(Properties ctx,WebUser wu,SelectionQuery query) { List selections = new ArrayList(); PreparedStatement stmt = null; try { StringBuffer sqlQuery = new StringBuffer( "SELECT * FROM IFM_Selection WHERE "); sqlQuery.append(" IFM_Selection.AD_Client_ID = ? "); ! sqlQuery.append(" AND EXISTS (select 1 from IFM_UserPermissions up WHERE IFM_Selection.IFM_PermissionGroup_ID = up.IFM_PermissionGroup_ID AND up.AD_User_ID = ?)"); if (isNotEmpty(query.getName())) { sqlQuery.append(" AND UPPER(Name) like UPPER(?)"); } ! if (query.getIsPrivate()!=null) { sqlQuery.append(" AND private=?"); } ! if (query.getCreated()!=null) { sqlQuery.append(" AND created=?"); } ! if (query.getCreatedBy()!=null) { sqlQuery.append(" AND createdBy=?"); ! } ! //String sql = MRole.getDefault(ctx,false).addAccessSQL(sqlQuery.toString(),"IFM_Contacts",true,false); stmt = DB.prepareStatement(sqlQuery.toString()); int pos = 1; stmt.setInt(pos++, Env.getAD_Client_ID(ctx)); ! stmt.setInt(pos++,wu.getAD_User_ID()); if (isNotEmpty(query.getName())) { ! stmt.setString(pos++, "%"+query.getName()+"%"); } ! if (query.getIsPrivate()!=null) { stmt.setBoolean(pos++, query.getIsPrivate().booleanValue()); } ! if (query.getCreated()!=null) { stmt.setDate(pos++, query.getCreated()); } ! if (query.getCreatedBy()!=null) { stmt.setInt(pos++, query.getCreatedBy().intValue()); ! } ! ! System.out.println("sql query = "+sqlQuery); ! ! ! ResultSet result = stmt.executeQuery(); int count = 0; while (result.next()) { ! X_IFM_Selection selection = new X_IFM_Selection(Env.getCtx(), result); selections.add(selection); count++; ! if(count==1000){ break; } } - //loadRelations(contacts); - } catch (SQLException e) { throw new RuntimeException("Could not execute search query", e); } finally { ! closeStatement(stmt); } ! System.out.println("selection size ="+selections.size()); return selections; } ! private static void closeStatement(PreparedStatement s) { if (s != null) { try { --- 50,185 ---- * @return */ ! public static List search(Properties ctx, WebUser wu, SelectionQuery query) { List selections = new ArrayList(); PreparedStatement stmt = null; + ResultSet result = null; try { StringBuffer sqlQuery = new StringBuffer( "SELECT * FROM IFM_Selection WHERE "); sqlQuery.append(" IFM_Selection.AD_Client_ID = ? "); ! sqlQuery ! .append(" AND EXISTS (select 1 from IFM_UserPermissions up WHERE IFM_Selection.IFM_PermissionGroup_ID = up.IFM_PermissionGroup_ID AND up.AD_User_ID = ?)"); if (isNotEmpty(query.getName())) { sqlQuery.append(" AND UPPER(Name) like UPPER(?)"); } ! if (query.getIsPrivate() != null) { sqlQuery.append(" AND private=?"); } ! if (query.getCreated() != null) { sqlQuery.append(" AND created=?"); } ! if (query.getCreatedBy() != null) { sqlQuery.append(" AND createdBy=?"); ! } ! //String sql = ! // MRole.getDefault(ctx,false).addAccessSQL(sqlQuery.toString(),"IFM_Contacts",true,false); stmt = DB.prepareStatement(sqlQuery.toString()); int pos = 1; stmt.setInt(pos++, Env.getAD_Client_ID(ctx)); ! stmt.setInt(pos++, wu.getAD_User_ID()); if (isNotEmpty(query.getName())) { ! stmt.setString(pos++, "%" + query.getName() + "%"); } ! if (query.getIsPrivate() != null) { stmt.setBoolean(pos++, query.getIsPrivate().booleanValue()); } ! if (query.getCreated() != null) { stmt.setDate(pos++, query.getCreated()); } ! if (query.getCreatedBy() != null) { stmt.setInt(pos++, query.getCreatedBy().intValue()); ! } ! ! result = stmt.executeQuery(); int count = 0; while (result.next()) { ! M_IFM_Selection selection = new M_IFM_Selection(Env.getCtx(), ! result); selections.add(selection); count++; ! if (count == 1000) { break; } } } catch (SQLException e) { throw new RuntimeException("Could not execute search query", e); } finally { ! close(result, stmt); } ! System.out.println("selection size =" + selections.size()); return selections; } ! public static void loadMembers(M_IFM_Selection selection) { ! List members = new ArrayList(30); ! List contactIds = new ArrayList(30); ! HashMap membersByContactId = new HashMap(members.size()); ! PreparedStatement stmt = null; ! ResultSet result = null; ! try { ! String sqlQuery = "SELECT * FROM IFM_Selection_Detail WHERE IFM_Selection_ID = ?"; ! stmt = DB.prepareStatement(sqlQuery); ! stmt.setInt(1, selection.getIFM_Selection_ID()); ! result = stmt.executeQuery(); ! int count = 0; ! while (result.next()) { ! M_IFM_Selection_Detail member = new M_IFM_Selection_Detail(Env ! .getCtx(), result); ! members.add(member); ! contactIds.add(new Integer(member.getIFM_Contacts_ID())); ! membersByContactId.put( ! new Integer(member.getIFM_Contacts_ID()), member); ! count++; ! if (count == 1000) { ! break; ! } ! } ! List contacts = ContactSearch.loadContacts(contactIds); ! for (Iterator iter = contacts.iterator(); iter.hasNext();) { ! M_IFM_Contacts element = (M_IFM_Contacts) iter.next(); ! M_IFM_Selection_Detail member = (M_IFM_Selection_Detail) membersByContactId ! .get(new Integer(element.getIFM_Contacts_ID())); ! member.setIFM_Contacts(element); ! } ! ! } catch (SQLException e) { ! throw new RuntimeException("Could not execute search query", e); ! } finally { ! close(result, stmt); ! } ! selection.setMembers(members); ! } ! ! public static void loadLetters(M_IFM_Selection selection) { ! List letters = new ArrayList(30); ! PreparedStatement stmt = null; ! ResultSet result = null; ! try { ! String sqlQuery = "SELECT * FROM IFM_Selection_Letter WHERE IFM_Selection_ID = ?"; ! stmt = DB.prepareStatement(sqlQuery); ! stmt.setInt(1, selection.getIFM_Selection_ID()); ! result = stmt.executeQuery(); ! int count = 0; ! while (result.next()) { ! M_IFM_Selection_Letter letter = new M_IFM_Selection_Letter(Env ! .getCtx(), result); ! letters.add(letter); ! } ! } catch (SQLException e) { ! throw new RuntimeException("Could not execute search query", e); ! } finally { ! close(result, stmt); ! } ! selection.setLetters(letters); ! } ! ! private static void close(ResultSet rs, PreparedStatement s) { ! if (rs != null) { ! try { ! rs.close(); ! } catch (SQLException e) { ! } ! } if (s != null) { try { *************** *** 119,122 **** } } - } \ No newline at end of file --- 190,192 ---- |