01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdbc.ejbql;
12:
13: import com.versant.core.jdbc.JdbcQueryResult;
14: import com.versant.core.jdbc.JdbcStorageManager;
15: import com.versant.core.jdbc.fetch.FetchResult;
16: import com.versant.core.jdbc.fetch.FetchSpec;
17: import com.versant.core.jdbc.query.JdbcCompiledQuery;
18: import com.versant.core.jdo.QueryDetails;
19: import com.versant.core.common.BindingSupportImpl;
20: import com.versant.core.common.OID;
21: import com.versant.core.common.State;
22: import com.versant.core.server.StateContainer;
23:
24: /**
25: * Hacked version of JdbcQueryResult to suite the new FetchSpec query
26: * processing. The old stuff needs to be refactored so everything uses
27: * FetchSpec etc. This is a hack so we can get EJBQL into our implementation.
28: */
29: public class JdbcQueryResultEJBQL extends JdbcQueryResult {
30:
31: private FetchResult res;
32: private Object[] row;
33:
34: public JdbcQueryResultEJBQL(JdbcStorageManager sm,
35: JdbcCompiledQuery cq, Object[] params, boolean cachable) {
36: super (sm, cq, params, cachable);
37: }
38:
39: public boolean isEJBQLHack() {
40: return true;
41: }
42:
43: public FetchSpec getFetchSpec() {
44: return ((JdbcCompiledQueryEJBQL) cq).getFetchSpec();
45: }
46:
47: public void executePrepareHack(Object[] params) {
48: FetchSpec spec = getFetchSpec();
49: QueryDetails q = getQueryDetails();
50: res = spec.createFetchResult(sm, sm.con(), params, false,
51: false, -1, -1, q.getResultBatchSize(), q
52: .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(
63: "skip > 0 not supported: " + skip);
64: }
65: return res.hasNext();
66: }
67:
68: public OID getResultOID() {
69: row = (Object[]) res.next();
70: return (OID) row[0];
71: }
72:
73: public State getResultState(boolean forUpdate,
74: StateContainer container) {
75: return (State) row[1];
76: }
77:
78: public void cancel() {
79: res.cancel();
80: }
81:
82: public boolean isClosed() {
83: return res.isClosed();
84: }
85:
86: public void closeImp() {
87: res.close();
88: }
89: }
|