tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [1/6] TAJO-456: Separate tajo-jdbc and tajo-client from tajo-core-backend. (hyunsik)
Date Mon, 30 Dec 2013 09:17:57 GMT
Updated Branches:
  refs/heads/master d39bb9980 -> b6a5ff0c3


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/b6a5ff0c/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
new file mode 100644
index 0000000..6fdda0d
--- /dev/null
+++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoPreparedStatement.java
@@ -0,0 +1,658 @@
+package org.apache.tajo.jdbc; /**
+ * 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.
+ */
+
+import org.apache.tajo.client.TajoClient;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.*;
+import java.util.Calendar;
+import java.util.HashMap;
+
+/**
+ * TajoPreparedStatement.
+ *
+ */
+public class TajoPreparedStatement implements PreparedStatement {
+  private final String sql;
+  private TajoClient tajoClient;
+  /**
+   * save the SQL parameters {paramLoc:paramValue}
+   */
+  private final HashMap<Integer, String> parameters=new HashMap<Integer, String>();
+
+  /**
+   * We need to keep a reference to the result set to support the following:
+   * <code>
+   * statement.execute(String sql);
+   * statement.getResultSet();
+   * </code>.
+   */
+  private ResultSet resultSet = null;
+
+  /**
+   * Add SQLWarnings to the warningChain if needed.
+   */
+  private  SQLWarning warningChain = null;
+
+  /**
+   * Keep state so we can fail certain calls made after close().
+   */
+  private boolean isClosed = false;
+
+  /**
+   * keep the current ResultRet update count
+   */
+  private final int updateCount = 0;
+
+  /**
+   *
+   */
+  public TajoPreparedStatement(TajoClient tajoClient,
+                               String sql) {
+    this.tajoClient = tajoClient;
+    this.sql = sql;
+  }
+
+  @Override
+  public void addBatch() throws SQLException {
+    throw new SQLFeatureNotSupportedException("addBatch");
+  }
+
+  @Override
+  public void clearParameters() throws SQLException {
+    this.parameters.clear();
+  }
+
+  @Override
+  public boolean execute() throws SQLException {
+    ResultSet rs = executeImmediate(sql);
+    return rs != null;
+  }
+
+  @Override
+  public ResultSet executeQuery() throws SQLException {
+    return executeImmediate(sql);
+  }
+
+  @Override
+  public int executeUpdate() throws SQLException {
+    executeImmediate(sql);
+    return updateCount;
+  }
+
+  protected ResultSet executeImmediate(String sql) throws SQLException {
+    if (isClosed) {
+      throw new SQLFeatureNotSupportedException("Can't execute after statement has been closed");
+    }
+
+    try {
+      if (sql.contains("?")) {
+        sql = updateSql(sql, parameters);
+      }
+      resultSet = tajoClient.executeQueryAndGetResult(sql);
+    } catch (Exception e) {
+      throw new SQLFeatureNotSupportedException(e.getMessage(), e);
+    }
+    return resultSet;
+  }
+
+  /**
+   * update the SQL string with parameters set by setXXX methods of {@link java.sql.PreparedStatement}
+   *
+   * @param sql
+   * @param parameters
+   * @return updated SQL string
+   */
+  private String updateSql(final String sql, HashMap<Integer, String> parameters) {
+
+    StringBuffer newSql = new StringBuffer(sql);
+
+    int paramLoc = 1;
+    while (getCharIndexFromSqlByParamLocation(sql, '?', paramLoc) > 0) {
+      // check the user has set the needs parameters
+      if (parameters.containsKey(paramLoc)) {
+        int tt = getCharIndexFromSqlByParamLocation(newSql.toString(), '?', 1);
+        newSql.deleteCharAt(tt);
+        newSql.insert(tt, parameters.get(paramLoc));
+      }
+      paramLoc++;
+    }
+
+    return newSql.toString();
+
+  }
+
+  /**
+   * Get the index of given char from the SQL string by parameter location
+   * </br> The -1 will be return, if nothing found
+   *
+   * @param sql
+   * @param cchar
+   * @param paramLoc
+   * @return
+   */
+  private int getCharIndexFromSqlByParamLocation(final String sql, final char cchar, final
int paramLoc) {
+    int signalCount = 0;
+    int charIndex = -1;
+    int num = 0;
+    for (int i = 0; i < sql.length(); i++) {
+      char c = sql.charAt(i);
+      if (c == '\'' || c == '\\')// record the count of char "'" and char "\"
+      {
+        signalCount++;
+      } else if (c == cchar && signalCount % 2 == 0) {// check if the ? is really
the parameter
+        num++;
+        if (num == paramLoc) {
+          charIndex = i;
+          break;
+        }
+      }
+    }
+    return charIndex;
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData() throws SQLException {
+    if(resultSet != null) {
+      return resultSet.getMetaData();
+    } else {
+      return null;
+    }
+  }
+
+  @Override
+  public ParameterMetaData getParameterMetaData() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getParameterMetaData not supported");
+  }
+
+  @Override
+  public void setArray(int i, Array x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setArray not supported");
+  }
+
+  @Override
+  public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setAsciiStream not supported");
+  }
+
+  @Override
+  public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException
{
+    throw new SQLFeatureNotSupportedException("setAsciiStream not supported");
+  }
+
+  @Override
+  public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException
{
+    throw new SQLFeatureNotSupportedException("setAsciiStream not supported");
+  }
+
+  @Override
+  public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setBigDecimal not supported");
+  }
+
+  @Override
+  public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setBinaryStream not supported");
+  }
+
+  @Override
+  public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException
{
+    throw new SQLFeatureNotSupportedException("setBinaryStream not supported");
+  }
+
+  @Override
+  public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException
{
+    throw new SQLFeatureNotSupportedException("setBinaryStream not supported");
+  }
+
+  @Override
+  public void setBlob(int i, Blob x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setBlob not supported");
+  }
+
+  @Override
+  public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setBlob not supported");
+  }
+
+  @Override
+  public void setBlob(int parameterIndex, InputStream inputStream, long length)
+          throws SQLException {
+    throw new SQLFeatureNotSupportedException("setBlob not supported");
+  }
+
+  @Override
+  public void setBoolean(int parameterIndex, boolean x) throws SQLException {
+    this.parameters.put(parameterIndex, "" + x);
+  }
+
+  @Override
+  public void setByte(int parameterIndex, byte x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setByte not supported");
+  }
+
+  @Override
+  public void setBytes(int parameterIndex, byte[] x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setBytes not supported");
+  }
+
+  @Override
+  public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setCharacterStream not supported");
+  }
+
+  @Override
+  public void setCharacterStream(int parameterIndex, Reader reader, int length)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException("setCharacterStream not supported");
+  }
+
+  @Override
+  public void setCharacterStream(int parameterIndex, Reader reader, long length)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException("setCharacterStream not supported");
+  }
+
+  @Override
+  public void setClob(int i, Clob x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setClob not supported");
+  }
+
+  @Override
+  public void setClob(int parameterIndex, Reader reader) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setClob not supported");
+  }
+
+  @Override
+  public void setClob(int parameterIndex, Reader reader, long length) throws SQLException
{
+    throw new SQLFeatureNotSupportedException("setClob not supported");
+  }
+
+  @Override
+  public void setDate(int parameterIndex, Date x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setDate not supported");
+  }
+
+  @Override
+  public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setDate not supported");
+  }
+
+  @Override
+  public void setDouble(int parameterIndex, double x) throws SQLException {
+    this.parameters.put(parameterIndex,"" + x);
+  }
+
+  @Override
+  public void setFloat(int parameterIndex, float x) throws SQLException {
+    this.parameters.put(parameterIndex,"" + x);
+  }
+
+  @Override
+  public void setInt(int parameterIndex, int x) throws SQLException {
+    this.parameters.put(parameterIndex,"" + x);
+  }
+
+  @Override
+  public void setLong(int parameterIndex, long x) throws SQLException {
+    this.parameters.put(parameterIndex,"" + x);
+  }
+
+  @Override
+  public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setNCharacterStream not supported");
+  }
+
+  @Override
+  public void setNCharacterStream(int parameterIndex, Reader value, long length)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException("setNCharacterStream not supported");
+  }
+
+  @Override
+  public void setNClob(int parameterIndex, NClob value) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setNClob not supported");
+  }
+
+  @Override
+  public void setNClob(int parameterIndex, Reader reader) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setNClob not supported");
+  }
+
+  @Override
+  public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException
{
+    throw new SQLFeatureNotSupportedException("setNClob not supported");
+  }
+
+  @Override
+  public void setNString(int parameterIndex, String value) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setNString not supported");
+  }
+
+  @Override
+  public void setNull(int parameterIndex, int sqlType) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setNull not supported");
+  }
+
+  @Override
+  public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setNull not supported");
+  }
+
+  @Override
+  public void setObject(int parameterIndex, Object x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setObject not supported");
+  }
+
+  @Override
+  public void setObject(int parameterIndex, Object x, int targetSqlType)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException("setObject not supported");
+  }
+
+  @Override
+  public void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException("setObject not supported");
+  }
+
+  @Override
+  public void setRef(int i, Ref x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setRef not supported");
+  }
+
+  @Override
+  public void setRowId(int parameterIndex, RowId x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setRowId not supported");
+  }
+
+  @Override
+  public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setSQLXML not supported");
+  }
+
+  @Override
+  public void setShort(int parameterIndex, short x) throws SQLException {
+    this.parameters.put(parameterIndex,"" + x);
+  }
+
+  @Override
+  public void setString(int parameterIndex, String x) throws SQLException {
+     x=x.replace("'", "\\'");
+     this.parameters.put(parameterIndex,"'" + x +"'");
+  }
+
+  @Override
+  public void setTime(int parameterIndex, Time x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setTime not supported");
+  }
+
+  @Override
+  public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setTime not supported");
+  }
+
+  @Override
+  public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setTimestamp not supported");
+  }
+
+  @Override
+  public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException("setTimestamp not supported");
+  }
+
+  @Override
+  public void setURL(int parameterIndex, URL x) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setURL not supported");
+  }
+
+  @Override
+  public void setUnicodeStream(int parameterIndex, InputStream x, int length)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException("setUnicodeStream not supported");
+  }
+
+  @Override
+  public void addBatch(String sql) throws SQLException {
+    throw new SQLFeatureNotSupportedException("addBatch not supported");
+  }
+
+  @Override
+  public void cancel() throws SQLException {
+    throw new SQLFeatureNotSupportedException("cancel not supported");
+  }
+
+  @Override
+  public void clearBatch() throws SQLException {
+    throw new SQLFeatureNotSupportedException("clearBatch not supported");
+  }
+
+  @Override
+  public void clearWarnings() throws SQLException {
+     warningChain=null;
+  }
+
+  public void closeOnCompletion() throws SQLException {
+    // JDK 1.7
+    throw new SQLFeatureNotSupportedException("closeOnCompletion");
+  }
+
+  @Override
+  public void close() throws SQLException {
+    if (resultSet!=null) {
+      resultSet.close();
+      resultSet = null;
+    }
+    isClosed = true;
+  }
+
+  @Override
+  public boolean execute(String sql) throws SQLException {
+    throw new SQLFeatureNotSupportedException("execute(sql) not supported");
+  }
+
+  @Override
+  public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+    throw new SQLFeatureNotSupportedException("execute(sql) not supported");
+  }
+
+  @Override
+  public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+    throw new SQLFeatureNotSupportedException("execute(sql) not supported");
+  }
+
+  @Override
+  public boolean execute(String sql, String[] columnNames) throws SQLException {
+    throw new SQLFeatureNotSupportedException("execute(sql) not supported");
+  }
+
+  @Override
+  public int[] executeBatch() throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeBatch not supported");
+  }
+
+  @Override
+  public ResultSet executeQuery(String sql) throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeQuery(sql) not supported");
+  }
+
+  @Override
+  public int executeUpdate(String sql) throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeUpdate not supported");
+  }
+
+  @Override
+  public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeUpdate not supported");
+  }
+
+  @Override
+  public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeUpdate not supported");
+  }
+
+  @Override
+  public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeUpdate not supported");
+  }
+
+  @Override
+  public Connection getConnection() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getConnection not supported");
+  }
+
+  @Override
+  public int getFetchDirection() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getFetchDirection not supported");
+  }
+
+  @Override
+  public int getFetchSize() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getFetchSize not supported");
+  }
+
+  @Override
+  public ResultSet getGeneratedKeys() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getGeneratedKeys not supported");
+  }
+
+  @Override
+  public int getMaxFieldSize() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getMaxFieldSize not supported");
+  }
+
+  @Override
+  public int getMaxRows() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getMaxRows not supported");
+  }
+
+  @Override
+  public boolean getMoreResults() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getMoreResults not supported");
+  }
+
+  @Override
+  public boolean getMoreResults(int current) throws SQLException {
+    throw new SQLFeatureNotSupportedException("getMoreResults not supported");
+  }
+
+  @Override
+  public int getQueryTimeout() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getQueryTimeout not supported");
+  }
+
+  @Override
+  public ResultSet getResultSet() throws SQLException {
+    return this.resultSet;
+  }
+
+  @Override
+  public int getResultSetConcurrency() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getResultSetConcurrency not supported");
+  }
+
+  @Override
+  public int getResultSetHoldability() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getResultSetHoldability not supported");
+  }
+
+  @Override
+  public int getResultSetType() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getResultSetType not supported");
+  }
+
+  @Override
+  public int getUpdateCount() throws SQLException {
+    return updateCount;
+  }
+
+  @Override
+  public SQLWarning getWarnings() throws SQLException {
+    return warningChain;
+  }
+
+  @Override
+  public boolean isClosed() throws SQLException {
+    return isClosed;
+  }
+
+   public boolean isCloseOnCompletion() throws SQLException {
+     //JDK 1.7
+     throw new SQLFeatureNotSupportedException("isCloseOnCompletion not supported");
+   }
+
+  @Override
+  public boolean isPoolable() throws SQLException {
+    throw new SQLFeatureNotSupportedException("isPoolable not supported");
+  }
+
+  @Override
+  public void setCursorName(String name) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setCursorName not supported");
+  }
+
+  @Override
+  public void setEscapeProcessing(boolean enable) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setEscapeProcessing not supported");
+  }
+
+  @Override
+  public void setFetchDirection(int direction) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setFetchDirection not supported");
+  }
+
+  @Override
+  public void setFetchSize(int rows) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setFetchSize not supported");
+  }
+
+  @Override
+  public void setMaxFieldSize(int max) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setMaxFieldSize not supported");
+  }
+
+  @Override
+  public void setMaxRows(int max) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setMaxRows not supported");
+  }
+
+  @Override
+  public void setPoolable(boolean poolable) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setPoolable not supported");
+  }
+
+  @Override
+  public void setQueryTimeout(int seconds) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setQueryTimeout not supported");
+  }
+
+  @Override
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    throw new SQLFeatureNotSupportedException("isWrapperFor not supported");
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    throw new SQLFeatureNotSupportedException("unwrap not supported");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/b6a5ff0c/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
new file mode 100644
index 0000000..b3afcdb
--- /dev/null
+++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
@@ -0,0 +1,287 @@
+package org.apache.tajo.jdbc; /**
+ * 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.
+ */
+
+import org.apache.tajo.client.TajoClient;
+
+import java.sql.*;
+
+public class TajoStatement implements Statement {
+  private TajoClient tajoClient;
+  private int fetchSize = 200;
+
+  /**
+   * We need to keep a reference to the result set to support the following:
+   * <code>
+   * statement.execute(String sql);
+   * statement.getResultSet();
+   * </code>.
+   */
+  private ResultSet resultSet = null;
+
+  /**
+   * Add SQLWarnings to the warningChain if needed.
+   */
+  private SQLWarning warningChain = null;
+
+  /**
+   * Keep state so we can fail certain calls made after close().
+   */
+  private boolean isClosed = false;
+
+  public TajoStatement(TajoClient tajoClient) {
+    this.tajoClient = tajoClient;
+  }
+
+  @Override
+  public void addBatch(String sql) throws SQLException {
+    throw new SQLFeatureNotSupportedException("addBatch not supported");
+  }
+
+  @Override
+  public void cancel() throws SQLException {
+    throw new SQLFeatureNotSupportedException("cancel not supported");
+  }
+
+  @Override
+  public void clearBatch() throws SQLException {
+    throw new SQLFeatureNotSupportedException("clearBatch not supported");
+  }
+
+  @Override
+  public void clearWarnings() throws SQLException {
+    warningChain = null;
+  }
+
+  @Override
+  public void close() throws SQLException {
+    resultSet = null;
+    isClosed = true;
+  }
+
+  public void closeOnCompletion() throws SQLException {
+     // JDK 1.7
+     throw new SQLFeatureNotSupportedException("closeOnCompletion not supported");
+  }
+
+  @Override
+  public boolean execute(String sql) throws SQLException {
+    resultSet = executeQuery(sql);
+
+    return resultSet != null;
+  }
+
+  @Override
+  public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+    throw new SQLFeatureNotSupportedException("execute not supported");
+  }
+
+  @Override
+  public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+    throw new SQLFeatureNotSupportedException("execute not supported");
+  }
+
+  @Override
+  public boolean execute(String sql, String[] columnNames) throws SQLException {
+    throw new SQLFeatureNotSupportedException("execute not supported");
+  }
+
+  @Override
+  public int[] executeBatch() throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeBatch not supported");
+  }
+
+  @Override
+  public ResultSet executeQuery(String sql) throws SQLException {
+    if (isClosed) {
+      throw new SQLFeatureNotSupportedException("Can't execute after statement has been closed");
+    }
+
+    try {
+      return tajoClient.executeQueryAndGetResult(sql);
+    } catch (Exception e) {
+      throw new SQLFeatureNotSupportedException(e.getMessage(), e);
+    }
+  }
+
+  @Override
+  public int executeUpdate(String sql) throws SQLException {
+    try {
+      tajoClient.executeQuery(sql);
+
+      return 1;
+    } catch (Exception ex) {
+      throw new SQLFeatureNotSupportedException(ex.toString());
+    }
+  }
+
+  @Override
+  public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeUpdate not supported");
+  }
+
+  @Override
+  public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeUpdate not supported");
+  }
+
+  @Override
+  public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+    throw new SQLFeatureNotSupportedException("executeUpdate not supported");
+  }
+
+  @Override
+  public Connection getConnection() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getConnection not supported");
+  }
+
+  @Override
+  public int getFetchDirection() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getFetchDirection not supported");
+  }
+
+  @Override
+  public int getFetchSize() throws SQLException {
+    return fetchSize;
+  }
+
+  @Override
+  public ResultSet getGeneratedKeys() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getGeneratedKeys not supported");
+  }
+
+  @Override
+  public int getMaxFieldSize() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getMaxFieldSize not supported");
+  }
+
+  @Override
+  public int getMaxRows() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getMaxRows not supported");
+  }
+
+  @Override
+  public boolean getMoreResults() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getMoreResults not supported");
+  }
+
+  @Override
+  public boolean getMoreResults(int current) throws SQLException {
+    throw new SQLFeatureNotSupportedException("getMoreResults not supported");
+  }
+
+  @Override
+  public int getQueryTimeout() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getQueryTimeout not supported");
+  }
+
+  @Override
+  public ResultSet getResultSet() throws SQLException {
+    return resultSet;
+  }
+
+  @Override
+  public int getResultSetConcurrency() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getResultSetConcurrency not supported");
+  }
+
+  @Override
+  public int getResultSetHoldability() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getResultSetHoldability not supported");
+  }
+
+  @Override
+  public int getResultSetType() throws SQLException {
+    throw new SQLFeatureNotSupportedException("getResultSetType not supported");
+  }
+
+  @Override
+  public int getUpdateCount() throws SQLException {
+    return 0;
+  }
+
+  @Override
+  public SQLWarning getWarnings() throws SQLException {
+    return warningChain;
+  }
+
+  @Override
+  public boolean isClosed() throws SQLException {
+    return isClosed;
+  }
+
+  public boolean isCloseOnCompletion() throws SQLException {
+    // JDK 1.7
+    throw new SQLFeatureNotSupportedException("isCloseOnCompletion not supported");
+  }
+
+  @Override
+  public boolean isPoolable() throws SQLException {
+    throw new SQLFeatureNotSupportedException("isPoolable not supported");
+  }
+
+  @Override
+  public void setCursorName(String name) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setCursorName not supported");
+  }
+
+  @Override
+  public void setEscapeProcessing(boolean enable) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setEscapeProcessing not supported");
+  }
+
+  @Override
+  public void setFetchDirection(int direction) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setFetchDirection not supported");
+  }
+
+  @Override
+  public void setFetchSize(int rows) throws SQLException {
+    fetchSize = rows;
+  }
+
+  @Override
+  public void setMaxFieldSize(int max) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setMaxFieldSize not supported");
+  }
+
+  @Override
+  public void setMaxRows(int max) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setMaxRows not supported");
+  }
+
+  @Override
+  public void setPoolable(boolean poolable) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setPoolable not supported");
+  }
+
+  @Override
+  public void setQueryTimeout(int seconds) throws SQLException {
+    throw new SQLFeatureNotSupportedException("setQueryTimeout not supported");
+  }
+
+  @Override
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    throw new SQLFeatureNotSupportedException("isWrapperFor not supported");
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    throw new SQLFeatureNotSupportedException("unwrap not supported");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/b6a5ff0c/tajo-jdbc/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/tajo-jdbc/src/main/resources/log4j.properties b/tajo-jdbc/src/main/resources/log4j.properties
new file mode 100644
index 0000000..606f2d4
--- /dev/null
+++ b/tajo-jdbc/src/main/resources/log4j.properties
@@ -0,0 +1,27 @@
+##
+# 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.
+#
+
+# log4j configuration used during build and unit tests
+
+log4j.rootLogger=info,stdout
+log4j.threshhold=INFO
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
+
+log4j.logger.org.apache.tajo.jdbc=FATAL
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/b6a5ff0c/tajo-project/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-project/pom.xml b/tajo-project/pom.xml
index 7f2e5bb..c3a6f82 100644
--- a/tajo-project/pom.xml
+++ b/tajo-project/pom.xml
@@ -598,6 +598,16 @@
       </dependency>
       <dependency>
         <groupId>org.apache.tajo</groupId>
+        <artifactId>tajo-client</artifactId>
+        <version>${tajo.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.tajo</groupId>
+        <artifactId>tajo-jdbc</artifactId>
+        <version>${tajo.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.tajo</groupId>
         <artifactId>tajo-rpc</artifactId>
         <version>${tajo.version}</version>
       </dependency>
@@ -651,6 +661,7 @@
         <groupId>org.apache.hadoop</groupId>
         <artifactId>hadoop-minicluster</artifactId>
         <version>${hadoop.version}</version>
+        <scope>test</scope>
       </dependency>
       <dependency>
         <groupId>org.apache.hadoop</groupId>
@@ -664,6 +675,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.hadoop</groupId>
+        <artifactId>hadoop-yarn-client</artifactId>
+        <version>${hadoop.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.hadoop</groupId>
         <artifactId>hadoop-yarn-server-nodemanager</artifactId>
         <version>${hadoop.version}</version>
         <scope>test</scope>
@@ -775,7 +791,7 @@
       <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
-        <version>13.0.1</version>
+        <version>15.0</version>
       </dependency>
       <dependency>
         <groupId>com.google.code.gson</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/b6a5ff0c/tajo-rpc/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-rpc/pom.xml b/tajo-rpc/pom.xml
index 227bec1..04cf780 100644
--- a/tajo-rpc/pom.xml
+++ b/tajo-rpc/pom.xml
@@ -1,9 +1,11 @@
 <!--
-  Copyright 2012 Database Lab., Korea Univ.
-
-  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
+  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
 
@@ -126,8 +128,40 @@
     <dependency>
       <groupId>org.apache.tajo</groupId>
       <artifactId>tajo-common</artifactId>
-      <type>jar</type>
-      <scope>compile</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>com.google.guava</groupId>
+          <artifactId>guava</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>joda-time</groupId>
+          <artifactId>joda-time</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>com.google.code.gson</groupId>
+          <artifactId>gson</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>com.google.inject</groupId>
+          <artifactId>guice</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>com.google.inject.extensions</groupId>
+          <artifactId>guice-servlet</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>com.sun.jersey.jersey-test-framework</groupId>
+          <artifactId>jersey-test-framework-grizzly2</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>com.sun.jersey.contribs</groupId>
+          <artifactId>jersey-guice</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>commons-logging</groupId>
@@ -140,11 +174,6 @@
     <dependency>
       <groupId>io.netty</groupId>
       <artifactId>netty</artifactId>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.hadoop</groupId>
-      <artifactId>hadoop-common</artifactId>
     </dependency>
     <dependency>
       <groupId>commons-logging</groupId>
@@ -153,6 +182,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>commons-lang</groupId>
@@ -215,7 +245,7 @@
             <executions>
               <execution>
                 <!-- builds source jars and attaches them to the project for publishing
-->
-                <id>hadoop-java-sources</id>
+                <id>tajo-java-sources</id>
                 <phase>package</phase>
                 <goals>
                   <goal>jar-no-fork</goal>

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/b6a5ff0c/tajo-rpc/src/main/java/org/apache/tajo/rpc/RpcConnectionPool.java
----------------------------------------------------------------------
diff --git a/tajo-rpc/src/main/java/org/apache/tajo/rpc/RpcConnectionPool.java b/tajo-rpc/src/main/java/org/apache/tajo/rpc/RpcConnectionPool.java
index 8eacaf5..06ef408 100644
--- a/tajo-rpc/src/main/java/org/apache/tajo/rpc/RpcConnectionPool.java
+++ b/tajo-rpc/src/main/java/org/apache/tajo/rpc/RpcConnectionPool.java
@@ -18,10 +18,10 @@
 
 package org.apache.tajo.rpc;
 
-import com.google.common.collect.Maps;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.util.TUtil;
 
 import java.net.InetSocketAddress;
 import java.util.Map;
@@ -29,7 +29,7 @@ import java.util.Map;
 public class RpcConnectionPool {
   private static final Log LOG = LogFactory.getLog(RpcConnectionPool.class);
 
-  private Map<RpcConnectionKey, NettyClientBase> connections = Maps.newConcurrentMap();
+  private Map<RpcConnectionKey, NettyClientBase> connections = TUtil.newConcurrentHashMap();
 
   private static RpcConnectionPool instance;
 


Mime
View raw message