1
/*****************************************************************************
2
* Copyright (C) 2008 EnterpriseDB Corporation.
3
* Copyright (C) 2011 Stado Global Development Group.
5
* This file is part of Stado.
7
* Stado is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* Stado 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
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with Stado. If not, see <http://www.gnu.org/licenses/>.
20
* You can find Stado at http://www.stado.us
22
****************************************************************************/
23
package org.postgresql.stado.parser;
25
import java.util.ArrayList;
26
import java.util.Collection;
27
import java.util.Collections;
29
import org.postgresql.stado.engine.Engine;
30
import org.postgresql.stado.engine.ExecutableRequest;
31
import org.postgresql.stado.engine.ExecutionResult;
32
import org.postgresql.stado.engine.IExecutable;
33
import org.postgresql.stado.engine.XDBSessionContext;
34
import org.postgresql.stado.exception.ErrorMessageRepository;
35
import org.postgresql.stado.exception.XDBServerException;
36
import org.postgresql.stado.metadata.DBNode;
37
import org.postgresql.stado.metadata.SysDatabase;
38
import org.postgresql.stado.metadata.SysTable;
39
import org.postgresql.stado.metadata.scheduler.ILockCost;
40
import org.postgresql.stado.metadata.scheduler.LockSpecification;
41
import org.postgresql.stado.optimizer.QueryTree;
42
import org.postgresql.stado.parser.core.syntaxtree.Deallocate;
43
import org.postgresql.stado.parser.core.syntaxtree.DeclareCursor;
44
import org.postgresql.stado.parser.core.visitor.ObjectDepthFirst;
45
import org.postgresql.stado.parser.handler.IdentifierHandler;
46
import org.postgresql.stado.parser.handler.QueryTreeHandler;
47
import org.postgresql.stado.parser.handler.QueryTreeTracker;
49
public class SqlDeclareCursor extends ObjectDepthFirst implements IXDBSql,
52
private XDBSessionContext client;
54
private String cursorName = null;
56
public QueryTree aQueryTree = null;
58
private Command commandToExecute;
60
public SqlDeclareCursor(XDBSessionContext client) {
63
commandToExecute = new Command(Command.SELECT, this,
64
new QueryTreeTracker(), client);
66
aQueryTree = new QueryTree();
70
// ******************************
72
// ******************************
77
* f1 -> Identifier(prn)
83
public Object visit(DeclareCursor n, Object argu) {
86
cursorName = (String) n.f1.accept(new IdentifierHandler(), argu);
88
QueryTreeHandler aQueryTreeHandler = new QueryTreeHandler(
90
n.f4.accept(aQueryTreeHandler, aQueryTree);
96
* This will return the cost of executing this statement in time , milli
100
public long getCost() {
101
return ILockCost.LOW_COST;
105
* This return the Lock Specification for the system
110
public LockSpecification<SysTable> getLockSpecs() {
111
Collection<SysTable> empty = Collections.emptyList();
112
LockSpecification<SysTable> aLspec = new LockSpecification<SysTable>(
120
* @see org.postgresql.stado.Parser.IXDBSql#getNodeList()
122
public Collection<DBNode> getNodeList() {
123
Collection<DBNode> empty = Collections.emptyList();
124
return new ArrayList<DBNode>(empty);
127
public ExecutionResult execute(Engine engine) throws Exception {
128
if (!client.isInTransaction()) {
129
throw new XDBServerException(
130
ErrorMessageRepository.DECLARE_CURSOR_TRANS,
132
ErrorMessageRepository.DECLARE_CURSOR_TRANS_CODE);
135
client.createCursor(cursorName, aQueryTree, false, false);
137
return ExecutionResult.createSuccessResult(ExecutionResult.COMMAND_DECLARE_CURSOR);
143
* @see org.postgresql.stado.MetaData.Scheduler.ILockCost#needCoordinatorConnection()
145
public boolean needCoordinatorConnection() {