Changeset 2613


Ignore:
Timestamp:
01/31/10 09:59:16 (2 years ago)
Author:
jvelde
Message:

Removed ForceCommit? option from CsvImport?. Improved transaction/error handling.

Location:
molgenis/3.3/src/org/molgenis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • molgenis/3.3/src/org/molgenis/generators/csv/CsvImportGen.java.ftl

    r2589 r2613  
    7272        public static void importAll(File directory, Database db, Tuple defaults) throws Exception 
    7373        { 
    74                 importAll(directory,db,defaults,null, DatabaseAction.ADD, "NA", false); 
    75         } 
    76          
    77         public static void importAll(File directory, Database db, Tuple defaults, boolean forceCommits) throws Exception 
    78         { 
    79                 importAll(directory,db,defaults,null, DatabaseAction.ADD, "NA", forceCommits); 
     74                importAll(directory, db, defaults, null, DatabaseAction.ADD, "NA"); 
    8075        } 
    8176 
     
    8479         * TODO: add filter parameters... 
    8580         */ 
    86         public static ImportResult importAll(File directory, Database db, Tuple defaults, List<String> components, DatabaseAction dbAction, String missingValue, boolean forceCommits) throws Exception 
     81        public static ImportResult importAll(File directory, Database db, Tuple defaults, List<String> components, DatabaseAction dbAction, String missingValue) throws Exception 
    8782        { 
    8883                ImportResult result = new ImportResult(); 
     
    9085                try 
    9186                { 
    92                         if(!db.inTx()){ db.beginTx(); } 
     87                        if (!db.inTx()) 
     88                        { 
     89                                db.beginTx(); 
     90                        }else{ 
     91                                throw new DatabaseException("Cannot continue CsvImport: database already in transaction."); 
     92                        } 
    9393                                                 
    9494                        if(dbAction.toString().startsWith("REMOVE")) 
     
    117117                                { 
    118118                                        try { 
    119                                                 if(forceCommits && !db.inTx()){ db.beginTx(); } 
    120119                                                int count = new ${JavaName(entity)}CsvReader().importCsv(db, new File(directory+"/${entity.name?lower_case}.txt"), defaults, dbAction, missingValue); 
    121120                                                result.getProgressLog().add("${entity.name?lower_case}"); 
    122121                                                result.getMessages().put("${entity.name?lower_case}",  "evaluated "+count+" ${entity.name?lower_case} elements"); 
    123                                                 if(forceCommits){ db.commitTx(); } 
    124122                                        } catch (Exception e) { 
    125123                                                result.setErrorItem("${entity.name?lower_case}"); 
     
    131129                        }                        
    132130                         
    133                         // insert back again... 
    134131                        logger.debug("commiting transactions..."); 
    135                         if(db.inTx() && !forceCommits) db.commitTx(); 
     132                        if (db.inTx()){ 
     133                                db.commitTx(); 
     134                        }else{ 
     135                                throw new DatabaseException("Cannot commit CsvImport: database not in transaction."); 
     136                        } 
    136137                } 
    137138                catch (Exception e) 
    138139                { 
    139                         logger.error("import failed: " + e.getMessage()); 
    140                         logger.debug("rolling back transactions..."); 
    141                         if(db.inTx()) db.rollbackTx(); 
    142  
     140                        logger.error("Import failed: " + e.getMessage()); 
     141                        if (db.inTx()){ 
     142                                logger.debug("Db in transaction, rolling back..."); 
     143                                db.rollbackTx(); 
     144                        }else{ 
     145                                logger.debug("Db not in transaction"); 
     146                        } 
    143147                        e.printStackTrace(); 
     148                         
     149                        //Don't throw to avoid 'try-catch' on usage. No harm done. 
    144150                        //throw e; 
    145151                } 
  • molgenis/3.3/src/org/molgenis/model/elements/Entity.java

    r2612 r2613  
    570570                        all_fields.put(f.getName(), f); 
    571571                } 
    572                  
    573                  
    574                 logger.info("herken " + all_fields.keySet()); 
    575572                return new Vector(all_fields.values()); 
    576573        } 
Note: See TracChangeset for help on using the changeset viewer.