KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc2 > EJBQLQueryCommand


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.jdbc2;
23
24 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2;
25 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMPFieldBridge2;
26 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQlQueryMetaData;
27 import org.jboss.ejb.plugins.cmp.jdbc.QLCompiler;
28 import org.jboss.ejb.plugins.cmp.jdbc.EJBQLToSQL92Compiler;
29 import org.jboss.logging.Logger;
30 import org.jboss.deployment.DeploymentException;
31
32
33 /**
34  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
35  * @version <tt>$Revision: 58402 $</tt>
36  */

37 public class EJBQLQueryCommand
38    extends AbstractQueryCommand
39 {
40    public EJBQLQueryCommand(JDBCEntityBridge2 entity, JDBCQlQueryMetaData metadata) throws DeploymentException
41    {
42       this.entity = entity;
43
44       JDBCStoreManager2 manager = (JDBCStoreManager2)entity.getManager();
45       QLCompiler compiler = new EJBQLToSQL92Compiler(manager.getCatalog());
46
47       try
48       {
49          compiler.compileEJBQL(
50             metadata.getEjbQl(),
51             metadata.getMethod().getReturnType(),
52             metadata.getMethod().getParameterTypes(),
53             metadata);
54       }
55       catch(Throwable JavaDoc t)
56       {
57          t.printStackTrace();
58          throw new DeploymentException("Error compiling EJBQL statement '" + metadata.getEjbQl() + "'", t);
59       }
60
61       sql = compiler.getSQL();
62
63       log = Logger.getLogger(getClass().getName() + "." + entity.getEntityName() + "#" + metadata.getMethod().getName());
64       log.debug("sql: " + sql);
65
66       setParameters(compiler.getInputParameters());
67       setResultType(metadata.getMethod().getReturnType());
68
69       if(!compiler.isSelectEntity())
70       {
71          if(compiler.isSelectField())
72          {
73             setFieldReader((JDBCCMPFieldBridge2)compiler.getSelectField());
74          }
75          else
76          {
77             setFunctionReader(compiler.getSelectFunction());
78          }
79       }
80       else
81       {
82          setEntityReader((JDBCEntityBridge2)compiler.getSelectEntity(), compiler.isSelectDistinct());
83       }
84    }
85 }
86
Popular Tags