incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/5] Moving the JDBC project to the contrib folder because it is not a production ready piece of software.
Date Thu, 06 Mar 2014 21:53:51 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 3fc741cae -> e0c1f6823


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/abstractimpl/AbstractBlurResultSetMetaData.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/abstractimpl/AbstractBlurResultSetMetaData.java
b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/abstractimpl/AbstractBlurResultSetMetaData.java
new file mode 100644
index 0000000..7b39828
--- /dev/null
+++ b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/abstractimpl/AbstractBlurResultSetMetaData.java
@@ -0,0 +1,138 @@
+package org.apache.blur.jdbc.abstractimpl;
+
+/**
+ * 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 java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+import org.apache.blur.jdbc.util.NotImplemented;
+
+/**
+ * This ResultSetMetaData implementation is simply to provide the major of the
+ * method implementations that only throw not implemented exceptions. That way
+ * it's easier to see what has been implemented in the real class.
+ */
+public abstract class AbstractBlurResultSetMetaData implements ResultSetMetaData {
+
+  private ResultSetMetaData throwExceptionDelegate;
+
+  public AbstractBlurResultSetMetaData() {
+    throwExceptionDelegate = (ResultSetMetaData) Proxy.newProxyInstance(ResultSetMetaData.class.getClassLoader(),
+        new Class[] { ResultSetMetaData.class }, new InvocationHandler() {
+          @Override
+          public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
+            throw new NotImplemented(method.getName());
+          }
+        });
+  }
+
+  public String getCatalogName(int column) throws SQLException {
+    return throwExceptionDelegate.getCatalogName(column);
+  }
+
+  public String getColumnClassName(int column) throws SQLException {
+    return throwExceptionDelegate.getColumnClassName(column);
+  }
+
+  public int getColumnCount() throws SQLException {
+    return throwExceptionDelegate.getColumnCount();
+  }
+
+  public int getColumnDisplaySize(int column) throws SQLException {
+    return throwExceptionDelegate.getColumnDisplaySize(column);
+  }
+
+  public String getColumnLabel(int column) throws SQLException {
+    return throwExceptionDelegate.getColumnLabel(column);
+  }
+
+  public String getColumnName(int column) throws SQLException {
+    return throwExceptionDelegate.getColumnName(column);
+  }
+
+  public int getColumnType(int column) throws SQLException {
+    return throwExceptionDelegate.getColumnType(column);
+  }
+
+  public String getColumnTypeName(int column) throws SQLException {
+    return throwExceptionDelegate.getColumnTypeName(column);
+  }
+
+  public int getPrecision(int column) throws SQLException {
+    return throwExceptionDelegate.getPrecision(column);
+  }
+
+  public int getScale(int column) throws SQLException {
+    return throwExceptionDelegate.getScale(column);
+  }
+
+  public String getSchemaName(int column) throws SQLException {
+    return throwExceptionDelegate.getSchemaName(column);
+  }
+
+  public String getTableName(int column) throws SQLException {
+    return throwExceptionDelegate.getTableName(column);
+  }
+
+  public boolean isAutoIncrement(int column) throws SQLException {
+    return throwExceptionDelegate.isAutoIncrement(column);
+  }
+
+  public boolean isCaseSensitive(int column) throws SQLException {
+    return throwExceptionDelegate.isCaseSensitive(column);
+  }
+
+  public boolean isCurrency(int column) throws SQLException {
+    return throwExceptionDelegate.isCurrency(column);
+  }
+
+  public boolean isDefinitelyWritable(int column) throws SQLException {
+    return throwExceptionDelegate.isDefinitelyWritable(column);
+  }
+
+  public int isNullable(int column) throws SQLException {
+    return throwExceptionDelegate.isNullable(column);
+  }
+
+  public boolean isReadOnly(int column) throws SQLException {
+    return throwExceptionDelegate.isReadOnly(column);
+  }
+
+  public boolean isSearchable(int column) throws SQLException {
+    return throwExceptionDelegate.isSearchable(column);
+  }
+
+  public boolean isSigned(int column) throws SQLException {
+    return throwExceptionDelegate.isSigned(column);
+  }
+
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    return throwExceptionDelegate.isWrapperFor(iface);
+  }
+
+  public boolean isWritable(int column) throws SQLException {
+    return throwExceptionDelegate.isWritable(column);
+  }
+
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    return throwExceptionDelegate.unwrap(iface);
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/abstractimpl/AbstractBlurStatement.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/abstractimpl/AbstractBlurStatement.java
b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/abstractimpl/AbstractBlurStatement.java
new file mode 100644
index 0000000..c986b72
--- /dev/null
+++ b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/abstractimpl/AbstractBlurStatement.java
@@ -0,0 +1,227 @@
+package org.apache.blur.jdbc.abstractimpl;
+
+/**
+ * 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 java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+
+import org.apache.blur.jdbc.util.NotImplemented;
+
+/**
+ * This Statement implementation is simply to provide the major of the
+ * method implementations that only throw not implemented exceptions. That way
+ * it's easier to see what has been implemented in the real class.
+ */
+public class AbstractBlurStatement implements Statement {
+
+  private Statement throwExceptionDelegate;
+
+  public AbstractBlurStatement() {
+    throwExceptionDelegate = (Statement) Proxy.newProxyInstance(Statement.class.getClassLoader(),
+        new Class[] { Statement.class }, new InvocationHandler() {
+          @Override
+          public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
+            throw new NotImplemented(method.getName());
+          }
+        });
+  }
+
+  public void addBatch(String sql) throws SQLException {
+    throwExceptionDelegate.addBatch(sql);
+  }
+
+  public void cancel() throws SQLException {
+    throwExceptionDelegate.cancel();
+  }
+
+  public void clearBatch() throws SQLException {
+    throwExceptionDelegate.clearBatch();
+  }
+
+  public void clearWarnings() throws SQLException {
+    throwExceptionDelegate.clearWarnings();
+  }
+
+  public void close() throws SQLException {
+    throwExceptionDelegate.close();
+  }
+
+  public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+    return throwExceptionDelegate.execute(sql, autoGeneratedKeys);
+  }
+
+  public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+    return throwExceptionDelegate.execute(sql, columnIndexes);
+  }
+
+  public boolean execute(String sql, String[] columnNames) throws SQLException {
+    return throwExceptionDelegate.execute(sql, columnNames);
+  }
+
+  public boolean execute(String sql) throws SQLException {
+    return throwExceptionDelegate.execute(sql);
+  }
+
+  public int[] executeBatch() throws SQLException {
+    return throwExceptionDelegate.executeBatch();
+  }
+
+  public ResultSet executeQuery(String sql) throws SQLException {
+    return throwExceptionDelegate.executeQuery(sql);
+  }
+
+  public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+    return throwExceptionDelegate.executeUpdate(sql, autoGeneratedKeys);
+  }
+
+  public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+    return throwExceptionDelegate.executeUpdate(sql, columnIndexes);
+  }
+
+  public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+    return throwExceptionDelegate.executeUpdate(sql, columnNames);
+  }
+
+  public int executeUpdate(String sql) throws SQLException {
+    return throwExceptionDelegate.executeUpdate(sql);
+  }
+
+  public Connection getConnection() throws SQLException {
+    return throwExceptionDelegate.getConnection();
+  }
+
+  public int getFetchDirection() throws SQLException {
+    return throwExceptionDelegate.getFetchDirection();
+  }
+
+  public int getFetchSize() throws SQLException {
+    return throwExceptionDelegate.getFetchSize();
+  }
+
+  public ResultSet getGeneratedKeys() throws SQLException {
+    return throwExceptionDelegate.getGeneratedKeys();
+  }
+
+  public int getMaxFieldSize() throws SQLException {
+    return throwExceptionDelegate.getMaxFieldSize();
+  }
+
+  public int getMaxRows() throws SQLException {
+    return throwExceptionDelegate.getMaxRows();
+  }
+
+  public boolean getMoreResults() throws SQLException {
+    return throwExceptionDelegate.getMoreResults();
+  }
+
+  public boolean getMoreResults(int current) throws SQLException {
+    return throwExceptionDelegate.getMoreResults(current);
+  }
+
+  public int getQueryTimeout() throws SQLException {
+    return throwExceptionDelegate.getQueryTimeout();
+  }
+
+  public ResultSet getResultSet() throws SQLException {
+    return throwExceptionDelegate.getResultSet();
+  }
+
+  public int getResultSetConcurrency() throws SQLException {
+    return throwExceptionDelegate.getResultSetConcurrency();
+  }
+
+  public int getResultSetHoldability() throws SQLException {
+    return throwExceptionDelegate.getResultSetHoldability();
+  }
+
+  public int getResultSetType() throws SQLException {
+    return throwExceptionDelegate.getResultSetType();
+  }
+
+  public int getUpdateCount() throws SQLException {
+    return throwExceptionDelegate.getUpdateCount();
+  }
+
+  public SQLWarning getWarnings() throws SQLException {
+    return throwExceptionDelegate.getWarnings();
+  }
+
+  public boolean isClosed() throws SQLException {
+    return throwExceptionDelegate.isClosed();
+  }
+
+  public boolean isPoolable() throws SQLException {
+    return throwExceptionDelegate.isPoolable();
+  }
+
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    return throwExceptionDelegate.isWrapperFor(iface);
+  }
+
+  public void setCursorName(String name) throws SQLException {
+    throwExceptionDelegate.setCursorName(name);
+  }
+
+  public void setEscapeProcessing(boolean enable) throws SQLException {
+    throwExceptionDelegate.setEscapeProcessing(enable);
+  }
+
+  public void setFetchDirection(int direction) throws SQLException {
+    throwExceptionDelegate.setFetchDirection(direction);
+  }
+
+  public void setFetchSize(int rows) throws SQLException {
+    throwExceptionDelegate.setFetchSize(rows);
+  }
+
+  public void setMaxFieldSize(int max) throws SQLException {
+    throwExceptionDelegate.setMaxFieldSize(max);
+  }
+
+  public void setMaxRows(int max) throws SQLException {
+    throwExceptionDelegate.setMaxRows(max);
+  }
+
+  public void setPoolable(boolean poolable) throws SQLException {
+    throwExceptionDelegate.setPoolable(poolable);
+  }
+
+  public void setQueryTimeout(int seconds) throws SQLException {
+    throwExceptionDelegate.setQueryTimeout(seconds);
+  }
+
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    return throwExceptionDelegate.unwrap(iface);
+  }
+
+  // java 7
+
+  public void closeOnCompletion() throws SQLException {
+    throw new SQLException("No supported");
+  }
+
+  public boolean isCloseOnCompletion() throws SQLException {
+    throw new SQLException("No supported");
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java
new file mode 100644
index 0000000..bb57789
--- /dev/null
+++ b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/parser/Parser.java
@@ -0,0 +1,223 @@
+package org.apache.blur.jdbc.parser;
+
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Parser {
+
+  private static final String SELECT = "select";
+  private static final String WHERE = "where";
+  private static final String FROM = "from";
+  private static final String SEP = new String(new char[] { 1 });
+
+  public static void main(String[] args) {
+    // System.out.println(new
+    // Parser().parse("select * from table where query('person.pn:(nice cool)')"));
+    // System.out.println(new
+    // Parser().parse("select * from table natural join table2 where person.pn = 'coandol''s'
and jon='asdndandanda' And person.pf ='niorce' or nice = 'be'"));
+    // System.out.println(new
+    // Parser().parse("select * from table where person.pn = 'coandol''s' and jon='asdndandanda'
And person.pf ='niorce' or nice = 'be'"));
+    System.out.println(new Parser().parse("SELECT * FROM TEST_TABLE T WHERE 1 = 0"));
+    System.out.println(new Parser().parse("select * from table t where 1 = 0"));
+    // System.out.println(new
+    // Parser().parse("select id,locationid,score,cf1.* from table where query('+person.pn:(nice
cool) AND cool.a:nice')"));
+  }
+
+  private String where;
+  private String tableName;
+  private List<String> columnNames;
+  private String tableNameAlias;
+
+  public Parser parse(String query) {
+    columnNames = getColumnNames(query);
+    tableName = getTableName(query);
+    tableNameAlias = getTableNameAlias(query);
+    where = getWhere(query);
+    return this;
+  }
+
+  private String getWhere(String query) {
+    StringBuilder result = new StringBuilder();
+    StringTokenizer tokenizer = new StringTokenizer(query);
+    while (tokenizer.hasMoreTokens()) {
+      if (WHERE.equals(tokenizer.nextToken().toLowerCase())) {
+        while (tokenizer.hasMoreTokens()) {
+          String token = tokenizer.nextToken();
+          result.append(token).append(' ');
+        }
+      }
+    }
+    return getQuery(result.toString().trim());
+  }
+
+  private String getQuery(String query) {
+    Pattern p = Pattern.compile("([qQ][uU][eE][rR][yY]\\s*\\(\\s*')(.*)('\\s*\\).*)");
+    Matcher matcher = p.matcher(query);
+    if (matcher.find()) {
+      if (matcher.groupCount() != 3) {// first one is the whole string
+        throw new RuntimeException("malformed query [" + query + "]");
+      }
+      return matcher.group(2);// 2nd group is the lucene query
+    } else {
+      return changeQueryToLucene(query);
+    }
+  }
+
+  private String changeQueryToLucene(String query) {
+    query = fixAndsOrs(query);
+    query = query.replaceAll("\\s*=\\s*", ":");
+    query = query.replace("''", SEP);
+    query = query.replaceAll("'", "");
+    query = query.replace(SEP, "'");
+    return query;
+  }
+
+  private String fixAndsOrs(String query) {
+    query = fixToUpperToken(query, "AND");
+    query = fixToUpperToken(query, "OR");
+    return query;
+  }
+
+  private String fixToUpperToken(String query, String token) {
+    String queryUpper = query.toUpperCase();
+    int start = 0;
+    int index = queryUpper.indexOf(token, start);
+    while (index != -1) {
+      if (!query.substring(index, index + token.length()).equals(token)) {
+        String everythingInStringToCurrentPosition = query.substring(0, index);
+        if (!isHitInParameter(everythingInStringToCurrentPosition)) {
+          query = query.substring(0, index) + token + query.substring(index + token.length());
+          return fixToUpperToken(query, token);
+        }
+      }
+      start = index + 1;
+      index = queryUpper.indexOf(token, start);
+    }
+    return query;
+  }
+
+  private boolean isHitInParameter(String everythingInStringToCurrentPosition) {
+    char[] charArray = everythingInStringToCurrentPosition.toCharArray();
+    int count = 0;
+    for (int i = 0; i < charArray.length; i++) {
+      if (charArray[i] == '\'') {
+        count++;
+      }
+    }
+    return count % 2 != 0;
+  }
+
+  private String getTableName(String query) {
+    StringTokenizer tokenizer = new StringTokenizer(query);
+    while (tokenizer.hasMoreTokens()) {
+      if (FROM.equals(tokenizer.nextToken().toLowerCase())) {
+        if (tokenizer.hasMoreTokens()) {
+          return tokenizer.nextToken();
+        }
+      }
+    }
+    throw new IllegalArgumentException("Table not found");
+  }
+
+  private String getTableNameAlias(String query) {
+    StringTokenizer tokenizer = new StringTokenizer(query);
+    while (tokenizer.hasMoreTokens()) {
+      if (FROM.equals(tokenizer.nextToken().toLowerCase())) {
+        while (tokenizer.hasMoreTokens()) {
+          tokenizer.nextToken();//table
+          if (!tokenizer.hasMoreTokens()) {
+            return null;
+          }
+          String token = tokenizer.nextToken().toLowerCase();
+          if (WHERE.equals(token)) {
+            return null;
+          }
+          return token;
+        }
+      }
+    }
+    return null;
+  }
+
+  private List<String> getColumnNames(String query) {
+    StringTokenizer tokenizer = new StringTokenizer(query);
+    List<String> columnNames = new ArrayList<String>();
+    while (tokenizer.hasMoreTokens()) {
+      if (SELECT.equals(tokenizer.nextToken().toLowerCase())) {
+        while (tokenizer.hasMoreTokens()) {
+          String token = tokenizer.nextToken().toLowerCase();
+          if (FROM.equals(token)) {
+            return columnNames;
+          }
+          processColumnToken(columnNames, token);
+        }
+      }
+    }
+    return null;
+  }
+
+  private void processColumnToken(List<String> columnNames, String token) {
+    StringTokenizer tokenizer = new StringTokenizer(token, ",");
+    while (tokenizer.hasMoreTokens()) {
+      columnNames.add(tokenizer.nextToken());
+    }
+  }
+
+  public String getTableName() {
+    return trimLiteralChars(tableName);
+  }
+
+  private static String trimLiteralChars(String s) {
+    if (s.startsWith("'") && s.endsWith("'")) {
+      return s.substring(1, s.length() - 1);
+    }
+    return s;
+  }
+
+  public List<String> getColumnNames() {
+    return removeTableAliases(columnNames);
+  }
+
+  private List<String> removeTableAliases(List<String> columnNames) {
+    List<String> result = new ArrayList<String>();
+    for (String col : columnNames) {
+      if (col.startsWith(tableNameAlias + ".")) {
+        result.add(col.substring(tableNameAlias.length() + 1));
+      } else {
+        result.add(col);
+      }
+    }
+    return result;
+  }
+
+  public String getWhere() {
+    if (where == null || where.trim().isEmpty()) {
+      return "*";
+    }
+    return where;
+  }
+
+  @Override
+  public String toString() {
+    return "Parser [columnNames=" + columnNames + ", tableName=" + tableName + ", where="
+ where + "]";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/EmptyResultSet.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/EmptyResultSet.java
b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/EmptyResultSet.java
new file mode 100644
index 0000000..1483a6b
--- /dev/null
+++ b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/EmptyResultSet.java
@@ -0,0 +1,42 @@
+package org.apache.blur.jdbc.util;
+
+/**
+ * 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 java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+import org.apache.blur.jdbc.abstractimpl.AbstractBlurResultSet;
+
+
+public class EmptyResultSet extends AbstractBlurResultSet {
+
+  @Override
+  public void close() throws SQLException {
+
+  }
+
+  @Override
+  public boolean next() throws SQLException {
+    return false;
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData() throws SQLException {
+    return new EmptyResultSetMetaData();
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/EmptyResultSetMetaData.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/EmptyResultSetMetaData.java
b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/EmptyResultSetMetaData.java
new file mode 100644
index 0000000..0a0c7ab
--- /dev/null
+++ b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/EmptyResultSetMetaData.java
@@ -0,0 +1,32 @@
+package org.apache.blur.jdbc.util;
+
+/**
+ * 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 java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+import org.apache.blur.jdbc.abstractimpl.AbstractBlurResultSetMetaData;
+
+
+public class EmptyResultSetMetaData extends AbstractBlurResultSetMetaData implements ResultSetMetaData
{
+
+  @Override
+  public int getColumnCount() throws SQLException {
+    return 0;
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/NotImplemented.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/NotImplemented.java
b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/NotImplemented.java
new file mode 100644
index 0000000..397d32d
--- /dev/null
+++ b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/NotImplemented.java
@@ -0,0 +1,41 @@
+package org.apache.blur.jdbc.util;
+
+/**
+ * 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.
+ */
+
+/**
+ * 
+ */
+public class NotImplemented extends RuntimeException {
+
+  public static final String BLUR_JDBC_DEBUG = "blur.jdbc.debug";
+  private static final long serialVersionUID = 4736975316647139778L;
+  public static final boolean debug = Boolean.getBoolean(BLUR_JDBC_DEBUG);
+
+  public NotImplemented() {
+    this(null);
+  }
+
+  public NotImplemented(String name) {
+    if (debug) {
+      if (name != null) {
+        System.err.println("Method [" + name + "]");
+      }
+      new Throwable().printStackTrace();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/SimpleStringResultSet.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/SimpleStringResultSet.java
b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/SimpleStringResultSet.java
new file mode 100644
index 0000000..eff7797
--- /dev/null
+++ b/contrib/blur-jdbc/src/main/java/org/apache/blur/jdbc/util/SimpleStringResultSet.java
@@ -0,0 +1,101 @@
+package org.apache.blur.jdbc.util;
+
+/**
+ * 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 java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.blur.jdbc.abstractimpl.AbstractBlurResultSet;
+import org.apache.blur.jdbc.abstractimpl.AbstractBlurResultSetMetaData;
+
+
+public class SimpleStringResultSet extends AbstractBlurResultSet {
+
+  private List<String> columnNames;
+  private List<Map<String, String>> data;
+  private int position = -1;
+  private String lastValue;
+
+  public SimpleStringResultSet(List<String> columnNames, List<Map<String, String>>
data) {
+    this.columnNames = columnNames;
+    this.data = data;
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData() throws SQLException {
+    return new SimpleStringResultSetMetaData(columnNames);
+  }
+
+  @Override
+  public boolean next() throws SQLException {
+    if (position + 1 >= data.size()) {
+      return false;
+    }
+    position++;
+    return true;
+  }
+
+  @Override
+  public String getString(int columnIndex) throws SQLException {
+    String name = columnNames.get(columnIndex - 1);
+    Map<String, String> row = data.get(position);
+    return lastValue = row.get(name);
+  }
+
+  @Override
+  public boolean wasNull() throws SQLException {
+    return lastValue == null ? true : false;
+  }
+
+  @Override
+  public void close() throws SQLException {
+
+  }
+
+  public static class SimpleStringResultSetMetaData extends AbstractBlurResultSetMetaData
{
+
+    private List<String> columnNames;
+
+    public SimpleStringResultSetMetaData(List<String> columnNames) {
+      this.columnNames = columnNames;
+    }
+
+    @Override
+    public int getColumnCount() throws SQLException {
+      return columnNames.size();
+    }
+
+    @Override
+    public String getColumnName(int column) throws SQLException {
+      return columnNames.get(column - 1);
+    }
+
+    @Override
+    public int getColumnType(int column) throws SQLException {
+      return Types.VARCHAR;
+    }
+
+    @Override
+    public String getColumnTypeName(int column) throws SQLException {
+      return "string";
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/test/java/org/apache/blur/jdbc/BlurJdbcTest.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/test/java/org/apache/blur/jdbc/BlurJdbcTest.java b/contrib/blur-jdbc/src/test/java/org/apache/blur/jdbc/BlurJdbcTest.java
new file mode 100644
index 0000000..73c8602
--- /dev/null
+++ b/contrib/blur-jdbc/src/test/java/org/apache/blur/jdbc/BlurJdbcTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.blur.jdbc;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.junit.Test;
+
+public class BlurJdbcTest {
+
+  @Test
+  public void testJdbcDriver() throws SQLException, ClassNotFoundException {
+    // Class.forName(BlurJdbc.class.getName());
+    // Connection connection =
+    // DriverManager.getConnection("jdbc:blur:blur-vm:40010");
+    // Statement statement = connection.createStatement();
+    // ResultSet resultSet = statement.executeQuery("select * from test8493");
+    // while (resultSet.next()) {
+    // System.out.println(resultSet.getString(1));
+    // }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/contrib/blur-jdbc/src/test/java/org/apache/blur/jdbc/parser/ParserTest.java
----------------------------------------------------------------------
diff --git a/contrib/blur-jdbc/src/test/java/org/apache/blur/jdbc/parser/ParserTest.java b/contrib/blur-jdbc/src/test/java/org/apache/blur/jdbc/parser/ParserTest.java
new file mode 100644
index 0000000..7757f32
--- /dev/null
+++ b/contrib/blur-jdbc/src/test/java/org/apache/blur/jdbc/parser/ParserTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.blur.jdbc.parser;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class ParserTest {
+
+  @Test
+  public void test1() {
+    Parser parser = new Parser();
+    parser.parse("select * from table1");
+    assertEquals("table1", parser.getTableName());
+    List<String> columnNames = parser.getColumnNames();
+    assertEquals(1, columnNames.size());
+    assertEquals("*", columnNames.get(0));
+    assertEquals("*", parser.getWhere());
+  }
+
+  @Test
+  public void test2() {
+    Parser parser = new Parser();
+    parser.parse("select * from 'table1'");
+    assertEquals("table1", parser.getTableName());
+    List<String> columnNames = parser.getColumnNames();
+    assertEquals(1, columnNames.size());
+    assertEquals("*", columnNames.get(0));
+    assertEquals("*", parser.getWhere());
+  }
+
+  @Test
+  public void test3() {
+    Parser parser = new Parser();
+    parser.parse("select tbl.* from 'table1' tbl");
+    assertEquals("table1", parser.getTableName());
+    List<String> columnNames = parser.getColumnNames();
+    assertEquals(1, columnNames.size());
+    assertEquals("*", columnNames.get(0));
+    assertEquals("*", parser.getWhere());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e0c1f682/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index bbb005a..4b6954c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -201,7 +201,6 @@ under the License.
 		<module>blur-util</module>
 		<module>blur-gui</module>
 		<module>blur-shell</module>
-		<module>blur-jdbc</module>
 		<module>distribution</module>
 	</modules>
 


Mime
View raw message