text: #
  # 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.
  
  from pypinot.cursor import Cursor
  from pypinot.exceptions import Error
  from pypinot.helper import check_closed
  
  
  class Connection(object):
  
      """Connection to a Pinot database."""
  
      def __init__(self, *args, **kwargs):
          self._debug = kwargs.get("debug", False)
          self._args = args
          self._kwargs = kwargs
          self.closed = False
          self.cursors = []
  
      @check_closed
      def close(self):
          """Close the connection now."""
          self.closed = True
          for cursor in self.cursors:
              try:
                  cursor.close()
              except Error:
                  pass  # already closed
  
      @check_closed
      def commit(self):
          """
          Commit any pending transaction to the database.
          Not supported.
          """
          pass
  
      @check_closed
      def cursor(self):
          """Return a new Cursor Object using the connection."""
          cursor = Cursor(*self._args, **self._kwargs)
          self.cursors.append(cursor)
  
          return cursor
  
      @check_closed
      def execute(self, operation, parameters=None):
          cursor = self.cursor()
          return cursor.execute(operation, parameters)
  
      def __enter__(self):
          return self.cursor()
  
      def __exit__(self, *exc):
          self.close()
  