public
Description: Java library for fetching and representing database metadata, with NetKernel support.
Clone URL: git://github.com/scharris/db-metadata.git
db-metadata / README
100644 105 lines (80 sloc) 3.826 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
db-metadata: provides a simple java library and NetKernel module for fetching database metadata information.
 
As a Java Library:
==================
  The db-metadata.jar archive may be used as a simple Java library for fetching metadata information for a
database schema. Use class com.github.scharris.db_metadata.DBMetaData to fetch metadata information about
tables, views, fields and foreign key links in a given schema.
 
 
As a NetKernel module:
======================
  The db-metadata.jar is also a valid self-contained NetKernel module which handles active:db-metadata
uri requests.
 
The metadata is returned in the following form:
 
<database-metadata schema="..." identifiers-case-sensitivity="...">
    <relations>
      <relation type="..." id="..." name="..." schema="..." comment="...">
        <field id="..." name="...">
          <type>
            <database-type/>
            <jdbc-type-code/>
            <jdbc-type-text/>
            [<max-chars/>]
            [<precision/>
             <scale/
             <radix/>]
          </type>
          <nullable/>
          [<primary-key-part/>]
     <comment/>
        </field>
        ...
      </relation>
      ...
    </relations>
        
    <foreign-key-links>
      <link>
        <referencing-relation name="..." rel-id="..." schema="..."/>
        <referenced-relation name="..." rel-id="..." schema="..."/>
        <match fk-field="..." pk-field="..."/>
        ...
      </link>
      ...
    </foreign-key-links>
</database-metadata>
 
 
Arguments for active:db-metadata requests in NetKernel
------------------------------------------------------
   +schema: either a direct schema name (not containing a ':'), or a uri which when sourced should return the
      schema name. To enter a schema name containing a ':', use the "data:" scheme, e.g. "data:text/plain,ACCOUNTING".
 
   +views: whether to include views.
    Valid values are y/yes/n/no/t/true/f/false or else a uri yielding one of these values.
 
   +tables: whether to include tables.
    Valid values are as described for the views argument.
 
   +fields: whether to include field metadata within table and view elements.
    Valid values are as described for the views argument.
 
   +fks: whether to include metadata describing foreign key links in the schema.
    Valid values are as described for the views argument.
 
Example uri:
 
  active:db-metadata+schema@myschema+views@ffcpl:/etc/include-views+fields@y+fks@y
 
 
NetKernel Module Installation:
------------------------------
 
  1) Copy the included db-metadata.jar file into your {NetKernel-Home}/modules directory,
     or wherever else you'd like to keep it.
  2) Register the module's location with netkernel by entering its location in
     {NetKernel-Home}/etc/deployedModules.xml, e.g. by adding a line like:
        <module>modules/db-metadata.jar</module>
  3) import the module into your own client modules:
      <import><uri>urn:com:github:scharris:db-metadata</uri></import>
 
Requests, suggestions and comments are welcome. Send to steveOfAR at domain gmail.com.
 
 
As a Standalone Program
=======================
The DBMetaData class includes a main method which can write database metadata as xml to an output file.
To do this, first create a properties file describing the database connnection information, with properties:
jdbc-connect-url, jdbc-driver-class, user, and password.
 
For example,
#file connection.props
jdbc-connect-url=jdbc:oracle:thin:@myhost.mydomain.org:1528:mysid
jdbc-driver-class=oracle.jdbc.OracleDriver
user=mydbuser
password=mypassword
 
Then invoke the command like this:
 
  java -cp db-metadata.jar:ojdbc14.jar com.github.scharris.db_metadata.DBMetaData myschema connection.props myschema.xml
 
which would write the database metadata for schema myschema to file myschema.xml.