change
This commit is contained in:
parent
17b4e8c6c8
commit
021eb5f27b
|
@ -12,6 +12,8 @@ import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class RestfulConnection implements Connection {
|
public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
|
private static final String CONNECTION_IS_CLOSED = "connection is closed.";
|
||||||
|
private static final String AUTO_COMMIT_IS_TRUE = "auto commit is true";
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
private final Properties props;
|
private final Properties props;
|
||||||
|
@ -35,44 +37,67 @@ public class RestfulConnection implements Connection {
|
||||||
@Override
|
@Override
|
||||||
public Statement createStatement() throws SQLException {
|
public Statement createStatement() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("connection is closed."));
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
return new RestfulStatement(this, database);
|
return new RestfulStatement(this, database);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
//TODO: prepareStatement
|
//TODO: prepareStatement
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String nativeSQL(String sql) throws SQLException {
|
public String nativeSQL(String sql) throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
|
//nothing did
|
||||||
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (!autoCommit)
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getAutoCommit() throws SQLException {
|
public boolean getAutoCommit() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void commit() throws SQLException {
|
public void commit() throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (getAutoCommit())
|
||||||
|
throw new SQLException(AUTO_COMMIT_IS_TRUE);
|
||||||
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rollback() throws SQLException {
|
public void rollback() throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (getAutoCommit())
|
||||||
|
throw new SQLException(AUTO_COMMIT_IS_TRUE);
|
||||||
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,56 +115,83 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseMetaData getMetaData() throws SQLException {
|
public DatabaseMetaData getMetaData() throws SQLException {
|
||||||
//TODO: RestfulDatabaseMetaData is not implemented
|
|
||||||
return this.metadata;
|
return this.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (!readOnly)
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isReadOnly() throws SQLException {
|
public boolean isReadOnly() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCatalog(String catalog) throws SQLException {
|
public void setCatalog(String catalog) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
//nothing to do
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCatalog() throws SQLException {
|
public String getCatalog() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
return this.database;
|
return this.database;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTransactionIsolation(int level) throws SQLException {
|
public void setTransactionIsolation(int level) throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
switch (level) {
|
||||||
|
case Connection.TRANSACTION_NONE:
|
||||||
|
break;
|
||||||
|
case Connection.TRANSACTION_READ_UNCOMMITTED:
|
||||||
|
case Connection.TRANSACTION_READ_COMMITTED:
|
||||||
|
case Connection.TRANSACTION_REPEATABLE_READ:
|
||||||
|
case Connection.TRANSACTION_SERIALIZABLE:
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
|
default:
|
||||||
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int getTransactionIsolation() throws SQLException {
|
public int getTransactionIsolation() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
//Connection.TRANSACTION_NONE specifies that transactions are not supported.
|
//Connection.TRANSACTION_NONE specifies that transactions are not supported.
|
||||||
return Connection.TRANSACTION_NONE;
|
return Connection.TRANSACTION_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLWarning getWarnings() throws SQLException {
|
public SQLWarning getWarnings() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearWarnings() throws SQLException {
|
public void clearWarnings() throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
|
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
@ -150,25 +202,32 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
|
||||||
}
|
|
||||||
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
|
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
|
|
||||||
}
|
|
||||||
return this.prepareStatement(sql);
|
return this.prepareStatement(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
|
||||||
|
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
synchronized (RestfulConnection.class) {
|
synchronized (RestfulConnection.class) {
|
||||||
if (this.typeMap == null) {
|
if (this.typeMap == null) {
|
||||||
this.typeMap = new HashMap<String, Class<?>>();
|
this.typeMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
return this.typeMap;
|
return this.typeMap;
|
||||||
}
|
}
|
||||||
|
@ -176,6 +235,9 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
synchronized (RestfulConnection.class) {
|
synchronized (RestfulConnection.class) {
|
||||||
this.typeMap = map;
|
this.typeMap = map;
|
||||||
}
|
}
|
||||||
|
@ -183,31 +245,53 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setHoldability(int holdability) throws SQLException {
|
public void setHoldability(int holdability) throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHoldability() throws SQLException {
|
public int getHoldability() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Savepoint setSavepoint() throws SQLException {
|
public Savepoint setSavepoint() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (getAutoCommit())
|
||||||
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
|
//nothing to do
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Savepoint setSavepoint(String name) throws SQLException {
|
public Savepoint setSavepoint(String name) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (getAutoCommit())
|
||||||
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
|
//nothing to do
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rollback(Savepoint savepoint) throws SQLException {
|
public void rollback(Savepoint savepoint) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (getAutoCommit())
|
||||||
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
|
//nothing to do
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,11 +361,16 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||||
|
if (isClosed)
|
||||||
|
throw new SQLClientInfoException();
|
||||||
clientInfoProps.setProperty(name, value);
|
clientInfoProps.setProperty(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
||||||
|
if (isClosed)
|
||||||
|
throw new SQLClientInfoException();
|
||||||
|
|
||||||
for (Enumeration<Object> enumer = properties.keys(); enumer.hasMoreElements(); ) {
|
for (Enumeration<Object> enumer = properties.keys(); enumer.hasMoreElements(); ) {
|
||||||
String name = (String) enumer.nextElement();
|
String name = (String) enumer.nextElement();
|
||||||
clientInfoProps.put(name, properties.getProperty(name));
|
clientInfoProps.put(name, properties.getProperty(name));
|
||||||
|
@ -290,11 +379,17 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getClientInfo(String name) throws SQLException {
|
public String getClientInfo(String name) throws SQLException {
|
||||||
|
if (isClosed)
|
||||||
|
throw new SQLClientInfoException();
|
||||||
|
|
||||||
return clientInfoProps.getProperty(name);
|
return clientInfoProps.getProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Properties getClientInfo() throws SQLException {
|
public Properties getClientInfo() throws SQLException {
|
||||||
|
if (isClosed)
|
||||||
|
throw new SQLClientInfoException();
|
||||||
|
|
||||||
return clientInfoProps;
|
return clientInfoProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,11 +405,15 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSchema(String schema) throws SQLException {
|
public void setSchema(String schema) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
//nothing to do
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSchema() throws SQLException {
|
public String getSchema() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
return this.database;
|
return this.database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,11 +434,15 @@ public class RestfulConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNetworkTimeout() throws SQLException {
|
public int getNetworkTimeout() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue