calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [01/11] incubator-calcite git commit: [CALCITE-912] Add Avatica OpenConnectionRequest (Bruno Dumon)
Date Fri, 23 Oct 2015 02:38:50 GMT
Repository: incubator-calcite
Updated Branches:
  refs/heads/master d50c46a1a -> 86610552e


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a63639b1/avatica/src/main/java/org/apache/calcite/avatica/remote/Service.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/remote/Service.java b/avatica/src/main/java/org/apache/calcite/avatica/remote/Service.java
index ae3bd77..3717ab5 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/remote/Service.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/remote/Service.java
@@ -52,6 +52,7 @@ public interface Service {
   FetchResponse apply(FetchRequest request);
   CreateStatementResponse apply(CreateStatementRequest request);
   CloseStatementResponse apply(CloseStatementRequest request);
+  OpenConnectionResponse apply(OpenConnectionRequest request);
   CloseConnectionResponse apply(CloseConnectionRequest request);
   ConnectionSyncResponse apply(ConnectionSyncRequest request);
   DatabasePropertyResponse apply(DatabasePropertyRequest request);
@@ -82,6 +83,8 @@ public interface Service {
           name = "createStatement"),
       @JsonSubTypes.Type(value = CloseStatementRequest.class,
           name = "closeStatement"),
+      @JsonSubTypes.Type(value = OpenConnectionRequest.class,
+          name = "openConnection"),
       @JsonSubTypes.Type(value = CloseConnectionRequest.class,
           name = "closeConnection"),
       @JsonSubTypes.Type(value = ConnectionSyncRequest.class, name = "connectionSync"),
@@ -98,6 +101,7 @@ public interface Service {
       property = "response",
       defaultImpl = ResultSetResponse.class)
   @JsonSubTypes({
+      @JsonSubTypes.Type(value = OpenConnectionResponse.class, name = "openConnection"),
       @JsonSubTypes.Type(value = ResultSetResponse.class, name = "resultSet"),
       @JsonSubTypes.Type(value = PrepareResponse.class, name = "prepare"),
       @JsonSubTypes.Type(value = FetchResponse.class, name = "fetch"),
@@ -116,8 +120,19 @@ public interface Service {
   }
 
   /** Request for
-   * {@link org.apache.calcite.avatica.Meta#getCatalogs()}. */
+   * {@link org.apache.calcite.avatica.Meta#getCatalogs(Meta.ConnectionHandle)}. */
   class CatalogsRequest extends Request {
+    public final String connectionId;
+
+    public CatalogsRequest() {
+      connectionId = null;
+    }
+
+    @JsonCreator
+    public CatalogsRequest(@JsonProperty("connectionId") String connectionId) {
+      this.connectionId = connectionId;
+    }
+
     ResultSetResponse accept(Service service) {
       return service.apply(this);
     }
@@ -128,31 +143,67 @@ public interface Service {
             "Expected CatalogsRequest, but got " + genericMsg.getClass().getName());
       }
 
-      // No state to set
-      return new CatalogsRequest();
+      final Requests.CatalogsRequest msg = (Requests.CatalogsRequest) genericMsg;
+      final Descriptor desc = msg.getDescriptorForType();
+
+      String connectionId = null;
+      if (ProtobufService.hasField(msg, desc,
+          Requests.CatalogsRequest.CONNECTION_ID_FIELD_NUMBER)) {
+        connectionId = msg.getConnectionId();
+      }
+
+      return new CatalogsRequest(connectionId);
     }
 
     @Override Requests.CatalogsRequest serialize() {
-      return Requests.CatalogsRequest.newBuilder().build();
+      Requests.CatalogsRequest.Builder builder = Requests.CatalogsRequest.newBuilder();
+
+      if (null != connectionId) {
+        builder.setConnectionId(connectionId);
+      }
+
+      return builder.build();
     }
 
     @Override public int hashCode() {
-      return 0;
+      return connectionId == null ? 0 : connectionId.hashCode();
     }
 
     @Override public boolean equals(Object o) {
       if (o == this) {
         return true;
       }
-      return o instanceof CatalogsRequest;
+
+      if (o instanceof CatalogsRequest) {
+        CatalogsRequest other = (CatalogsRequest) o;
+
+        if (null == connectionId) {
+          if (null != other.connectionId) {
+            return false;
+          }
+        } else if (!connectionId.equals(other.connectionId)) {
+          return false;
+        }
+
+        return true;
+      }
+
+      return false;
     }
   }
 
   /** Request for
-   * {@link org.apache.calcite.avatica.Meta#getDatabaseProperties()}. */
+   * {@link org.apache.calcite.avatica.Meta#getDatabaseProperties(Meta.ConnectionHandle)}.
*/
   class DatabasePropertyRequest extends Request {
-    @JsonCreator
+    public final String connectionId;
+
     public DatabasePropertyRequest() {
+      connectionId = null;
+    }
+
+    @JsonCreator
+    public DatabasePropertyRequest(@JsonProperty("connectionId") String connectionId) {
+      this.connectionId = connectionId;
     }
 
     DatabasePropertyResponse accept(Service service) {
@@ -165,38 +216,73 @@ public interface Service {
             "Expected DatabasePropertyRequest, but got " + genericMsg.getClass().getName());
       }
 
-      return new DatabasePropertyRequest();
+      final Requests.DatabasePropertyRequest msg = (Requests.DatabasePropertyRequest) genericMsg;
+      final Descriptor desc = msg.getDescriptorForType();
+
+      String connectionId = null;
+      if (ProtobufService.hasField(msg, desc,
+          Requests.DatabasePropertyRequest.CONNECTION_ID_FIELD_NUMBER)) {
+        connectionId = msg.getConnectionId();
+      }
+
+      return new DatabasePropertyRequest(connectionId);
     }
 
     @Override Requests.DatabasePropertyRequest serialize() {
-      return Requests.DatabasePropertyRequest.newBuilder().build();
+      Requests.DatabasePropertyRequest.Builder builder =
+          Requests.DatabasePropertyRequest.newBuilder();
+
+      if (null != connectionId) {
+        builder.setConnectionId(connectionId);
+      }
+
+      return builder.build();
     }
 
     @Override public int hashCode() {
-      return 0;
+      return connectionId == null ? 0 : connectionId.hashCode();
     }
 
     @Override public boolean equals(Object o) {
       if (o == this) {
         return true;
       }
-      return o instanceof DatabasePropertyRequest;
+
+      if (o instanceof DatabasePropertyRequest) {
+        DatabasePropertyRequest other = (DatabasePropertyRequest) o;
+
+        if (null == connectionId) {
+          if (null != other.connectionId) {
+            return false;
+          }
+        } else if (!connectionId.equals(other.connectionId)) {
+          return false;
+        }
+
+        return true;
+      }
+
+      return false;
     }
   }
   /** Request for
-   * {@link Meta#getSchemas(String, org.apache.calcite.avatica.Meta.Pat)}. */
+   * {@link Meta#getSchemas(Meta.ConnectionHandle, String, Meta.Pat)}. */
   class SchemasRequest extends Request {
+    public final String connectionId;
     public final String catalog;
     public final String schemaPattern;
 
     SchemasRequest() {
+      connectionId = null;
       catalog = null;
       schemaPattern = null;
     }
 
     @JsonCreator
-    public SchemasRequest(@JsonProperty("catalog") String catalog,
+    public SchemasRequest(@JsonProperty("connectionId") String connectionId,
+        @JsonProperty("catalog") String catalog,
         @JsonProperty("schemaPattern") String schemaPattern) {
+      this.connectionId = connectionId;
       this.catalog = catalog;
       this.schemaPattern = schemaPattern;
     }
@@ -214,6 +300,11 @@ public interface Service {
       final Requests.SchemasRequest msg = (Requests.SchemasRequest) genericMsg;
       final Descriptor desc = msg.getDescriptorForType();
 
+      String connectionId = null;
+      if (ProtobufService.hasField(msg, desc, Requests.SchemasRequest.CONNECTION_ID_FIELD_NUMBER))
{
+        connectionId = msg.getConnectionId();
+      }
+
       String catalog = null;
       if (ProtobufService.hasField(msg, desc, Requests.SchemasRequest.CATALOG_FIELD_NUMBER))
{
         catalog = msg.getCatalog();
@@ -225,11 +316,14 @@ public interface Service {
         schemaPattern = msg.getSchemaPattern();
       }
 
-      return new SchemasRequest(catalog, schemaPattern);
+      return new SchemasRequest(connectionId, catalog, schemaPattern);
     }
 
     @Override Requests.SchemasRequest serialize() {
       Requests.SchemasRequest.Builder builder = Requests.SchemasRequest.newBuilder();
+      if (null != connectionId) {
+        builder.setConnectionId(connectionId);
+      }
       if (null != catalog) {
         builder.setCatalog(catalog);
       }
@@ -243,6 +337,7 @@ public interface Service {
     @Override public int hashCode() {
       final int prime = 31;
       int result = 1;
+      result = prime * result + ((connectionId == null) ? 0 : connectionId.hashCode());
       result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
       result = prime * result + ((schemaPattern == null) ? 0 : schemaPattern.hashCode());
       return result;
@@ -255,6 +350,14 @@ public interface Service {
       if (o instanceof SchemasRequest) {
         SchemasRequest other = (SchemasRequest) o;
 
+        if (null == connectionId) {
+          if (null != other.connectionId) {
+            return false;
+          }
+        } else if (!connectionId.equals(other.connectionId)) {
+          return false;
+        }
+
         if (null == catalog) {
           // We're null, other is not
           if (null != other.catalog) {
@@ -281,15 +384,17 @@ public interface Service {
   }
 
   /** Request for
-   * {@link Meta#getTables(String, org.apache.calcite.avatica.Meta.Pat, org.apache.calcite.avatica.Meta.Pat,
java.util.List)}
+   * {@link Meta#getTables(Meta.ConnectionHandle, String, org.apache.calcite.avatica.Meta.Pat,
org.apache.calcite.avatica.Meta.Pat, java.util.List)}
    */
   class TablesRequest extends Request {
+    public final String connectionId;
     public final String catalog;
     public final String schemaPattern;
     public final String tableNamePattern;
     public final List<String> typeList;
 
     TablesRequest() {
+      connectionId = null;
       catalog = null;
       schemaPattern = null;
       tableNamePattern = null;
@@ -297,10 +402,12 @@ public interface Service {
     }
 
     @JsonCreator
-    public TablesRequest(@JsonProperty("catalog") String catalog,
+    public TablesRequest(@JsonProperty("connectionId") String connectionId,
+        @JsonProperty("catalog") String catalog,
         @JsonProperty("schemaPattern") String schemaPattern,
         @JsonProperty("tableNamePattern") String tableNamePattern,
         @JsonProperty("typeList") List<String> typeList) {
+      this.connectionId = connectionId;
       this.catalog = catalog;
       this.schemaPattern = schemaPattern;
       this.tableNamePattern = tableNamePattern;
@@ -320,6 +427,11 @@ public interface Service {
       final Requests.TablesRequest msg = (Requests.TablesRequest) genericMsg;
       final Descriptor desc = msg.getDescriptorForType();
 
+      String connectionId = null;
+      if (ProtobufService.hasField(msg, desc, Requests.TablesRequest.CONNECTION_ID_FIELD_NUMBER))
{
+        connectionId = msg.getConnectionId();
+      }
+
       String catalog = null;
       if (ProtobufService.hasField(msg, desc, Requests.TablesRequest.CATALOG_FIELD_NUMBER))
{
         catalog = msg.getCatalog();
@@ -343,12 +455,15 @@ public interface Service {
         typeList = msg.getTypeListList();
       }
 
-      return new TablesRequest(catalog, schemaPattern, tableNamePattern, typeList);
+      return new TablesRequest(connectionId, catalog, schemaPattern, tableNamePattern, typeList);
     }
 
     @Override Requests.TablesRequest serialize() {
       Requests.TablesRequest.Builder builder = Requests.TablesRequest.newBuilder();
 
+      if (null != connectionId) {
+        builder.setConnectionId(connectionId);
+      }
       if (null != catalog) {
         builder.setCatalog(catalog);
       }
@@ -371,6 +486,7 @@ public interface Service {
     @Override public int hashCode() {
       final int prime = 31;
       int result = 1;
+      result = prime * result + ((connectionId == null) ? 0 : connectionId.hashCode());
       result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
       result = prime * result + ((schemaPattern == null) ? 0 : schemaPattern.hashCode());
       result = prime * result + ((tableNamePattern == null) ? 0 : tableNamePattern.hashCode());
@@ -385,8 +501,16 @@ public interface Service {
       if (o instanceof TablesRequest) {
         TablesRequest other = (TablesRequest) o;
 
+        if (null == connectionId) {
+          if (null != other.connectionId) {
+            return false;
+          }
+        } else if (!connectionId.equals(other.connectionId)) {
+          return false;
+        }
+
         if (null == catalog) {
-          if (null != catalog) {
+          if (null != other.catalog) {
             return false;
           }
         } else if (!catalog.equals(other.catalog)) {
@@ -425,9 +549,20 @@ public interface Service {
   }
 
   /**
-   * Request for {@link Meta#getTableTypes()}.
+   * Request for {@link Meta#getTableTypes(Meta.ConnectionHandle)}.
    */
   class TableTypesRequest extends Request {
+    public final String connectionId;
+
+    public TableTypesRequest() {
+      this.connectionId = null;
+    }
+
+    @JsonCreator
+    public TableTypesRequest(@JsonProperty("connectionId") String connectionId) {
+      this.connectionId = connectionId;
+    }
+
     @Override ResultSetResponse accept(Service service) {
       return service.apply(this);
     }
@@ -438,35 +573,65 @@ public interface Service {
             "Expected TableTypesRequest, but got " + genericMsg.getClass().getName());
       }
 
-      return new TableTypesRequest();
+      final Requests.TableTypesRequest msg = (Requests.TableTypesRequest) genericMsg;
+      final Descriptor desc = msg.getDescriptorForType();
+
+      String connectionId = null;
+      if (ProtobufService.hasField(msg, desc,
+          Requests.TableTypesRequest.CONNECTION_ID_FIELD_NUMBER)) {
+        connectionId = msg.getConnectionId();
+      }
+
+      return new TableTypesRequest(connectionId);
     }
 
     @Override Requests.TableTypesRequest serialize() {
-      return Requests.TableTypesRequest.newBuilder().build();
+      Requests.TableTypesRequest.Builder builder = Requests.TableTypesRequest.newBuilder();
+      if (null != connectionId) {
+        builder.setConnectionId(connectionId);
+      }
+
+      return builder.build();
     }
 
     @Override public int hashCode() {
-      return 0;
+      return connectionId == null ? 0 : connectionId.hashCode();
     }
 
     @Override public boolean equals(Object o) {
       if (o == this) {
         return true;
       }
-      return o instanceof TableTypesRequest;
+      if (o instanceof TableTypesRequest) {
+        TableTypesRequest other = (TableTypesRequest) o;
+
+        if (null == connectionId) {
+          if (null != other.connectionId) {
+            return false;
+          }
+        } else if (!connectionId.equals(other.connectionId)) {
+          return false;
+        }
+
+        return true;
+      }
+
+      return false;
     }
   }
 
   /** Request for
-   * {@link Meta#getColumns(String, org.apache.calcite.avatica.Meta.Pat, org.apache.calcite.avatica.Meta.Pat,
org.apache.calcite.avatica.Meta.Pat)}.
+   * {@link Meta#getColumns(Meta.ConnectionHandle, String, org.apache.calcite.avatica.Meta.Pat,
org.apache.calcite.avatica.Meta.Pat, org.apache.calcite.avatica.Meta.Pat)}.
    */
   class ColumnsRequest extends Request {
+    public final String connectionId;
     public final String catalog;
     public final String schemaPattern;
     public final String tableNamePattern;
     public final String columnNamePattern;
 
     ColumnsRequest() {
+      connectionId = null;
       catalog = null;
       schemaPattern = null;
       tableNamePattern = null;
@@ -474,10 +639,12 @@ public interface Service {
     }
 
     @JsonCreator
-    public ColumnsRequest(@JsonProperty("catalog") String catalog,
+    public ColumnsRequest(@JsonProperty("connectionId") String connectionId,
+        @JsonProperty("catalog") String catalog,
         @JsonProperty("schemaPattern") String schemaPattern,
         @JsonProperty("tableNamePattern") String tableNamePattern,
         @JsonProperty("columnNamePattern") String columnNamePattern) {
+      this.connectionId = connectionId;
       this.catalog = catalog;
       this.schemaPattern = schemaPattern;
       this.tableNamePattern = tableNamePattern;
@@ -497,6 +664,11 @@ public interface Service {
       final Requests.ColumnsRequest msg = (Requests.ColumnsRequest) genericMsg;
       final Descriptor desc = msg.getDescriptorForType();
 
+      String connectionId = null;
+      if (ProtobufService.hasField(msg, desc, Requests.ColumnsRequest.CONNECTION_ID_FIELD_NUMBER))
{
+        connectionId = msg.getConnectionId();
+      }
+
       String catalog = null;
       if (ProtobufService.hasField(msg, desc, Requests.ColumnsRequest.CATALOG_FIELD_NUMBER))
{
         catalog = msg.getCatalog();
@@ -520,12 +692,16 @@ public interface Service {
         columnNamePattern = msg.getColumnNamePattern();
       }
 
-      return new ColumnsRequest(catalog, schemaPattern, tableNamePattern, columnNamePattern);
+      return new ColumnsRequest(connectionId, catalog, schemaPattern, tableNamePattern,
+          columnNamePattern);
     }
 
     @Override Requests.ColumnsRequest serialize() {
       Requests.ColumnsRequest.Builder builder = Requests.ColumnsRequest.newBuilder();
 
+      if (null != connectionId) {
+        builder.setConnectionId(connectionId);
+      }
       if (null != catalog) {
         builder.setCatalog(catalog);
       }
@@ -545,6 +721,7 @@ public interface Service {
     @Override public int hashCode() {
       final int prime = 31;
       int result = 1;
+      result = prime * result + ((connectionId == null) ? 0 : connectionId.hashCode());
       result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
       result = prime * result + ((columnNamePattern == null) ? 0 : columnNamePattern.hashCode());
       result = prime * result + ((schemaPattern == null) ? 0 : schemaPattern.hashCode());
@@ -559,6 +736,14 @@ public interface Service {
       if (o instanceof ColumnsRequest) {
         ColumnsRequest other = (ColumnsRequest) o;
 
+        if (null == connectionId) {
+          if (null != other.connectionId) {
+            return false;
+          }
+        } else if (!connectionId.equals(other.connectionId)) {
+          return false;
+        }
+
         if (null == catalog) {
           if (null != other.catalog) {
             return false;
@@ -599,8 +784,19 @@ public interface Service {
   }
 
   /** Request for
-   * {@link Meta#getTypeInfo()}. */
+   * {@link Meta#getTypeInfo(Meta.ConnectionHandle)}. */
   class TypeInfoRequest extends Request {
+    public final String connectionId;
+
+    public TypeInfoRequest() {
+      connectionId = null;
+    }
+
+    @JsonCreator
+    public TypeInfoRequest(@JsonProperty("connectionId") String connectionId) {
+      this.connectionId = connectionId;
+    }
+
     @Override ResultSetResponse accept(Service service) {
       return service.apply(this);
     }
@@ -611,22 +807,50 @@ public interface Service {
             "Expected TypeInfoRequest, but got " + genericMsg.getClass().getName());
       }
 
-      return new TypeInfoRequest();
+      final Requests.TypeInfoRequest msg = (Requests.TypeInfoRequest) genericMsg;
+      final Descriptor desc = msg.getDescriptorForType();
+
+      String connectionId = null;
+      if (ProtobufService.hasField(msg, desc,
+          Requests.TypeInfoRequest.CONNECTION_ID_FIELD_NUMBER)) {
+        connectionId = msg.getConnectionId();
+      }
+
+      return new TypeInfoRequest(connectionId);
     }
 
     @Override Requests.TypeInfoRequest serialize() {
-      return Requests.TypeInfoRequest.newBuilder().build();
+      Requests.TypeInfoRequest.Builder builder = Requests.TypeInfoRequest.newBuilder();
+      if (null != connectionId) {
+        builder.setConnectionId(connectionId);
+      }
+
+      return builder.build();
     }
 
     @Override public int hashCode() {
-      return 0;
+      return connectionId == null ? 0 : connectionId.hashCode();
     }
 
     @Override public boolean equals(Object o) {
       if (o == this) {
         return true;
       }
-      return o instanceof TypeInfoRequest;
+      if (o instanceof TypeInfoRequest) {
+        TypeInfoRequest other = (TypeInfoRequest) o;
+
+        if (null == connectionId) {
+          if (null != other.connectionId) {
+            return false;
+          }
+        } else if (!connectionId.equals(other.connectionId)) {
+          return false;
+        }
+
+        return true;
+      }
+
+      return false;
     }
   }
 
@@ -637,10 +861,10 @@ public interface Service {
    * no signature and no other data.
    *
    * <p>Several types of request, including
-   * {@link org.apache.calcite.avatica.Meta#getCatalogs()} and
-   * {@link org.apache.calcite.avatica.Meta#getSchemas(String, org.apache.calcite.avatica.Meta.Pat)}
-   * {@link Meta#getTables(String, Meta.Pat, Meta.Pat, List)}
-   * {@link Meta#getTableTypes()}
+   * {@link org.apache.calcite.avatica.Meta#getCatalogs(Meta.ConnectionHandle)} and
+   * {@link org.apache.calcite.avatica.Meta#getSchemas(Meta.ConnectionHandle, String, org.apache.calcite.avatica.Meta.Pat)}
+   * {@link Meta#getTables(Meta.ConnectionHandle, String, Meta.Pat, Meta.Pat, List)}
+   * {@link Meta#getTableTypes(Meta.ConnectionHandle)}
    * return this response. */
   class ResultSetResponse extends Response {
     public final String connectionId;
@@ -1679,6 +1903,136 @@ public interface Service {
   }
 
   /** Request for
+   * {@link Meta#openConnection}. */
+  class OpenConnectionRequest extends Request {
+    public final String connectionId;
+    public final Map<String, String> info;
+
+    public OpenConnectionRequest() {
+      connectionId = null;
+      info = null;
+    }
+
+    @JsonCreator
+    public OpenConnectionRequest(@JsonProperty("connectionId") String connectionId,
+        @JsonProperty("info") Map<String, String> info) {
+      this.connectionId = connectionId;
+      this.info = info;
+    }
+
+    @Override OpenConnectionResponse accept(Service service) {
+      return service.apply(this);
+    }
+
+    @Override
+    Request deserialize(Message genericMsg) {
+      if (!(genericMsg instanceof Requests.OpenConnectionRequest)) {
+        throw new IllegalArgumentException(
+            "Expected OpenConnectionRequest, but got" + genericMsg.getClass().getName());
+      }
+
+      final Requests.OpenConnectionRequest msg = (Requests.OpenConnectionRequest) genericMsg;
+      final Descriptor desc = msg.getDescriptorForType();
+
+      String connectionId = null;
+      if (ProtobufService.hasField(msg, desc,
+          Requests.OpenConnectionRequest.CONNECTION_ID_FIELD_NUMBER)) {
+        connectionId = msg.getConnectionId();
+      }
+
+      Map<String, String> info = msg.getInfo();
+      if (info.isEmpty()) {
+        info = null;
+      }
+
+      return new OpenConnectionRequest(connectionId, info);
+    }
+
+    @Override
+    Message serialize() {
+      Requests.OpenConnectionRequest.Builder builder = Requests.OpenConnectionRequest.newBuilder();
+      if (null != connectionId) {
+        builder.setConnectionId(connectionId);
+      }
+      if (null != info) {
+        builder.getMutableInfo().putAll(info);
+      }
+
+      return builder.build();
+    }
+
+    @Override public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((connectionId == null) ? 0 : connectionId.hashCode());
+      result = prime * result + ((info == null) ? 0 : info.hashCode());
+      return result;
+    }
+
+    @Override public boolean equals(Object o) {
+      if (o == this) {
+        return true;
+      }
+      if (o instanceof OpenConnectionRequest) {
+        OpenConnectionRequest other = (OpenConnectionRequest) o;
+
+        if (null == connectionId) {
+          if (null != other.connectionId) {
+            return false;
+          }
+        } else if (!connectionId.equals(other.connectionId)) {
+          return false;
+        }
+
+        if (null == info) {
+          if (null != other.info) {
+            return false;
+          }
+        } else if (!info.equals(other.info)) {
+          return false;
+        }
+
+        return true;
+      }
+
+      return false;
+    }
+  }
+
+  /** Response from
+   * {@link org.apache.calcite.avatica.remote.Service.OpenConnectionRequest}. */
+  class OpenConnectionResponse extends Response {
+
+    @JsonCreator
+    public OpenConnectionResponse() {
+    }
+
+    @Override OpenConnectionResponse deserialize(Message genericMsg) {
+      if (!(genericMsg instanceof Responses.OpenConnectionResponse)) {
+        throw new IllegalArgumentException(
+            "Expected OpenConnectionResponse, but got " + genericMsg.getClass().getName());
+      }
+
+      return new OpenConnectionResponse();
+    }
+
+    @Override Responses.OpenConnectionResponse serialize() {
+      return Responses.OpenConnectionResponse.newBuilder().build();
+    }
+
+    @Override public int hashCode() {
+      return 0;
+    }
+
+    @Override public boolean equals(Object o) {
+      if (o == this) {
+        return true;
+      }
+      return o instanceof OpenConnectionResponse;
+    }
+  }
+
+  /** Request for
    * {@link Meta#closeConnection(org.apache.calcite.avatica.Meta.ConnectionHandle)}. */
   class CloseConnectionRequest extends Request {
     public final String connectionId;
@@ -1951,7 +2305,7 @@ public interface Service {
   }
 
   /** Response for
-   * {@link Meta#getDatabaseProperties()}. */
+   * {@link Meta#getDatabaseProperties(Meta.ConnectionHandle)}. */
   class DatabasePropertyResponse extends Response {
     public final Map<Meta.DatabaseProperty, Object> map;
 
@@ -2082,6 +2436,78 @@ public interface Service {
       return false;
     }
   }
+
+  /**
+   * ErrorResponse can be used in response to any kind of request. It is used internally
+   * by the transport layers to format errors for transport over the wire.
+   * Thus, {@link Request#apply} will never return an ErrorResponse.
+   */
+  class ErrorResponse extends Response {
+    public final String message;
+
+    public ErrorResponse() {
+      message = null;
+    }
+
+    @JsonCreator
+    public ErrorResponse(@JsonProperty("message") String message) {
+      this.message = message;
+    }
+
+    @Override ErrorResponse deserialize(Message genericMsg) {
+      if (!(genericMsg instanceof Responses.ErrorResponse)) {
+        throw new IllegalArgumentException(
+            "Expected ErrorResponse, but got " + genericMsg.getClass().getName());
+      }
+
+      final Responses.ErrorResponse msg = (Responses.ErrorResponse) genericMsg;
+      final Descriptor desc = msg.getDescriptorForType();
+
+      String message = null;
+      if (ProtobufService.hasField(msg, desc,
+          Responses.ErrorResponse.MESSAGE_FIELD_NUMBER)) {
+        message = msg.getMessage();
+      }
+
+      return new ErrorResponse(message);
+    }
+
+    @Override Responses.ErrorResponse serialize() {
+      Responses.ErrorResponse.Builder builder = Responses.ErrorResponse.newBuilder();
+
+      if (null != message) {
+        builder.setMessage(message);
+      }
+
+      return builder.build();
+    }
+
+    @Override public int hashCode() {
+      return message == null ? 0 : message.hashCode();
+    }
+
+    @Override public boolean equals(Object o) {
+      if (o == this) {
+        return true;
+      }
+
+      if (o instanceof ErrorResponse) {
+        ErrorResponse other = (ErrorResponse) o;
+
+        if (null == message) {
+          if (null != other.message) {
+            return false;
+          }
+        } else if (!message.equals(other.message)) {
+          return false;
+        }
+
+        return true;
+      }
+
+      return false;
+    }
+  }
 }
 
 // End Service.java

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a63639b1/avatica/src/main/protobuf/requests.proto
----------------------------------------------------------------------
diff --git a/avatica/src/main/protobuf/requests.proto b/avatica/src/main/protobuf/requests.proto
index 2a144c1..02451da 100644
--- a/avatica/src/main/protobuf/requests.proto
+++ b/avatica/src/main/protobuf/requests.proto
@@ -22,18 +22,19 @@ import "common.proto";
 
 // Request for Meta#getCatalogs()
 message CatalogsRequest {
-
+  string connection_id = 1;
 }
 
 // Request for Meta#getDatabaseProperties()
 message DatabasePropertyRequest {
-
+  string connection_id = 1;
 }
 
 // Request for Meta#getSchemas(String, org.apache.calcite.avatica.Meta.Pat)}
 message SchemasRequest {
   string catalog = 1;
   string schema_pattern = 2;
+  string connection_id = 3;
 }
 
 // Request for Request for Meta#getTables(String, org.apache.calcite.avatica.Meta.Pat,
@@ -44,11 +45,12 @@ message TablesRequest {
   string table_name_pattern = 3;
   repeated string type_list = 4;
   bool has_type_list = 6; // Having an empty type_list is distinct from a null type_list
+  string connection_id = 7;
 }
 
 // Request for Meta#getTableTypes()
 message TableTypesRequest {
-
+  string connection_id = 1;
 }
 
 // Request for Meta#getColumns(String, org.apache.calcite.avatica.Meta.Pat,
@@ -58,11 +60,12 @@ message ColumnsRequest {
   string schema_pattern = 2;
   string table_name_pattern = 3;
   string column_name_pattern = 4;
+  string connection_id = 5;
 }
 
 // Request for Meta#getTypeInfo()
 message TypeInfoRequest {
-
+  string connection_id = 1;
 }
 
 // Request for Meta#prepareAndExecute(Meta.StatementHandle, String, long, Meta.PrepareCallback)
@@ -99,6 +102,12 @@ message CloseStatementRequest {
   uint32 statement_id = 2;
 }
 
+// Request for Meta#openConnection(Meta.ConnectionHandle, Map<String, String>)
+message OpenConnectionRequest {
+  string connection_id = 1;
+  map<string, string> info = 2;
+}
+
 // Request for Meta#closeConnection(Meta.ConnectionHandle)
 message CloseConnectionRequest {
   string connection_id = 1;

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a63639b1/avatica/src/main/protobuf/responses.proto
----------------------------------------------------------------------
diff --git a/avatica/src/main/protobuf/responses.proto b/avatica/src/main/protobuf/responses.proto
index 1fad9c8..e4f52a3 100644
--- a/avatica/src/main/protobuf/responses.proto
+++ b/avatica/src/main/protobuf/responses.proto
@@ -57,6 +57,11 @@ message CloseStatementResponse {
 
 }
 
+// Response to OpenConnectionRequest {
+message OpenConnectionResponse {
+
+}
+
 // Response to CloseConnectionRequest {
 message CloseConnectionResponse {
 
@@ -76,3 +81,7 @@ message DatabasePropertyElement {
 message DatabasePropertyResponse {
   repeated DatabasePropertyElement props = 1;
 }
+
+message ErrorResponse {
+  string message = 1;
+}

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a63639b1/avatica/src/test/java/org/apache/calcite/avatica/remote/ProtobufTranslationImplTest.java
----------------------------------------------------------------------
diff --git a/avatica/src/test/java/org/apache/calcite/avatica/remote/ProtobufTranslationImplTest.java
b/avatica/src/test/java/org/apache/calcite/avatica/remote/ProtobufTranslationImplTest.java
index c76fd1a..337932e 100644
--- a/avatica/src/test/java/org/apache/calcite/avatica/remote/ProtobufTranslationImplTest.java
+++ b/avatica/src/test/java/org/apache/calcite/avatica/remote/ProtobufTranslationImplTest.java
@@ -27,6 +27,7 @@ import org.apache.calcite.avatica.Meta.Style;
 import org.apache.calcite.avatica.MetaImpl;
 import org.apache.calcite.avatica.remote.Service.CatalogsRequest;
 import org.apache.calcite.avatica.remote.Service.CloseConnectionRequest;
+import org.apache.calcite.avatica.remote.Service.CloseConnectionResponse;
 import org.apache.calcite.avatica.remote.Service.CloseStatementRequest;
 import org.apache.calcite.avatica.remote.Service.CloseStatementResponse;
 import org.apache.calcite.avatica.remote.Service.ColumnsRequest;
@@ -36,9 +37,12 @@ import org.apache.calcite.avatica.remote.Service.CreateStatementRequest;
 import org.apache.calcite.avatica.remote.Service.CreateStatementResponse;
 import org.apache.calcite.avatica.remote.Service.DatabasePropertyRequest;
 import org.apache.calcite.avatica.remote.Service.DatabasePropertyResponse;
+import org.apache.calcite.avatica.remote.Service.ErrorResponse;
 import org.apache.calcite.avatica.remote.Service.ExecuteResponse;
 import org.apache.calcite.avatica.remote.Service.FetchRequest;
 import org.apache.calcite.avatica.remote.Service.FetchResponse;
+import org.apache.calcite.avatica.remote.Service.OpenConnectionRequest;
+import org.apache.calcite.avatica.remote.Service.OpenConnectionResponse;
 import org.apache.calcite.avatica.remote.Service.PrepareAndExecuteRequest;
 import org.apache.calcite.avatica.remote.Service.PrepareRequest;
 import org.apache.calcite.avatica.remote.Service.PrepareResponse;
@@ -158,13 +162,13 @@ public class ProtobufTranslationImplTest<T> {
 
     requests.add(new CatalogsRequest());
     requests.add(new DatabasePropertyRequest());
-    requests.add(new SchemasRequest("catalog", "schemaPattern"));
+    requests.add(new SchemasRequest("connectionId", "catalog", "schemaPattern"));
     requests.add(
-        new TablesRequest("catalog", "schemaPattern", "tableNamePattern",
+        new TablesRequest("connectionId", "catalog", "schemaPattern", "tableNamePattern",
             Arrays.asList("STRING", "BOOLEAN", "INT")));
     requests.add(new TableTypesRequest());
     requests.add(
-        new ColumnsRequest("catalog", "schemaPattern", "tableNamePattern",
+        new ColumnsRequest("connectionId", "catalog", "schemaPattern", "tableNamePattern",
             "columnNamePattern"));
     requests.add(new TypeInfoRequest());
     requests.add(
@@ -181,6 +185,10 @@ public class ProtobufTranslationImplTest<T> {
 
     requests.add(new CreateStatementRequest("connectionId"));
     requests.add(new CloseStatementRequest("connectionId", Integer.MAX_VALUE));
+    Map<String, String> info = new HashMap<>();
+    info.put("param1", "value1");
+    info.put("param2", "value2");
+    requests.add(new OpenConnectionRequest("connectionId", info));
     requests.add(new CloseConnectionRequest("connectionId"));
     requests.add(
         new ConnectionSyncRequest("connectionId",
@@ -194,14 +202,15 @@ public class ProtobufTranslationImplTest<T> {
     LinkedList<Request> requests = new LinkedList<>();
 
     // We're pretty fast and loose on what can be null.
-    requests.add(new SchemasRequest(null, null));
+    requests.add(new SchemasRequest(null, null, null));
     // Repeated fields default to an empty list
-    requests.add(new TablesRequest(null, null, null, Collections.<String>emptyList()));
-    requests.add(new ColumnsRequest(null, null, null, null));
+    requests.add(new TablesRequest(null, null, null, null, Collections.<String>emptyList()));
+    requests.add(new ColumnsRequest(null, null, null, null, null));
     requests.add(new PrepareAndExecuteRequest(null, 0, null, 0));
     requests.add(new PrepareRequest(null, null, 0));
     requests.add(new CreateStatementRequest(null));
     requests.add(new CloseStatementRequest(null, 0));
+    requests.add(new OpenConnectionRequest(null, null));
     requests.add(new CloseConnectionRequest(null));
     requests.add(new ConnectionSyncRequest(null, null));
 
@@ -246,6 +255,9 @@ public class ProtobufTranslationImplTest<T> {
         Integer.MAX_VALUE, "catalog", "schema");
     responses.add(new ConnectionSyncResponse(connProps));
 
+    responses.add(new OpenConnectionResponse());
+    responses.add(new CloseConnectionResponse());
+
     responses.add(new CreateStatementResponse("connectionId", Integer.MAX_VALUE));
 
     Map<Meta.DatabaseProperty, Object> propertyMap = new HashMap<>();
@@ -261,6 +273,8 @@ public class ProtobufTranslationImplTest<T> {
             new Meta.StatementHandle("connectionId", Integer.MAX_VALUE,
                 signature)));
 
+    responses.add(new ErrorResponse("an error occurred"));
+
     return responses;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a63639b1/avatica/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java
----------------------------------------------------------------------
diff --git a/avatica/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java b/avatica/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java
index 14d4bd2..18d66e9 100644
--- a/avatica/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java
+++ b/avatica/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java
@@ -95,6 +95,10 @@ public class JsonHandlerTest {
       return null;
     }
 
+    @Override public OpenConnectionResponse apply(OpenConnectionRequest request) {
+      return null;
+    }
+
     @Override public CloseConnectionResponse apply(CloseConnectionRequest request) {
       return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a63639b1/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
index f836a71..73c0880 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
@@ -214,7 +214,7 @@ public class CalciteMetaImpl extends MetaImpl {
     return (CalciteConnectionImpl) connection;
   }
 
-  @Override public Map<DatabaseProperty, Object> getDatabaseProperties() {
+  @Override public Map<DatabaseProperty, Object> getDatabaseProperties(ConnectionHandle
ch) {
     final ImmutableMap.Builder<DatabaseProperty, Object> builder =
         ImmutableMap.builder();
     for (DatabaseProperty p : DatabaseProperty.values()) {
@@ -243,7 +243,8 @@ public class CalciteMetaImpl extends MetaImpl {
     }
   }
 
-  public MetaResultSet getTables(String catalog,
+  public MetaResultSet getTables(ConnectionHandle ch,
+      String catalog,
       final Pat schemaPattern,
       final Pat tableNamePattern,
       final List<String> typeList) {
@@ -280,7 +281,7 @@ public class CalciteMetaImpl extends MetaImpl {
         "REF_GENERATION");
   }
 
-  public MetaResultSet getTypeInfo() {
+  public MetaResultSet getTypeInfo(ConnectionHandle ch) {
     return createResultSet(allTypeInfo(),
         MetaTypeInfo.class,
         "TYPE_NAME",
@@ -303,7 +304,8 @@ public class CalciteMetaImpl extends MetaImpl {
         "NUM_PREC_RADIX");
   }
 
-  public MetaResultSet getColumns(String catalog,
+  public MetaResultSet getColumns(ConnectionHandle ch,
+      String catalog,
       Pat schemaPattern,
       Pat tableNamePattern,
       Pat columnNamePattern) {
@@ -506,7 +508,7 @@ public class CalciteMetaImpl extends MetaImpl {
             });
   }
 
-  public MetaResultSet getSchemas(String catalog, Pat schemaPattern) {
+  public MetaResultSet getSchemas(ConnectionHandle ch, String catalog, Pat schemaPattern)
{
     final Predicate1<MetaSchema> schemaMatcher = namedMatcher(schemaPattern);
     return createResultSet(schemas(catalog).where(schemaMatcher),
         MetaSchema.class,
@@ -514,13 +516,13 @@ public class CalciteMetaImpl extends MetaImpl {
         "TABLE_CATALOG");
   }
 
-  public MetaResultSet getCatalogs() {
+  public MetaResultSet getCatalogs(ConnectionHandle ch) {
     return createResultSet(catalogs(),
         MetaCatalog.class,
         "TABLE_CAT");
   }
 
-  public MetaResultSet getTableTypes() {
+  public MetaResultSet getTableTypes(ConnectionHandle ch) {
     return createResultSet(tableTypes(),
         MetaTableType.class,
         "TABLE_TYPE");

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a63639b1/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0cac4a1..ae53317 100644
--- a/pom.xml
+++ b/pom.xml
@@ -317,6 +317,12 @@ limitations under the License.
         <artifactId>xalan</artifactId>
         <version>2.7.1</version>
       </dependency>
+      <dependency>
+        <groupId>com.github.stephenc.jcip</groupId>
+        <artifactId>jcip-annotations</artifactId>
+        <version>1.0-1</version>
+        <scope>test</scope>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 



Mime
View raw message