Author: vgritsenko Date: Thu Feb 3 09:11:06 2005 New Revision: 151186 URL: http://svn.apache.org/viewcvs?view=rev&rev=151186 Log: code cleanup
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactory.java cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactoryImpl.java cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/AbstractOjbImpl.java cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/ConnectionFactoryAvalonDataSource.java Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactory.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactory.java?view=diff&r1=151185&r2=151186 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactory.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactory.java Thu Feb 3 09:11:06 2005 @@ -1,12 +1,12 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -29,24 +29,24 @@ * @version CVS $Id$ */ public interface PBFactory extends Component { - + /** * The <code>ROLE</code> */ String ROLE = PBFactory.class.getName(); - + /** * Get the default Persistence BrokerManager. * @return a PersistenceBroker Object * @throws PBFactoryException - If the operation failed. */ PersistenceBroker defaultPersistenceBroker() - throws PBFactoryException; - + throws PBFactoryException; + /** * Create a new PersistenceBroker with the given parameters. * Using this method we can access diferents datasources. - * + * * @param jcdAlias - name of the jdbc connection descriptor to be used. * @param user - Datasource user's name * @param password - Datasource user's password @@ -54,8 +54,10 @@ * @throws PBFactoryException - If the operation failed. */ PersistenceBroker createPersistenceBroker(String jcdAlias, - String user, String password) throws PBFactoryException; - + String user, + String password) + throws PBFactoryException; + /** * Create a new PersistenceBroker with the given parameters. * @param key - A immutable key that identify the PB instance in pools @@ -63,5 +65,5 @@ * @throws PBFactoryException - If the operation failed. */ PersistenceBroker createPersistenceBroker(PBKey key) - throws PBFactoryException; + throws PBFactoryException; } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactoryImpl.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactoryImpl.java?view=diff&r1=151185&r2=151186 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactoryImpl.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactoryImpl.java Thu Feb 3 09:11:06 2005 @@ -1,12 +1,12 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,34 +28,24 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Antonio Gallardo</a> * @version CVS $Id$ */ -public class PBFactoryImpl -extends AbstractOjbImpl -implements PBFactory, ThreadSafe { - +public class PBFactoryImpl + extends AbstractOjbImpl + implements PBFactory, ThreadSafe { + /* (non-Javadoc) * @see org.apache.avalon.framework.activity.Disposable#dispose() */ public void dispose() { super.dispose(); - if (this.getLogger().isDebugEnabled()) { - this.getLogger().debug("OJB-PB: Disposed OK!"); - } + getLogger().debug("Disposed"); } /* (non-Javadoc) * @see org.apache.avalon.framework.activity.Initializable#initialize() */ public void initialize() throws Exception { - super.initialize(); - try { - if (this.getLogger().isDebugEnabled()) { - this.getLogger().debug("OJB-PB: Started OK!"); - } - } catch (Throwable t) { - if (this.getLogger().isFatalErrorEnabled()) { - this.getLogger().fatalError("OJB-PB: Started failed: Cannot create a Persistence Broker Factory.",t); - } - } + super.initialize(); + getLogger().debug("Started"); } /* (non-Javadoc) Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/AbstractOjbImpl.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/AbstractOjbImpl.java?view=diff&r1=151185&r2=151186 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/AbstractOjbImpl.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/AbstractOjbImpl.java Thu Feb 3 09:11:06 2005 @@ -1,12 +1,12 @@ /* * Copyright 1999-2002,2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,27 +22,33 @@ import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; - /** - * Base class for different DB-OBJ wrapper implementations. This base class is responsible to initialize and dispose of - * the helper class <code>ConnectionFactoryAvalonDataSource</code> which can be used as a ConnectionFactory class in - * the OJB Configuration + * Base class for different OJB wrapper implementations. This base class + * is responsible to initialize and dispose of the helper class + * <code>ConnectionFactoryAvalonDataSource</code> which can be used as a + * ConnectionFactory class in the OJB Configuration. * * @author giacomo * @version $Id$ */ public class AbstractOjbImpl - extends AbstractLogEnabled - implements Initializable, Disposable, Serviceable { - + extends AbstractLogEnabled + implements Initializable, Disposable, Serviceable { + /** The <code>ServiceManager</code> instance */ protected ServiceManager manager; /* (non-Javadoc) + * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) + */ + public void service(final ServiceManager manager) throws ServiceException { + this.manager = manager; + } + + /* (non-Javadoc) * @see org.apache.avalon.framework.activity.Initializable#initialize() */ - public void initialize() - throws Exception { + public void initialize() throws Exception { ConnectionFactoryAvalonDataSource.initialize(this.manager); } @@ -51,13 +57,6 @@ */ public void dispose() { ConnectionFactoryAvalonDataSource.dispose(); - } - - /* (non-Javadoc) - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(final ServiceManager manager) - throws ServiceException { - this.manager = manager; + this.manager = null; } } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/ConnectionFactoryAvalonDataSource.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/ConnectionFactoryAvalonDataSource.java?view=diff&r1=151185&r2=151186 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/ConnectionFactoryAvalonDataSource.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/ojb/java/org/apache/cocoon/ojb/components/ConnectionFactoryAvalonDataSource.java Thu Feb 3 09:11:06 2005 @@ -1,12 +1,12 @@ /* * Copyright 1999-2002,2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,7 +28,6 @@ import org.apache.ojb.broker.accesslayer.LookupException; import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor; - /** * OJBConnectionFactory implemenation to bridge into the Avalon DataSource Connection Pooling * Component defined in the Cocoon configuration. @@ -37,8 +36,8 @@ * @version $Id$ */ public class ConnectionFactoryAvalonDataSource - implements ConnectionFactory { - + implements ConnectionFactory { + /** The <code>ServiceManager</code> to be used */ private static ServiceManager manager; @@ -51,40 +50,48 @@ * needed <code>ServiceManager</code>. * * @param serviceManager The ServiceManager - * * @throws ServiceException In case we cannot obtain a DataSource */ public static void initialize(final ServiceManager serviceManager) - throws ServiceException { + throws ServiceException { + if (ConnectionFactoryAvalonDataSource.manager != null) { + throw new IllegalStateException("ConnectionFactoryAvalonDataSource is already initialized"); + } + ConnectionFactoryAvalonDataSource.manager = serviceManager; ConnectionFactoryAvalonDataSource.dbselector = - (ServiceSelector)ConnectionFactoryAvalonDataSource.manager.lookup(DataSourceComponent.ROLE + - "Selector"); + (ServiceSelector) ConnectionFactoryAvalonDataSource.manager.lookup(DataSourceComponent.ROLE + + "Selector"); } /** * Signal disposal to this helper class. */ public static void dispose() { - ConnectionFactoryAvalonDataSource.manager.release(ConnectionFactoryAvalonDataSource.dbselector); + if (ConnectionFactoryAvalonDataSource.manager != null) { + ConnectionFactoryAvalonDataSource.manager.release(ConnectionFactoryAvalonDataSource.dbselector); + ConnectionFactoryAvalonDataSource.dbselector = null; + ConnectionFactoryAvalonDataSource.manager = null; + } } /* (non-Javadoc) * @see org.apache.ojb.broker.accesslayer.ConnectionFactory#lookupConnection(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor) */ public Connection lookupConnection(final JdbcConnectionDescriptor conDesc) - throws LookupException { - if (null == ConnectionFactoryAvalonDataSource.manager) { - throw new LookupException("ServiceManager was not set!"); + throws LookupException { + if (ConnectionFactoryAvalonDataSource.manager == null) { + throw new LookupException("ConnectionFactoryAvalonDataSource is not initialized!"); } try { - return ((DataSourceComponent)ConnectionFactoryAvalonDataSource.dbselector.select(conDesc.getJcdAlias())).getConnection(); - } catch (final ServiceException se) { - throw new LookupException("Cannot lookup DataSources named " + conDesc.getJcdAlias(), se); - } catch (final SQLException sqle) { - throw new LookupException("Cannot get Connection from DataSource named " + - conDesc.getDbAlias(), sqle); + return ((DataSourceComponent) ConnectionFactoryAvalonDataSource.dbselector.select(conDesc.getJcdAlias())).getConnection(); + } catch (final ServiceException e) { + throw new LookupException("Cannot lookup DataSource named " + + conDesc.getJcdAlias(), e); + } catch (final SQLException e) { + throw new LookupException("Cannot get connection from DataSource named " + + conDesc.getDbAlias(), e); } } @@ -93,10 +100,11 @@ */ public void releaseConnection(JdbcConnectionDescriptor conDesc, Connection con) { try { - con.close(); // The DataSource itself from where this connection comes from will take care of pooling - } catch (final SQLException sqle) { - // This should not happend, but in case - throw new CascadingRuntimeException("Cannot release SQL Connection to DataSource", sqle); + // The DataSource of this connection will take care of pooling + con.close(); + } catch (final SQLException e) { + // This should not happen, but in case + throw new CascadingRuntimeException("Cannot release SQL Connection to DataSource", e); } } @@ -104,6 +112,6 @@ * @see org.apache.ojb.broker.accesslayer.ConnectionFactory#releaseAllResources() */ public void releaseAllResources() { - //Nothing to do here + // Nothing to do here } }