當前位置: 首頁>>代碼示例>>Java>>正文


Java PersistenceManagerFactory類代碼示例

本文整理匯總了Java中javax.jdo.PersistenceManagerFactory的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceManagerFactory類的具體用法?Java PersistenceManagerFactory怎麽用?Java PersistenceManagerFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PersistenceManagerFactory類屬於javax.jdo包,在下文中一共展示了PersistenceManagerFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testLocalPersistenceManagerFactoryBeanWithFile

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
@Test
public void testLocalPersistenceManagerFactoryBeanWithFile() throws IOException {
	LocalPersistenceManagerFactoryBean pmfb = new LocalPersistenceManagerFactoryBean() {
		@Override
		protected PersistenceManagerFactory newPersistenceManagerFactory(Map props) {
			throw new IllegalArgumentException((String) props.get("myKey"));
		}
	};
	pmfb.setConfigLocation(new ClassPathResource("test.properties", getClass()));
	try {
		pmfb.afterPropertiesSet();
		fail("Should have thrown IllegalArgumentException");
	}
	catch (IllegalArgumentException ex) {
		// expected
		assertTrue("Correct exception", "myValue".equals(ex.getMessage()));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:LocalPersistenceManagerFactoryTests.java

示例2: testLocalPersistenceManagerFactoryBeanWithName

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
@Test
public void testLocalPersistenceManagerFactoryBeanWithName() throws IOException {
	LocalPersistenceManagerFactoryBean pmfb = new LocalPersistenceManagerFactoryBean() {
		@Override
		protected PersistenceManagerFactory newPersistenceManagerFactory(String name) {
			throw new IllegalArgumentException(name);
		}
	};
	pmfb.setPersistenceManagerFactoryName("myName");
	try {
		pmfb.afterPropertiesSet();
		fail("Should have thrown IllegalArgumentException");
	}
	catch (IllegalArgumentException ex) {
		// expected
		assertTrue("Correct exception", "myName".equals(ex.getMessage()));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:LocalPersistenceManagerFactoryTests.java

示例3: testLocalPersistenceManagerFactoryBeanWithNameAndProperties

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
@Test
public void testLocalPersistenceManagerFactoryBeanWithNameAndProperties() throws IOException {
	LocalPersistenceManagerFactoryBean pmfb = new LocalPersistenceManagerFactoryBean() {
		@Override
		protected PersistenceManagerFactory newPersistenceManagerFactory(String name) {
			throw new IllegalArgumentException(name);
		}
	};
	pmfb.setPersistenceManagerFactoryName("myName");
	pmfb.getJdoPropertyMap().put("myKey", "myValue");
	try {
		pmfb.afterPropertiesSet();
		fail("Should have thrown IllegalStateException");
	}
	catch (IllegalStateException ex) {
		// expected
		assertTrue(ex.getMessage().indexOf("persistenceManagerFactoryName") != -1);
		assertTrue(ex.getMessage().indexOf("jdoProp") != -1);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:LocalPersistenceManagerFactoryTests.java

示例4: init

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
public void init(int doublesPerRow) {
	System.out.println("Storing to database");
	ZooHelper.getDataStoreManager().createDb(dbName);
	
	ZooJdoProperties prop = new ZooJdoProperties(dbName);
	PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(prop);
	pmf.setRetainValues(false);
	pm = pmf.getPersistenceManager();
	pm.currentTransaction().begin();
	
	list = new PersistentArrayDoubleParent(doublesPerRow);
	pm.makePersistent(list);
	
	pad = list.getNextForWrite2();
	data = pad.getData();
}
 
開發者ID:tzaeschke,項目名稱:TinSpin,代碼行數:17,代碼來源:DbWriter.java

示例5: getPersistManager

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
private PersistenceManager getPersistManager(MetadbConf metadbConf) {
  //TODO: get params from dbConf
  String driver = metadbConf.getJdbcDriverName();

  LOG.info("Connecting to Metastore with driver: " + driver);

  Properties properties = new Properties();
  properties.setProperty("javax.jdo.option.ConnectionURL",
          "jdbc:derby:metastore_db;create=true");

  properties.setProperty("javax.jdo.option.ConnectionDriverName",
          driver);

  properties.setProperty("javax.jdo.option.ConnectionUserName", "");
  properties.setProperty("javax.jdo.option.ConnectionPassword", "");
  properties.setProperty("datanucleus.schema.autoCreateSchema", "true");
  properties.setProperty("datanucleus.schema.autoCreateTables", "true");
  properties.setProperty("datanucleus.schema.validateTables", "false");
  properties.setProperty("datanucleus.schema.validateConstraints", "false");

  PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);
  PersistenceManager pm = pmf.getPersistenceManager();

  return  pm;
}
 
開發者ID:andyhehk,項目名稱:SecureDB,代碼行數:26,代碼來源:ConnectionPool.java

示例6: getPersistenceManager

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
public  Object getPersistenceManager(String client,PersistenceManagerFactory pmf) 
{
	Map<String,PersistenceManager> map = (Map<String,PersistenceManager>)super.get();
	PersistenceManager pm = null;
	if (map != null)
		pm = map.get(client);
	
    if(pm == null || pm.isClosed()) 
    {
        pm = pmf.getPersistenceManager( ); 
        pm.setUserObject(client);
        if (map == null)
        	map = new HashMap<>();
        map.put(client, pm);
        set(map);
    }

    return pm;
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:20,代碼來源:JDOPMRetriever.java

示例7: getPersistenceManager

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
public PersistenceManager getPersistenceManager(String key)
 {
  PersistenceManagerFactory pmf = factories.get(key);
  if (pmf == null)
  {
throw new APIException(APIException.INTERNAL_DB_ERROR);
  }
  if (pmf != null)
  {
  	PersistenceManager pm = (PersistenceManager) pmRet.getPersistenceManager(key,pmf);
  	if (!pm.currentTransaction().isActive())
  		TransactionPeer.startReadOnlyTransaction(pm);
  	return pm;
  }
  else
  	return null;
 }
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:18,代碼來源:JDOFactory.java

示例8: testJdoDaoSupportWithPersistenceManagerFactory

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
@Test
public void testJdoDaoSupportWithPersistenceManagerFactory() throws Exception {
	PersistenceManagerFactory pmf = mock(PersistenceManagerFactory.class);
	pmf.getConnectionFactory();
	final List test = new ArrayList();
	JdoDaoSupport dao = new JdoDaoSupport() {
		@Override
		protected void initDao() {
			test.add("test");
		}
	};
	dao.setPersistenceManagerFactory(pmf);
	dao.afterPropertiesSet();
	assertEquals("Correct PersistenceManagerFactory", pmf, dao.getPersistenceManagerFactory());
	assertEquals("Correct JdoTemplate", pmf, dao.getJdoTemplate().getPersistenceManagerFactory());
	assertEquals("initDao called", test.size(), 1);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:18,代碼來源:JdoDaoSupportTests.java

示例9: testInterceptor

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
@Test
public void testInterceptor() {
	PersistenceManagerFactory pmf = mock(PersistenceManagerFactory.class);
	PersistenceManager pm = mock(PersistenceManager.class);
	given(pmf.getPersistenceManager()).willReturn(pm);

	JdoInterceptor interceptor = new JdoInterceptor();
	interceptor.setPersistenceManagerFactory(pmf);
	try {
		interceptor.invoke(new TestInvocation(pmf));
	}
	catch (Throwable t) {
		fail("Should not have thrown Throwable: " + t.getMessage());
	}

	verify(pm).close();
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:18,代碼來源:JdoInterceptorTests.java

示例10: testInterceptorWithPrebound

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
@Test
public void testInterceptorWithPrebound() {
	PersistenceManagerFactory pmf = mock(PersistenceManagerFactory.class);
	PersistenceManager pm = mock(PersistenceManager.class);

	TransactionSynchronizationManager.bindResource(pmf, new PersistenceManagerHolder(pm));
	JdoInterceptor interceptor = new JdoInterceptor();
	interceptor.setPersistenceManagerFactory(pmf);
	try {
		interceptor.invoke(new TestInvocation(pmf));
	}
	catch (Throwable t) {
		fail("Should not have thrown Throwable: " + t.getMessage());
	}
	finally {
		TransactionSynchronizationManager.unbindResource(pmf);
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:19,代碼來源:JdoInterceptorTests.java

示例11: initializeDatastore

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
public void initializeDatastore(PersistenceManagerFactory pmf) {
    /*
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();

    try {
        tx.begin();

        // TODO: Initialize datastore

        tx.commit();
    } catch (Exception ex) {
        LOG.error("Unable to initialize repository", ex);
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    */
}
 
開發者ID:damiancarrillo,項目名稱:crash-reporter,代碼行數:22,代碼來源:DatastoreInitializer.java

示例12: doGetPersistenceManager

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
/**
 * Obtain a JDO PersistenceManager via the given factory. Is aware of a
 * corresponding PersistenceManager bound to the current thread,
 * for example when using JdoTransactionManager. Will create a new
 * PersistenceManager else, if "allowCreate" is {@code true}.
 * <p>Same as {@code getPersistenceManager}, but throwing the original JDOException.
 * @param pmf PersistenceManagerFactory to create the PersistenceManager with
 * @param allowCreate if a non-transactional PersistenceManager should be created
 * when no transactional PersistenceManager can be found for the current thread
 * @return the PersistenceManager
 * @throws JDOException if the PersistenceManager couldn't be created
 * @throws IllegalStateException if no thread-bound PersistenceManager found and
 * "allowCreate" is {@code false}
 * @see #getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)
 * @see JdoTransactionManager
 */
public static PersistenceManager doGetPersistenceManager(PersistenceManagerFactory pmf, boolean allowCreate)
	throws JDOException, IllegalStateException {

	Assert.notNull(pmf, "No PersistenceManagerFactory specified");

	PersistenceManagerHolder pmHolder =
			(PersistenceManagerHolder) TransactionSynchronizationManager.getResource(pmf);
	if (pmHolder != null) {
		if (!pmHolder.isSynchronizedWithTransaction() &&
				TransactionSynchronizationManager.isSynchronizationActive()) {
			pmHolder.setSynchronizedWithTransaction(true);
			TransactionSynchronizationManager.registerSynchronization(
					new PersistenceManagerSynchronization(pmHolder, pmf, false));
		}
		return pmHolder.getPersistenceManager();
	}

	if (!allowCreate && !TransactionSynchronizationManager.isSynchronizationActive()) {
		throw new IllegalStateException("No JDO PersistenceManager bound to thread, " +
				"and configuration does not allow creation of non-transactional one here");
	}

	logger.debug("Opening JDO PersistenceManager");
	PersistenceManager pm = pmf.getPersistenceManager();

	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		logger.debug("Registering transaction synchronization for JDO PersistenceManager");
		// Use same PersistenceManager for further JDO actions within the transaction.
		// Thread object will get removed by synchronization at transaction completion.
		pmHolder = new PersistenceManagerHolder(pm);
		pmHolder.setSynchronizedWithTransaction(true);
		TransactionSynchronizationManager.registerSynchronization(
				new PersistenceManagerSynchronization(pmHolder, pmf, true));
		TransactionSynchronizationManager.bindResource(pmf, pmHolder);
	}

	return pm;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:55,代碼來源:PersistenceManagerFactoryUtils.java

示例13: isPersistenceManagerTransactional

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
/**
 * Return whether the given JDO PersistenceManager is transactional, that is,
 * bound to the current thread by Spring's transaction facilities.
 * @param pm the JDO PersistenceManager to check
 * @param pmf JDO PersistenceManagerFactory that the PersistenceManager
 * was created with (can be {@code null})
 * @return whether the PersistenceManager is transactional
 */
public static boolean isPersistenceManagerTransactional(
		PersistenceManager pm, PersistenceManagerFactory pmf) {

	if (pmf == null) {
		return false;
	}
	PersistenceManagerHolder pmHolder =
			(PersistenceManagerHolder) TransactionSynchronizationManager.getResource(pmf);
	return (pmHolder != null && pm == pmHolder.getPersistenceManager());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:PersistenceManagerFactoryUtils.java

示例14: applyTransactionTimeout

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
/**
 * Apply the current transaction timeout, if any, to the given JDO Query object.
 * @param query the JDO Query object
 * @param pmf JDO PersistenceManagerFactory that the Query was created for
 * @throws JDOException if thrown by JDO methods
 */
public static void applyTransactionTimeout(Query query, PersistenceManagerFactory pmf) throws JDOException {
	Assert.notNull(query, "No Query object specified");
	PersistenceManagerHolder pmHolder =
			(PersistenceManagerHolder) TransactionSynchronizationManager.getResource(pmf);
	if (pmHolder != null && pmHolder.hasTimeout() &&
			pmf.supportedOptions().contains("javax.jdo.option.DatastoreTimeout")) {
		int timeout = (int) pmHolder.getTimeToLiveInMillis();
		query.setDatastoreReadTimeoutMillis(timeout);
		query.setDatastoreWriteTimeoutMillis(timeout);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:PersistenceManagerFactoryUtils.java

示例15: doReleasePersistenceManager

import javax.jdo.PersistenceManagerFactory; //導入依賴的package包/類
/**
 * Actually release a PersistenceManager for the given factory.
 * Same as {@code releasePersistenceManager}, but throwing the original JDOException.
 * @param pm PersistenceManager to close
 * @param pmf PersistenceManagerFactory that the PersistenceManager was created with
 * (can be {@code null})
 * @throws JDOException if thrown by JDO methods
 */
public static void doReleasePersistenceManager(PersistenceManager pm, PersistenceManagerFactory pmf)
		throws JDOException {

	if (pm == null) {
		return;
	}
	// Only release non-transactional PersistenceManagers.
	if (!isPersistenceManagerTransactional(pm, pmf)) {
		logger.debug("Closing JDO PersistenceManager");
		pm.close();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:PersistenceManagerFactoryUtils.java


注:本文中的javax.jdo.PersistenceManagerFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。