Changeset 2403


Ignore:
Timestamp:
11/01/09 14:14:20 (2 years ago)
Author:
jvelde
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molgenis/3.3/src/org/molgenis/framework/db/jdbc/AbstractJDBCMapper.java

    r2393 r2403  
    591591        } 
    592592 
    593         public void find(CsvWriter writer, boolean skipIdFields, QueryRule... rules) throws DatabaseException 
    594         { 
    595                 try 
    596                 { 
     593        /** 
     594         * Reason for backup: function needs to be looked at - possible bug 
     595         * See other find() function below for explanation! 
     596         */ 
     597        public void findBACKUP(CsvWriter writer, boolean skipIdFields, QueryRule... rules) throws DatabaseException 
     598        { 
     599                try 
     600                { 
     601                        System.out.println("new ResultSetTuple(executeSelect(rules)...."); 
    597602                        ResultSetTuple rs = new ResultSetTuple(executeSelect(rules)); 
    598603                        System.out.println("executeSelect(rules)"); 
     
    666671                } 
    667672        } 
     673         
     674        public void find(CsvWriter writer, boolean skipIdFields, QueryRule... rules) throws DatabaseException 
     675        { 
     676                try 
     677                { 
     678                        System.out.println("new ResultSetTuple(executeSelect(rules)...."); 
     679                        ResultSetTuple rs = new ResultSetTuple(executeSelect(rules)); 
     680                        System.out.println("executeSelect(rules)"); 
     681                        for(QueryRule q : rules){ 
     682                                System.out.println("rule: " + q.toString()); 
     683                        } 
     684                        // transform result set in writer 
     685                        E entity = create(); 
     686                        Vector<String> fields; 
     687                         
     688                        if (skipIdFields) 
     689                        { 
     690                                fields = entity.getFields(); 
     691                                Vector<String> fieldsCopy = entity.getFields(); 
     692                                fieldsCopy.remove("id"); 
     693                                for(String field : fields){ 
     694                                        if(hasXrefByNameEquivalent(field, fields)){ 
     695                                                fieldsCopy.remove(field); 
     696                                        } 
     697                                } 
     698                                fields = fieldsCopy; 
     699                        } 
     700                        else 
     701                        { 
     702                                fields = entity.getFields(); 
     703                        } 
     704                        writer.setHeaders(fields); 
     705                        writer.writeHeader(); 
     706                        int i = 0; 
     707                        List<E> entityBatch = new ArrayList<E>(); 
     708                        while (rs.next()) 
     709                        { 
     710                                entity = create(); 
     711                                entity.set(rs); 
     712                                entityBatch.add(entity); 
     713                                i++; 
     714 
     715                                // write batch 
     716                                if (i % BATCH_SIZE == 0) 
     717                                { 
     718                                        // load mrefs 
     719                                        try{ 
     720                                        mapMrefs(entityBatch); 
     721                                        //FIXME: this FAILS because rs is open!! program ends without try-catch 
     722                                        //strange: problem seems to occur in very specific cases.. 
     723                                        //reasons? speculation.. 
     724                                        // a) either the function gets usually empty values and exits (no mrefs) 
     725                                        // b) the specific data causes an error that bugs the function, rs is not closed, and errors here 
     726                                        // c) ... ? 
     727                                        //is the function that opens another rs allowed here? 
     728                                        //ie. can it be executed at all? and why would it fail if it has been tested? 
     729                                        } 
     730                                        catch(Exception e){ 
     731                                                e.printStackTrace(); 
     732                                        } 
     733                                        for (E e : entityBatch) 
     734                                        { 
     735                                                writer.writeRow(e); 
     736                                        } 
     737                                        entityBatch.clear(); 
     738                                } 
     739                        } 
     740                        // write remaining 
     741                        // load mrefs 
     742                        mapMrefs(entityBatch); 
     743                        for (E e : entityBatch) 
     744                        { 
     745                                writer.writeRow(e); 
     746                        } 
     747                        entityBatch.clear(); 
     748 
     749                        rs.close(); 
     750 
     751                        logger.debug("find(" + create().getClass().getSimpleName() + ", CsvWriter, " + Arrays.asList(rules) 
     752                                        + "): wrote " + i + " lines."); 
     753                } 
     754                catch (Exception e) 
     755                { 
     756                        throw new DatabaseException(e); 
     757                } 
     758                finally 
     759                { 
     760                        getDatabase().closeConnection(); 
     761                } 
     762        } 
    668763 
    669764        /** 
Note: See TracChangeset for help on using the changeset viewer.