History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CASTOR-918
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Ralf Joachim
Reporter: Martin Fuchs
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

JDO2.loadConfiguration(JdoConf) - use JDoConfFactory with JDO2

Created: 03/Nov/04 03:03 PM   Updated: 04/Aug/05 03:37 AM
Component/s: JDO
Affects Version/s:
Fix Version/s: 0.9.7 M1

Time Tracking:
Not Specified

File Attachments: 1. Text File castor-1781.patch (44 kb)
2. Text File patch-1781-2.txt (5 kb)
3. Text File patch-1781-3.txt (28 kb)

Operating System: All
Platform: PC

Bugzilla Id: 1781

 Description  « Hide
Moving the enhancement to use JdoConfFactory with JDO2 from bug 1511 to this new


Martin, it looks like JDO is working again, but JDO2 still lacks a
loadConfiguration(JdoConf) method. Whilst this is not high priority, I think we
should try to make it for the 0.9.6 release.

And maybe we should try to pick up on this old idea below as well.

> When setting a URI for a JDO configuration file, try to unmarshall
> the configuration file immediately, and store the result in one and
> one instance variable only: _jdoConf (of type JdoConf).


The proposed patch includes the requested method JDO2.loadConfiguration(JdoConf)
as well as a revised version of the old JDO class to load the JDO configuration
file immediately when calling JDO.setConfiguration().

Creating an JDO2 instance using JdoConfFactory is achieved by calling a new
JDO2.createInstance() overload with both parameters "JdoConf jdoConf" and
"String databaseName" at one time, not by using two distinct calls, because we
need both informations at the same time.

Here is a small usage example:

org.exolab.castor.jdo.conf.Database jdoDbConf;

String db_url = "jdbc:mysql://localhost:3306/test";
String username = "test";
String password = "";

URL map_url = DeptEmp.class.getResource("mapping.xml");

// Set up JDO with the configuration the specified database driver and
connection information
jdoDbConf = JdoConfFactory.createJdoDbConf("db", "mysql",
db_url, username, password));

// Store mapping file location in the configuration

// Activate the JDO configuration
JDO2 jdo = JDO2.createInstance(JdoConfFactory.createJdoConf(jdoDbConf), "db");

The documentation update contains the JDO2 example from above. It also fixes a
few small mistakes of the old JDO examples, and indents them to make it a bit
easier to read.

The changes already work for my test applications, both using XML configuration
files and JDOConfFactory.
However the JTF tests don't yet run - they print the following exception

Caused by: unable to add attribute "configuration"
to 'org.exolab.castor.jdo.JDO' due to the following error: org.exolab
.castor.mapping.MappingRuntimeException: Nested error:
org.exolab.castor.mapping.MappingException: Nested error: Parsing
Error : File "file:///D:/java/castor-1511/sybase.xml" not found.
Line : 0
Column : 0

{file: [not available]; line: 11; column: 62}

at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:622)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:516)
at Main.run(Main.java:146)
at Main.main(Main.java:226)
Caused by: org.xml.sax.SAXException: unable to add attribute "configuration"
to 'org.exolab.castor.jdo.JDO' due to the f
ollowing error: org.exolab.castor.mapping.MappingRuntimeException: Nested
error: org.exolab.castor.mapping.MappingExcept
ion: Nested error: Parsing Error : File "file:///D:/java/castor-
1511/sybase.xml" not found.
Line : 0
Column : 0

It seems the BASE URI used to load the config file is the current directory
instead of the class directory.
May be some one else can have a look at this?


if you look into the patch you will see it also addresses some other small
issues I found on the way:

  • JDO2_jdoConfURI was incorrectly used as string in
    JDO2.getReference/getObjectInstance(). I removed it completely.
  • Some JDO2 comments contained "JDOold", I think this was a thing left over from
    creating JDO2.
  • some more comment and white space changes

I asked myself if it would not be better to remove the static variable
JDOConfLoader._jdoConf completely. Providing the method unmarshalConfiguration()
to unmarshal the JDO configuration from an input source and returning the
configuration object immediately should be enough. Anything other, like the
database or transaction configuration can be queried directly from this returned

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Martin Fuchs - 03/Nov/04 03:06 PM
Created an attachment (id=760)
proposed patch (in working state)

Ralf Joachim - 07/Mar/05 03:48 PM
Gregory, how should your code look like if you want to pass a ready configured
driver or datasource into castor as discussed on IRC.

Werner Guttmann - 01/Apr/05 02:51 AM
Gregory ?

Ralf Joachim - 21/Apr/05 04:25 PM
Simple patch that allows to configure JDOManager with JdoConf instance.

Ralf Joachim - 23/Apr/05 07:01 PM
At trying to write a test case for the JDOManager.loadConfiguration(JdoConf) methods I quite needed some time to find JdoConfFactory as I expected to find it at org.exolab.castor.jdo or one of its subpackages and not under org.exolab.castor.util. In addition there had been a failure in javadoc and it was not possible to specify mapping at the create method for the database.

According to this I decided to declare org.exolab.castor.util.JdoConfFactory as deprecated and refactored it into the new org.exolab.castor.jdo.util.JDOConfFactory.

Patch now also includes a preliminary test case that needs to be integrated in test framework later.