ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [1/2] ignite git commit: IGNITE-1786: Minor reworks in OdbcCommandHandler.
Date Wed, 27 Jan 2016 12:24:20 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1786 8bd28cd0a -> d55dc3690


IGNITE-1786: Minor reworks in OdbcCommandHandler.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8b16efcd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8b16efcd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8b16efcd

Branch: refs/heads/ignite-1786
Commit: 8b16efcd7cf363338d2124ccfca3c4b93d89dbac
Parents: 8bd28cd
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Jan 27 13:56:43 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Jan 27 13:56:43 2016 +0300

----------------------------------------------------------------------
 .../processors/odbc/OdbcCommandHandler.java     | 178 +++++++++----------
 1 file changed, 81 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8b16efcd/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java
index 4073168..48851ca 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.odbc;
 
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
@@ -25,6 +26,7 @@ import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.cache.QueryCursorImpl;
 import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata;
 import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.lang.IgniteBiTuple;
 
 import java.util.*;
@@ -37,19 +39,21 @@ import static org.apache.ignite.internal.processors.odbc.OdbcRequest.*;
  * SQL query handler.
  */
 public class OdbcCommandHandler {
+    /** Query ID sequence. */
+    private static final AtomicLong qryIdGen = new AtomicLong();
+
     /** Kernel context. */
-    protected final GridKernalContext ctx;
+    private final GridKernalContext ctx;
 
     /** Logger. */
-    protected final IgniteLogger log;
-
-    /** Query ID sequence. */
-    private static final AtomicLong qryIdGen = new AtomicLong();
+    private final IgniteLogger log;
 
     /** Current queries cursors. */
     private final ConcurrentHashMap<Long, IgniteBiTuple<QueryCursor, Iterator>>
qryCurs = new ConcurrentHashMap<>();
 
     /**
+     * Constructor.
+     *
      * @param ctx Context.
      */
     public OdbcCommandHandler(GridKernalContext ctx) {
@@ -59,108 +63,42 @@ public class OdbcCommandHandler {
     }
 
     /**
+     * Handle request.
+     *
      * @param req Request.
      * @return Response.
+     * @throws IgniteCheckedException If failed.
      */
-    public OdbcResponse handle(OdbcRequest req) {
+    public OdbcResponse handle(OdbcRequest req) throws IgniteCheckedException {
         assert req != null;
 
         switch (req.command()) {
-            case EXECUTE_SQL_QUERY: {
-                return executeQuery((OdbcQueryExecuteRequest)req, qryCurs);
-            }
+            case EXECUTE_SQL_QUERY:
+                return executeQuery((OdbcQueryExecuteRequest)req);
 
-            case FETCH_SQL_QUERY: {
-                return fetchQuery((OdbcQueryFetchRequest)req, qryCurs);
-            }
+            case FETCH_SQL_QUERY:
+                return fetchQuery((OdbcQueryFetchRequest)req);
 
-            case CLOSE_SQL_QUERY: {
-                return closeQuery((OdbcQueryCloseRequest)req, qryCurs);
-            }
+            case CLOSE_SQL_QUERY:
+                return closeQuery((OdbcQueryCloseRequest)req);
 
-            case GET_COLUMNS_META: {
+            case GET_COLUMNS_META:
                 return getColumnsMeta((OdbcQueryGetColumnsMetaRequest) req);
-            }
 
-            case GET_TABLES_META: {
+            case GET_TABLES_META:
                 return getTablesMeta((OdbcQueryGetTablesMetaRequest) req);
-            }
         }
 
         return null;
     }
 
     /**
-     * @param cur Current cursor.
-     * @param req Sql fetch request.
-     * @param qryId Query id.
-     * @return Query result with items.
-     */
-    private static OdbcQueryFetchResult createQueryResult(Iterator cur, OdbcQueryFetchRequest
req, Long qryId) {
-
-        List<Object> items = new ArrayList<>();
-
-        for (int i = 0; i < req.pageSize() && cur.hasNext(); ++i)
-            items.add(cur.next());
-
-        return new OdbcQueryFetchResult(qryId, items, !cur.hasNext());
-    }
-
-    /**
-     * Convert metadata in collection from {@link GridQueryFieldMetadata} to
-     * {@link OdbcColumnMeta}.
-     *
-     * @param meta Internal query field metadata.
-     * @return Odbc query field metadata.
-     */
-    private static Collection<OdbcColumnMeta> convertMetadata(Collection<?> meta)
{
-        List<OdbcColumnMeta> res = new ArrayList<>();
-
-        if (meta != null) {
-            for (Object info : meta) {
-                assert info instanceof GridQueryFieldMetadata;
-
-                res.add(new OdbcColumnMeta((GridQueryFieldMetadata)info));
-            }
-        }
-
-        return res;
-    }
-
-    /**
-     * Checks whether string matches SQL pattern.
-     *
-     * @param str String.
-     * @param ptrn Pattern.
-     * @return Whether string matches pattern.
-     */
-    private boolean matches(String str, String ptrn) {
-        return str != null && (ptrn == null || ptrn.isEmpty() ||
-                str.toUpperCase().matches(ptrn.toUpperCase().replace("%", ".*").replace("_",
".")));
-    }
-
-    /**
-     * Remove quotation marks at the beginning and end of the string if present.
-     *
-     * @param str Input string.
-     * @return String without leading and trailing quotation marks.
-     */
-    private String RemoveQuotationMarksIfNeeded(String str) {
-        if (str.startsWith("\"") && str.endsWith("\""))
-            return str.substring(1, str.length() - 1);
-
-        return str;
-    }
-
-    /**
      * {@link OdbcQueryExecuteRequest} command handler.
      *
      * @param req Execute query request.
-     * @param qryCurs Queries cursors.
      * @return Response.
      */
-    private OdbcResponse executeQuery(OdbcQueryExecuteRequest req,
-                                      ConcurrentHashMap<Long, IgniteBiTuple<QueryCursor,
Iterator>> qryCurs) {
+    private OdbcResponse executeQuery(OdbcQueryExecuteRequest req) {
         long qryId = qryIdGen.getAndIncrement();
 
         try {
@@ -172,7 +110,7 @@ public class OdbcCommandHandler {
 
             if (cache == null)
                 return new OdbcResponse(OdbcResponse.STATUS_FAILED,
-                        "Failed to find cache with name: " + req.cacheName());
+                    "Failed to find cache with name: " + req.cacheName());
 
             QueryCursor qryCur = cache.query(qry);
 
@@ -199,17 +137,14 @@ public class OdbcCommandHandler {
      * {@link OdbcQueryCloseRequest} command handler.
      *
      * @param req Execute query request.
-     * @param qryCurs Queries cursors.
      * @return Response.
      */
-    private OdbcResponse closeQuery(OdbcQueryCloseRequest req,
-                                    ConcurrentHashMap<Long, IgniteBiTuple<QueryCursor,
Iterator>> qryCurs) {
+    private OdbcResponse closeQuery(OdbcQueryCloseRequest req) {
         try {
             QueryCursor cur = qryCurs.get(req.queryId()).get1();
 
             if (cur == null)
-                return new OdbcResponse(OdbcResponse.STATUS_FAILED,
-                        "Failed to find query with ID: " + req.queryId());
+                return new OdbcResponse(OdbcResponse.STATUS_FAILED, "Failed to find query
with ID: " + req.queryId());
 
             cur.close();
 
@@ -230,11 +165,9 @@ public class OdbcCommandHandler {
      * {@link OdbcQueryFetchRequest} command handler.
      *
      * @param req Execute query request.
-     * @param qryCurs Queries cursors.
      * @return Response.
      */
-    private OdbcResponse fetchQuery(OdbcQueryFetchRequest req,
-                                    ConcurrentHashMap<Long, IgniteBiTuple<QueryCursor,
Iterator>> qryCurs) {
+    private OdbcResponse fetchQuery(OdbcQueryFetchRequest req) {
         try {
             Iterator cur = qryCurs.get(req.queryId()).get2();
 
@@ -242,7 +175,12 @@ public class OdbcCommandHandler {
                 return new OdbcResponse(OdbcResponse.STATUS_FAILED,
                         "Failed to find query with ID: " + req.queryId());
 
-            OdbcQueryFetchResult res = createQueryResult(cur, req, req.queryId());
+            List<Object> items = new ArrayList<>();
+
+            for (int i = 0; i < req.pageSize() && cur.hasNext(); ++i)
+                items.add(cur.next());
+
+            OdbcQueryFetchResult res = new OdbcQueryFetchResult(req.queryId(), items, !cur.hasNext());
 
             return new OdbcResponse(res);
         }
@@ -270,12 +208,12 @@ public class OdbcCommandHandler {
                 // Parsing two-part table name.
                 String[] parts = req.tableName().split("\\.");
 
-                cacheName = RemoveQuotationMarksIfNeeded(parts[0]);
+                cacheName = removeQuotationMarksIfNeeded(parts[0]);
 
                 tableName = parts[1];
             }
             else {
-                cacheName = RemoveQuotationMarksIfNeeded(req.cacheName());
+                cacheName = removeQuotationMarksIfNeeded(req.cacheName());
 
                 tableName = req.tableName();
             }
@@ -316,7 +254,7 @@ public class OdbcCommandHandler {
         try {
             List<OdbcTableMeta> meta = new ArrayList<>();
 
-            String realSchema = RemoveQuotationMarksIfNeeded(req.schema());
+            String realSchema = removeQuotationMarksIfNeeded(req.schema());
 
             Collection<GridQueryTypeDescriptor> tablesMeta = ctx.query().types(realSchema);
 
@@ -342,4 +280,50 @@ public class OdbcCommandHandler {
             return new OdbcResponse(OdbcResponse.STATUS_FAILED, e.getMessage());
         }
     }
+
+    /**
+     * Convert metadata in collection from {@link GridQueryFieldMetadata} to
+     * {@link OdbcColumnMeta}.
+     *
+     * @param meta Internal query field metadata.
+     * @return Odbc query field metadata.
+     */
+    private static Collection<OdbcColumnMeta> convertMetadata(Collection<?> meta)
{
+        List<OdbcColumnMeta> res = new ArrayList<>();
+
+        if (meta != null) {
+            for (Object info : meta) {
+                assert info instanceof GridQueryFieldMetadata;
+
+                res.add(new OdbcColumnMeta((GridQueryFieldMetadata)info));
+            }
+        }
+
+        return res;
+    }
+
+    /**
+     * Checks whether string matches SQL pattern.
+     *
+     * @param str String.
+     * @param ptrn Pattern.
+     * @return Whether string matches pattern.
+     */
+    private static boolean matches(String str, String ptrn) {
+        return str != null && (F.isEmpty(ptrn) ||
+            str.toUpperCase().matches(ptrn.toUpperCase().replace("%", ".*").replace("_",
".")));
+    }
+
+    /**
+     * Remove quotation marks at the beginning and end of the string if present.
+     *
+     * @param str Input string.
+     * @return String without leading and trailing quotation marks.
+     */
+    private static String removeQuotationMarksIfNeeded(String str) {
+        if (str.startsWith("\"") && str.endsWith("\""))
+            return str.substring(1, str.length() - 1);
+
+        return str;
+    }
 }


Mime
View raw message