openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r550185 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-kernel/src/main/java/org/apache/openjpa/event/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/resources/org/apache/o...
Date Sun, 24 Jun 2007 09:16:58 GMT
Author: pcl
Date: Sun Jun 24 02:16:57 2007
New Revision: 550185

URL: http://svn.apache.org/viewvc?view=rev&rev=550185
Log:
OPENJPA-262

Added:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEvent.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEventManager.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestBrokerFactoryEventManager.java
Removed:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/AbstractEventManager.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties
    openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestAbstractEventManager.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java?view=diff&rev=550185&r1=550184&r2=550185
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
Sun Jun 24 02:16:57 2007
@@ -39,6 +39,7 @@
 import org.apache.openjpa.kernel.RestoreState;
 import org.apache.openjpa.kernel.SavepointManager;
 import org.apache.openjpa.kernel.Seq;
+import org.apache.openjpa.event.BrokerFactoryEventManager;
 import org.apache.openjpa.kernel.exps.AggregateListener;
 import org.apache.openjpa.kernel.exps.FilterListener;
 import org.apache.openjpa.lib.conf.Configuration;
@@ -1386,4 +1387,10 @@
      * configuration.
      */
     public StoreFacadeTypeRegistry getStoreFacadeTypeRegistry();
+
+    /**
+     * Return the {@link org.apache.openjpa.event.BrokerFactoryEventManager} associated with
this
+     * configuration.
+     */
+    public BrokerFactoryEventManager getBrokerFactoryEventManager();
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?view=diff&rev=550185&r1=550184&r2=550185
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
Sun Jun 24 02:16:57 2007
@@ -31,6 +31,7 @@
 import org.apache.openjpa.event.OrphanedKeyAction;
 import org.apache.openjpa.event.RemoteCommitEventManager;
 import org.apache.openjpa.event.RemoteCommitProvider;
+import org.apache.openjpa.event.BrokerFactoryEventManager;
 import org.apache.openjpa.kernel.AutoClear;
 import org.apache.openjpa.kernel.BrokerImpl;
 import org.apache.openjpa.kernel.ConnectionRetainModes;
@@ -140,6 +141,8 @@
     private String spec = null;
     private final StoreFacadeTypeRegistry _storeFacadeRegistry =
         new StoreFacadeTypeRegistry();
+    private BrokerFactoryEventManager _brokerFactoryEventManager =
+        new BrokerFactoryEventManager(this);
 
     /**
      * Default constructor. Attempts to load global properties.
@@ -1408,7 +1411,11 @@
     public StoreFacadeTypeRegistry getStoreFacadeTypeRegistry() {
         return _storeFacadeRegistry;
     }
-    
+
+    public BrokerFactoryEventManager getBrokerFactoryEventManager() {
+        return _brokerFactoryEventManager;
+    }
+
     public void instantiateAll() {
         super.instantiateAll();
         getMetaDataRepositoryInstance();

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEvent.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEvent.java?view=auto&rev=550185
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEvent.java
(added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEvent.java
Sun Jun 24 02:16:57 2007
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.event;
+
+import java.util.EventObject;
+
+import org.apache.openjpa.kernel.BrokerFactory;
+
+/**
+ * Event fired when a {@link BrokerFactory} is created.
+ *
+ * @since 1.0.0
+ */
+public class BrokerFactoryEvent
+    extends EventObject {
+
+    public final static int BROKER_FACTORY_CREATED = 0;
+
+    private int eventType;
+
+    public BrokerFactoryEvent(BrokerFactory brokerFactory, int eventType) {
+        super(brokerFactory);
+        this.eventType = eventType;
+    }
+
+    public BrokerFactory getBrokerFactory() {
+        return (BrokerFactory) getSource();
+    }
+
+    /**
+     * @return one of the event type codes defined in this event class.
+     */
+    public int getEventType() {
+        return eventType;
+    }
+}

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEventManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEventManager.java?view=auto&rev=550185
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEventManager.java
(added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryEventManager.java
Sun Jun 24 02:16:57 2007
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.event;
+
+import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.conf.Configuration;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+
+/**
+ * {@link EventManager} responsible for notifying listeners of
+ * {@link BrokerFactoryEvent}s.
+ *
+ * @since 1.0.0
+ */
+public class BrokerFactoryEventManager
+    extends AbstractConcurrentEventManager {
+
+    private static final Localizer _loc = Localizer.forPackage(
+        BrokerFactoryEventManager.class);
+
+    private final Configuration _conf;
+
+    public BrokerFactoryEventManager(Configuration conf) {
+        _conf = conf;
+    }
+
+    protected void fireEvent(Object event, Object listener) {
+        try {
+            BrokerFactoryEvent e = (BrokerFactoryEvent) event;
+            ((BrokerFactoryListener) listener).afterBrokerFactoryCreate(e);
+        } catch (Exception e) {
+            _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(
+                _loc.get("broker-factory-listener-exception"), e);
+        }
+    }
+}

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java?view=auto&rev=550185
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java
(added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java
Sun Jun 24 02:16:57 2007
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.event;
+
+/**
+ * Interface for listening to {@link BrokerFactoryEvent} objects. Should be
+ * registered with a {@link OpenJPAConfiguration}'s
+ * {@link BrokerFactoryEventManager}.
+ *
+ * @since 1.0.0
+ */
+public interface BrokerFactoryListener {
+
+    /**
+     * Invoked after a {@link AbstractBrokerFactory} has been fully created.
+     * This happens after the factory has been made read-only.
+     */
+    public void afterBrokerFactoryCreate(BrokerFactoryEvent event);
+}

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?view=diff&rev=550185&r1=550184&r2=550185
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Sun Jun 24 02:16:57 2007
@@ -37,6 +37,7 @@
 import org.apache.openjpa.datacache.DataCacheStoreManager;
 import org.apache.openjpa.enhance.PCRegistry;
 import org.apache.openjpa.event.RemoteCommitEventManager;
+import org.apache.openjpa.event.BrokerFactoryEvent;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.ReferenceHashSet;
@@ -545,6 +546,12 @@
             // avoid synchronization
             _conf.setReadOnly(true);
             _conf.instantiateAll();
+
+            // fire an event for all the broker factory listeners
+            // registered on the configuration.
+            _conf.getBrokerFactoryEventManager().fireEvent(
+                new BrokerFactoryEvent(this,
+                    BrokerFactoryEvent.BROKER_FACTORY_CREATED));
         } finally {
             unlock();
         }

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties?view=diff&rev=550185&r1=550184&r2=550185
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties
Sun Jun 24 02:16:57 2007
@@ -95,3 +95,5 @@
     accessible no-args constructor.
 method-notfound: Method "{1}" with arguments of type: {2} \
     not found in class "{0}".
+broker-factory-listener-exception: Exception thrown while calling a \
+    BrokerFactoryListener. This exception will be ignored.
\ No newline at end of file

Modified: openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestAbstractEventManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestAbstractEventManager.java?view=diff&rev=550185&r1=550184&r2=550185
==============================================================================
--- openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestAbstractEventManager.java
(original)
+++ openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestAbstractEventManager.java
Sun Jun 24 02:16:57 2007
@@ -22,9 +22,10 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
+import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
 
 /**
- * Tests the {@link AbstractEventManager}.
+ * Tests the {@link AbstractConcurrentEventManager}.
  *
  * @author Abe White
  */
@@ -67,7 +68,7 @@
         TestRunner.run(suite());
     }
 
-    private static class EventManager extends AbstractEventManager {
+    private static class EventManager extends AbstractConcurrentEventManager {
 
         protected void fireEvent(Object event, Object listener) {
             ((Listener) listener).fire();

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestBrokerFactoryEventManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestBrokerFactoryEventManager.java?view=auto&rev=550185
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestBrokerFactoryEventManager.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestBrokerFactoryEventManager.java
Sun Jun 24 02:16:57 2007
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.kernel;
+
+import javax.persistence.Persistence;
+
+import junit.framework.TestCase;
+import org.apache.openjpa.event.BrokerFactoryListener;
+import org.apache.openjpa.event.BrokerFactoryEvent;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+
+public class TestBrokerFactoryEventManager
+    extends TestCase {
+
+    public void testCreateEvent() {
+        OpenJPAEntityManagerFactory emf = OpenJPAPersistence.cast(
+            Persistence.createEntityManagerFactory("test"));
+        ListenerImpl listener = new ListenerImpl();
+        emf.getConfiguration().getBrokerFactoryEventManager()
+            .addListener(listener);
+        emf.createEntityManager().close();
+        assertTrue(listener.createEventReceived);
+        emf.close();
+    }
+
+    private class ListenerImpl implements BrokerFactoryListener {
+
+        boolean createEventReceived = false;
+
+        public void afterBrokerFactoryCreate(BrokerFactoryEvent event) {
+            createEventReceived = true;
+        }
+    }
+}



Mime
View raw message