use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.
the class EntityManagerObjectProvider method getOrCreateProxy.
@SuppressWarnings({ "unchecked", "rawtypes" })
private EntityManager getOrCreateProxy(final AnnotationProvider annotationProvider, final ObjectLocator objectLocator) {
final PersistenceContext annotation = annotationProvider.getAnnotation(PersistenceContext.class);
final String unitName = annotation == null ? null : annotation.unitName();
EntityManager proxy = emProxyByName.get(unitName);
if (proxy == null)
synchronized (this) {
final PlasticProxyFactory proxyFactory = objectLocator.getService("PlasticProxyFactory", PlasticProxyFactory.class);
proxy = proxyFactory.createProxy(EntityManager.class, new ObjectCreator() {
@Override
public Object createObject() {
final EntityManagerManager entityManagerManager = objectLocator.getService(EntityManagerManager.class);
return JpaInternalUtils.getEntityManager(entityManagerManager, annotation);
}
}, "<EntityManagerProxy>");
emProxyByName.put(unitName, proxy);
}
return proxy;
}
use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.
the class PersistenceContextWorker method transform.
@Override
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
for (final PlasticField field : plasticClass.getFieldsWithAnnotation(PersistenceContext.class)) {
final PersistenceContext annotation = field.getAnnotation(PersistenceContext.class);
field.claim(annotation);
field.setConduit(new ReadOnlyComponentFieldConduit(plasticClass.getClassName(), field.getName()) {
@Override
public Object get(Object instance, InstanceContext context) {
return JpaInternalUtils.getEntityManager(entityManagerManager, annotation);
}
});
}
}
use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.
the class JpaTest method trySomething.
@Test
public void trySomething() {
ThingOne thingOne = new ThingOne();
thingOne.setId(1);
PersistedEntity entity = JpaInternalUtils.convertApplicationValueToPersisted(entityManagerManager, thingOne);
}
use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.
the class JpaModule method buildEntityManagerManager.
@Scope(ScopeConstants.PERTHREAD)
public static EntityManagerManager buildEntityManagerManager(final EntityManagerSource entityManagerSource, final PerthreadManager perthreadManager, final Logger logger) {
final EntityManagerManagerImpl service = new EntityManagerManagerImpl(entityManagerSource, logger);
perthreadManager.addThreadCleanupListener(service);
return service;
}
use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.
the class JpaModule method provideValueEncoders.
@Contribute(ValueEncoderSource.class)
public static void provideValueEncoders(final MappedConfiguration<Class, ValueEncoderFactory> configuration, @Symbol(JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERS) final boolean provideEncoders, final EntityManagerSource entityManagerSource, final EntityManagerManager entityManagerManager, final TypeCoercer typeCoercer, final PropertyAccess propertyAccess, final LoggerSource loggerSource) {
if (!provideEncoders)
return;
for (final PersistenceUnitInfo info : entityManagerSource.getPersistenceUnitInfos()) {
final EntityManagerFactory emf = entityManagerSource.getEntityManagerFactory(info.getPersistenceUnitName());
final Metamodel metamodel = emf.getMetamodel();
for (final EntityType<?> entity : metamodel.getEntities()) {
final Class<?> javaType = entity.getJavaType();
final ValueEncoderFactory factory = new ValueEncoderFactory() {
@Override
public ValueEncoder create(final Class type) {
return new JpaValueEncoder(entity, entityManagerManager, info.getPersistenceUnitName(), propertyAccess, typeCoercer, loggerSource.getLogger(javaType));
}
};
configuration.add(javaType, factory);
}
}
}
Aggregations