本文整理汇总了Java中javax.jdo.JDOHelper类的典型用法代码示例。如果您正苦于以下问题:Java JDOHelper类的具体用法?Java JDOHelper怎么用?Java JDOHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JDOHelper类属于javax.jdo包,在下文中一共展示了JDOHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import javax.jdo.JDOHelper; //导入依赖的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: start
import javax.jdo.JDOHelper; //导入依赖的package包/类
@Override
public void start(Properties conf, UpdateLoggerFactory updateLoggerFactory)
throws MetaException {
Properties props = new Properties();
props.setProperty("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
props.setProperty("datanucleus.ConnectionDriverName", conf.getProperty("metastore.jdo.connection.drivername"));
props.setProperty("datanucleus.ConnectionURL", conf.getProperty("metastore.jdo.connection.URL"));
props.setProperty("datanucleus.ConnectionUserName", conf.getProperty("metastore.jdo.connection.username"));
props.setProperty("datanucleus.ConnectionPassword", conf.getProperty("metastore.jdo.connection.password"));
props.setProperty("datanucleus.connectionPoolingType", "DBCP");
props.setProperty("datanucleus.schema.autoCreateAll", "true");
if (conf.getProperty("metastore.jdo.connection.drivername").equals("org.sqlite.JDBC")) {
// for sequences
props.setProperty("datanucleus.valuegeneration.transactionAttribute", "UsePM");
// connection pooling occurs NullPointerException
props.setProperty("datanucleus.connectionPoolingType", "None");
props.setProperty("datanucleus.connectionPoolingType.nontx", "None");
}
pmf = JDOHelper.getPersistenceManagerFactory(props);
JDOMetaStore.ulf = updateLoggerFactory;
}
示例3: getPersistManager
import javax.jdo.JDOHelper; //导入依赖的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;
}
示例4: prepareTestDB
import javax.jdo.JDOHelper; //导入依赖的package包/类
public MetaStore prepareTestDB() {
MetaStore metadb;
try {
Class.forName(driver).newInstance();
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
e.printStackTrace();
}
Properties properties = TestUtility.createProperty();
pmf = JDOHelper.getPersistenceManagerFactory(properties);
pm = pmf.getPersistenceManager();
DBMeta dbMeta = TestQuery.createDBMeta();
metadb = new MetaStore(dbMeta.getName(), pm);
metadb.addDB(dbMeta);
return metadb;
}
示例5: prepareTestDB
import javax.jdo.JDOHelper; //导入依赖的package包/类
/**
* Prepare a in-memory database for testing
*/
@Before
public void prepareTestDB() {
try {
Class.forName(driver).newInstance();
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
e.printStackTrace();
}
Properties properties = new Properties();
properties.setProperty("javax.jdo.option.ConnectionURL",
"jdbc:derby:memory:test_db;create=true");
properties.setProperty("javax.jdo.option.ConnectionDriverName",
"org.apache.derby.jdbc.EmbeddedDriver");
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");
pmf = JDOHelper.getPersistenceManagerFactory(properties);
pm = pmf.getPersistenceManager();
}
示例6: prepareTestDB
import javax.jdo.JDOHelper; //导入依赖的package包/类
public MetaStore prepareTestDB() {
MetaStore metadb;
try {
Class.forName(driver).newInstance();
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
e.printStackTrace();
}
Properties properties = TestUtility.createProperty();
pmf = JDOHelper.getPersistenceManagerFactory(properties);
pm = pmf.getPersistenceManager();
DBMeta dbMeta = TestQuery.createDBMetaSimple();
metadb = new MetaStore(dbMeta.getName(), pm);
metadb.addDB(dbMeta);
return metadb;
}
示例7: updateRetrievedItem
import javax.jdo.JDOHelper; //导入依赖的package包/类
public static <T> void updateRetrievedItem(Class<T> clazz, T candidateObject, T retrievedObject) {
final Field[] itemFields = clazz.getDeclaredFields();
for (Field itemField : itemFields) {
itemField.setAccessible(true);
try {
final Object submissionFieldValue = itemField.get(candidateObject);
if (submissionFieldValue != null) {
final String fieldName = itemField.getName();
if (fieldName.startsWith("jdo")) {
continue;
}
logger.info("Setting retrieved candidateObject's " + fieldName + " to " + submissionFieldValue);
itemField.set(retrievedObject, submissionFieldValue);
JDOHelper.makeDirty(retrievedObject, fieldName);
}
} catch (IllegalAccessException e) {
logger.info(e.getMessage());
}
}
}
示例8: update
import javax.jdo.JDOHelper; //导入依赖的package包/类
@Override
@Transactional
public T update(final T object) {
if (JDOHelper.getObjectState(object) == ObjectState.TRANSIENT) {
return updateFromTransient(object);
} else {
validateCredentials(object);
updateModificationData(object);
final T updatedInstance = repository.update(object);
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
if (allowUpdateEvent) {
sendEvent((Long) getId(updatedInstance), UPDATE);
}
}
});
return updatedInstance;
}
}
示例9: shouldRecordHistory
import javax.jdo.JDOHelper; //导入依赖的package包/类
private boolean shouldRecordHistory(Class<?> historyClass, Object instance) {
// we don't want duplicate history instances
// this checks will prevent double history being recorder from cascade events etc.
Long instanceId = getInstanceId(instance);
if (JDOHelper.isNew(instance)) {
// always record for new instances, no need for db query
return true;
} else if (getRecordRepository().contains(historyClass.getName(), instanceId)) {
// if it was already recorded in this tx, then we want to update it
return true;
} else {
// check if there are any changes, this will prevent double history in case of cascading etc.
Object latestHistoryRev = getLatestRevision(historyClass, instanceId);
if (latestHistoryRev == null) {
// no history, record data (possible in case of changing the record history setting for an entity)
return true;
} else {
// check if any fields changed
List<String> changedFields = PropertyUtil.findChangedFields(instance, latestHistoryRev, getRelConverter());
return !changedFields.isEmpty();
}
}
}
示例10: createDatastore
import javax.jdo.JDOHelper; //导入依赖的package包/类
@BeforeClass
public static void createDatastore() {
Map<String, String> props = new HashMap<>();
props.put("javax.jdo.option.ConnectionURL", "jdbc:hsqldb:mem:test");
props.put("javax.jdo.option.ConnectionDriverName", "org.hsqldb.jdbcDriver");
props.put("javax.jdo.option.ConnectionUserName", "sa");
props.put("javax.jdo.option.ConnectionPassword", "");
props.put("datanucleus.schema.autoCreateAll", "true");
/*
* The RetainValues option is important if we verify interaction involving objects which outlive
* their persistence manager. While this should not happen during normal interaction, it does
* happen when verifying interactions with mockito.
*/
props.put("javax.jdo.option.RetainValues", "true");
pmf = JDOHelper.getPersistenceManagerFactory(props, "core");
}
示例11: testThreeArg
import javax.jdo.JDOHelper; //导入依赖的package包/类
@Test
public void testThreeArg() throws Exception {
AtomicReference<OsuUser> ref1 = new AtomicReference<>();
AtomicReference<OsuUser> ref2 = new AtomicReference<>();
AtomicReference<OsuUser> ref3 = new AtomicReference<>();
ExecutorServiceHelper.detachAndSchedule(exec, log, pm, (x, y, z) -> {
ref1.set(x);
ref2.set(y);
ref3.set(z);
}, osuUser, osuUser2, osuUser3);
assertTrue(JDOHelper.isDetached(ref1.get()));
assertTrue(JDOHelper.isDetached(ref2.get()));
assertTrue(JDOHelper.isDetached(ref3.get()));
}
示例12: save
import javax.jdo.JDOHelper; //导入依赖的package包/类
public Calendar save(Calendar calendar) {
PersistenceManager pm;
if (calendar.getKey() == null) {
pm = PMF.get().getPersistenceManager();
} else {
pm = JDOHelper.getPersistenceManager(calendar);
}
try {
pm.makePersistent(calendar);
} finally {
pm.close();
}
return calendar;
}
示例13: save
import javax.jdo.JDOHelper; //导入依赖的package包/类
public AlarmClock save(AlarmClock alarmClock) {
PersistenceManager pm = null;
if (alarmClock.getId() == null) {
pm = PMF.get().getPersistenceManager();
}
else {
pm = JDOHelper.getPersistenceManager(alarmClock);
}
try {
pm.makePersistent(alarmClock);
} finally {
pm.close();
}
return alarmClock;
}
示例14: equals
import javax.jdo.JDOHelper; //导入依赖的package包/类
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
final Object thisOid = JDOHelper.getObjectId(this);
if (thisOid == null) {
return false;
}
final Object otherOid = JDOHelper.getObjectId(obj);
return thisOid.equals(otherOid);
}
示例15: hashCode
import javax.jdo.JDOHelper; //导入依赖的package包/类
@Override
public int hashCode() {
if (hashCode == 0) {
// Freeze the hashCode.
//
// We make sure the hashCode does not change after it was once initialised, because the object might
// have been added to a HashSet (or Map) before being persisted. During persistence, the object's id is
// assigned and without freezing the hashCode, the object is thus not found in the Map/Set, anymore.
//
// This new strategy seems to be working well; messages like this do not occur anymore:
//
// Aug 22, 2014 9:44:23 AM org.datanucleus.store.rdbms.mapping.java.PersistableMapping postInsert
// INFO: Object "[email protected]" has field "co.codewizards.cloudstore.local.persistence.FileChunk.normalFile" with an N-1 bidirectional relation set to relate to "[email protected]" but the collection at "co.codewizards.cloudstore.local.persistence.NormalFile.fileChunks" doesnt contain this object.
final Object thisOid = JDOHelper.getObjectId(this);
if (thisOid == null)
hashCode = super.hashCode();
else
hashCode = thisOid.hashCode();
if (hashCode == 0) // very unlikely, but we want our code to be 100% robust.
hashCode = 1;
}
return hashCode;
}