Changeset 2632 for molgenis4animaldb


Ignore:
Timestamp:
02/08/10 14:53:20 (2 years ago)
Author:
erikroos
Message:

Corresponding event types also updated/deleted when feature is updated/removed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molgenis4animaldb/handwritten/java/decorators/FeatureDecorator.java

    r2631 r2632  
    3131                super(generatedMapper); 
    3232        } 
    33  
    34         public int add(List<Feature> entities) throws DatabaseException { 
    35                 // add your pre-processing here 
    36  
    37                 // here we call the standard 'add' 
    38                 int count = super.add(entities); 
    39  
    40                 // post-processing: 
     33         
     34        private boolean makeCorrEventType(List<Feature> entities) { 
    4135                String eventTypeName; 
    4236                String featureName; 
    43                 Database db = null; 
    44                 db = this.getDatabase(); 
     37                Database db = this.getDatabase(); 
    4538 
    4639                for (animaldb.Feature e : entities) { 
     
    5649                        } catch (IOException e1) { 
    5750                                e1.printStackTrace(); 
     51                                return false; 
     52                        } catch (DatabaseException e1) { 
     53                                e1.printStackTrace(); 
     54                                return false; 
    5855                        } 
    5956 
     
    6360                        q.addRules(new QueryRule("name", Operator.EQUALS, eventTypeName)); 
    6461                        try { 
    65                                 List<EventType> eventTypeList = q.find(); 
     62                                List<EventType> eventTypeList = q.find();                
    6663                                for (EventType et : eventTypeList) { 
    6764                                        etId = et.getId(); 
     
    6966                        } catch (ParseException e1) { 
    7067                                e1.printStackTrace(); 
     68                                return false; 
     69                        } catch (DatabaseException e1) { 
     70                                e1.printStackTrace(); 
     71                                return false; 
    7172                        } 
    7273                        int featId = -99; 
     
    8081                        } catch (ParseException e1) { 
    8182                                e1.printStackTrace(); 
     83                                return false; 
     84                        } catch (DatabaseException e1) { 
     85                                e1.printStackTrace(); 
     86                                return false; 
    8287                        } 
    8388 
     
    9095                        } catch (IOException e1) { 
    9196                                e1.printStackTrace(); 
     97                                return false; 
     98                        } catch (DatabaseException e1) { 
     99                                e1.printStackTrace(); 
     100                                return false; 
    92101                        } 
     102                } 
     103                return true; 
     104        } 
     105         
     106        private boolean remCorrEventType(List<Feature> entities) { 
     107                String eventTypeName; 
     108                String featureName; 
     109                Database db = this.getDatabase(); 
     110         
     111                for (animaldb.Feature e : entities) { 
     112                        featureName = e.getName(); 
     113 
     114                        // Remove corresponding event type 
     115                        eventTypeName = "Set" + featureName; 
     116                        Query q = db.query(EventType.class); 
     117                        q.addRules(new QueryRule("name", Operator.EQUALS, eventTypeName)); 
     118                        try { 
     119                                List<EventType> eventTypeList = q.find(); 
     120                                for (EventType et : eventTypeList) { 
     121                                        db.remove(et); 
     122                                } 
     123                        } catch (DatabaseException e1) { 
     124                                e1.printStackTrace(); 
     125                                return false; 
     126                        } catch (ParseException e1) { 
     127                                e1.printStackTrace(); 
     128                                return false; 
     129                        } catch (IOException e1) { 
     130                                e1.printStackTrace(); 
     131                                return false; 
     132                        } 
     133                } 
     134                return true; 
     135        } 
     136 
     137        public int add(List<Feature> entities) throws DatabaseException { 
     138                // add your pre-processing here 
     139 
     140                // here we call the standard 'add' 
     141                int count = super.add(entities); 
     142                 
     143                // post-processing: 
     144                if (!makeCorrEventType(entities)) { 
     145                        throw new DatabaseException("Could not make corresponding event type - feature not added"); 
    93146                } 
    94147 
     
    96149        } 
    97150 
    98         public int update(List<animaldb.Feature> entities) throws DatabaseException { 
     151        public int update(List<Feature> entities) throws DatabaseException { 
    99152 
    100                 // add your pre-processing here, e.g. 
    101                 // for (animaldb.Feature e : entities) 
    102                 // { 
    103                 // e.setTriggeredField("Before update called!!!"); 
    104                 // } 
     153                // add your pre-processing here 
     154                if (!remCorrEventType(entities) || !makeCorrEventType(entities)) { 
     155                        throw new DatabaseException("Could not update corresponding event type - feature not updated"); 
     156                } 
    105157 
    106158                // here we call the standard 'update' 
    107159                int count = super.update(entities); 
    108  
    109                 // add your post-processing here 
    110                 // if you throw and exception the previous add will be rolled back 
    111  
     160                 
     161                // post-processing: 
     162                 
    112163                return count; 
    113164        } 
     
    115166        public int remove(List<animaldb.Feature> entities) throws DatabaseException { 
    116167                // add your pre-processing here 
     168                if (!remCorrEventType(entities)) { 
     169                        throw new DatabaseException("Could not remove corresponding event type - feature not removed"); 
     170                } 
    117171 
    118172                // here we call the standard 'remove' 
    119173                int count = super.remove(entities); 
    120174 
    121                 // add your post-processing here, e.g. 
    122                 // if(true) throw new 
    123                 // SQLException("Because of a post trigger the remove is cancelled."); 
     175                // post-processing: 
    124176 
    125177                return count; 
Note: See TracChangeset for help on using the changeset viewer.