Difference between revisions of "Documentation/DevGuide/Database/Table Service"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
 
(3 intermediate revisions by one other user not shown)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/Database/Column Service
 
|NextPage=Documentation/DevGuide/Database/Column Service
 
}}
 
}}
{{DISPLAYTITLE:Table Service}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Database/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Table Service}}
 
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 <code>Name</code>, <code>CatalogName</code>, <code>SchemaName</code>, <code>Description</code>, and an optional <code>Type</code>. The properties <code>CatalogName</code> and <code>SchemaName</code> can be empty when the database does not support these features. The <code>Description</code> property contains any comments that were added to the table object at creation time. The optional property <code>Type</code> 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.
 
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 <code>Name</code>, <code>CatalogName</code>, <code>SchemaName</code>, <code>Description</code>, and an optional <code>Type</code>. The properties <code>CatalogName</code> and <code>SchemaName</code> can be empty when the database does not support these features. The <code>Description</code> property contains any comments that were added to the table object at creation time. The optional property <code>Type</code> 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.
  
Line 21: Line 22:
 
The code example below shows the use of the table container and prints the table properties of the first table in the container.  
 
The code example below shows the use of the table container and prints the table properties of the first table in the container.  
 
<!--[SOURCE:Database/sdbcx.java]-->
 
<!--[SOURCE:Database/sdbcx.java]-->
 
+
<syntaxhighlight lang="java">
 
   ...
 
   ...
 
   XNameAccess xTables = xTabSup.getTables();
 
   XNameAccess xTables = xTabSup.getTables();
Line 35: Line 36:
 
             System.out.println("Type: " + xProp.getPropertyValue("Type"));
 
             System.out.println("Type: " + xProp.getPropertyValue("Type"));
 
   }
 
   }
 
+
</syntaxhighlight>
 
The Table object contains access to the columns, keys, and indexes when the above mentioned interfaces are supported.  
 
The Table object contains access to the columns, keys, and indexes when the above mentioned interfaces are supported.  
 
<!--[SOURCE:Database/sdbcx.java]-->
 
<!--[SOURCE:Database/sdbcx.java]-->
 
+
<syntaxhighlight lang="java">
 
   // print all columns of a XColumnsSupplier
 
   // print all columns of a XColumnsSupplier
 
   // later on used for keys and indexes as well
 
   // later on used for keys and indexes as well
Line 92: Line 93:
 
       }
 
       }
 
   }
 
   }
 
+
</syntaxhighlight>
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Database Access]]
+
 
 +
[[Category:Documentation/Developer's Guide/Database Access]]

Latest revision as of 15:07, 21 December 2020



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