Permalink
Browse files

JIPI-11 allow two phase bootstrap approach to creating entity manager…

… factory
  • Loading branch information...
1 parent 9c2d43b commit db861170076cc9dbc4c07b6fb2facb30c0bc0e8e @scottmarlow committed Jun 12, 2013
@@ -20,22 +20,27 @@
import java.util.Map;
import java.util.Properties;
+import javax.persistence.spi.PersistenceUnitInfo;
+
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.jboss.as.jpa.hibernate4.management.HibernateManagementAdaptor;
+import org.jboss.as.jpa.hibernate4.management.TwoPhaseBootstrapImpl;
import org.jipijapa.cache.spi.Classification;
import org.jipijapa.event.impl.internal.Notification;
+import org.jipijapa.plugin.spi.EntityManagerFactoryBuilder;
import org.jipijapa.plugin.spi.JtaManager;
import org.jipijapa.plugin.spi.ManagementAdaptor;
import org.jipijapa.plugin.spi.PersistenceProviderAdaptor;
import org.jipijapa.plugin.spi.PersistenceUnitMetadata;
+import org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable;
/**
* Implements the PersistenceProviderAdaptor for Hibernate
*
* @author Scott Marlow
*/
-public class HibernatePersistenceProviderAdaptor implements PersistenceProviderAdaptor {
+public class HibernatePersistenceProviderAdaptor implements PersistenceProviderAdaptor, TwoPhaseBootstrapCapable {
@Override
public void injectJtaManager(JtaManager jtaManager) {
@@ -111,5 +116,13 @@ public boolean doesScopedPersistenceUnitNameIdentifyCacheRegionName(PersistenceU
public void cleanup(PersistenceUnitMetadata pu) {
}
+
+ /* start of TwoPhaseBootstrapCapable methods */
+
+ public EntityManagerFactoryBuilder getBootstrap(final PersistenceUnitInfo info, final Map map) {
+ return new TwoPhaseBootstrapImpl(info, map);
+ }
+
+ /* end of TwoPhaseBootstrapCapable methods */
}
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.as.jpa.hibernate4.management;
+
+import java.util.Map;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceUnitInfo;
+
+import org.hibernate.jpa.boot.spi.Bootstrap;
+import org.jipijapa.plugin.spi.EntityManagerFactoryBuilder;
+
+/**
+ * TwoPhaseBootstrapImpl
+ *
+ * @author Scott Marlow
+ */
+public class TwoPhaseBootstrapImpl implements EntityManagerFactoryBuilder {
+
+ final org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder entityManagerFactoryBuilder;
+
+ public TwoPhaseBootstrapImpl(final PersistenceUnitInfo info, final Map map) {
+ entityManagerFactoryBuilder =
+ Bootstrap.getEntityManagerFactoryBuilder(info, map);
+ }
+
+ @Override
+ public EntityManagerFactory build() {
+ return entityManagerFactoryBuilder.build();
+ }
+
+ @Override
+ public void cancel() {
+ entityManagerFactoryBuilder.cancel();
+ }
+
+}
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jipijapa.plugin.spi;
+
+import javax.persistence.EntityManagerFactory;
+
+/**
+ * EntityManagerFactoryBuilder is based on org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder.
+ * Represents a 2-phase JPA bootstrap process for building an EntityManagerFactory.
+ *
+ * @author Scott Marlow
+ * @author Steve Ebersole
+ */
+public interface EntityManagerFactoryBuilder {
+ /**
+ * Build {@link EntityManagerFactory} instance
+ *
+ * @return The built {@link EntityManagerFactory}
+ */
+ EntityManagerFactory build();
+
+ /**
+ * Cancel the building processing. This is used to signal the builder to release any resources in the case of
+ * something having gone wrong during the bootstrap process
+ */
+ void cancel();
+}
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jipijapa.plugin.spi;
+
+import java.util.Map;
+
+import javax.persistence.spi.PersistenceUnitInfo;
+
+/**
+ * TwoPhaseBootstrapCapable obtains a two phase EntityManagerFactory builder
+ *
+ * @author Scott Marlow
+ * @author Steve Ebersole
+ */
+public interface TwoPhaseBootstrapCapable {
+
+ /**
+ * Returns a two phase EntityManagerFactory builder
+ *
+ * @param info
+ * @param map
+ * @return
+ */
+ EntityManagerFactoryBuilder getBootstrap(final PersistenceUnitInfo info, final Map map);
+}

0 comments on commit db86117

Please sign in to comment.