当前位置: 首页>>代码示例>>Java>>正文


Java PersistenceUnitTransactionType类代码示例

本文整理汇总了Java中javax.persistence.spi.PersistenceUnitTransactionType的典型用法代码示例。如果您正苦于以下问题:Java PersistenceUnitTransactionType类的具体用法?Java PersistenceUnitTransactionType怎么用?Java PersistenceUnitTransactionType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PersistenceUnitTransactionType类属于javax.persistence.spi包,在下文中一共展示了PersistenceUnitTransactionType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startElement

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
@Override
public void startElement(String uri, String localName, String name, Attributes attributes)
    throws SAXException {
    // Do this setting first as we use it later.
    elementName = (localName == null || "".equals(localName)) ? name : localName;

    if ("persistence-unit".equals(elementName)) {
        String tranTypeSt = attributes.getValue("transaction-type");
        PersistenceUnitTransactionType tranType = tranTypeSt == null ? null : PersistenceUnitTransactionType.valueOf(tranTypeSt);
        persistenceUnits.push(new PersistenceUnit(bundle, 
                                                  attributes.getValue("name"), 
                                                  tranType));
    } else if ("exclude-unlisted-classes".equals(elementName))
        persistenceUnits.peek().setExcludeUnlisted(true);
    else if ("property".equals(elementName))
        persistenceUnits.peek().addProperty(attributes.getValue("name"), attributes.getValue("value"));

}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:19,代码来源:JPAHandler.java

示例2: build

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
public EntityManagerFactory build() {

		Properties properties = createProperties();

		DefaultPersistenceUnitInfoImpl persistenceUnitInfo = new DefaultPersistenceUnitInfoImpl(JSPARE_GATEWAY_DATASOURCE);
		persistenceUnitInfo.setProperties(properties);

		// Using RESOURCE_LOCAL for manage transactions on DAO side.
		persistenceUnitInfo.setTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL);

		// Add all entities to configuration
		ClassAnnotationMatchProcessor processor = (c) -> persistenceUnitInfo.addAnnotatedClassName(c);
		ClasspathScannerUtils.scanner(ALL_SCAN_QUOTE).matchClassesWithAnnotation(Entity.class, processor)
				.scan(NUMBER_CLASSPATH_SCANNER_THREADS);

		Map<String, Object> configuration = new HashMap<>();
		properties.forEach((k, v) -> configuration.put((String) k, v));

		EntityManagerFactory entityManagerFactory = persistenceProvider.createContainerEntityManagerFactory(persistenceUnitInfo,
				configuration);
		return entityManagerFactory;
	}
 
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:23,代码来源:JDBCProvider.java

示例3: configurePersistenceUnit

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnit(
        MappedConfiguration<String, PersistenceUnitConfigurer> cfg,
        final ObjectLocator objectLocator)
{
    PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer()
    {
        @Override
        public void configure(TapestryPersistenceUnitInfo unitInfo)
        {
            unitInfo.transactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL)
                    .persistenceProviderClassName("org.eclipse.persistence.jpa.PersistenceProvider")
                    .excludeUnlistedClasses(false)
                    .addProperty("javax.persistence.jdbc.user", "sa")
                    .addProperty("javax.persistence.jdbc.password", "sa")
                    .addProperty("javax.persistence.jdbc.driver", "org.h2.Driver")
                    .addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:jpatest_eclipselink")
                    .addProperty("eclipselink.ddl-generation", "create-or-extend-tables")
                    .addProperty("eclipselink.logging.level", "FINE");

            unitInfo.getProperties().put("javax.persistence.bean.manager",
                    objectLocator.autobuild(TapestryCDIBeanManagerForJPAEntityListeners.class));
        }
    };
    cfg.add("jpatest", configurer);
}
 
开发者ID:satago,项目名称:tapestry-jpa-transactions,代码行数:27,代码来源:EclipseLinkJpaTestModule.java

示例4: configurePersistenceUnit

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnit(
        MappedConfiguration<String, PersistenceUnitConfigurer> cfg,
        final ObjectLocator objectLocator)
{
        PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer()
    {
        @Override
        public void configure(TapestryPersistenceUnitInfo unitInfo)
        {
            unitInfo.transactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL)
                    .persistenceProviderClassName("org.hibernate.jpa.HibernatePersistenceProvider")
                    .excludeUnlistedClasses(false)
                    .addProperty("javax.persistence.jdbc.user", "sa")
                    .addProperty("javax.persistence.jdbc.password", "sa")
                    .addProperty("javax.persistence.jdbc.driver", "org.h2.Driver")
                    .addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:jpatest_hibernate")
                    .addProperty("hibernate.hbm2ddl.auto", "update")
                    .addProperty("hibernate.show_sql", "true");

            unitInfo.getProperties().put(AvailableSettings.CDI_BEAN_MANAGER,
                    objectLocator.autobuild(TapestryCDIBeanManagerForJPAEntityListeners.class));
        }
    };
    cfg.add("jpatest", configurer);
}
 
开发者ID:satago,项目名称:tapestry-jpa-transactions,代码行数:27,代码来源:HibernateJpaTestModule.java

示例5: HSQLDBProvider

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
public HSQLDBProvider() {
	scan.limitSearchingPathTo(full());
	generator = new RuntimePersistenceGenerator("test", PersistenceUnitTransactionType.RESOURCE_LOCAL, getProvider());
	setProperties(generator);
	
	generateAnnotedClasses();
	for (Class<?> annotatedClass : entities) {
		generator.addAnnotatedClass(annotatedClass);
	}
	
	if (haveSchema()) {
		try {
			executeStatement("CREATE SCHEMA " + schema + " AUTHORIZATION DBA;");
		} catch (Exception e) {
		}
	}
}
 
开发者ID:geraldox100,项目名称:testyourquery,代码行数:18,代码来源:HSQLDBProvider.java

示例6: register

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
/**
 * Register an entity manager for a factory. Is called during the dynamics
 * (either at start or afterwards) to handle the creation of an entity
 * manager.
 *
 * @param factory The factory used
 * @param properties The service properties of the factory
 */
private synchronized void register(EntityManagerFactory factory, Map<String, Object> properties) {
    if (context == null || transactionManager == null || entityManagers.containsKey(factory)) {
        return;
    }
    String unitName = unitName(properties);
    PersistenceUnitTransactionType type = transactionType(properties);
    // Proxy an entity manager.
    EntityManager manager = proxy(factory, type);
    // Register the proxy as service.
    Hashtable<String, Object> props = new Hashtable<>();
    props.put(UNITNAME, unitName);
    ServiceRegistration<EntityManager> sr = context.registerService(
            EntityManager.class, manager, props);
    entityManagers.put(factory, sr);
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:24,代码来源:EntityManagerFactoryTracker.java

示例7: create

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
private void create(Bundle bundle, Context context) {
    Map.Entry<String, PersistenceProvider> pp = provider.get(context.definition.provider);
    // Do the registration of the service asynchronously. Since it may imply all kinds of
    // listening actions performed as a result of it, it may block the bundle handling.
    // However, indicate that we are in the process of the actions by
    // setting the used provider.
    context.usedProvider = pp.getKey();
    new Thread(() -> {
        synchronized (context) {
            if (context.usedProvider != null) {
                PersistenceUnitInfo info = PersistenceUnitProcessor.getPersistenceUnitInfo(bundle,
                        context.definition, pp.getValue());
                context.factory = PersistenceUnitProcessor.createFactory(pp.getValue(), info);
                Hashtable<String, Object> props = new Hashtable<>();
                props.put(EntityManagerFactoryBuilder.JPA_UNIT_NAME, context.definition.name);
                props.put(PersistenceUnitTransactionType.class.getName(), info.getTransactionType().name());
                context.registration = bundle.getBundleContext().registerService(
                        EntityManagerFactory.class, context.factory, props);
            }
        }
    }).start();
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:23,代码来源:JpaBundleChangeListener.java

示例8: testJta

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
public void testJta() throws Exception {
    transactionType = PersistenceUnitTransactionType.JTA;
    entityManagerFactory = createEntityManagerFactory();

    final Object jpaTestObject = getClass().getClassLoader().loadClass("org.apache.openejb.core.cmp.jpa.JpaTestObject").newInstance();
    set(jpaTestObject, "EntityManagerFactory", EntityManagerFactory.class, entityManagerFactory);
    set(jpaTestObject, "TransactionManager", TransactionManager.class, transactionManager);
    set(jpaTestObject, "NonJtaDs", DataSource.class, nonJtaDs);

    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    invoke(jpaTestObject, "setUp");
    try {
        invoke(jpaTestObject, "jpaLifecycle");
    } finally {
        invoke(jpaTestObject, "tearDown");
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:18,代码来源:JpaTest.java

示例9: testResourceLocal

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
public void testResourceLocal() throws Exception {
    transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
    entityManagerFactory = createEntityManagerFactory();

    final Object jpaTestObject = getClass().getClassLoader().loadClass("org.apache.openejb.core.cmp.jpa.JpaTestObject").newInstance();
    set(jpaTestObject, "EntityManagerFactory", EntityManagerFactory.class, entityManagerFactory);
    set(jpaTestObject, "NonJtaDs", DataSource.class, nonJtaDs);

    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    invoke(jpaTestObject, "setUp");
    try {
        invoke(jpaTestObject, "jpaLifecycle");
    } finally {
        invoke(jpaTestObject, "tearDown");
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:17,代码来源:JpaTest.java

示例10: decodeTransactionType

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
private void decodeTransactionType(
    ParsedPersistenceXmlDescriptor persistenceUnit) {
// if transaction type is set already
// use that value
// else
// if JTA DS
// use JTA
// else if NOT JTA DS
// use RESOURCE_LOCAL
// else
// use defaultTransactionType
if (persistenceUnit.getTransactionType() != null) {
    return;
}

if (persistenceUnit.getJtaDataSource() != null) {
    persistenceUnit
	    .setTransactionType(PersistenceUnitTransactionType.JTA);
} else if (persistenceUnit.getNonJtaDataSource() != null) {
    persistenceUnit
	    .setTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL);
} else {
    persistenceUnit.setTransactionType(defaultTransactionType);
}
   }
 
开发者ID:levants,项目名称:lightmare,代码行数:26,代码来源:PersistenceXmlParserImpl.java

示例11: PersistenceUnitInfoImpl

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param rootUrl                the URL for the jar file or directory that is the root of the persistence unit.
 * @param provider               provider class name.
 * @param name                   the persistence unit name.
 * @param transactionType        the transaction type.
 * @param jtaDataSource          the JTA data source.
 * @param properties             the properties.
 * @param jarFileUrls            <code>jar-file</code> elements from <code>persistence.xml</code>.
 * @param mappingFileNames       <code>mapping-file</code> elements from <code>persistence.xml</code>.
 * @param managedClassNames      <code>class</code> elements from <code>persistence.xml</code>.
 * @param excludeUnlistedClasses <code>exclude-unlisted-classes</code> element from <code>persistence.xml</code>.
 * @param classLoader            the class loader to use.
 */
public PersistenceUnitInfoImpl(
        final URL rootUrl,
        final String provider,
        final String name,
        final String actualName,
        final PersistenceUnitTransactionType transactionType,
        final DataSource jtaDataSource,
        final Properties properties,
        final List<URL> jarFileUrls,
        final List<String> mappingFileNames,
        final List<String> managedClassNames,
        final boolean excludeUnlistedClasses,
        final ClassLoader classLoader
) {
    this.rootUrl = rootUrl;
    this.provider = provider;
    this.name = name;
    this.actualName = actualName;
    this.transactionType = transactionType;
    this.jtaDataSource = jtaDataSource;
    this.properties = properties;
    this.jarFileUrls = jarFileUrls;
    this.mappingFileNames = mappingFileNames;
    this.managedClassNames = managedClassNames;
    this.excludeUnlistedClasses = excludeUnlistedClasses;
    this.classLoader = classLoader;
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:43,代码来源:PersistenceUnitInfoImpl.java

示例12: PersistenceUnit

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
public PersistenceUnit(Bundle bundle, String persistenceUnitName,
                       PersistenceUnitTransactionType transactionType) {
    this.bundle = bundle;
    this.persistenceUnitName = persistenceUnitName;
    this.transactionType = transactionType;
    this.props = new Properties();
    this.classLoader = bundle.adapt(BundleWiring.class).getClassLoader();
    this.classNames = new HashSet<String>();
    this.mappingFileNames = new HashSet<String>();
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:11,代码来源:PersistenceUnit.java

示例13: dataSourceReady

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
private void dataSourceReady(DataSource ds, Map<String, Object> props) {
	if (persistenceUnit.getTransactionType() == PersistenceUnitTransactionType.JTA) {
		props.put(JAVAX_PERSISTENCE_JTA_DATASOURCE, ds);
	} else {
		props.put(JAVAX_PERSISTENCE_NON_JTA_DATASOURCE, ds);
	}
	createEntityManagerFactory(props);
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:9,代码来源:AriesEntityManagerFactoryBuilder.java

示例14: setup

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
	
	when(punit.getPersistenceUnitName()).thenReturn("test-props");
	when(punit.getPersistenceProviderClassName())
		.thenReturn(ECLIPSE_PERSISTENCE_PROVIDER);
	when(punit.getTransactionType()).thenReturn(PersistenceUnitTransactionType.JTA);
	when(punit.getBundle()).thenReturn(punitBundle);
	when(punit.getProperties()).thenReturn(punitProperties);
	
	when(punitBundle.getBundleContext()).thenReturn(punitContext);
	when(punitBundle.getVersion()).thenReturn(Version.parseVersion("1.2.3"));
	
	when(containerContext.registerService(eq(ManagedService.class), 
			any(ManagedService.class), any(Dictionary.class))).thenReturn(msReg);
	when(containerContext.getService(dsfRef)).thenReturn(dsf);
	when(containerContext.getService(dsRef)).thenReturn(ds);
	when(containerContext.createFilter(Mockito.anyString()))
		.thenAnswer(new Answer<Filter>() {
			@Override
			public Filter answer(InvocationOnMock i) throws Throwable {
				return FrameworkUtil.createFilter(i.getArguments()[0].toString());
			}
		});
	
	when(punitContext.registerService(eq(EntityManagerFactory.class), any(EntityManagerFactory.class), 
			any(Dictionary.class))).thenReturn(emfReg);
	
	when(emf.isOpen()).thenReturn(true);
	
	
	Properties jdbcProps = new Properties();
	jdbcProps.setProperty("url", JDBC_URL);
	jdbcProps.setProperty("user", JDBC_USER);
	jdbcProps.setProperty("password", JDBC_PASSWORD);
	
	when(dsf.createDataSource(jdbcProps)).thenReturn(ds);
	
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:41,代码来源:PropsConfigurationTest.java

示例15: testIncompleteEmfWithoutProps

import javax.persistence.spi.PersistenceUnitTransactionType; //导入依赖的package包/类
@Test
public void testIncompleteEmfWithoutProps() throws InvalidSyntaxException, ConfigurationException {
    
	when(provider.createContainerEntityManagerFactory(eq(punit), 
			eq(singletonMap(PersistenceUnitTransactionType.class.getName(), JTA))))
		.thenReturn(emf);
	
	AriesEntityManagerFactoryBuilder emfb = new AriesEntityManagerFactoryBuilder(
    		containerContext, provider, providerBundle, punit);
	
	assertEquals(ECLIPSE_PERSISTENCE_PROVIDER, emfb.getPersistenceProviderName());
	assertEquals(providerBundle, emfb.getPersistenceProviderBundle());
	
	try {
		emfb.createEntityManagerFactory(null);
		fail("Should throw an exception as incomplete");
	} catch (IllegalArgumentException iae) {
		// Expected
	}
    
    
    // No EMF created as incomplete
 	verifyZeroInteractions(emf, emfReg, provider);
    
    emfb.close();
    
    verifyZeroInteractions(emf, emfReg, provider);
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:29,代码来源:PropsConfigurationTest.java


注:本文中的javax.persistence.spi.PersistenceUnitTransactionType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。