List of usage examples for javax.persistence PersistenceException getMessage
public String getMessage()
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * @param guid//from w w w.j a v a 2s .co m * GUID of the project to load * @param majorVersion * Major version number of the project to load * @param minorVersion * Minor version number of the project to load * @return the Project with the given attributes, or <code>null</code> if * no such Project could be found. The returned Project is not * associated with an Entity Manager. * @throws JBException * ... */ public static synchronized IProjectPO loadProjectByGuidAndVersion(String guid, int majorVersion, int minorVersion) throws JBException { EntityManager session = null; try { session = Persistor.instance().openSession(); Query query = session.createQuery("select project from ProjectPO as project" //$NON-NLS-1$ + " inner join fetch project.properties where project.guid = :guid" //$NON-NLS-1$ + " and project.properties.majorNumber = :majorNumber and project.properties.minorNumber = :minorNumber"); //$NON-NLS-1$ query.setParameter("guid", guid); //$NON-NLS-1$ query.setParameter("majorNumber", majorVersion); //$NON-NLS-1$ query.setParameter("minorNumber", minorVersion); //$NON-NLS-1$ try { IProjectPO project = (IProjectPO) query.getSingleResult(); UsedToolkitBP.getInstance().readUsedToolkitsFromDB(project); return project; } catch (NoResultException nre) { // No result found. Return null as per the javadoc. return null; } } catch (PersistenceException e) { OperationCanceledException oce = checkForCancel(e); if (oce != null) { throw oce; } log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } finally { Persistor.instance().dropSessionWithoutLockRelease(session); } }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * @param guid// w ww .j a v a 2s .com * GUID of the project to load * @param majorVersion * Major version number of the project to load * @param minorVersion * Minor version number of the project to load * @return the Project with the given attributes, or <code>null</code> if * no such Project could be found. The returned Project is not * associated with an Entity Manager. * @throws JBException * ... */ public static synchronized Long findProjectIDByGuidAndVersion(String guid, int majorVersion, int minorVersion) throws JBException { EntityManager session = null; try { session = Persistor.instance().openSession(); Query query = session.createQuery("select project.id from ProjectPO as project" //$NON-NLS-1$ + " inner join fetch project.properties where project.guid = :guid" //$NON-NLS-1$ + " and project.properties.majorNumber = :majorNumber and project.properties.minorNumber = :minorNumber"); //$NON-NLS-1$ query.setParameter("guid", guid); //$NON-NLS-1$ query.setParameter("majorNumber", majorVersion); //$NON-NLS-1$ query.setParameter("minorNumber", minorVersion); //$NON-NLS-1$ try { Long projectID = (Long) query.getSingleResult(); return projectID; } catch (NoResultException nre) { // No result found. Return null as per the javadoc. return null; } } catch (PersistenceException e) { OperationCanceledException oce = checkForCancel(e); if (oce != null) { throw oce; } log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } finally { Persistor.instance().dropSessionWithoutLockRelease(session); } }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * @param name/*w ww.ja va 2s. c o m*/ * Name of the project to load * @param majorVersion * Major version number of the project to load * @param minorVersion * Minor version number of the project to load * @return the Project with the given attributes, or <code>null</code> if * no such Project could be found. The returned Project is not * associated with an Entity Manager. * @throws JBException * ... */ public static synchronized IProjectPO loadProjectByNameAndVersion(String name, int majorVersion, int minorVersion) throws JBException { EntityManager session = null; String guid = StringConstants.EMPTY; try { session = Persistor.instance().openSession(); Query query = session.createQuery("select name.hbmGuid " //$NON-NLS-1$ + "from ProjectNamePO as name" //$NON-NLS-1$ + " where name.hbmName = :name"); //$NON-NLS-1$ query.setParameter("name", name); //$NON-NLS-1$ try { guid = (String) query.getSingleResult(); } catch (NoResultException nre) { // No result found. Return null as per the javadoc. return null; } } catch (PersistenceException e) { log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } finally { Persistor.instance().dropSessionWithoutLockRelease(session); } return loadProjectByGuidAndVersion(guid, majorVersion, minorVersion); }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * @return the project with the given name and the highest version number, * or <code>null</code> if no project with the given name is found. * The project instance is detached from the session. * @param name//from w w w. j av a2 s. com * Name of the project to load * @throws JBException * ... */ public static synchronized IProjectPO loadLatestVersionOfProjectByName(String name) throws JBException { EntityManager session = null; String guid = StringConstants.EMPTY; int majorVersion = 0; int minorVersion = 0; try { session = Persistor.instance().openSession(); Query query = session.createQuery("select project.hbmGuid " //$NON-NLS-1$ + "from ProjectNamePO as project" //$NON-NLS-1$ + " where project.hbmName = :name"); //$NON-NLS-1$ query.setParameter("name", name); //$NON-NLS-1$ try { guid = (String) query.getSingleResult(); } catch (NoResultException nre) { return null; } String versionNumber = findHighestVersionNumber(guid); int index = versionNumber.indexOf('.'); majorVersion = Integer.parseInt(versionNumber.substring(0, index)); minorVersion = Integer.parseInt(versionNumber.substring(index + 1)); } catch (NumberFormatException nfe) { log.error(Messages.InvalidProjectVersionNumber, nfe); throw new JBException(nfe.getMessage(), MessageIDs.E_INVALID_PROJECT_VERSION); } catch (PersistenceException e) { log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } finally { Persistor.instance().dropSessionWithoutLockRelease(session); } return loadProjectByGuidAndVersion(guid, majorVersion, minorVersion); }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * Loads the project in a session. This is shared code for detached in * master session loading./* w w w .j a v a 2 s .c om*/ * @param reused * The reused project information for this project. * @param session * Session context for db ops * @return the ProjectPO or null if no project in db * @throws JBFatalAbortException * @throws OperationCanceledException * @throws JBException in case of general db access errors (db disconnect, shutdown, etc) */ private static IProjectPO loadProjectInSession(IReusedProjectPO reused, EntityManager session) throws JBFatalAbortException, OperationCanceledException, JBException { try { Query query = session.createQuery("select project from ProjectPO as project" //$NON-NLS-1$ + " inner join fetch project.properties where project.guid = :guid" //$NON-NLS-1$ + " and project.properties.majorNumber = :majorNumber and project.properties.minorNumber = :minorNumber"); //$NON-NLS-1$ query.setParameter("guid", reused.getProjectGuid()); //$NON-NLS-1$ query.setParameter("majorNumber", reused.getMajorNumber()); //$NON-NLS-1$ query.setParameter("minorNumber", reused.getMinorNumber()); //$NON-NLS-1$ try { return (IProjectPO) query.getSingleResult(); } catch (NoResultException nre) { return null; } } catch (PersistenceException e) { OperationCanceledUtil.checkForOperationCanceled(e); log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * Loads the project represented by the ReusedProjectPO into the master * session./*from w ww . j av a 2 s. c o m*/ * * @param reused The reused project information for the project. * @return the loaded project. * @throws JBException */ public static synchronized IProjectPO loadReusedProjectInMasterSession(IReusedProjectPO reused) throws JBException { EntityManager masterSession = GeneralStorage.getInstance().getMasterSession(); try { Query query = masterSession.createQuery("select project from ProjectPO project" //$NON-NLS-1$ + " inner join fetch project.properties where project.guid = :guid" //$NON-NLS-1$ + " and project.properties.majorNumber = :majorNumber and project.properties.minorNumber = :minorNumber"); //$NON-NLS-1$ query.setParameter("guid", reused.getProjectGuid()); //$NON-NLS-1$ query.setParameter("majorNumber", reused.getMajorNumber()); //$NON-NLS-1$ query.setParameter("minorNumber", reused.getMinorNumber()); //$NON-NLS-1$ IProjectPO project = null; try { project = (IProjectPO) query.getSingleResult(); } catch (NoResultException nre) { // No result found. project remains null. } ParamNameBP.getInstance().initParamNamesOfReusedProject(reused); UsedToolkitBP.getInstance().readUsedToolkitsFromDB(project); return project; } catch (PersistenceException e) { log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * Loads the project in a new session and then closes the session. * //from w w w. jav a2 s. c o m * @return the project with the given identifying information, or * <code>null</code> if the project could not be found. * @param reusedProjectInfo * Information for finding the reused project * @throws JBException * ... */ public static synchronized IProjectPO loadReusedProject(IReusedProjectPO reusedProjectInfo) throws JBException { EntityManager session = null; try { session = Persistor.instance().openSession(); return loadReusedProject(reusedProjectInfo, session); } catch (PersistenceException e) { log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } finally { Persistor.instance().dropSessionWithoutLockRelease(session); } }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * Loads the project in the given session. * //ww w .ja va2 s . c o m * @return the project with the given identifying information, or * <code>null</code> if the project could not be found. * @param reusedProjectInfo * Information for finding the reused project * @param session * The session into which the Project will be loaded * @throws JBException * ... */ public static synchronized IProjectPO loadReusedProject(IReusedProjectPO reusedProjectInfo, EntityManager session) throws JBException { try { Query query = session.createQuery("select project from ProjectPO project" //$NON-NLS-1$ + " inner join fetch project.properties where project.guid = :guid and project.properties.majorNumber = :major " //$NON-NLS-1$ + "and project.properties.minorNumber = :minor"); //$NON-NLS-1$ query.setParameter("guid", reusedProjectInfo.getProjectGuid()); //$NON-NLS-1$ query.setParameter("major", reusedProjectInfo.getMajorNumber()); //$NON-NLS-1$ query.setParameter("minor", reusedProjectInfo.getMinorNumber()); //$NON-NLS-1$ try { return (IProjectPO) query.getSingleResult(); } catch (NoResultException nre) { return null; } } catch (PersistenceException e) { log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * Finds the Project ID of the Project with the given GUID, Major Version * and Minor Version./* w ww . j a va 2s . c om*/ * @param projGuid the GUID * @param projMajVers the Major Version * @param projMinVers the Minor Version * @return an ID or null if not found * @throws JBException ... */ public static final synchronized Long findProjectId(String projGuid, Integer projMajVers, Integer projMinVers) throws JBException { EntityManager session = null; try { session = Persistor.instance().openSession(); Query query = session.createQuery("select project.id from ProjectPO project" //$NON-NLS-1$ + " inner join fetch project.properties where project.guid = :guid and project.properties.majorNumber = :major " //$NON-NLS-1$ + "and project.properties.minorNumber = :minor"); //$NON-NLS-1$ query.setParameter("guid", projGuid); //$NON-NLS-1$ query.setParameter("major", projMajVers); //$NON-NLS-1$ query.setParameter("minor", projMinVers); //$NON-NLS-1$ try { return (Long) query.getSingleResult(); } catch (NoResultException nre) { return null; } } catch (PersistenceException e) { log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } finally { Persistor.instance().dropSessionWithoutLockRelease(session); } }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * Gets a List of IReusedProjectPO of the Project with the given ID. * @param projectId the ID of the Project which IReusedProjectPOs are wanted. * @return a List of IReusedProjectPO or an empty List of nothing found. * @throws JBException .../*from ww w . j av a2 s. c om*/ */ public static final List<IReusedProjectPO> loadReusedProjectsRO(Long projectId) throws JBException { final List<IReusedProjectPO> cachedList = rpCache.get(projectId); if (cachedList != null && !cachedList.isEmpty()) { return cachedList; } EntityManager session = GeneralStorage.getInstance().getMasterSession(); final List<IReusedProjectPO> list = new ArrayList<IReusedProjectPO>(); try { if (projectId != null) { final Query query = session.createQuery("select reusedProj from ReusedProjectPO reusedProj" //$NON-NLS-1$ + " where reusedProj.hbmParentProjectId = :parentProjId"); //$NON-NLS-1$ query.setParameter("parentProjId", projectId); //$NON-NLS-1$ list.addAll(query.getResultList()); } } catch (PersistenceException e) { log.error(Messages.PersistenceLoadFailed, e); throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED); } rpCache.put(projectId, list); return list; }