本文整理匯總了Java中javax.jdo.PersistenceManagerFactory.getPersistenceManager方法的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceManagerFactory.getPersistenceManager方法的具體用法?Java PersistenceManagerFactory.getPersistenceManager怎麽用?Java PersistenceManagerFactory.getPersistenceManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jdo.PersistenceManagerFactory
的用法示例。
在下文中一共展示了PersistenceManagerFactory.getPersistenceManager方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: main
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
public static void main(String[] args) {
PersistenceManagerFactory persistenceManagerFactory = JDOHelper.getPersistenceManagerFactory("Tutorial");
PersistenceManager persistenceManager = persistenceManagerFactory.getPersistenceManager();
List<Item> executeList = persistenceManager.newQuery(Item.class).filter("").executeList();
System.out.println(executeList);
Item pc = persistenceManager.newInstance(Item.class);
//pc.related.add(executeList.get(0));
//pc.id=1;
Product ps=new Product();
pc.product=ps;
pc.url="DD";
persistenceManager.makePersistent(pc);
//persistenceManager.currentTransaction().commit();
}
示例6: getTransactionalPersistenceManager
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
protected PersistenceManager getTransactionalPersistenceManager(final File localRoot) {
final PersistenceManagerFactory pmf;
try (final LocalRepoManager localRepoManagerLocal = localRepoManagerFactory.createLocalRepoManagerForExistingRepository(localRoot);)
{
try (final LocalRepoTransaction transaction = localRepoManagerLocal.beginWriteTransaction();)
{
pmf = ((LocalRepoTransactionImpl)transaction).getPersistenceManager().getPersistenceManagerFactory();
}
}
final PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
return pm;
}
示例7: printAll
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
private static void printAll(PersistenceManagerFactory pmf, Class clazz) {
PersistenceManager pm = pmf.getPersistenceManager();
Query q = pm.newQuery(clazz);
for (Object o : (List) q.execute()) {
System.out.println(o);
}
}
示例8: readFromDB_Array
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
private double[] readFromDB_Array(String dbName, TestStats ts) {
log("Reading from database");
ZooJdoProperties prop = new ZooJdoProperties(dbName);
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(prop);
//pmf.setRetainValues(false);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
Extent<PersistentArrayDoubleParent> ext = pm.getExtent(PersistentArrayDoubleParent.class);
PersistentArrayDoubleParent pa = ext.iterator().next();
ext.closeAll();
int maxEntries;
if (pa.getEntryCount() < ts.cfgNEntries) {
maxEntries = pa.getEntryCount();
ts.cfgNEntries = maxEntries;
} else {
maxEntries = ts.cfgNEntries;
}
double[] ret = new double[maxEntries*2*DIM];
int pos = 0;
for (PersistentArrayDouble d: pa.getData()) {
double[] da = d.getData();
if (pos+da.length <= ret.length) {
System.arraycopy(da, 0, ret, pos, da.length);
} else {
//special case for last 'da' if we do not read all data
if (ret.length-pos > 0) {
System.arraycopy(da, 0, ret, pos, ret.length-pos);
}
break;
}
pos += da.length;
}
pm.currentTransaction().commit();
pm.close();
pmf.close();
return ret;
}
示例9: readFromDB_Array
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
private double[] readFromDB_Array(String dbName, TestStats ts) {
log("Reading from database");
ZooJdoProperties prop = new ZooJdoProperties(dbName);
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(prop);
//pmf.setRetainValues(false);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
Extent<PersistentArrayDoubleParent> ext = pm.getExtent(PersistentArrayDoubleParent.class);
PersistentArrayDoubleParent pa = ext.iterator().next();
ext.closeAll();
int maxEntries;
if (pa.getEntryCount() < ts.cfgNEntries) {
maxEntries = pa.getEntryCount();
ts.cfgNEntries = maxEntries;
} else {
maxEntries = ts.cfgNEntries;
}
double[] ret = new double[maxEntries*2];
int pos = 0;
for (PersistentArrayDouble d: pa.getData()) {
double[] da = d.getData();
if (pos+da.length <= ret.length) {
System.arraycopy(da, 0, ret, pos, da.length);
} else {
//special case for last 'da' if we do not read all data
if (ret.length-pos > 0) {
System.arraycopy(da, 0, ret, pos, ret.length-pos);
}
break;
}
pos += da.length;
}
pm.currentTransaction().commit();
pm.close();
pmf.close();
return ret;
}
示例10: readFromDB_Array
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
private static double[] readFromDB_Array(String dbName, TestStats ts) {
log("Reading from database");
ZooJdoProperties prop = new ZooJdoProperties(dbName);
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(prop);
pmf.setRetainValues(false);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
Extent<PersistentArrayDoubleParent> ext = pm.getExtent(PersistentArrayDoubleParent.class);
PersistentArrayDoubleParent pa = ext.iterator().next();
ext.closeAll();
int maxEntries;
if (pa.getEntryCount() < ts.cfgNEntries) {
maxEntries = pa.getEntryCount();
ts.cfgNEntries = maxEntries;
} else {
maxEntries = ts.cfgNEntries;
}
double[] ret = new double[maxEntries*2];
int pos = 0;
for (PersistentArrayDouble d: pa.getData()) {
double[] da = d.getData();
if (pos+da.length <= ret.length) {
System.arraycopy(da, 0, ret, pos, da.length);
} else {
//special case for last 'da' if we do not read all data
if (ret.length-pos > 0) {
System.arraycopy(da, 0, ret, pos, ret.length-pos);
}
break;
}
pos += da.length;
}
pm.currentTransaction().commit();
pm.close();
pmf.close();
return ret;
}
示例11: readFromDB_Array
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
private static double[] readFromDB_Array(String dbName, TestStats ts) {
log("Reading from database");
ZooJdoProperties prop = new ZooJdoProperties(dbName);
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(prop);
pmf.setRetainValues(false);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
Extent<PersistentArrayDoubleParent> ext = pm.getExtent(PersistentArrayDoubleParent.class);
PersistentArrayDoubleParent pa = ext.iterator().next();
ext.closeAll();
int maxEntries;
if (pa.getEntryCount() < ts.cfgNEntries) {
maxEntries = pa.getEntryCount();
ts.cfgNEntries = maxEntries;
} else {
maxEntries = ts.cfgNEntries;
}
double[] ret = new double[maxEntries*2*ts.cfgNDims];
int pos = 0;
for (PersistentArrayDouble d: pa.getData()) {
double[] da = d.getData();
if (pos+da.length <= ret.length) {
System.arraycopy(da, 0, ret, pos, da.length);
} else {
//special case for last 'da' if we do not read all data
if (ret.length-pos > 0) {
System.arraycopy(da, 0, ret, pos, ret.length-pos);
}
break;
}
pos += da.length;
}
pm.currentTransaction().commit();
pm.close();
pmf.close();
return ret;
}
示例12: createPersistanceManager
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
protected PersistanceManager createPersistanceManager(){
PersistenceManagerFactory persistenceManagerFactory = JDOHelper.getPersistenceManagerFactory("Tutorial");
return new JDOPersistanceManager( persistenceManagerFactory.getPersistenceManager());
}
示例13: createPersistenceManager
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
public PersistenceManager createPersistenceManager() {
final PersistenceManagerFactory emf = getPersistenceManagerFactory();
return emf.getPersistenceManager();
}
示例14: getPersistenceManager
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
public PersistenceManager getPersistenceManager() {
final PersistenceManagerFactory emf = getPersistenceManagerFactory();
return emf.getPersistenceManager();
}
示例15: getPersistenceManager
import javax.jdo.PersistenceManagerFactory; //導入方法依賴的package包/類
@Provides @RequestScoped @Inject
PersistenceManager getPersistenceManager(PersistenceManagerFactory pmf) {
return pmf.getPersistenceManager();
}