Changeset 2632 for molgenis4animaldb
- Timestamp:
- 02/08/10 14:53:20 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
molgenis4animaldb/handwritten/java/decorators/FeatureDecorator.java
r2631 r2632 31 31 super(generatedMapper); 32 32 } 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) { 41 35 String eventTypeName; 42 36 String featureName; 43 Database db = null; 44 db = this.getDatabase(); 37 Database db = this.getDatabase(); 45 38 46 39 for (animaldb.Feature e : entities) { … … 56 49 } catch (IOException e1) { 57 50 e1.printStackTrace(); 51 return false; 52 } catch (DatabaseException e1) { 53 e1.printStackTrace(); 54 return false; 58 55 } 59 56 … … 63 60 q.addRules(new QueryRule("name", Operator.EQUALS, eventTypeName)); 64 61 try { 65 List<EventType> eventTypeList = q.find(); 62 List<EventType> eventTypeList = q.find(); 66 63 for (EventType et : eventTypeList) { 67 64 etId = et.getId(); … … 69 66 } catch (ParseException e1) { 70 67 e1.printStackTrace(); 68 return false; 69 } catch (DatabaseException e1) { 70 e1.printStackTrace(); 71 return false; 71 72 } 72 73 int featId = -99; … … 80 81 } catch (ParseException e1) { 81 82 e1.printStackTrace(); 83 return false; 84 } catch (DatabaseException e1) { 85 e1.printStackTrace(); 86 return false; 82 87 } 83 88 … … 90 95 } catch (IOException e1) { 91 96 e1.printStackTrace(); 97 return false; 98 } catch (DatabaseException e1) { 99 e1.printStackTrace(); 100 return false; 92 101 } 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"); 93 146 } 94 147 … … 96 149 } 97 150 98 public int update(List< animaldb.Feature> entities) throws DatabaseException {151 public int update(List<Feature> entities) throws DatabaseException { 99 152 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 } 105 157 106 158 // here we call the standard 'update' 107 159 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 112 163 return count; 113 164 } … … 115 166 public int remove(List<animaldb.Feature> entities) throws DatabaseException { 116 167 // add your pre-processing here 168 if (!remCorrEventType(entities)) { 169 throw new DatabaseException("Could not remove corresponding event type - feature not removed"); 170 } 117 171 118 172 // here we call the standard 'remove' 119 173 int count = super.remove(entities); 120 174 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: 124 176 125 177 return count;
Note: See TracChangeset
for help on using the changeset viewer.