javax.jdo.JDOObjectNotFoundException Java Examples

The following examples show how to use javax.jdo.JDOObjectNotFoundException. 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: PersistenceManagerFactoryUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert the given JDOException to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * <p>The most important cases like object not found or optimistic locking failure
 * are covered here. For more fine-granular conversion, JdoTransactionManager
 * supports sophisticated translation of exceptions via a JdoDialect.
 * @param ex JDOException that occured
 * @return the corresponding DataAccessException instance
 * @see JdoTransactionManager#convertJdoAccessException
 * @see JdoDialect#translateException
 */
public static DataAccessException convertJdoAccessException(JDOException ex) {
	if (ex instanceof JDOObjectNotFoundException) {
		throw new JdoObjectRetrievalFailureException((JDOObjectNotFoundException) ex);
	}
	if (ex instanceof JDOOptimisticVerificationException) {
		throw new JdoOptimisticLockingFailureException((JDOOptimisticVerificationException) ex);
	}
	if (ex instanceof JDODataStoreException) {
		return new JdoResourceFailureException((JDODataStoreException) ex);
	}
	if (ex instanceof JDOFatalDataStoreException) {
		return new JdoResourceFailureException((JDOFatalDataStoreException) ex);
	}
	if (ex instanceof JDOUserException) {
		return new JdoUsageException((JDOUserException) ex);
	}
	if (ex instanceof JDOFatalUserException) {
		return new JdoUsageException((JDOFatalUserException) ex);
	}
	// fallback
	return new JdoSystemException(ex);
}
 
Example #2
Source File: PersistenceManagerFactoryUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the given JDOException to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * <p>The most important cases like object not found or optimistic locking failure
 * are covered here. For more fine-granular conversion, JdoTransactionManager
 * supports sophisticated translation of exceptions via a JdoDialect.
 * @param ex JDOException that occured
 * @return the corresponding DataAccessException instance
 * @see JdoTransactionManager#convertJdoAccessException
 * @see JdoDialect#translateException
 */
public static DataAccessException convertJdoAccessException(JDOException ex) {
	if (ex instanceof JDOObjectNotFoundException) {
		throw new JdoObjectRetrievalFailureException((JDOObjectNotFoundException) ex);
	}
	if (ex instanceof JDOOptimisticVerificationException) {
		throw new JdoOptimisticLockingFailureException((JDOOptimisticVerificationException) ex);
	}
	if (ex instanceof JDODataStoreException) {
		return new JdoResourceFailureException((JDODataStoreException) ex);
	}
	if (ex instanceof JDOFatalDataStoreException) {
		return new JdoResourceFailureException((JDOFatalDataStoreException) ex);
	}
	if (ex instanceof JDOUserException) {
		return new JdoUsageException((JDOUserException) ex);
	}
	if (ex instanceof JDOFatalUserException) {
		return new JdoUsageException((JDOFatalUserException) ex);
	}
	// fallback
	return new JdoSystemException(ex);
}
 
Example #3
Source File: TaskServlet.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
private void processFileWithContent( final PersistenceManager pm, final Key fileKey, final String fileTypeString ) throws IOException {
	LOGGER.fine( "File key: " + fileKey + ", file type: " + fileTypeString );
	
	final FileType fileType = FileType.fromString( fileTypeString );
	
	final FileMetaData fmd;
	try {
		fmd =  (FileMetaData) pm.getObjectById( FILE_TYPE_CLASS_MAP.get( fileType ), fileKey );
	} catch ( final JDOObjectNotFoundException jonfe ) {
		LOGGER.warning( "File not found! (Deleted?)" );
		return;
	}
	LOGGER.fine( "sha1: " + fmd.getSha1() );
	if ( fmd.getBlobKey() != null && fmd.getContent() == null ) {
		LOGGER.warning( "This file is already processed!" );
		return;
	}
	if ( fmd.getContent() == null ) {
		LOGGER.warning( "File does not have content!" );
		return;
	}
	
	// Store content in the Blobstore
	final FileService      fileService = FileServiceFactory.getFileService();
	final AppEngineFile    appeFile    = fileService.createNewBlobFile( FILE_TYPE_MIME_TYPE_MAP.get( fileType ), fmd.getSha1() );
	final FileWriteChannel channel     = fileService.openWriteChannel( appeFile, true );
	final ByteBuffer       bb          = ByteBuffer.wrap( fmd.getContent().getBytes() );
	while ( bb.hasRemaining() )
		channel.write( bb );
	channel.closeFinally();
	
	fmd.setBlobKey( fileService.getBlobKey( appeFile ) );
	fmd.setContent( null );
	
	// I do not catch exceptions (so the task will be retried)
}
 
Example #4
Source File: SimpleLoginFormHandler.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public void renderLogin(String userRecordKey, Wavelet wavelet) {
  // Clear login form.
  wavelet.getRootBlip().all().delete();

  PersistenceManager pm = SingletonPersistenceManagerFactory.get().getPersistenceManager();
  OAuthUser userProfile = null;
  try {
    userProfile = pm.getObjectById(OAuthUser.class, userRecordKey);
  } catch (JDOObjectNotFoundException objectNotFound) {
    LOG.severe("Error fetching object from datastore with key: " + userRecordKey);
  } finally {
    pm.close();
  }
  String url = userProfile.getAuthUrl();

  // Add authentication prompt and insert link to service provider log-in page
  // to wavelet.
  wavelet.getRootBlip().all().delete();
  StringBuilder b = new StringBuilder();
  b.append("\n");
  int startIndex = b.length();
  b.append(LOGIN_LINK_TEXT + "\n\n");
  wavelet.getRootBlip().append(b.toString());

  // Add button to click when authentication is complete.
  wavelet.getRootBlip().append(new FormElement(ElementType.BUTTON, LOGIN_BUTTON_ID,
      LOGIN_BUTTON_CAPTION));

  // Linkify the authorization link.
  wavelet.getRootBlip().range(startIndex, startIndex + LOGIN_LINK_TEXT.length()).annotate(
      LINK_ANNOTATION_KEY, url);
}
 
Example #5
Source File: OAuthServiceImpl.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves user's oauth information from Datastore.
 * 
 * @return the user profile (or null if not found).
 */
private OAuthUser retrieveUserProfile() {
  PersistenceManager pm = pmf.getPersistenceManager();
  OAuthUser userProfile = null;
  try {
    userProfile = pm.getObjectById(OAuthUser.class, userRecordKey);
  } catch (JDOObjectNotFoundException e) {
    LOG.info("Datastore object not yet initialized with key: " + userRecordKey);
  } finally {
    pm.close();
  }
  return userProfile;
}
 
Example #6
Source File: OAuthHmacThreeLeggedFlow.java    From google-oauth-java-client with Apache License 2.0 5 votes vote down vote up
public Credential loadCredential(PersistenceManager pm) {
  try {
    return pm.getObjectById(OAuthHmacCredential.class, userId);
  } catch (JDOObjectNotFoundException e) {
    return null;
  }
}
 
Example #7
Source File: SimpleLoginFormHandler.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void renderLogin(String userRecordKey, Wavelet wavelet) {
  // Clear login form.
  wavelet.getRootBlip().all().delete();

  PersistenceManager pm = SingletonPersistenceManagerFactory.get().getPersistenceManager();
  OAuthUser userProfile = null;
  try {
    userProfile = pm.getObjectById(OAuthUser.class, userRecordKey);
  } catch (JDOObjectNotFoundException objectNotFound) {
    LOG.severe("Error fetching object from datastore with key: " + userRecordKey);
  } finally {
    pm.close();
  }
  String url = userProfile.getAuthUrl();

  // Add authentication prompt and insert link to service provider log-in page
  // to wavelet.
  wavelet.getRootBlip().all().delete();
  StringBuilder b = new StringBuilder();
  b.append("\n");
  int startIndex = b.length();
  b.append(LOGIN_LINK_TEXT + "\n\n");
  wavelet.getRootBlip().append(b.toString());

  // Add button to click when authentication is complete.
  wavelet.getRootBlip().append(new FormElement(ElementType.BUTTON, LOGIN_BUTTON_ID,
      LOGIN_BUTTON_CAPTION));

  // Linkify the authorization link.
  wavelet.getRootBlip().range(startIndex, startIndex + LOGIN_LINK_TEXT.length()).annotate(
      LINK_ANNOTATION_KEY, url);
}
 
Example #8
Source File: OAuthServiceImpl.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves user's oauth information from Datastore.
 * 
 * @return the user profile (or null if not found).
 */
private OAuthUser retrieveUserProfile() {
  PersistenceManager pm = pmf.getPersistenceManager();
  OAuthUser userProfile = null;
  try {
    userProfile = pm.getObjectById(OAuthUser.class, userRecordKey);
  } catch (JDOObjectNotFoundException e) {
    LOG.info("Datastore object not yet initialized with key: " + userRecordKey);
  } finally {
    pm.close();
  }
  return userProfile;
}
 
Example #9
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 #10
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 #11
Source File: AbstractCallbackServlet.java    From google-oauth-java-client with Apache License 2.0 4 votes vote down vote up
@Override
protected final void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException, ServletException {
  // Parse the token that will be used to look up the flow object
  String completionCode = req.getParameter(completionCodeQueryParam);
  String errorCode = req.getParameter(ERROR_PARAM);

  if ((completionCode == null || "".equals(completionCode))
      && (errorCode == null || "".equals(errorCode))) {
    resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    resp.getWriter().print("Must have a query parameter: " + completionCodeQueryParam);
    return;
  } else if (errorCode != null && !"".equals(errorCode)) {
    resp.sendRedirect(deniedRedirectUrl);
    return;
  }

  // Get a key for the logged in user to retrieve the flow
  String userId = getUserId();

  // Get flow from the data store
  PersistenceManager manager = pmf.getPersistenceManager();
  try {
    ThreeLeggedFlow flow = null;
    try {
      flow = manager.getObjectById(flowType, userId);
    } catch (JDOObjectNotFoundException e) {
      LOG.severe("Unable to locate flow by user: " + userId);
      resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
      resp.getWriter().print("Unable to find flow for user: " + userId);
      return;
    }

    flow.setHttpTransport(getHttpTransport());
    flow.setJsonFactory(getJsonFactory());

    // Complete the flow object with the token we got in our query parameters
    Credential c = flow.complete(completionCode);
    manager.makePersistent(c);
    manager.deletePersistent(flow);
    resp.sendRedirect(redirectUrl);
  } finally {
    manager.close();
  }
}