1 23 24 package transactionsDiscRack.business.disc; 25 26 import transactionsDiscRack.spec.*; 27 import transactionsDiscRack.data.person.PersonDO; 28 import transactionsDiscRack.data.disc.*; 29 30 import transactionsDiscRack.business.TransactionsDiscRackBusinessException; 31 import com.lutris.dods.builder.generator.query.*; 32 33 import com.lutris.appserver.server.sql.DatabaseManagerException; 34 import com.lutris.appserver.server.sql.ObjectIdException; 35 import com.lutris.dods.builder.generator.query.DataObjectException; 36 import org.enhydra.dods.exceptions.AssertionDataObjectException; 37 import com.lutris.appserver.server.sql.DBTransaction; 38 import org.enhydra.dods.*; 39 40 43 public class DiscImpl implements Disc{ 44 47 protected DiscDO myDO = null; 48 49 52 public DiscImpl() throws TransactionsDiscRackBusinessException { 53 DBTransaction trans = null; 54 try { 55 try{ 56 trans = DODS.getDatabaseManager().createTransaction(); 57 }catch(Exception ex){ 58 throw new DatabaseManagerException("Error creating transaction!", ex); 59 } 60 prep(trans); 61 this.myDO = DiscDO.createVirgin(trans); 62 } catch(DatabaseManagerException ex) { 63 throw new TransactionsDiscRackBusinessException("Error creating empty Disc", ex); 64 } catch(ObjectIdException ex) { 65 throw new TransactionsDiscRackBusinessException("Error creating empty Disc", ex); 66 } 67 } 68 69 73 protected DiscImpl(DiscDO theDisc) 74 throws TransactionsDiscRackBusinessException { 75 this.myDO = theDisc; 76 } 77 78 86 public String getHandle() 87 throws TransactionsDiscRackBusinessException { 88 try { 89 return this.myDO.getHandle(); 90 } catch(DatabaseManagerException ex) { 91 throw new TransactionsDiscRackBusinessException("Error getting disc's handle", ex); 92 } 93 } 94 95 103 public String getTitle() 104 throws TransactionsDiscRackBusinessException { 105 try { 106 return myDO.getTitle(); 107 } catch(DataObjectException ex) { 108 throw new TransactionsDiscRackBusinessException("Error getting disc's title", ex); 109 } 110 } 111 112 120 public String getArtist() 121 throws TransactionsDiscRackBusinessException { 122 try { 123 return myDO.getArtist(); 124 } catch(DataObjectException ex) { 125 throw new TransactionsDiscRackBusinessException("Error getting disc's artist", ex); 126 } 127 } 128 129 137 public String getGenre() 138 throws TransactionsDiscRackBusinessException { 139 try { 140 return myDO.getGenre(); 141 } catch(DataObjectException ex) { 142 throw new TransactionsDiscRackBusinessException("Error getting disc's genre", ex); 143 } 144 } 145 146 154 public boolean isLiked() 155 throws TransactionsDiscRackBusinessException { 156 try { 157 return myDO.getIsLiked(); 158 } catch(DataObjectException ex) { 159 throw new TransactionsDiscRackBusinessException("Error getting disc's likedness", ex); 160 } 161 } 162 163 171 public void setTitle(String title) 172 throws TransactionsDiscRackBusinessException { 173 try { 174 this.myDO .setTitle(title); 175 } catch(DataObjectException ex) { 176 throw new TransactionsDiscRackBusinessException("Error setting disc's title", ex); 177 } 178 } 179 180 188 public void setArtist(String artist) 189 throws TransactionsDiscRackBusinessException { 190 try { 191 this.myDO.setArtist(artist); 192 } catch(DataObjectException ex) { 193 throw new TransactionsDiscRackBusinessException("Error setting disc's artist", ex); 194 } 195 } 196 197 205 public void setGenre(String genre) 206 throws TransactionsDiscRackBusinessException { 207 try { 208 this.myDO.setGenre(genre); 209 } catch(DataObjectException ex) { 210 throw new TransactionsDiscRackBusinessException("Error setting disc's genre", ex); 211 } 212 } 213 214 222 public void setOwner(Person owner) 223 throws TransactionsDiscRackException 224 { 225 try { 226 this.myDO.setOwner(PersonDO.createExisting(owner.getHandle(),myDO.get_transaction())); 227 } catch(DataObjectException ex) { 228 ex.printStackTrace(); 229 throw new TransactionsDiscRackBusinessException("Error setting disc's owner", ex); 230 } 231 } 232 233 241 public void setLiked(boolean isLiked) 242 throws TransactionsDiscRackBusinessException { 243 try { 244 this.myDO.setIsLiked(isLiked); 245 } catch(DataObjectException ex) { 246 throw new TransactionsDiscRackBusinessException("Error setting disc's likedness", ex); 247 } 248 } 249 250 251 258 public void save() 259 throws TransactionsDiscRackBusinessException, AssertionDataObjectException { 260 try { 261 prep(this.myDO.get_transaction()); 262 this.myDO.save(); 263 this.myDO.get_transaction().commit(); 264 } 265 catch (AssertionDataObjectException ex) { 266 throw new AssertionDataObjectException("Read-only table: DML operations not allowed", ex); 267 } 268 catch(Exception ex) { 269 throw new TransactionsDiscRackBusinessException("Error saving disc", ex); 270 } 271 } 272 private void prep(DBTransaction trans) { 273 try { 274 DiscQuery query = new DiscQuery(trans); 275 query.setQueryHandle("0"); 276 query.requireUniqueInstance(); 277 query.getNextDO(); 278 } catch (Exception exc){} 279 } 280 281 288 public void delete() 289 throws TransactionsDiscRackBusinessException, AssertionDataObjectException { 290 try { 291 prep(this.myDO.get_transaction()); 292 this.myDO.delete(); 293 this.myDO.get_transaction().commit(); 294 } 295 catch (AssertionDataObjectException ex) { 296 throw new AssertionDataObjectException("Read-only table: DML operations not allowed", ex); 297 } 298 catch(Exception ex) { 299 throw new TransactionsDiscRackBusinessException("Error deleting disc", ex); 300 } 301 } 302 305 public void dbtRelease() { 306 myDO.get_transaction().release(); 307 } 308 } 309 | Popular Tags |