Skip to content

Commit

Permalink
add jpa spi, remove deprecated methods
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2215 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Mar 26, 2009
1 parent b3a1f8f commit 13b91f0
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 0 deletions.
@@ -0,0 +1,126 @@
package org.jboss.webbeans.bootstrap.api.helpers;

import org.jboss.webbeans.bootstrap.api.Bootstrap;
import org.jboss.webbeans.bootstrap.api.Environment;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.jpa.spi.JpaServices;
import org.jboss.webbeans.manager.api.WebBeansManager;
import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.transaction.spi.TransactionServices;

/**
* A bean version of bootstrap that delegates to the underlying bootstrap impl
*
* @author Pete Muir
*
*/
public class BootstrapBean implements Bootstrap
{

private final Bootstrap bootstrap;

public BootstrapBean(Bootstrap bootstrap)
{
this.bootstrap = bootstrap;
}

public void setEjbServices(EjbServices ejbServices)
{
bootstrap.getServices().add(EjbServices.class, ejbServices);
}

public EjbServices getEjbServices()
{
return bootstrap.getServices().get(EjbServices.class);
}

public void setJpaServices(JpaServices jpaServices)
{
bootstrap.getServices().add(JpaServices.class, jpaServices);
}

public JpaServices getJpaServices()
{
return bootstrap.getServices().get(JpaServices.class);
}

public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery)
{
bootstrap.getServices().add(WebBeanDiscovery.class, webBeanDiscovery);
}

public WebBeanDiscovery getWebBeanDiscovery()
{
return bootstrap.getServices().get(WebBeanDiscovery.class);
}

public void setTransactionServices(TransactionServices transactionServices)
{
bootstrap.getServices().add(TransactionServices.class, transactionServices);
}

public TransactionServices getTransactionServices()
{
return bootstrap.getServices().get(TransactionServices.class);
}

public void setApplicationContext(BeanStore applicationContext)
{
bootstrap.setApplicationContext(applicationContext);
}

public void setNamingContext(NamingContext namingContext)
{
bootstrap.getServices().add(NamingContext.class, namingContext);
}

public NamingContext getNamingContext()
{
return bootstrap.getServices().get(NamingContext.class);
}

public void setResourceLoader(ResourceLoader resourceLoader)
{
bootstrap.getServices().add(ResourceLoader.class, resourceLoader);
}

public ResourceLoader getResourceLoader()
{
return bootstrap.getServices().get(ResourceLoader.class);
}

public void boot()
{
bootstrap.boot();
}

public WebBeansManager getManager()
{
return bootstrap.getManager();
}

public ServiceRegistry getServices()
{
return bootstrap.getServices();
}

public void initialize()
{
bootstrap.initialize();
}

public void setEnvironment(Environment environment)
{
bootstrap.setEnvironment(environment);
}

public void shutdown()
{
bootstrap.shutdown();
}

}
55 changes: 55 additions & 0 deletions spi/src/main/java/org/jboss/webbeans/jpa/spi/JpaServices.java
@@ -0,0 +1,55 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, 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.webbeans.jpa.spi;

import javax.inject.manager.InjectionPoint;

import org.jboss.webbeans.bootstrap.api.Service;

/**
* A container should implement this interface to allow the Web Beans RI to
* resolve JPA persistence units and discover entities
*
* @author Pete Muir
*
*/
public interface JpaServices extends Service
{

/**
* Gets the class for each entity in the application
*
* @return the entity classes
*/
public Iterable<Class<?>> discoverEntities();

/**
* Resolve the value for the given @PersistenceContext injection point
*
* @param injectionPoint
* the injection point metadata
* @return an instance of the persistence unit
* @throws IllegalArgumentException
* if the injection point is not annotated with
* @PersistenceContext, or, if the injection point is a method that doesn't
* follow JavaBean conventions
* @throws IllegalStateException
* if no suitable persistence units can be resolved for injection
*/
public Object resolvePersistenceContext(InjectionPoint injectionPoint);

}
@@ -0,0 +1,66 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, 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.webbeans.jpa.spi.helpers;

import javax.inject.manager.InjectionPoint;

import org.jboss.webbeans.jpa.spi.JpaServices;

/**
* An implementation of {@link JpaServices} which forwards all its method calls
* to another {@link JpaServices}}. Subclasses should override one or more
* methods to modify the behavior of the backing {@link JpaServices} as desired
* per the <a
* href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
*
* @author Pete Muir
*
*/
public abstract class ForwardingJpaServices implements JpaServices
{

protected abstract JpaServices delegate();

public Iterable<Class<?>> discoverEntities()
{
return delegate().discoverEntities();
}

public Object resolvePersistenceContext(InjectionPoint injectionPoint)
{
return delegate().resolvePersistenceContext(injectionPoint);
}

@Override
public String toString()
{
return delegate().toString();
}

@Override
public int hashCode()
{
return delegate().hashCode();
}

@Override
public boolean equals(Object obj)
{
return delegate().equals(obj);
}

}

0 comments on commit 13b91f0

Please sign in to comment.