Java Code Examples for javax.jdo.JDOHelper#getObjectId()

The following examples show how to use javax.jdo.JDOHelper#getObjectId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncomingInvoiceRepository.java    From estatio with Apache License 2.0 6 votes vote down vote up
@Programmatic
public boolean findCreditNotesInStateOf(
        final BankAccount creditorBankAccount,
        final List<IncomingInvoiceApprovalState> upstreamStates) {
    final PersistenceManager jdoPersistenceManager = isisJdoSupport.getJdoPersistenceManager();
    final String sql = constructSqlForCreditNotesInStateOf(upstreamStates);
    final Query query = jdoPersistenceManager.newQuery("javax.jdo.query.SQL", sql);
    try {
        query.setResultClass(Integer.class);
        final DatastoreIdImpl datastoreId = (DatastoreIdImpl) JDOHelper.getObjectId(creditorBankAccount);
        final long idKeyAsObject = (long) datastoreId.getKeyAsObject();
        final ForwardQueryResult result = (ForwardQueryResult) query.executeWithMap(ImmutableMap.of("bankAccountId", idKeyAsObject));
        return !result.isEmpty();
    } finally {
        if (query!=null) query.closeAll();
    }
}
 
Example 2
Source File: UdoDomainObject.java    From estatio with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: CommunicationChannel.java    From estatio with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: Communication.java    From estatio with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 5
Source File: CommChannelRole.java    From estatio with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: DocumentAbstract.java    From estatio with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: JdoObjectRetrievalFailureException.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example 8
Source File: JdoOptimisticLockingFailureException.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example 9
Source File: JdoObjectRetrievalFailureException.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 10
Source File: JdoOptimisticLockingFailureException.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 11
Source File: RoundtripTest.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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();

	}