Catalog Service

From Apache OpenOffice Wiki
Jump to: navigation, search



The Catalog object is the highest-level container in the SDBCX layer. It contains structural features of databases, like the schema and security model for the database. The connection, for instance, represents the database, and the Catalog is the database container for the tables, views, groups, and users within a connection or database. To create a catalog object, the database driver must support the interface com.sun.star.sdbcx.XDataDefinitionSupplier and an existing connection object. The following code fragment lists tables in a database.

  // create the Driver with the implementation name
  Object aDriver = xORB.createInstance("com.sun.star.comp.sdbcx.adabas.ODriver");
  // query for the interface
  com.sun.star.sdbc.XDriver xDriver;
  xDriver = (XDriver)UnoRuntime.queryInterface(XDriver.class, aDriver);
  if (xDriver != null) {
      // first create the needed url
      String adabasURL = "sdbc:adabas::MYDB0";
      // second create the necessary properties
      com.sun.star.beans.PropertyValue [] adabasProps = new com.sun.star.beans.PropertyValue[] {
          new com.sun.star.beans.PropertyValue("user", 0, "test1",
              com.sun.star.beans.PropertyState.DIRECT_VALUE),
          new com.sun.star.beans.PropertyValue("password", 0, "test1",
              com.sun.star.beans.PropertyState.DIRECT_VALUE)
      };
 
      // now create a connection to adabas
      XConnection adabasConnection = xDriver.connect(adabasURL, a dabasProps);
      if(adabasConnection != null) {
          System.out.println("Connection could be created!");
          // we need the XDatabaseDefinitionSupplier interface 
          // from the driver to get the XTablesSupplier
          XDataDefinitionSupplier xDDSup = (XDataDefinitionSupplier)UnoRuntime.queryInterface(
              XDataDefinitionSupplier.class, xDriver);
          if (xDDSup != null) {
              XTablesSupplier xTabSup = xDDSup.getDataDefinitionByConnection(adabasConnection);
          if (xTabSup != null) {
              XNameAccess xTables = xTabSup.getTables();
              // now print all table names
              System.out.println("Tables available:");
              String [] aTableNames = xTables.getElementNames();
              for ( int i =0; i<= aTableNames.length-1; i++)
                  System.out.println(aTableNames[i]);
              }
          }
          else {
              System.out.println("The driver is not SDBCX capable!");
          }
 
          // now we dispose the connection to close it
          XComponent xComponent = (XComponent)UnoRuntime.queryInterface(
              XComponent.class, adabasConnection);
          if (xComponent != null) {
              xComponent.dispose();
              System.out.println("Connection disposed!");
          }
      }
      else {
          System.out.println("Connection could not be created!");
      }
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages