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
****************************************************************************/
24
* SqlStopDatabase.java
28
package org.postgresql.stado.parser;
30
import java.util.Collection;
31
import java.util.Collections;
33
import org.postgresql.stado.common.util.XLogger;
34
import org.postgresql.stado.engine.Engine;
35
import org.postgresql.stado.engine.ExecutionResult;
36
import org.postgresql.stado.engine.IPreparable;
37
import org.postgresql.stado.engine.XDBSessionContext;
38
import org.postgresql.stado.exception.XDBSecurityException;
39
import org.postgresql.stado.metadata.DBNode;
40
import org.postgresql.stado.metadata.SysLogin;
41
import org.postgresql.stado.metadata.SysTable;
42
import org.postgresql.stado.metadata.scheduler.LockSpecification;
43
import org.postgresql.stado.parser.core.syntaxtree.AlterCluster;
44
import org.postgresql.stado.parser.core.visitor.DepthFirstVoidArguVisitor;
50
public class SqlAlterCluster extends DepthFirstVoidArguVisitor implements IXDBSql,
52
private static final XLogger logger = XLogger
53
.getLogger(SqlAlterCluster.class);
55
private XDBSessionContext client;
57
private boolean prepared = false;
59
private boolean setReadOnly = false;
61
/** Creates a new instance of SqlAlterCluster */
62
public SqlAlterCluster(XDBSessionContext client) {
69
* @see org.postgresql.stado.Engine.IPreparable#isPrepared()
71
public boolean isPrepared() {
78
* @see org.postgresql.stado.Parser.IXDBSql#getNodeList()
80
public Collection<DBNode> getNodeList() {
81
return Collections.emptyList();
87
* @see org.postgresql.stado.MetaData.Scheduler.ILockCost#getCost()
89
public long getCost() {
96
* @see org.postgresql.stado.MetaData.Scheduler.ILockCost#getLockSpecs()
98
public LockSpecification<SysTable> getLockSpecs() {
99
Collection<SysTable> empty = Collections.emptyList();
100
return new LockSpecification<SysTable>(empty, empty);
106
* @see org.postgresql.stado.MetaData.Scheduler.ILockCost#needCoordinatorConnection()
108
public boolean needCoordinatorConnection() {
115
* @see org.postgresql.stado.Engine.IPreparable#prepare()
117
public void prepare() throws Exception {
118
final String method = "prepare";
119
logger.entering(method);
123
if (client.getCurrentUser().getLogin().getUserClass() != SysLogin.USER_CLASS_DBA) {
124
throw new XDBSecurityException(
125
"You are not allowed to alter the cluster");
131
logger.exiting(method);
138
* @see org.postgresql.stado.Engine.IExecutable#execute(org.postgresql.stado.Engine.Engine)
140
public ExecutionResult execute(Engine engine) throws Exception {
141
final String method = "execute";
142
logger.entering(method, new Object[] { engine });
149
// DatabaseState state;
150
// if (setReadOnly) {
151
// state = DatabaseState.USER_REQUESTED_READ_ONLY;
153
// state = DatabaseState.READ_WRITE;
155
// SysDatabase.setState(state);
158
logger.exiting(method);
160
return ExecutionResult
161
.createSuccessResult(ExecutionResult.COMMAND_STOP_DATABASE);
165
public void visit(AlterCluster n, Object argu) {
166
if (n.f3.which == 0) {
173
// This does not actually write out to the database so its read-only
175
public boolean isReadOnly() {