本文整理汇总了Java中javax.jdo.JDOHelper.getObjectId方法的典型用法代码示例。如果您正苦于以下问题:Java JDOHelper.getObjectId方法的具体用法?Java JDOHelper.getObjectId怎么用?Java JDOHelper.getObjectId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jdo.JDOHelper
的用法示例。
在下文中一共展示了JDOHelper.getObjectId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: getId
import javax.jdo.JDOHelper; //导入方法依赖的package包/类
@Programmatic
public String getId() {
Object objectId = JDOHelper.getObjectId(this);
if (objectId == null) {
return "";
}
String objectIdStr = objectId.toString();
final String id = objectIdStr.split("\\[OID\\]")[0];
return id;
}
示例4: preDelete
import javax.jdo.JDOHelper; //导入方法依赖的package包/类
@Override
public void preDelete(final InstanceLifecycleEvent event) {
// We want to ensure that the revision is incremented, even if we do not have any remote repository connected
// (and thus no DeleteModification being created).
getTransactionOrFail().getLocalRevision();
final Object oid = JDOHelper.getObjectId(event.getPersistentInstance());
oid2LastChanged.remove(oid);
}
示例5: JdoObjectRetrievalFailureException
import javax.jdo.JDOHelper; //导入方法依赖的package包/类
public JdoObjectRetrievalFailureException(JDOObjectNotFoundException ex) {
// Extract information about the failed object from the JDOException, if available.
super((ex.getFailedObject() != null ? ex.getFailedObject().getClass() : null),
(ex.getFailedObject() != null ? JDOHelper.getObjectId(ex.getFailedObject()) : null),
ex.getMessage(), ex);
}
示例6: JdoOptimisticLockingFailureException
import javax.jdo.JDOHelper; //导入方法依赖的package包/类
public JdoOptimisticLockingFailureException(JDOOptimisticVerificationException ex) {
// Extract information about the failed object from the JDOException, if available.
super((ex.getFailedObject() != null ? ex.getFailedObject().getClass() : null),
(ex.getFailedObject() != null ? JDOHelper.getObjectId(ex.getFailedObject()) : null),
ex.getMessage(), ex);
}
示例7: checkSample
import javax.jdo.JDOHelper; //导入方法依赖的package包/类
@Override
protected void checkSample(File sample) throws Exception {
// TODO Auto-generated method stub
final JAXBContext context = createContext();
logger.debug("Unmarshalling.");
final Unmarshaller unmarshaller = context.createUnmarshaller();
// Unmarshall the document
final JAXBElement element = (JAXBElement) unmarshaller
.unmarshal(sample);
final Object object = element.getValue();
logger.debug("Opening session.");
// Open the session, save object into the database
logger.debug("Saving the object.");
final PersistenceManager saveManager = createPersistenceManager();
// saveManager.setDetachAllOnCommit(true);
final Transaction saveTransaction = saveManager.currentTransaction();
saveTransaction.setNontransactionalRead(true);
saveTransaction.begin();
// final Object merged = saveSession.merge(object);
// saveSession.replicate(object, ReplicationMode.OVERWRITE);
// saveSession.get
// final Serializable id =
final Object mergedObject = saveManager.makePersistent(object);
// final Object asd = saveManager.detachCopy(object);
saveTransaction.commit();
// final Object id = saveManager.getObjectId(mergedObject);
final Object identity = JDOHelper.getObjectId(object);
final Object id = identity instanceof SingleFieldIdentity ? ((SingleFieldIdentity) identity).getKeyAsObject() : identity;
// Close the session
saveManager.close();
logger.debug("Opening session.");
// Open the session, load the object
final PersistenceManager loadManager = createPersistenceManager();
final Transaction loadTransaction = loadManager.currentTransaction();
loadTransaction.setNontransactionalRead(true);
logger.debug("Loading the object.");
final Object loadedObject = loadManager.getObjectById(mergedObject.getClass(), id);
logger.debug("Closing the session.");
final JAXBElement mergedElement = new JAXBElement(element.getName(),
element.getDeclaredType(), object);
final JAXBElement loadedElement = new JAXBElement(element.getName(),
element.getDeclaredType(), loadedObject);
logger.debug("Checking the document identity.");
logger.debug("Source object:\n"
+ ContextUtils.toString(context, mergedElement));
logger.debug("Result object:\n"
+ ContextUtils.toString(context, loadedElement));
checkObjects(mergedObject, loadedObject);
loadManager.close();
}
示例8: toString_getProperties
import javax.jdo.JDOHelper; //导入方法依赖的package包/类
protected String toString_getProperties() {
return "id=" + JDOHelper.getObjectId(this);
}