Repository: tajo Updated Branches: refs/heads/master 8741e6829 -> f80beaf64
http://git-wip-us.apache.org/repos/asf/tajo/blob/f80beaf6/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java ---------------------------------------------------------------------- diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java new file mode 100644 index 0000000..4250da4 --- /dev/null +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java @@ -0,0 +1,444 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.tajo.jdbc; + +import com.google.protobuf.ServiceException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tajo.TajoConstants; +import org.apache.tajo.client.CatalogAdminClient; +import org.apache.tajo.client.QueryClient; +import org.apache.tajo.client.TajoClient; +import org.apache.tajo.client.TajoClientImpl; +import org.apache.tajo.conf.TajoConf; +import org.jboss.netty.handler.codec.http.QueryStringDecoder; + +import java.io.IOException; +import java.net.URI; +import java.sql.*; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicBoolean; + +public class JdbcConnection implements Connection { + private static Log LOG = LogFactory.getLog(JdbcConnection.class); + + private final TajoClient tajoClient; + private final AtomicBoolean closed = new AtomicBoolean(true); + private final String rawURI; + private final Properties properties; + + private final URI uri; + private final String hostName; + private final int port; + private final String databaseName; + @SuppressWarnings("unused") + /** it will be used soon. */ + private final Map<String, List<String>> params; + + public JdbcConnection(String rawURI, Properties properties) throws SQLException { + this.rawURI = rawURI; + this.properties = properties; + + try { + if (!rawURI.startsWith(TajoDriver.TAJO_JDBC_URL_PREFIX)) { + throw new SQLException("Invalid URL: " + rawURI, "TAJO-001"); + } + + // URI form: jdbc:tajo://hostname:port/databasename + int startIdx = rawURI.indexOf(":"); + if (startIdx < 0) { + throw new SQLException("Invalid URL: " + rawURI, "TAJO-001"); + } + + String uri = rawURI.substring(startIdx+1, rawURI.length()); + try { + this.uri = URI.create(uri); + } catch (IllegalArgumentException iae) { + throw new SQLException("Invalid URL: " + rawURI, "TAJO-001"); + } + + hostName = this.uri.getHost(); + if(hostName == null) { + throw new SQLException("Invalid JDBC URI: " + rawURI, "TAJO-001"); + } + if (this.uri.getPort() < 1) { + port = 26002; + } else { + port = this.uri.getPort(); + } + + if (this.uri.getPath() == null || this.uri.getPath().equalsIgnoreCase("")) { // if no database is given, set default. + databaseName = TajoConstants.DEFAULT_DATABASE_NAME; + } else { + // getPath() will return '/database'. + databaseName = this.uri.getPath().split("/")[1]; + } + + params = new QueryStringDecoder(rawURI).getParameters(); + } catch (SQLException se) { + throw se; + } catch (Throwable t) { // for unexpected exceptions like ArrayIndexOutOfBoundsException. + throw new SQLException("Invalid JDBC URI: " + rawURI, "TAJO-001"); + } + + TajoConf tajoConf = new TajoConf(); + if(properties != null) { + for(Map.Entry<Object, Object> entry: properties.entrySet()) { + tajoConf.set(entry.getKey().toString(), entry.getValue().toString()); + } + } + + try { + tajoClient = new TajoClientImpl(hostName, port, databaseName); + } catch (Exception e) { + throw new SQLException("Cannot create TajoClient instance:" + e.getMessage(), "TAJO-002"); + } + closed.set(false); + } + + public String getUri() { + return this.rawURI; + } + + public QueryClient getQueryClient() { + return tajoClient; + } + + public CatalogAdminClient getCatalogAdminClient() { + return tajoClient; + } + + @Override + public void clearWarnings() throws SQLException { + } + + @Override + public void close() throws SQLException { + if(!closed.get()) { + if(tajoClient != null) { + tajoClient.close(); + } + + closed.set(true); + } + } + + @Override + public void commit() throws SQLException { + throw new SQLFeatureNotSupportedException("commit"); + } + + @Override + public Array createArrayOf(String arg0, Object[] arg1) throws SQLException { + throw new SQLFeatureNotSupportedException("createArrayOf"); + } + + @Override + public Blob createBlob() throws SQLException { + throw new SQLFeatureNotSupportedException("createBlob"); + } + + @Override + public Clob createClob() throws SQLException { + throw new SQLFeatureNotSupportedException("createClob"); + } + + @Override + public NClob createNClob() throws SQLException { + throw new SQLFeatureNotSupportedException("createNClob"); + } + + @Override + public SQLXML createSQLXML() throws SQLException { + throw new SQLFeatureNotSupportedException("createSQLXML"); + } + + @Override + public Statement createStatement() throws SQLException { + if (isClosed()) { + throw new SQLException("Can't create Statement, connection is closed"); + } + return new TajoStatement(this, tajoClient); + } + + @Override + public Statement createStatement(int resultSetType, int resultSetConcurrency) + throws SQLException { + throw new SQLFeatureNotSupportedException("createStatement"); + } + + @Override + public Statement createStatement(int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + throw new SQLFeatureNotSupportedException("createStatement"); + } + + @Override + public Struct createStruct(String typeName, Object[] attributes) + throws SQLException { + throw new SQLFeatureNotSupportedException("createStruct"); + } + + @Override + public boolean getAutoCommit() throws SQLException { + return true; + } + + @Override + public String getCatalog() throws SQLException { + try { + return tajoClient.getCurrentDatabase(); + } catch (ServiceException e) { + throw new SQLException(e); + } + } + + @Override + public Properties getClientInfo() throws SQLException { + throw new SQLFeatureNotSupportedException("getClientInfo"); + } + + @Override + public String getClientInfo(String name) throws SQLException { + throw new SQLFeatureNotSupportedException("getClientInfo"); + } + + @Override + public int getHoldability() throws SQLException { + throw new SQLFeatureNotSupportedException("getHoldability"); + } + + @Override + public DatabaseMetaData getMetaData() throws SQLException { + return new TajoDatabaseMetaData(this); + } + + @Override + public int getTransactionIsolation() throws SQLException { + return Connection.TRANSACTION_NONE; + } + + @Override + public Map<String, Class<?>> getTypeMap() throws SQLException { + throw new SQLFeatureNotSupportedException("getTypeMap"); + } + + @Override + public SQLWarning getWarnings() throws SQLException { + throw new SQLFeatureNotSupportedException("getWarnings"); + } + + @Override + public boolean isClosed() throws SQLException { + return closed.get(); + } + + @Override + public boolean isReadOnly() throws SQLException { + return false; + } + + @Override + public boolean isValid(int timeout) throws SQLException { + try { + if (tajoClient.isConnected()) { + ResultSet resultSet = tajoClient.executeQueryAndGetResult("SELECT 1;"); + boolean next = resultSet.next(); + boolean valid = next && resultSet.getLong(1) == 1; + resultSet.close(); + return valid; + } else { + return false; + } + } catch (ServiceException e) { + LOG.error("TajoMaster is not available."); + return false; + } catch (IOException e) { + LOG.error("JDBC connection is not valid."); + return false; + } + } + + @Override + public String nativeSQL(String sql) throws SQLException { + throw new SQLFeatureNotSupportedException("nativeSQL"); + } + + @Override + public CallableStatement prepareCall(String sql) throws SQLException { + throw new SQLFeatureNotSupportedException("prepareCall"); + } + + @Override + public CallableStatement prepareCall(String sql, int resultSetType, + int resultSetConcurrency) throws SQLException { + throw new SQLFeatureNotSupportedException("prepareCall"); + } + + @Override + public CallableStatement prepareCall(String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) throws SQLException { + throw new SQLFeatureNotSupportedException("prepareCall"); + } + + @Override + public PreparedStatement prepareStatement(String sql) throws SQLException { + return new TajoPreparedStatement(this, tajoClient, sql); + } + + @Override + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) + throws SQLException { + return new TajoPreparedStatement(this, tajoClient, sql); + } + + @Override + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) + throws SQLException { + throw new SQLFeatureNotSupportedException("prepareStatement"); + } + + @Override + public PreparedStatement prepareStatement(String sql, String[] columnNames) + throws SQLException { + throw new SQLFeatureNotSupportedException("prepareStatement"); + } + + @Override + public PreparedStatement prepareStatement(String sql, int resultSetType, + int resultSetConcurrency) throws SQLException { + return new TajoPreparedStatement(this, tajoClient, sql); + } + + @Override + public PreparedStatement prepareStatement(String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) throws SQLException { + throw new SQLFeatureNotSupportedException("prepareStatement"); + } + + @Override + public void releaseSavepoint(Savepoint savepoint) throws SQLException { + throw new SQLFeatureNotSupportedException("releaseSavepoint"); + } + + @Override + public void rollback() throws SQLException { + throw new SQLFeatureNotSupportedException("rollback"); + } + + @Override + public void rollback(Savepoint savepoint) throws SQLException { + throw new SQLFeatureNotSupportedException("rollback"); + } + + @Override + public void setAutoCommit(boolean autoCommit) throws SQLException { + throw new SQLFeatureNotSupportedException("setAutoCommit"); + } + + @Override + public void setCatalog(String catalog) throws SQLException { + try { + tajoClient.selectDatabase(catalog); + } catch (ServiceException e) { + throw new SQLException(e); + } + } + + @Override + public void setClientInfo(Properties properties) + throws SQLClientInfoException { + throw new UnsupportedOperationException("setClientInfo"); + } + + @Override + public void setClientInfo(String name, String value) + throws SQLClientInfoException { + throw new UnsupportedOperationException("setClientInfo"); + } + + @Override + public void setHoldability(int holdability) throws SQLException { + throw new SQLFeatureNotSupportedException("setHoldability"); + } + + @Override + public void setReadOnly(boolean readOnly) throws SQLException { + throw new SQLFeatureNotSupportedException("setReadOnly"); + } + + @Override + public Savepoint setSavepoint() throws SQLException { + throw new SQLFeatureNotSupportedException("setSavepoint"); + } + + @Override + public Savepoint setSavepoint(String name) throws SQLException { + throw new SQLFeatureNotSupportedException("setSavepoint"); + } + + @Override + public void setTransactionIsolation(int level) throws SQLException { + throw new SQLFeatureNotSupportedException("setTransactionIsolation"); + } + + @Override + public void setTypeMap(Map<String, Class<?>> map) throws SQLException { + throw new SQLFeatureNotSupportedException("setTypeMap"); + } + + @Override + public <T> T unwrap(Class<T> tClass) throws SQLException { + if (isWrapperFor(tClass)) { + return (T) this; + } + throw new SQLException("No wrapper for " + tClass); + } + + @Override + public boolean isWrapperFor(Class<?> tClass) throws SQLException { + return tClass.isInstance(this); + } + + public void abort(Executor executor) throws SQLException { + // JDK 1.7 + throw new SQLFeatureNotSupportedException("abort is not supported"); + } + + public int getNetworkTimeout() throws SQLException { + // JDK 1.7 + throw new SQLFeatureNotSupportedException("getNetworkTimeout is not supported"); + } + + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { + // JDK 1.7 + throw new SQLFeatureNotSupportedException("setNetworkTimeout not supported"); + } + + public String getSchema() throws SQLException { + return TajoConstants.DEFAULT_SCHEMA_NAME; + } + + public void setSchema(String schema) throws SQLException { + throw new SQLFeatureNotSupportedException("setSchema() is not supported yet"); + } +} http://git-wip-us.apache.org/repos/asf/tajo/blob/f80beaf6/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoConnection.java ---------------------------------------------------------------------- diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoConnection.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoConnection.java deleted file mode 100644 index 1a2c6c5..0000000 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoConnection.java +++ /dev/null @@ -1,437 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.tajo.jdbc; - -import com.google.protobuf.ServiceException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tajo.TajoConstants; -import org.apache.tajo.client.TajoClient; -import org.apache.tajo.conf.TajoConf; -import org.jboss.netty.handler.codec.http.QueryStringDecoder; - -import java.io.IOException; -import java.net.URI; -import java.sql.*; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.Executor; -import java.util.concurrent.atomic.AtomicBoolean; - -public class TajoConnection implements Connection { - private static Log LOG = LogFactory.getLog(TajoConnection.class); - - private final TajoClient tajoClient; - private final AtomicBoolean closed = new AtomicBoolean(true); - private final String rawURI; - private final Properties properties; - - private final URI uri; - private final String hostName; - private final int port; - private final String databaseName; - @SuppressWarnings("unused") - /** it will be used soon. */ - private final Map<String, List<String>> params; - - public TajoConnection(String rawURI, Properties properties) throws SQLException { - this.rawURI = rawURI; - this.properties = properties; - - try { - if (!rawURI.startsWith(TajoDriver.TAJO_JDBC_URL_PREFIX)) { - throw new SQLException("Invalid URL: " + rawURI, "TAJO-001"); - } - - // URI form: jdbc:tajo://hostname:port/databasename - int startIdx = rawURI.indexOf(":"); - if (startIdx < 0) { - throw new SQLException("Invalid URL: " + rawURI, "TAJO-001"); - } - - String uri = rawURI.substring(startIdx+1, rawURI.length()); - try { - this.uri = URI.create(uri); - } catch (IllegalArgumentException iae) { - throw new SQLException("Invalid URL: " + rawURI, "TAJO-001"); - } - - hostName = this.uri.getHost(); - if(hostName == null) { - throw new SQLException("Invalid JDBC URI: " + rawURI, "TAJO-001"); - } - if (this.uri.getPort() < 1) { - port = 26002; - } else { - port = this.uri.getPort(); - } - - if (this.uri.getPath() == null || this.uri.getPath().equalsIgnoreCase("")) { // if no database is given, set default. - databaseName = TajoConstants.DEFAULT_DATABASE_NAME; - } else { - // getPath() will return '/database'. - databaseName = this.uri.getPath().split("/")[1]; - } - - params = new QueryStringDecoder(rawURI).getParameters(); - } catch (SQLException se) { - throw se; - } catch (Throwable t) { // for unexpected exceptions like ArrayIndexOutOfBoundsException. - throw new SQLException("Invalid JDBC URI: " + rawURI, "TAJO-001"); - } - - TajoConf tajoConf = new TajoConf(); - if(properties != null) { - for(Map.Entry<Object, Object> entry: properties.entrySet()) { - tajoConf.set(entry.getKey().toString(), entry.getValue().toString()); - } - } - - try { - tajoClient = new TajoClient(hostName, port, databaseName); - } catch (Exception e) { - throw new SQLException("Cannot create TajoClient instance:" + e.getMessage(), "TAJO-002"); - } - closed.set(false); - } - - public String getUri() { - return this.rawURI; - } - - public TajoClient getTajoClient() { - return tajoClient; - } - - @Override - public void clearWarnings() throws SQLException { - } - - @Override - public void close() throws SQLException { - if(!closed.get()) { - if(tajoClient != null) { - tajoClient.close(); - } - - closed.set(true); - } - } - - @Override - public void commit() throws SQLException { - throw new SQLFeatureNotSupportedException("commit"); - } - - @Override - public Array createArrayOf(String arg0, Object[] arg1) throws SQLException { - throw new SQLFeatureNotSupportedException("createArrayOf"); - } - - @Override - public Blob createBlob() throws SQLException { - throw new SQLFeatureNotSupportedException("createBlob"); - } - - @Override - public Clob createClob() throws SQLException { - throw new SQLFeatureNotSupportedException("createClob"); - } - - @Override - public NClob createNClob() throws SQLException { - throw new SQLFeatureNotSupportedException("createNClob"); - } - - @Override - public SQLXML createSQLXML() throws SQLException { - throw new SQLFeatureNotSupportedException("createSQLXML"); - } - - @Override - public Statement createStatement() throws SQLException { - if (isClosed()) { - throw new SQLException("Can't create Statement, connection is closed"); - } - return new TajoStatement(this, tajoClient); - } - - @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency) - throws SQLException { - throw new SQLFeatureNotSupportedException("createStatement"); - } - - @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - throw new SQLFeatureNotSupportedException("createStatement"); - } - - @Override - public Struct createStruct(String typeName, Object[] attributes) - throws SQLException { - throw new SQLFeatureNotSupportedException("createStruct"); - } - - @Override - public boolean getAutoCommit() throws SQLException { - return true; - } - - @Override - public String getCatalog() throws SQLException { - try { - return tajoClient.getCurrentDatabase(); - } catch (ServiceException e) { - throw new SQLException(e); - } - } - - @Override - public Properties getClientInfo() throws SQLException { - throw new SQLFeatureNotSupportedException("getClientInfo"); - } - - @Override - public String getClientInfo(String name) throws SQLException { - throw new SQLFeatureNotSupportedException("getClientInfo"); - } - - @Override - public int getHoldability() throws SQLException { - throw new SQLFeatureNotSupportedException("getHoldability"); - } - - @Override - public DatabaseMetaData getMetaData() throws SQLException { - return new TajoDatabaseMetaData(this); - } - - @Override - public int getTransactionIsolation() throws SQLException { - return Connection.TRANSACTION_NONE; - } - - @Override - public Map<String, Class<?>> getTypeMap() throws SQLException { - throw new SQLFeatureNotSupportedException("getTypeMap"); - } - - @Override - public SQLWarning getWarnings() throws SQLException { - throw new SQLFeatureNotSupportedException("getWarnings"); - } - - @Override - public boolean isClosed() throws SQLException { - return closed.get(); - } - - @Override - public boolean isReadOnly() throws SQLException { - return false; - } - - @Override - public boolean isValid(int timeout) throws SQLException { - try { - if (tajoClient.isConnected()) { - ResultSet resultSet = tajoClient.executeQueryAndGetResult("SELECT 1;"); - boolean next = resultSet.next(); - boolean valid = next && resultSet.getLong(1) == 1; - resultSet.close(); - return valid; - } else { - return false; - } - } catch (ServiceException e) { - LOG.error("TajoMaster is not available."); - return false; - } catch (IOException e) { - LOG.error("JDBC connection is not valid."); - return false; - } - } - - @Override - public String nativeSQL(String sql) throws SQLException { - throw new SQLFeatureNotSupportedException("nativeSQL"); - } - - @Override - public CallableStatement prepareCall(String sql) throws SQLException { - throw new SQLFeatureNotSupportedException("prepareCall"); - } - - @Override - public CallableStatement prepareCall(String sql, int resultSetType, - int resultSetConcurrency) throws SQLException { - throw new SQLFeatureNotSupportedException("prepareCall"); - } - - @Override - public CallableStatement prepareCall(String sql, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) throws SQLException { - throw new SQLFeatureNotSupportedException("prepareCall"); - } - - @Override - public PreparedStatement prepareStatement(String sql) throws SQLException { - return new TajoPreparedStatement(this, tajoClient, sql); - } - - @Override - public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) - throws SQLException { - return new TajoPreparedStatement(this, tajoClient, sql); - } - - @Override - public PreparedStatement prepareStatement(String sql, int[] columnIndexes) - throws SQLException { - throw new SQLFeatureNotSupportedException("prepareStatement"); - } - - @Override - public PreparedStatement prepareStatement(String sql, String[] columnNames) - throws SQLException { - throw new SQLFeatureNotSupportedException("prepareStatement"); - } - - @Override - public PreparedStatement prepareStatement(String sql, int resultSetType, - int resultSetConcurrency) throws SQLException { - return new TajoPreparedStatement(this, tajoClient, sql); - } - - @Override - public PreparedStatement prepareStatement(String sql, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) throws SQLException { - throw new SQLFeatureNotSupportedException("prepareStatement"); - } - - @Override - public void releaseSavepoint(Savepoint savepoint) throws SQLException { - throw new SQLFeatureNotSupportedException("releaseSavepoint"); - } - - @Override - public void rollback() throws SQLException { - throw new SQLFeatureNotSupportedException("rollback"); - } - - @Override - public void rollback(Savepoint savepoint) throws SQLException { - throw new SQLFeatureNotSupportedException("rollback"); - } - - @Override - public void setAutoCommit(boolean autoCommit) throws SQLException { - throw new SQLFeatureNotSupportedException("setAutoCommit"); - } - - @Override - public void setCatalog(String catalog) throws SQLException { - try { - tajoClient.selectDatabase(catalog); - } catch (ServiceException e) { - throw new SQLException(e); - } - } - - @Override - public void setClientInfo(Properties properties) - throws SQLClientInfoException { - throw new UnsupportedOperationException("setClientInfo"); - } - - @Override - public void setClientInfo(String name, String value) - throws SQLClientInfoException { - throw new UnsupportedOperationException("setClientInfo"); - } - - @Override - public void setHoldability(int holdability) throws SQLException { - throw new SQLFeatureNotSupportedException("setHoldability"); - } - - @Override - public void setReadOnly(boolean readOnly) throws SQLException { - throw new SQLFeatureNotSupportedException("setReadOnly"); - } - - @Override - public Savepoint setSavepoint() throws SQLException { - throw new SQLFeatureNotSupportedException("setSavepoint"); - } - - @Override - public Savepoint setSavepoint(String name) throws SQLException { - throw new SQLFeatureNotSupportedException("setSavepoint"); - } - - @Override - public void setTransactionIsolation(int level) throws SQLException { - throw new SQLFeatureNotSupportedException("setTransactionIsolation"); - } - - @Override - public void setTypeMap(Map<String, Class<?>> map) throws SQLException { - throw new SQLFeatureNotSupportedException("setTypeMap"); - } - - @Override - public <T> T unwrap(Class<T> tClass) throws SQLException { - if (isWrapperFor(tClass)) { - return (T) this; - } - throw new SQLException("No wrapper for " + tClass); - } - - @Override - public boolean isWrapperFor(Class<?> tClass) throws SQLException { - return tClass.isInstance(this); - } - - public void abort(Executor executor) throws SQLException { - // JDK 1.7 - throw new SQLFeatureNotSupportedException("abort is not supported"); - } - - public int getNetworkTimeout() throws SQLException { - // JDK 1.7 - throw new SQLFeatureNotSupportedException("getNetworkTimeout is not supported"); - } - - public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { - // JDK 1.7 - throw new SQLFeatureNotSupportedException("setNetworkTimeout not supported"); - } - - public String getSchema() throws SQLException { - return TajoConstants.DEFAULT_SCHEMA_NAME; - } - - public void setSchema(String schema) throws SQLException { - throw new SQLFeatureNotSupportedException("setSchema() is not supported yet"); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/f80beaf6/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java ---------------------------------------------------------------------- diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java index 0ceb589..150e9bf 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDatabaseMetaData.java @@ -21,15 +21,13 @@ import com.google.common.collect.Lists; import com.google.protobuf.ServiceException; import org.apache.tajo.annotation.Nullable; import org.apache.tajo.catalog.*; +import org.apache.tajo.client.CatalogAdminClient; import org.apache.tajo.client.ResultSetUtil; -import org.apache.tajo.client.TajoClient; import org.apache.tajo.common.TajoDataTypes.Type; import org.apache.tajo.common.type.TajoTypeUtil; import org.apache.tajo.datum.Datum; import org.apache.tajo.datum.NullDatum; import org.apache.tajo.datum.TextDatum; -import org.apache.tajo.storage.Tuple; -import org.apache.tajo.storage.VTuple; import org.apache.tajo.util.VersionInfo; import java.sql.*; @@ -49,9 +47,9 @@ public class TajoDatabaseMetaData implements DatabaseMetaData { "radians,round,sign,sin,sqrt,tan"; private static final String STRING_FUNCTIONS = "ascii,chr,concat,left,length,ltrim,repeat,rtrim,substring"; - private final TajoConnection conn; + private final JdbcConnection conn; - public TajoDatabaseMetaData(TajoConnection conn) { + public TajoDatabaseMetaData(JdbcConnection conn) { this.conn = conn; } @@ -375,15 +373,15 @@ public class TajoDatabaseMetaData implements DatabaseMetaData { } try { - TajoClient tajoClient = conn.getTajoClient(); + CatalogAdminClient catalogAdmin = conn.getCatalogAdminClient(); // if catalog is null, all databases are targets. if (targetCatalogs.isEmpty()) { - targetCatalogs.addAll(tajoClient.getAllDatabaseNames()); + targetCatalogs.addAll(catalogAdmin.getAllDatabaseNames()); } for (String databaseName : targetCatalogs) { - List<String> tableNames = tajoClient.getTableList(databaseName); + List<String> tableNames = catalogAdmin.getTableList(databaseName); for (String eachTableName: tableNames) { if (eachTableName.matches(regtableNamePattern)) { MetaDataTuple tuple = new MetaDataTuple(5); @@ -424,7 +422,7 @@ public class TajoDatabaseMetaData implements DatabaseMetaData { public ResultSet getSchemas() throws SQLException { String databaseName; try { - databaseName = conn.getTajoClient().getCurrentDatabase(); + databaseName = conn.getQueryClient().getCurrentDatabase(); } catch (ServiceException e) { throw new SQLException(e); } @@ -443,7 +441,7 @@ public class TajoDatabaseMetaData implements DatabaseMetaData { public ResultSet getCatalogs() throws SQLException { Collection<String> databaseNames; try { - databaseNames = conn.getTajoClient().getAllDatabaseNames(); + databaseNames = conn.getCatalogAdminClient().getAllDatabaseNames(); } catch (ServiceException e) { throw new SQLException(e); } @@ -501,16 +499,17 @@ public class TajoDatabaseMetaData implements DatabaseMetaData { List<MetaDataTuple> columns = new ArrayList<MetaDataTuple>(); try { if (targetCatalogs.isEmpty()) { - targetCatalogs.addAll(conn.getTajoClient().getAllDatabaseNames()); + targetCatalogs.addAll(conn.getCatalogAdminClient().getAllDatabaseNames()); } for (String databaseName : targetCatalogs) { String regtableNamePattern = convertPattern(tableNamePattern == null ? null : tableNamePattern); String regcolumnNamePattern = convertPattern(columnNamePattern == null ? null : columnNamePattern); - List<String> tables = conn.getTajoClient().getTableList(databaseName); + List<String> tables = conn.getCatalogAdminClient().getTableList(databaseName); for (String table: tables) { if (table.matches(regtableNamePattern)) { - TableDesc tableDesc = conn.getTajoClient().getTableDesc(CatalogUtil.buildFQName(databaseName, table)); + TableDesc tableDesc = conn.getCatalogAdminClient().getTableDesc( + CatalogUtil.buildFQName(databaseName, table)); int pos = 0; for (Column column: tableDesc.getLogicalSchema().getColumns()) { @@ -766,7 +765,7 @@ public class TajoDatabaseMetaData implements DatabaseMetaData { public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { String databaseName; try { - databaseName = conn.getTajoClient().getCurrentDatabase(); + databaseName = conn.getQueryClient().getCurrentDatabase(); } catch (ServiceException e) { throw new SQLException(e); } http://git-wip-us.apache.org/repos/asf/tajo/blob/f80beaf6/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDriver.java ---------------------------------------------------------------------- diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDriver.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDriver.java index cfc5299..73c3060 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDriver.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoDriver.java @@ -52,7 +52,7 @@ public class TajoDriver implements Driver, Closeable { @Override public Connection connect(String url, Properties properties) throws SQLException { - return acceptsURL(url) ? new TajoConnection(url, properties) : null; + return acceptsURL(url) ? new JdbcConnection(url, properties) : null; } @Override http://git-wip-us.apache.org/repos/asf/tajo/blob/f80beaf6/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoPreparedStatement.java ---------------------------------------------------------------------- diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoPreparedStatement.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoPreparedStatement.java index d4c89c0..fa3df98 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoPreparedStatement.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoPreparedStatement.java @@ -31,7 +31,7 @@ import java.util.HashMap; * */ public class TajoPreparedStatement implements PreparedStatement { - private TajoConnection conn; + private JdbcConnection conn; private final String sql; private TajoClient tajoClient; /** @@ -66,7 +66,7 @@ public class TajoPreparedStatement implements PreparedStatement { /** * */ - public TajoPreparedStatement(TajoConnection conn, + public TajoPreparedStatement(JdbcConnection conn, TajoClient tajoClient, String sql) { this.conn = conn; http://git-wip-us.apache.org/repos/asf/tajo/blob/f80beaf6/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java ---------------------------------------------------------------------- diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java index 69aa68e..8308211 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java @@ -21,13 +21,12 @@ import com.google.common.collect.Lists; import com.google.protobuf.ServiceException; import org.apache.tajo.client.TajoClient; -import java.io.IOException; import java.sql.*; import java.util.HashMap; import java.util.Map; public class TajoStatement implements Statement { - private TajoConnection conn; + private JdbcConnection conn; private TajoClient tajoClient; private int fetchSize = 200; @@ -50,7 +49,7 @@ public class TajoStatement implements Statement { */ private boolean isClosed = false; - public TajoStatement(TajoConnection conn, TajoClient tajoClient) { + public TajoStatement(JdbcConnection conn, TajoClient tajoClient) { this.conn = conn; this.tajoClient = tajoClient; }
