KickJava   Java API By Example, From Geeks To Geeks.

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


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

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