Table Service

From Apache OpenOffice Wiki
Jump to: navigation, search



The Table object is a member of the tables container that is a member of the Catalog object. Each Table object supports the same properties, such as Name, CatalogName, SchemaName, Description, and an optional Type. The properties CatalogName and SchemaName can be empty when the database does not support these features. The Description property contains any comments that were added to the table object at creation time. The optional property Type is a string property may contain a database specific table type when supported, . Common table types are "TABLE", "VIEW", "SYSTEM TABLE", and "TEMPORARY TABLE". All these properties are read-only as long as this is not a descriptor. The descriptor pattern is described later.

Table

The Table object also supports the com.sun.star.sdbcx.XColumnsSupplier interface, because a table can not exist without columns. The other interfaces are optional, that is, they do not have to be supported by the actual table object:

The code example below shows the use of the table container and prints the table properties of the first table in the container.

  ...
  XNameAccess xTables = xTabSup.getTables();
  if (0 != aTableNames.length) {
        Object table = xTables.getByName(aTableNames[0]);
        XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, table);
        System.out.println("Name: " + xProp.getPropertyValue("Name"));
        System.out.println("CatalogName: " + xProp.getPropertyValue("CatalogName"));
        System.out.println("SchemaName: " + xProp.getPropertyValue("SchemaName"));
        System.out.println("Description: " + xProp.getPropertyValue("Description"));
        // the following property is optional so we first must check if it exists
        if(xProp.getPropertySetInfo().hasPropertyByName("Type"))
            System.out.println("Type: " + xProp.getPropertyValue("Type"));
  }

The Table object contains access to the columns, keys, and indexes when the above mentioned interfaces are supported.

  // print all columns of a XColumnsSupplier
  // later on used for keys and indexes as well
  public static void printColumns(XColumnsSupplier xColumnsSup) 
          throws com.sun.star.uno.Exception,SQLException {
      System.out.println("Example printColumns");
      // the table must at least support a XColumnsSupplier interface
      System.out.println("--- Columns ---");
      XNameAccess xColumns = xColumnsSup.getColumns();
      String [] aColumnNames = xColumns.getElementNames();
      for (int i =0; i<= aColumnNames.length-1; i++)
          System.out.println(" " + aColumnNames[i]);
  }
 
  // print all keys including the columns of a key
  public static void printKeys(XColumnsSupplier xColumnsSup) 
          throws com.sun.star.uno.Exception,SQLException {
      System.out.println("Example printKeys");
      XKeysSupplier xKeysSup = (XKeysSupplier)UnoRuntime.queryInterface(
          XKeysSupplier.class, xColumnsSup);
      if (xKeysSup != null) {
          System.out.println("--- Keys ---");
          XIndexAccess xKeys = xKeysSup.getKeys();
          for ( int i =0; i < xKeys.getCount(); i++) {
              Object key = xKeys.getByIndex(i);
              XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(
                  XPropertySet.class,key);
              System.out.println(" " + xProp.getPropertyValue("Name"));
              XColumnsSupplier xKeyColumnsSup = (XColumnsSupplier)UnoRuntime.queryInterface(
                  XColumnsSupplier.class, xProp);
              printColumns(xKeyColumnsSup);
          }
      }
  }
 
  // print all indexes including the columns of an index
  public static void printIndexes(XColumnsSupplier xColumnsSup)
          throws com.sun.star.uno.Exception,SQLException {
      System.out.println("Example printIndexes");
      XIndexesSupplier xIndexesSup = (XIndexesSupplier)UnoRuntime.queryInterface(
          XIndexesSupplier.class, xColumnsSup);
      if (xIndexesSup != null) {
          System.out.println("--- Indexes ---");
          XNameAccess xIndexs = xIndexesSup.getIndexes();
          String [] aIndexNames = xIndexs.getElementNames();
          for ( int i =0; i<= aIndexNames.length-1; i++) {
              System.out.println(" " + aIndexNames[i]);
              Object index = xIndexs.getByName(aIndexNames[i]);
              XColumnsSupplier xIndexColumnsSup = (XColumnsSupplier)UnoRuntime.queryInterface(
                  XColumnsSupplier.class, index);
              printColumns(xIndexColumnsSup);
          }
      }
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages