KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc > JDBCCommandFactory


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins.cmp.jdbc;
23
24 import org.jboss.deployment.DeploymentException;
25 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData;
26 import org.jboss.logging.Logger;
27
28 /**
29  * JDBCCommandFactory creates all required CMP command and some JDBC
30  * specific commands. This class should not store any data, which
31  * should be put in the store manager.
32  *
33  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
34  * @author <a HREF="mailto:justin@j-m-f.demon.co.uk">Justin Forder</a>
35  * @author <a HREF="danch@nvisia.com">danch (Dan Christopherson</a>
36  * @author <a HREF="loubyansky@ua.fm">Alex Loubyansky</a>
37  * @version $Revision: 43506 $
38  */

39 public class JDBCCommandFactory
40 {
41
42    private final Logger log;
43    private final JDBCStoreManager manager;
44
45    public JDBCCommandFactory(JDBCStoreManager manager) throws Exception JavaDoc
46    {
47       this.manager = manager;
48
49       log = Logger.getLogger(
50          this.getClass().getName() +
51          "." +
52          manager.getContainer().getBeanMetaData().getEjbName());
53    }
54
55    public JDBCQueryCommand createFindByPrimaryKeyQuery(JDBCQueryMetaData q)
56       throws DeploymentException
57    {
58       return new JDBCFindByPrimaryKeyQuery(manager, q);
59    }
60
61    public JDBCQueryCommand createFindAllQuery(JDBCQueryMetaData q) throws DeploymentException
62    {
63       return new JDBCFindAllQuery(manager, q);
64    }
65
66    public JDBCQueryCommand createDeclaredSQLQuery(JDBCQueryMetaData q)
67       throws DeploymentException
68    {
69       return new JDBCDeclaredSQLQuery(manager, q);
70    }
71
72    public JDBCQueryCommand createEJBQLQuery(JDBCQueryMetaData q)
73       throws DeploymentException
74    {
75       return new JDBCEJBQLQuery(manager, q);
76    }
77
78    public JDBCQueryCommand createDynamicQLQuery(JDBCQueryMetaData q)
79       throws DeploymentException
80    {
81       return new JDBCDynamicQLQuery(manager, q);
82    }
83
84    public JDBCQueryCommand createJBossQLQuery(JDBCQueryMetaData q)
85       throws DeploymentException
86    {
87       return new JDBCJBossQLQuery(manager, q);
88    }
89
90    public JDBCQueryCommand createFindByQuery(JDBCQueryMetaData q)
91       throws DeploymentException
92    {
93       return new JDBCFindByQuery(manager, q);
94    }
95
96    public JDBCLoadRelationCommand createLoadRelationCommand()
97    {
98       return new JDBCLoadRelationCommand(manager);
99    }
100
101    public JDBCDeleteRelationsCommand createDeleteRelationsCommand()
102    {
103       return new JDBCDeleteRelationsCommand(manager);
104    }
105
106    public JDBCInsertRelationsCommand createInsertRelationsCommand()
107    {
108       return new JDBCInsertRelationsCommand(manager);
109    }
110
111    // lifecycle commands
112

113    public JDBCInitCommand createInitCommand()
114    {
115       return new JDBCInitCommand(manager);
116    }
117
118    public JDBCStartCommand createStartCommand()
119    {
120       return new JDBCStartCommand(manager);
121    }
122
123    public JDBCStopCommand createStopCommand()
124    {
125       return new JDBCStopCommand(manager);
126    }
127
128    public JDBCDestroyCommand createDestroyCommand()
129    {
130       return new JDBCDestroyCommand(manager);
131    }
132
133    // entity life cycle commands
134

135    public JDBCCreateBeanClassInstanceCommand
136       createCreateBeanClassInstanceCommand() throws Exception JavaDoc
137    {
138
139       return new JDBCCreateBeanClassInstanceCommand(manager);
140    }
141
142    public JDBCInitEntityCommand createInitEntityCommand()
143    {
144       return new JDBCInitEntityCommand(manager);
145    }
146
147    public JDBCFindEntityCommand createFindEntityCommand()
148    {
149       return new JDBCFindEntityCommand(manager);
150    }
151
152    public JDBCFindEntitiesCommand createFindEntitiesCommand()
153    {
154       return new JDBCFindEntitiesCommand(manager);
155    }
156
157    public JDBCCreateCommand createCreateEntityCommand()
158       throws DeploymentException
159    {
160
161       JDBCCreateCommand cec;
162       try
163       {
164          cec = (JDBCCreateCommand)manager.getMetaData().
165             getEntityCommand().getCommandClass().newInstance();
166          cec.init(manager);
167       }
168       catch(DeploymentException de)
169       {
170          throw de;
171       }
172       catch(Exception JavaDoc e)
173       {
174          throw new DeploymentException("Couldn't create entity command: ", e);
175       }
176
177       if(log.isDebugEnabled())
178          log.debug("entity-command: " + manager.getMetaData().getEntityCommand());
179
180       return cec;
181    }
182
183
184    public JDBCPostCreateEntityCommand createPostCreateEntityCommand()
185    {
186
187       return new JDBCPostCreateEntityCommand(manager);
188
189    }
190
191
192    public JDBCRemoveEntityCommand createRemoveEntityCommand()
193       throws DeploymentException
194    {
195       return new JDBCRemoveEntityCommand(manager);
196    }
197
198    public JDBCLoadEntityCommand createLoadEntityCommand() throws DeploymentException
199    {
200       return new JDBCLoadEntityCommand(manager);
201    }
202
203    public JDBCIsModifiedCommand createIsModifiedCommand()
204    {
205       return new JDBCIsModifiedCommand(manager);
206    }
207
208    public JDBCStoreEntityCommand createStoreEntityCommand()
209    {
210       return new JDBCStoreEntityCommand(manager);
211    }
212
213    // entity activation and passivation commands
214
public JDBCActivateEntityCommand createActivateEntityCommand()
215    {
216       return new JDBCActivateEntityCommand(manager);
217    }
218
219    public JDBCPassivateEntityCommand createPassivateEntityCommand()
220    {
221       return new JDBCPassivateEntityCommand(manager);
222    }
223 }
224
Popular Tags