KickJava   Java API By Example, From Geeks To Geeks.

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


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.bridge.JDBCEntityBridge;
26 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge;
27 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCFieldBridge;
28 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQlQueryMetaData;
29 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData;
30 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData;
31
32 /**
33  * This class generates a query from EJB-QL.
34  *
35  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
36  * @author <a HREF="mailto:alex@jboss.org">Alex Loubyansky</a>
37  * @version $Revision: 58402 $
38  */

39 public final class JDBCEJBQLQuery extends JDBCAbstractQueryCommand
40 {
41
42    public JDBCEJBQLQuery(JDBCStoreManager manager,
43                          JDBCQueryMetaData q)
44       throws DeploymentException
45    {
46       super(manager, q);
47
48       JDBCQlQueryMetaData metadata = (JDBCQlQueryMetaData) q;
49       if(getLog().isDebugEnabled())
50       {
51          getLog().debug("EJB-QL: " + metadata.getEjbQl());
52       }
53
54       QLCompiler compiler = JDBCQueryManager.getInstance(metadata.getQLCompilerClass(), manager.getCatalog());
55
56       try
57       {
58          compiler.compileEJBQL(
59             metadata.getEjbQl(),
60             metadata.getMethod().getReturnType(),
61             metadata.getMethod().getParameterTypes(),
62             metadata);
63       }
64       catch(Throwable JavaDoc t)
65       {
66          log.error(t.getMessage(), t);
67          throw new DeploymentException("Error compiling EJB-QL statement for EJB '" +
68             manager.getContainer().getBeanMetaData().getEjbName() + "': " + metadata.getEjbQl(), t);
69       }
70
71       setSQL(compiler.getSQL());
72
73       // set select object
74
if(compiler.isSelectEntity())
75       {
76          JDBCEntityBridge selectEntity = (JDBCEntityBridge) compiler.getSelectEntity();
77
78          // set the select entity
79
setSelectEntity(selectEntity);
80
81          // set the preload fields
82
JDBCReadAheadMetaData readahead = metadata.getReadAhead();
83          if(readahead.isOnFind())
84          {
85             setEagerLoadGroup(readahead.getEagerLoadGroup());
86             setOnFindCMRList(compiler.getLeftJoinCMRList());
87
88             // exclude non-searchable columns if distinct is used
89
if(compiler.isSelectDistinct())
90             {
91                boolean[] mask = getEagerLoadMask();
92                JDBCFieldBridge[] tableFields = selectEntity.getTableFields();
93                for(int i = 0; i < tableFields.length; ++i)
94                {
95                   if(mask[i] && !tableFields[i].getJDBCType().isSearchable())
96                   {
97                      mask[i] = false;
98                   }
99                }
100             }
101          }
102       }
103       else if(compiler.isSelectField())
104       {
105          setSelectField((JDBCCMPFieldBridge)compiler.getSelectField());
106       }
107       else
108       {
109          setSelectFunction(compiler.getSelectFunction(), manager);
110       }
111
112       // get the parameter order
113
setParameterList(compiler.getInputParameters());
114    }
115 }
116
Popular Tags