/*
* Copyright 2014-2015 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wplatform.ddal.engine;
import java.io.Closeable;
import com.wplatform.ddal.command.CommandInterface;
import com.wplatform.ddal.message.Trace;
import com.wplatform.ddal.value.Value;
/**
* A local or remote session. A session represents a database connection.
*/
public interface SessionInterface extends Closeable {
/**
* Parse a command and prepare it for execution.
*
* @param sql the SQL statement
* @param fetchSize the number of rows to fetch in one step
* @return the prepared command
*/
CommandInterface prepareCommand(String sql, int fetchSize);
/**
* Roll back pending transactions and close the session.
*/
@Override
void close();
/**
* Get the trace object
*
* @return the trace object
*/
Trace getTrace();
/**
* Check if close was called.
*
* @return if the session has been closed
*/
boolean isClosed();
/**
* Check whether this session has a pending transaction.
*
* @return true if it has
*/
boolean hasPendingTransaction();
/**
* Cancel the current or next command (called when closing a connection).
*/
void cancel();
/**
* Check if the database changed and therefore reconnecting is required.
*
* @param write if the next operation may be writing
* @return true if reconnecting is required
*/
boolean isReconnectNeeded(boolean write);
/**
* Close the connection and open a new connection.
*
* @param write if the next operation may be writing
* @return the new connection
*/
SessionInterface reconnect(boolean write);
/**
* Add a temporary LOB, which is closed when the session commits.
*
* @param v the value
*/
void addTemporaryLob(Value v);
}