KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > ejbql > JdbcQueryResultEJBQL


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.ejbql;
13
14 import com.versant.core.jdbc.JdbcQueryResult;
15 import com.versant.core.jdbc.JdbcStorageManager;
16 import com.versant.core.jdbc.fetch.FetchResult;
17 import com.versant.core.jdbc.fetch.FetchSpec;
18 import com.versant.core.jdbc.query.JdbcCompiledQuery;
19 import com.versant.core.jdo.QueryDetails;
20 import com.versant.core.common.BindingSupportImpl;
21 import com.versant.core.common.OID;
22 import com.versant.core.common.State;
23 import com.versant.core.server.StateContainer;
24
25 /**
26  * Hacked version of JdbcQueryResult to suite the new FetchSpec query
27  * processing. The old stuff needs to be refactored so everything uses
28  * FetchSpec etc. This is a hack so we can get EJBQL into our implementation.
29  */

30 public class JdbcQueryResultEJBQL extends JdbcQueryResult {
31
32     private FetchResult res;
33     private Object JavaDoc[] row;
34
35     public JdbcQueryResultEJBQL(JdbcStorageManager sm, JdbcCompiledQuery cq,
36             Object JavaDoc[] params, boolean cachable) {
37         super(sm, cq, params, cachable);
38     }
39
40     public boolean isEJBQLHack() {
41         return true;
42     }
43
44     public FetchSpec getFetchSpec() {
45         return ((JdbcCompiledQueryEJBQL)cq).getFetchSpec();
46     }
47
48     public void executePrepareHack(Object JavaDoc[] params) {
49         FetchSpec spec = getFetchSpec();
50         QueryDetails q = getQueryDetails();
51         res = spec.createFetchResult(sm, sm.con(), params, false,
52                 false, -1, -1, q.getResultBatchSize(), q.isRandomAccess());
53         ps = res.getPreparedStatement();
54     }
55
56     public void executeActualHack() {
57         res.execute();
58     }
59
60     public boolean next(int skip) {
61         if (skip > 0) {
62             BindingSupportImpl.getInstance().internal("skip > 0 not supported: " +
63                     skip);
64         }
65         return res.hasNext();
66     }
67
68     public OID getResultOID() {
69         row = (Object JavaDoc[])res.next();
70         return (OID)row[0];
71     }
72
73     public State getResultState(boolean forUpdate, StateContainer container) {
74         return (State)row[1];
75     }
76
77     public void cancel() {
78         res.cancel();
79     }
80
81     public boolean isClosed() {
82         return res.isClosed();
83     }
84
85     public void closeImp() {
86         res.close();
87     }
88 }
89
90
Popular Tags