ExoLab     OpenEJB     OpenJMS     OpenORB     Castor     Tyrex     
 

Main
  Home
  Download
  API
  Schema
  Mailing Lists
  CVS

XML
  Using XML
  Source Generator
  Schema Support
  XML Mapping

JDO
  Using JDO
  New features
  JDO Config
  Types
  FAQs
  Presentation

Advanced JDO
  OQL
  Trans. & Locks
  Design
  KeyGen
  Long Trans.
  Nested Attrs.

More
  Presentations
  The Examples
  Configuration
  Tips & Tricks
  Full JavaDoc

About
  License
  Contributors
  Status, Todo
  Changelog
  Library
  Contact

  



The Castor configuration file
Sample Configuration File
Configuration For Various Databases
The JDO Configuration DTD

The Castor configuration file

The database configuration specifies the means to obtain a connection to the database server, the mapping between Java classes and tables in that database server, and the service provider to use for talking to that server.

The application will access the database by its given name (database/name) and will be able to persist all objects specified in the included mapping file(s).

The engine attribute specifies the persistence engine for this database server. Different database servers vary in the SQL syntax and capabilites they support, and this attribute names the service provider to use.

The following names are supported in Castor 1.0:

genericGeneric JDBC support
oracleOracle 7 and Oracle 8
sybaseSybase 11
sql-serverMicrosoft SQL Server
db2DB/2
informixInformix
postgresqlPostgreSQL 7.1
hsqlHypersonic SQL
instantdbInstantDB
interbaseInterbase
mysqlMySQL
sapdbSAP DB

Note: Castor doesn't work with JDBC-ODBC bridge from Sun. In particular, MS Access is not supported.

The means to acquire a database connection is specified in one of three ways: as a JDBC 2.0 driver URL, as a JDBC 2.0 DataSource, or as a DataSource to lookup through JNDI. When Castor is used inside a J2EE application server it is recommended to use JNDI lookup (see the jndi element), allowing the application server to manage connection pooling and distributed transactions.

The class mapping is included from an external mapping file, allowing multiple mappings to be included in the same database configuration, or two databases to share the same mappings. For concurrency and integrity reasons, two database configurations should never attempt to use overlapping mappings. It is recommended to use one database configuration per database server.

The mapping file is specified using a URL, typically a file: URL. If the database configuration file and mapping file reside in the same directory, use a relative URL. Relative URLs also work if the database configuration and mapping files are obtained from the application JAR and reside in the same classpath.

The driver element specifies the JDBC 2.0 driver for obtaining new connections to the database server. The driver is obtained from the JDBC DriverManager and must be located in the class path. The JDBC URL locates the driver and provides the access properties. Additional properties may be specified using the param element (e.g. buffer size, network protocol, etc).

Use the class-name attribute to specify the driver class for automatic registration with the JDBC DriverManager. If missing, the driver must be registered in any other means, including properties file, Class.forName(), etc.

For example, to configure an Oracle 8 thin driver, use:

  
    
    
  

The data-source element specifies the JDBC 2.0 DataSource for obtaining new connections to the database server. DataSources are defined in the JDBC 2.0 standard extension API which is included with Castor, and implement the interface javax.sql.DataSource.

The DataSource implementation class name is specified by the class-name attribute and configured through Bean-like accessor methods specified for the param element. The DTD for the param element is undefined and depends on the DataSource being used.

For example, to configure a PostgreSQL 7.1 DataSource, use:

  
    
  

The jndi element specifies the JDBC 2.0 DataSource for obtaining new connections to the database server through JNDI lookup. The JNDI environment naming context (ENC) is used to obtain a suitable DataSource..

When running inside a J2EE application server, this is the preferred method for obtaining database connections. It enables the J2EE application server to configure the connection, maintain a connection pool, and manage distributed transactions.

For example, to specify a J2EE DataSource, use:

  

Sample Configuration File

The following configuration file uses an Oracle 8 thin JDBC driver and three mapping files:

  
    
      
    
    
    
    
  

The following configuration file uses a connection obtained from the J2EE application server and a single mapping file:

  
    
    
  

Configuration For Various Databases

DriverConfiguration
Sybase jConnect
  
    
  
Oracle Thin Driver
  
    
  
PostgreSQL
  
    
  
InstantDB
  
    
    
  

The JDO Configuration DTD

For validation, the configuration file should include the following document type definition. For DTD validation use:

  
      
For XML Schema validation use:
  
      
The Castor namespace URI is http://castor.exolab.org/.

The Castor JDO database configuration DTD is:

  
  

  
  

  
  

  
  

  
  

  
  
      

 
   
  
   
 


Copyright © 1999-2001 ExoLab Group. All rights reserved.
 
Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners.