Search in sources :

Example 1 with JpaValueEncoder

use of org.apache.tapestry5.internal.jpa.JpaValueEncoder 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);
        }
    }
}
Also used : JpaValueEncoder(org.apache.tapestry5.internal.jpa.JpaValueEncoder) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) Metamodel(javax.persistence.metamodel.Metamodel) ValueEncoderFactory(org.apache.tapestry5.services.ValueEncoderFactory) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

EntityManagerFactory (javax.persistence.EntityManagerFactory)1 Metamodel (javax.persistence.metamodel.Metamodel)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 JpaValueEncoder (org.apache.tapestry5.internal.jpa.JpaValueEncoder)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 ValueEncoderFactory (org.apache.tapestry5.services.ValueEncoderFactory)1