? nbproject Index: src/main/org/exolab/castor/jdo/JDO2.java =================================================================== RCS file: /cvs/castor/castor/src/main/org/exolab/castor/jdo/JDO2.java,v retrieving revision 1.3 diff -u -r1.3 JDO2.java --- a/src/main/org/exolab/castor/jdo/JDO2.java 3 Nov 2004 09:36:43 -0000 1.3 +++ b/src/main/org/exolab/castor/jdo/JDO2.java 6 Nov 2004 01:09:30 -0000 @@ -144,7 +144,7 @@ implements DataObjects, Referenceable, ObjectFactory, Serializable { - + /** * The Jakarta * Commons Logging instance used for all logging. @@ -199,7 +199,7 @@ /** * The name of this database. */ - private String _databaseName; + //private String _databaseName; /** @@ -227,19 +227,19 @@ /** * The application class loader. */ - private static ClassLoader _classLoader; + private ClassLoader _classLoader; /** * The resolver can be used to resolve cached entities, e.g. * for external mapping documents. */ - private static EntityResolver _entityResolver; + private EntityResolver _entityResolver; /** * Location of the JDOOld configuration file. */ - private static InputSource _source; + //private static InputSource _source; /** * The transactions to databases map for database pooling @@ -268,9 +268,21 @@ */ private JDO2 (String name) { - _databaseName = name; + //_databaseName = name; } + /** + *This could defenitly be better, having to know the URL is just plain icky. + * + */ + public static JDO2 getInstance(String url) throws PersistenceException{ + if(_jdoInstances.get(url) == null){ + throw new PersistenceException("No JDO2 conf found with that url!"); //change to key string + } + + return (JDO2)_jdoInstances.get(url); + } + /** * Factory method for creating a JDOOld instance for one of the databases configured in the * JDOOld config file. Please make sure that you call loadConfiguration() first. @@ -279,7 +291,7 @@ * @throws MappingException The mapping file is invalid, or any * error occured trying to load the JDO configuration/mapping */ - public static JDO2 createInstance (String databaseName) + /* public static JDO2 createInstance (String databaseName) throws MappingException { if (!DatabaseRegistry.hasDatabaseRegistries()) { @@ -305,7 +317,7 @@ } return jdoInstance; - } + } */ /** * Returns the log writer for this database source. @@ -469,7 +481,7 @@ */ public String getDatabaseName() { - return _databaseName; + return null;// _databaseName; } /** @@ -596,14 +608,22 @@ * that does not exist * @throws PersistenceException Database access failed */ - public Database getDatabase() + public Database getDatabase(String databaseName) throws DatabaseNotFoundException, PersistenceException { - if ( _databaseName == null ) + if (!DatabaseRegistry.hasDatabaseRegistries()) { + throw new MappingException (Messages.message ("jdo.missing.jdo.configuration")); + } + + if (DatabaseRegistry.getDatabaseRegistry (databaseName) == null) { + throw new MappingException (Messages.format ("jdo.missing.database.configuration", databaseName)); + } + + if ( databaseName == null ) throw new IllegalStateException( Messages.message ("jdo.missing.database.name")); - if ( DatabaseRegistry.getDatabaseRegistry( _databaseName ) == null ) { + if ( DatabaseRegistry.getDatabaseRegistry( databaseName ) == null ) { if ( _jdoConfURI == null ) - throw new DatabaseNotFoundException( Messages.format( "jdo.dbNoMapping", _databaseName ) ); + throw new DatabaseNotFoundException( Messages.format( "jdo.dbNoMapping", databaseName ) ); try { DatabaseRegistry.loadDatabase( _jdoConfURI, _entityResolver, _classLoader ); } catch ( MappingException except ) { @@ -698,7 +718,7 @@ return _txDbPool.get( tx ); if ( tx != null && tx.getStatus() == Status.STATUS_ACTIVE ) { - dbImpl = new DatabaseImpl( _databaseName, _lockTimeout, + dbImpl = new DatabaseImpl( databaseName, _lockTimeout, _callbackInterceptor, _instanceFactory, tx, _classLoader, _autoStore ); if ( _txDbPool != null ) @@ -714,11 +734,20 @@ } } - return new DatabaseImpl( _databaseName, _lockTimeout, + return new DatabaseImpl( databaseName, _lockTimeout, _callbackInterceptor, _instanceFactory, null, _classLoader, _autoStore ); } /** + * Just to make the DataObject interface happy. + */ + public Database getDatabase() + throws DatabaseNotFoundException, PersistenceException + { + return null; + } + + /** * Load the JDO configuration from the specified input source using * a custom class loader. In addition, a custom entity resolver can be * provided. @@ -734,10 +763,18 @@ throws MappingException { DatabaseRegistry.loadDatabase (source, resolver, loader); + //maybe we dont care about this!? This would allow a user to + //reload a configuration in the mid stride, possibly. + if(_jdoInstances.get(source.getSystemId()) != null){ + throw new MappingException("Configuration already loaded!"); + } + JDO2 instance = new JDO2(); + instance.setConfiguration(source); + instance.setClassLoader(loader); + instance.setEntityResolver(resolver); - _classLoader = loader; - _entityResolver = resolver; - _source = source; + _jdoInstances.put(source.getSystemId(), instance); + _log.debug ("Successfully created JDO instance: " + jdoInstance); } /** @@ -766,6 +803,10 @@ loadConfiguration (new InputSource (url), null, null); } + /** + * Question...what the heck is this used for!!?!? + * For J2EE stuff?? + */ public synchronized Reference getReference() { Reference ref; @@ -775,8 +816,9 @@ if ( _description != null ) ref.add( new StringRefAddr( "description", _description ) ); - if ( _databaseName != null ) - ref.add( new StringRefAddr( "databaseName", _databaseName ) ); + //Arent tied to a database now + //if ( _databaseName != null ) + // ref.add( new StringRefAddr( "databaseName", _databaseName ) ); if ( _jdoConfURI != null ) ref.add( new StringRefAddr( "configuration", _jdoConfURI.toString() ) ); ref.add( new StringRefAddr( "lockTimeout", Integer.toString( _lockTimeout ) ) ); @@ -812,10 +854,11 @@ if ( addr != null ) { ds._description = (String) addr.getContent(); } - addr = ref.get ("databaseName"); - if ( addr != null ) { - ds._databaseName = (String) addr.getContent(); - } + //again, arent tied to a particular database. + //addr = ref.get ("databaseName"); + //if ( addr != null ) { + // ds._databaseName = (String) addr.getContent(); + //} addr = ref.get ("configuration"); if ( addr != null ) { ds._jdoConfURI = (InputSource) addr.getContent();