Connection Service

From Apache OpenOffice Wiki
Jump to: navigation, search



The com.sun.star.sdbc.Connection is the database client side. It is responsible for the creation of the Statements and the information about the database itself. The service consists of three interfaces that have to be supported:

The first two interfaces introduce some access and closing mechanisms that can be best described inside the code fragment of the Connection class. To understand the interface com.sun.star.sdbc.XConnection, we must have a closer look at some methods. The others not described are simple enough to handle them in the code fragment.

First there is the method getMetaData() that returns an object which implements the interface com.sun.star.sdbc.XDatabaseMetaData. This object has many methods and depends on the capabilities of the database. Most return values are found in the database documentation or in the first step, assuming some values match. The methods, such as getTables(), getColumns() and getTypeInfo() are described in the next chapter.

The following methods are used to create statements. Each of them is a factory method that creates the three different kinds of statements.

Important Methods of com.sun.star.sdbc.XConnection
createStatement() Creates a new com.sun.star.sdbc.Statement object for sending SQL statements to the database. SQL statements without parameters are executed using Statement objects.
prepareStatement(sql) Creates a com.sun.star.sdbc.PreparedStatement object for sending parameterized SQL statements to the database.
prepareCall(sql) Creates a com.sun.star.sdbc.CallableStatement object for calling database stored procedures.
  Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException)
  {
      ::osl::MutexGuard aGuard( m_aMutex );
      checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
      // create a statement
      // the statement can only be executed once
      Reference< XStatement > xReturn = new OStatement(this);
      m_aStatements.push_back(WeakReferenceHelper(xReturn));
      return xReturn;
  }
  // --------------------------------------------------------------------------------
  Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& _sSql ) 
            throw(SQLException, RuntimeException)
  {
      ::osl::MutexGuard aGuard( m_aMutex );
      checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
      // the pre
      if(m_aTypeInfo.empty())
        buildTypeInfo();
 
      // create a statement
      // the statement can only be executed more than once
      Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,m_aTypeInfo,_sSql);
      m_aStatements.push_back(WeakReferenceHelper(xReturn));
      return xReturn;
  }
  // --------------------------------------------------------------------------------
  Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& _sSql ) 
            throw(SQLException, RuntimeException)
  {
      ::osl::MutexGuard aGuard( m_aMutex );
      checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
      // not implemented yet :-) a task to do 
      return NULL;
  }

All other methods can be omitted at this stage. For detailed descriptions, refer to the API Reference Manual.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages