类javax.persistence.SynchronizationType源码实例Demo

下面列出了怎么用javax.persistence.SynchronizationType的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: SessionFactoryImpl.java
private Session buildEntityManager(SynchronizationType synchronizationType, Map map) {
	assert !isClosed;

	SessionBuilderImplementor builder = withOptions();
	if ( synchronizationType == SynchronizationType.SYNCHRONIZED ) {
		builder.autoJoinTransactions( true );
	}
	else {
		builder.autoJoinTransactions( false );
	}

	final Session session = builder.openSession();
	if ( map != null ) {
		map.keySet().forEach( key -> {
			if ( key instanceof String ) {
				session.setProperty( (String) key, map.get( key ) );
			}
		} );
	}
	return session;
}
 
void init(final PersistenceUnitInfo info, final BeanManager bm) {
    final PersistenceProvider provider;
    try {
        provider = PersistenceProvider.class.cast(
                Thread.currentThread().getContextClassLoader().loadClass(info.getPersistenceProviderClassName()).newInstance());
    } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new IllegalArgumentException("Bad provider: " + info.getPersistenceProviderClassName());
    }
    final EntityManagerFactory factory = provider.createContainerEntityManagerFactory(info, new HashMap() {{
        put("javax.persistence.bean.manager", bm);
        if (ValidationMode.NONE != info.getValidationMode()) {
            ofNullable(findValidatorFactory(bm)).ifPresent(factory -> put("javax.persistence.validation.factory", factory));
        }
    }});
    instanceFactory = synchronization == SynchronizationType.SYNCHRONIZED ? factory::createEntityManager : () -> factory.createEntityManager(synchronization);
}
 
源代码3 项目: tomee   文件: JtaEntityManager.java
public JtaEntityManager(final String unitName, final JtaEntityManagerRegistry registry, final EntityManagerFactory entityManagerFactory,
                        final Map properties, final boolean extended, final String synchronizationType) {
    if (registry == null) {
        throw new NullPointerException("registry is null");
    }
    if (entityManagerFactory == null) {
        throw new NullPointerException("entityManagerFactory is null");
    }
    this.unitName = unitName;
    this.registry = registry;
    this.entityManagerFactory = entityManagerFactory;
    this.properties = properties;
    this.extended = extended;
    this.synchronizationType = !isJPA21(entityManagerFactory) || synchronizationType == null ?
            null : SynchronizationType.valueOf(synchronizationType.toUpperCase(Locale.ENGLISH));
    final String globalTimerConfig = SystemInstance.get().getProperty("openejb.jpa.timer");
    final Object localTimerConfig = properties == null ? null : properties.get("openejb.jpa.timer");
    this.timer = localTimerConfig == null ? (globalTimerConfig == null || Boolean.parseBoolean(globalTimerConfig)) : Boolean.parseBoolean(localTimerConfig.toString());
    logger = unitName == null ? baseLogger : baseLogger.getChildLogger(unitName);
    final String wrapConfig = ReloadableEntityManagerFactory.class.isInstance(entityManagerFactory) ?
            ReloadableEntityManagerFactory.class.cast(entityManagerFactory).getUnitProperties().getProperty("openejb.jpa.query.wrap-no-tx", "true") : "true";
    this.wrapNoTxQueries = wrapConfig == null || "true".equalsIgnoreCase(wrapConfig);
}
 
@Override
public JpaConnectionProvider create(KeycloakSession session) {
    logger.trace("Create JpaConnectionProvider");
    lazyInit(session);

    EntityManager em;
    if (!jtaEnabled) {
        logger.trace("enlisting EntityManager in JpaKeycloakTransaction");
        em = emf.createEntityManager();
    } else {

        em = emf.createEntityManager(SynchronizationType.SYNCHRONIZED);
    }
    em = PersistenceExceptionConverter.create(em);
    if (!jtaEnabled) session.getTransactionManager().enlist(new JpaKeycloakTransaction(em));
    return new DefaultJpaConnectionProvider(em);
}
 
@Override
public JpaConnectionProvider create(KeycloakSession session) {
    logger.trace("Create QuarkusJpaConnectionProvider");
    EntityManager em;
    if (!jtaEnabled) {
        logger.trace("enlisting EntityManager in JpaKeycloakTransaction");
        em = emf.createEntityManager();
        try {
            SessionImpl.class.cast(em).connection().setAutoCommit(false);
        } catch (SQLException cause) {
            throw new RuntimeException(cause);
        }
    } else {

        em = emf.createEntityManager(SynchronizationType.SYNCHRONIZED);
    }
    em = PersistenceExceptionConverter.create(em);
    if (!jtaEnabled) session.getTransactionManager().enlist(new JpaKeycloakTransaction(em));
    return new DefaultJpaConnectionProvider(em);
}
 
源代码6 项目: BotLibre   文件: DatabaseReadOnlyNetwork.java
public DatabaseReadOnlyNetwork(EntityManager entityManager, boolean isShortTerm) {
	super(new EntityManagerImpl(entityManager.unwrap(ServerSession.class), SynchronizationType.UNSYNCHRONIZED), isShortTerm);
	ServerSession server = entityManager.unwrap(ServerSession.class);
	if (!server.getProperties().containsKey("network")) {
		server.setProperty("network", this);
	}
}
 
源代码7 项目: tomee   文件: JtaEntityManager.java
public static boolean isJPA21(final EntityManagerFactory entityManagerFactory) {
    return ReloadableEntityManagerFactory.class.isInstance(entityManagerFactory) ?
            hasMethod(
                    ReloadableEntityManagerFactory.class.cast(entityManagerFactory).getEntityManagerFactoryCallable().getProvider(),
                    "generateSchema", String.class, Map.class)
            : hasMethod(entityManagerFactory.getClass(), "createEntityManager", SynchronizationType.class);
}
 
源代码8 项目: tomee   文件: ReloadableEntityManagerFactory.java
@Override
public EntityManager createEntityManager(final SynchronizationType synchronizationType) {
    EntityManager em;
    try {
        em = delegate().createEntityManager(synchronizationType);
    } catch (final LinkageError le) {
        em = delegate.createEntityManager(synchronizationType);
    }

    if (logCriteriaJpql) {
        return new QueryLogEntityManager(em, logCriteriaJpqlLevel);
    }
    return em;
}
 
源代码9 项目: tomee   文件: ReloadableEntityManagerFactory.java
@Override
public EntityManager createEntityManager(final SynchronizationType synchronizationType, final Map map) {
    EntityManager em;
    try {
        em = delegate().createEntityManager(synchronizationType, map);
    } catch (final LinkageError le) {
        em = delegate.createEntityManager(synchronizationType, map);
    }

    if (logCriteriaJpql) {
        return new QueryLogEntityManager(em, logCriteriaJpqlLevel);
    }
    return em;
}
 
源代码10 项目: tomee   文件: StatefulContainer.java
private Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> createEntityManagers(final BeanContext beanContext) {
    // create the extended entity managers
    final Index<EntityManagerFactory, BeanContext.EntityManagerConfiguration> factories = beanContext.getExtendedEntityManagerFactories();
    Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> entityManagers = null;
    if (factories != null && factories.size() > 0) {
        entityManagers = new Index<>(new ArrayList<>(factories.keySet()));
        for (final Map.Entry<EntityManagerFactory, BeanContext.EntityManagerConfiguration> entry : factories.entrySet()) {
            final EntityManagerFactory entityManagerFactory = entry.getKey();

            JtaEntityManagerRegistry.EntityManagerTracker entityManagerTracker = entityManagerRegistry.getInheritedEntityManager(entityManagerFactory);
            final EntityManager entityManager;
            if (entityManagerTracker == null) {
                final Map properties = entry.getValue().getProperties();
                final SynchronizationType synchronizationType = entry.getValue().getSynchronizationType();
                if (synchronizationType != null) {
                    if (properties != null) {
                        entityManager = entityManagerFactory.createEntityManager(synchronizationType, properties);
                    } else {
                        entityManager = entityManagerFactory.createEntityManager(synchronizationType);
                    }
                } else if (properties != null) {
                    entityManager = entityManagerFactory.createEntityManager(properties);
                } else {
                    entityManager = entityManagerFactory.createEntityManager();
                }
                entityManagerTracker = new JtaEntityManagerRegistry.EntityManagerTracker(entityManager, synchronizationType != SynchronizationType.UNSYNCHRONIZED);
            } else {
                entityManagerTracker.incCounter();
            }
            entityManagers.put(entityManagerFactory, entityManagerTracker);
        }
    }
    return entityManagers;
}
 
源代码11 项目: tomee   文件: ManagedContainer.java
private Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> createEntityManagers(final BeanContext beanContext) {
    // create the extended entity managers
    final Index<EntityManagerFactory, BeanContext.EntityManagerConfiguration> factories = beanContext.getExtendedEntityManagerFactories();
    Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> entityManagers = null;
    if (factories != null && factories.size() > 0) {
        entityManagers = new Index<>(new ArrayList<>(factories.keySet()));
        for (final Map.Entry<EntityManagerFactory, BeanContext.EntityManagerConfiguration> entry : factories.entrySet()) {
            final EntityManagerFactory entityManagerFactory = entry.getKey();

            JtaEntityManagerRegistry.EntityManagerTracker entityManagerTracker = entityManagerRegistry.getInheritedEntityManager(entityManagerFactory);
            final EntityManager entityManager;
            if (entityManagerTracker == null) {
                final SynchronizationType synchronizationType = entry.getValue().getSynchronizationType();
                final Map properties = entry.getValue().getProperties();
                if (synchronizationType != null) {
                    if (properties != null) {
                        entityManager = entityManagerFactory.createEntityManager(synchronizationType, properties);
                    } else {
                        entityManager = entityManagerFactory.createEntityManager(synchronizationType);
                    }
                } else if (properties != null) {
                    entityManager = entityManagerFactory.createEntityManager(properties);
                } else {
                    entityManager = entityManagerFactory.createEntityManager();
                }
                entityManagerTracker = new JtaEntityManagerRegistry.EntityManagerTracker(entityManager, synchronizationType != SynchronizationType.UNSYNCHRONIZED);
            } else {
                entityManagerTracker.incCounter();
            }
            entityManagers.put(entityManagerFactory, entityManagerTracker);
        }
    }
    return entityManagers;
}
 
源代码12 项目: judgels   文件: LegacySessionFactory.java
@Override
public EntityManager createEntityManager(SynchronizationType synchronizationType) {
    return null;
}
 
源代码13 项目: judgels   文件: LegacySessionFactory.java
@Override
public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map) {
    return null;
}
 
源代码14 项目: lams   文件: SessionFactoryDelegatingImpl.java
@Override
public EntityManager createEntityManager(SynchronizationType synchronizationType) {
	return delegate.createEntityManager( synchronizationType );
}
 
源代码15 项目: lams   文件: SessionFactoryDelegatingImpl.java
@Override
public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map) {
	return delegate.createEntityManager( synchronizationType, map );
}
 
源代码16 项目: lams   文件: SessionFactoryImpl.java
@Override
public Session createEntityManager() {
	validateNotClosed();
	return buildEntityManager( SynchronizationType.SYNCHRONIZED, Collections.emptyMap() );
}
 
源代码17 项目: lams   文件: SessionFactoryImpl.java
@Override
public Session createEntityManager(Map map) {
	validateNotClosed();
	return buildEntityManager( SynchronizationType.SYNCHRONIZED, map );
}
 
源代码18 项目: lams   文件: SessionFactoryImpl.java
@Override
public Session createEntityManager(SynchronizationType synchronizationType) {
	validateNotClosed();
	errorIfResourceLocalDueToExplicitSynchronizationType();
	return buildEntityManager( synchronizationType, Collections.emptyMap() );
}
 
源代码19 项目: lams   文件: SessionFactoryImpl.java
@Override
public Session createEntityManager(SynchronizationType synchronizationType, Map map) {
	validateNotClosed();
	errorIfResourceLocalDueToExplicitSynchronizationType();
	return buildEntityManager( synchronizationType, map );
}
 
EntityManagerBean(final EntityManagerContext context, final String name, final SynchronizationType synchronization) {
    this.entityManagerContext = context;
    this.qualifiers.addAll(asList(new UnitLiteral(name, synchronization), AnyLiteral.INSTANCE));
    this.id = "meecrowave::jpa::entitymanager::" + name + "/" + synchronization.name();
    this.synchronization = synchronization;
}
 
源代码21 项目: openwebbeans-meecrowave   文件: UnitLiteral.java
UnitLiteral(final String name, final SynchronizationType synchronization) {
    this.name = name;
    this.synchronization = synchronization;
}
 
源代码22 项目: openwebbeans-meecrowave   文件: UnitLiteral.java
@Override
public SynchronizationType synchronization() {
    return synchronization;
}
 
源代码23 项目: openwebbeans-meecrowave   文件: JpaExtension.java
private UnitKey(final String unitName, final SynchronizationType synchronizationType) {
    this.unitName = unitName;
    this.synchronizationType = synchronizationType;
    this.hash = 31 * unitName.hashCode() + synchronizationType.hashCode();
}
 
public EntityManager createEntityManager(SynchronizationType st) {
    throw new UnsupportedOperationException("Not supported.");
}
 
public EntityManager createEntityManager(SynchronizationType st, Map map) {
    throw new UnsupportedOperationException("Not supported.");
}
 
public PersistenceContextResourceFactory(String unitName, EntityManagerFactory emf, TransactionType transactionType, SynchronizationType sync) {
    this.unitName = unitName;
    this.emf = emf;
    this.sync = sync;
    this.transactionType = transactionType;
}
 
@Override public EntityManager createEntityManager(SynchronizationType synchronizationType) {
    return null;
}
 
@Override public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map) {
    return null;
}
 
源代码29 项目: lutece-core   文件: TestEntityManagerFactory.java
@Override
public EntityManager createEntityManager( SynchronizationType st )
{
    // TODO Auto-generated method stub
    return null;
}
 
源代码30 项目: lutece-core   文件: TestEntityManagerFactory.java
@Override
public EntityManager createEntityManager( SynchronizationType st, Map map )
{
    // TODO Auto-generated method stub
    return null;
}
 
 类所在包
 类方法
 同包方法