KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > distrans > persistence > ReadWrapper


1 /*
2   Copyright (C) 2001-2003 Lionel Seinturier <Lionel.Seinturier@lip6.fr>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.distrans.persistence;
19
20 import org.enhydra.jdbc.standard.StandardXADataSource;
21
22 import org.objectweb.jac.core.AspectComponent;
23 import org.objectweb.jac.core.Interaction;
24 import org.objectweb.jac.core.NameRepository;
25 import org.objectweb.jac.core.Wrapper;
26 import org.objectweb.jac.util.Repository;
27
28 import org.aopalliance.intercept.ConstructorInvocation;
29 import org.aopalliance.intercept.MethodInvocation;
30
31 /**
32  * This class define a wrapping method (read) for wrappees that perform
33  * read operations on transactional ressources.
34  * This wrapper may wrap several wrappees from different classes.
35  * Each wrappee field is mapped onto a SQL table attribute.
36  * The SQL tables contain one more attribute which is the name of the wrappee,
37  * and which is also the primary key of the table.
38  *
39  * @author Lionel Seinturier <Lionel.Seinturier@lip6.fr>
40  * @version 1.0
41  */

42 public class ReadWrapper extends Wrapper {
43
44     /**
45      * The instance implementing the technical API for persistence.
46      * SimpleDbPersistence implements it.
47      */

48     private PersistenceItf storage;
49     
50     /**
51      * The data source used to open a connection towards the database
52      * where the data is stored.
53      */

54     private StandardXADataSource ds;
55     
56     /**
57      * @param ac the AC managing this wrapper
58      * @param storage the technical instance for persistence
59      * @param ds the data source used to create a connection towards
60      * the database where the data is stored
61      */

62     public ReadWrapper(
63         AspectComponent ac, PersistenceItf storage, StandardXADataSource ds ) {
64         
65         super(ac);
66         this.storage = storage;
67         this.ds = ds;
68     }
69
70     /**
71      * Wrapping method for wrappees that perform
72      * write operations on transactional ressources.
73      * After proceeding the interaction, fields value are saved
74      * into the database.
75      * Fetching (ie reading) the data before, is a way to let the database
76      * manage the blocking mechanism whenever concurrent transactions occur.
77      */

78     public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
79         
80         Interaction interaction = (Interaction) invocation;
81
82         Object JavaDoc wrappee = interaction.wrappee;
83         String JavaDoc wrappeeName = names.getName(wrappee);
84         
85         try {
86             storage.load(wrappee,wrappeeName,ds);
87         } catch (Exception JavaDoc e) {
88             e.printStackTrace();
89             System.exit(1);
90         }
91         
92         return proceed(interaction);
93     }
94         
95     
96     /**
97      * The reference towards the JAC name repository.
98      * Needed by applyPersistence().
99      */

100     private Repository names = NameRepository.get();
101
102     public Object JavaDoc construct(ConstructorInvocation invocation)
103         throws Throwable JavaDoc {
104         throw new Exception JavaDoc("This wrapper does not support constructor wrapping");
105     }
106 }
107
Popular Tags