Example usage for org.springframework.dao DataAccessException getMessage

List of usage examples for org.springframework.dao DataAccessException getMessage

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:com.sfs.whichdoctor.dao.AddressDAOImpl.java

/**
 * Gets the country based on the supplied country abbreviation.
 *
 * @param countryAbbreviation the country abbreviation
 * @return the country/*from w ww  .ja v  a  2s.  c om*/
 */
public final String getCountryFromAbbreviation(final String countryAbbreviation) {

    String country = "";

    if (StringUtils.isNotBlank(countryAbbreviation)) {
        try {
            country = this.getJdbcTemplateReader().queryForObject(
                    this.getSQL().getValue("address/findCountryFromAbbreviation"),
                    new Object[] { countryAbbreviation }, String.class);
        } catch (DataAccessException dae) {
            dataLogger.error("Error loading country: " + dae.getMessage());
        }

        if (StringUtils.isBlank(country)) {
            country = countryAbbreviation;
        }
    }
    return country;
}

From source file:org.openspaces.rest.space.SpaceAPIController.java

/**
 * REST GET by query request handler//from ww  w.  java2  s  .c o  m
 *
 * @param type
 * @param query
 * @return
 * @throws ObjectNotFoundException
 */
@ApiMethod(path = "{type}/", verb = ApiVerb.GET, description = "Read multiple entries from space that matches the query.", produces = {
        MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/{type}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> getByQuery(
        @PathVariable() @ApiPathParam(name = "type", description = TYPE_DESCRIPTION) String type,
        @RequestParam(value = QUERY_PARAM, required = false) @ApiQueryParam(name = "query", description = "a SQLQuery that is a SQL-like syntax") String query,
        @RequestParam(value = MAX_PARAM, required = false) @ApiQueryParam(name = "size", description = "") Integer size)
        throws ObjectNotFoundException {
    if (logger.isLoggable(Level.FINE))
        logger.fine("creating read query with type: " + type + " and query: " + query);

    if (query == null) {
        query = ""; //Query all the data
    }

    GigaSpace gigaSpace = ControllerUtils.xapCache.get();
    SQLQuery<Object> sqlQuery = new SQLQuery<Object>(type, query);
    int maxSize = (size == null ? maxReturnValues : size.intValue());
    Object[] docs;
    try {
        docs = gigaSpace.readMultiple(sqlQuery, maxSize);
    } catch (DataAccessException e) {
        throw translateDataAccessException(gigaSpace, e, type);
    }

    try {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("status", "success");
        result.put("data", ControllerUtils.mapper.readValue(ControllerUtils.mapper.writeValueAsString(docs),
                ArrayList.class));
        return result;
    } catch (IOException e) {
        throw new RestException(e.getMessage());
    }
}

From source file:org.openspaces.rest.space.SpaceAPIController.java

/**
 * REST DELETE by id request handler/*  w  w  w  . j ava  2s  .  co  m*/
 *
 * @param type
 * @param id
 * @return
 * @throws ObjectNotFoundException
 */
@ApiMethod(path = "{type}/{id}", verb = ApiVerb.DELETE, description = "Gets and deletes the entry from space with the provided id.", produces = {
        MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/{type}/{id}", method = RequestMethod.DELETE, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> deleteById(
        @ApiPathParam(name = "type", description = TYPE_DESCRIPTION) @PathVariable String type,
        @ApiPathParam(name = "id") @PathVariable String id) throws ObjectNotFoundException {

    GigaSpace gigaSpace = ControllerUtils.xapCache.get();
    //take by id
    Object typedBasedId = getTypeBasedIdObject(gigaSpace, type, id);
    if (logger.isLoggable(Level.FINE))
        logger.fine("creating takebyid query with type: " + type + " and id: " + id);
    Object doc;
    try {
        doc = gigaSpace.takeById(new IdQuery<Object>(type, typedBasedId));
    } catch (DataAccessException e) {
        throw translateDataAccessException(gigaSpace, e, type);
    }

    if (doc == null) {
        doc = emptyObject;
    }

    try {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("status", "success");
        result.put("data",
                ControllerUtils.mapper.readValue(ControllerUtils.mapper.writeValueAsString(doc), Map.class));
        return result;
    } catch (IOException e) {
        throw new RestException(e.getMessage());
    }
}

From source file:org.openspaces.rest.space.SpaceAPIController.java

/**
 * REST DELETE by query request handler//  ww  w . java2  s  .c  o m
 *
 * @param type
 * @param query
 * @return
 */
@ApiMethod(path = "{type}/", verb = ApiVerb.DELETE, description = "Gets and deletes entries from space that matches the query.", produces = {
        MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/{type}", method = RequestMethod.DELETE, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> deleteByQuery(
        @ApiPathParam(name = "type", description = TYPE_DESCRIPTION) @PathVariable String type,
        @ApiQueryParam(name = "query") @RequestParam(value = QUERY_PARAM) String query,
        @ApiQueryParam(name = "max", description = "The maximum number of entries to return. Default is Integer.MAX_VALUE") @RequestParam(value = MAX_PARAM, required = false) Integer max) {
    if (logger.isLoggable(Level.FINE))
        logger.fine("creating take query with type: " + type + " and query: " + query);

    GigaSpace gigaSpace = ControllerUtils.xapCache.get();
    SQLQuery<Object> sqlQuery = new SQLQuery<Object>(type, query);
    int maxSize = (max == null ? maxReturnValues : max.intValue());
    Object[] docs;
    try {
        docs = gigaSpace.takeMultiple(sqlQuery, maxSize);
    } catch (DataAccessException e) {
        throw translateDataAccessException(gigaSpace, e, type);
    }

    if (docs == null) {
        docs = new Object[] {};
    }

    try {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("status", "success");
        result.put("data", ControllerUtils.mapper.readValue(ControllerUtils.mapper.writeValueAsString(docs),
                ArrayList.class));
        return result;
    } catch (IOException e) {
        throw new RestException(e.getMessage());
    }
}

From source file:org.openspaces.rest.space.SpaceAPIController.java

/**
 * REST GET by ID request handler//from w ww  .ja  v  a  2  s.  com
 *
 * @param type
 * @param id
 * @return
 * @throws ObjectNotFoundException
 * @throws UnknownTypeException
 */
@ApiMethod(path = "{type}/{id}", verb = ApiVerb.GET, description = "Read entry from space with the provided id", produces = {
        MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/{type}/{id}", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> getById(
        @PathVariable @ApiPathParam(name = "type", description = TYPE_DESCRIPTION) String type,
        @PathVariable @ApiPathParam(name = "id") String id) throws ObjectNotFoundException {
    GigaSpace gigaSpace = ControllerUtils.xapCache.get();
    //read by id request
    Object typedBasedId = getTypeBasedIdObject(gigaSpace, type, id);
    if (logger.isLoggable(Level.FINE))
        logger.fine("creating readbyid query with type: " + type + " and id: " + id);
    IdQuery<Object> idQuery = new IdQuery<Object>(type, typedBasedId);
    Object doc;
    try {
        doc = gigaSpace.readById(idQuery);
    } catch (DataAccessException e) {
        throw translateDataAccessException(gigaSpace, e, type);
    }

    if (doc == null) {
        doc = emptyObject;
    }

    try {
        Map<String, Object> result = new LinkedHashMap<String, Object>();
        result.put("status", "success");
        result.put("data", ControllerUtils.mapper.readValue(ControllerUtils.mapper.writeValueAsString(doc),
                LinkedHashMap.class));
        return result;
    } catch (IOException e) {
        throw new RestException(e.getMessage());
    }
}

From source file:com.sfs.whichdoctor.dao.MembershipDAOImpl.java

/**
 * Update the training status.//from w  w w .  jav a  2s. c  om
 *
 * @param person the person
 * @param trainingStatusId the training status id
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private void updateTrainingStatus(final PersonBean person, final int trainingStatusId)
        throws WhichDoctorDaoException {

    String trainingStatus = "";
    String trainingStatusDetail = "";

    switch (trainingStatusId) {
    case NOT_IN_TRAINING:
        trainingStatus = "Not in training";
        break;
    case STANDARD_TRAINING:
        trainingStatus = "Training";
        trainingStatusDetail = "Standard";
        break;
    case STANDARD_NO_CURRENT:
        trainingStatus = "Training";
        trainingStatusDetail = "No current rotation";
        break;
    case STANDARD_POST_FRACP:
        trainingStatus = "Training";
        trainingStatusDetail = "Post-FRACP";
        break;
    case CONDITIONAL_REQUIRES_UPGRADE:
        trainingStatus = "Conditional training";
        trainingStatusDetail = "Requires upgrade";
        break;
    case CONDITIONAL_UNMET:
        trainingStatus = "Conditional training";
        trainingStatusDetail = "Unmet requirements";
        break;
    case CONDITIONAL_NO_CURRENT:
        trainingStatus = "Conditional training";
        trainingStatusDetail = "No current rotation";
        break;
    case CONDITIONAL_CONTINUING:
        trainingStatus = "Conditional training";
        trainingStatusDetail = "Continuing training";
        break;
    }

    int objectTypeId = 0;
    try {
        ObjectTypeBean object = this.getObjectTypeDAO().load("Training Status", trainingStatusDetail,
                trainingStatus);
        objectTypeId = object.getObjectTypeId();
    } catch (SFSDaoException sfe) {
        dataLogger.error("Error loading objecttype for the training status: " + sfe.getMessage());
    }

    dataLogger.info("Training status update for GUID: " + person.getGUID());
    dataLogger.info("Training status: " + trainingStatus);
    dataLogger.info("Training status detail: " + trainingStatusDetail);

    boolean updateTrainingStatus = false;

    if (!StringUtils.equalsIgnoreCase(person.getTrainingStatus(), trainingStatus)) {
        updateTrainingStatus = true;
    }
    if (!StringUtils.equalsIgnoreCase(person.getTrainingStatusDetail(), trainingStatusDetail)) {
        updateTrainingStatus = true;
    }

    if (updateTrainingStatus) {

        /* Begin the ISB transaction */
        IsbTransactionBean isbTransaction = this.isbTransactionDAO.begin(person.getGUID());

        int updateCount = 0;

        try {
            updateCount = this.getJdbcTemplateWriter().update(
                    this.getSQL().getValue("person/updateTrainingStatus"),
                    new Object[] { objectTypeId, person.getGUID() });

        } catch (DataAccessException de) {
            dataLogger.error("Error updating the training status id for person guid: " + person.getGUID() + ", "
                    + de.getMessage());
        }
        if (updateCount > 0) {
            /* Commit the ISB transaction */
            this.isbTransactionDAO.commit(isbTransaction);
        }
    }
}

From source file:com.sfs.whichdoctor.dao.RotationDAOImpl.java

/**
 * Load a RotationBean for a specified name and supplied load details.
 *
 * @param strRotation the str rotation//from   ww w  . j  av  a2s  .c o m
 * @param loadDetails the load details
 *
 * @return the rotation bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final RotationBean load(final String strRotation, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

    dataLogger.info("Rotation Name: " + strRotation + " requested");

    int rotationGUID = 0;

    final String loadSQL = getSQL().getValue("rotation/loadName");

    try {
        rotationGUID = this.getJdbcTemplateReader().queryForInt(loadSQL, new Object[] { strRotation });
    } catch (DataAccessException de) {
        dataLogger.error("Error getting guid for supplied rotation: " + de.getMessage());
    }
    if (rotationGUID > 0) {
        return loadGUID(rotationGUID, loadDetails);
    } else {
        throw new WhichDoctorDaoException("Sorry no rotation matching " + "those details could be identified");
    }
}

From source file:com.sfs.whichdoctor.dao.RotationDAOImpl.java

/**
 * Update excess level./*from   ww  w . j a  va 2 s  .  co m*/
 *
 * @param guid the guid
 * @param trainingTypeId the training type id
 */
private void updateExcessLevel(final int guid, final int trainingTypeId) {
    try {
        this.getJdbcTemplateWriter().update(this.getSQL().getValue("rotation/updateRotationExcess"),
                new Object[] { trainingTypeId, guid });

    } catch (DataAccessException de) {
        dataLogger.error("Error updating excess flag of rotation guid: " + guid + ", " + de.getMessage());
    }
}

From source file:com.sfs.whichdoctor.dao.RotationDAOImpl.java

/**
 * Rebuild the workplace index for all rotations.
 *
 * @param user the user//from w  w  w .  java2s .c  o m
 * @param privileges the privileges
 */
public final void rebuildWorkplaceReferences(final UserBean user, final PrivilegesBean privileges) {

    // Delete the existing linked workplace details as this process will recreate them
    try {
        // Delete the corresponding GUID entries for these workplace entries
        this.getJdbcTemplateWriter().update(this.getSQL().getValue("rotation/deleteWorkplaceGUIDEntries"),
                new Object[] {});

        // Delete item entries with a ReferenceGUID > 0
        this.getJdbcTemplateWriter().update(this.getSQL().getValue("rotation/deleteWorkplaceEntries"),
                new Object[] {});

    } catch (DataAccessException dae) {
        dataLogger.error("Error removing existing rotation linked workplaces: " + dae.getMessage());
    }

    SearchBean search = this.getSearchDAO().initiate("rotation", new UserBean());
    search.setLimit(0);
    SearchResultsBean results = null;
    try {
        final BuilderBean loadDetails = new BuilderBean();
        loadDetails.setParameter("SUPERVISORS", true);
        results = this.getSearchDAO().search(search, loadDetails);
    } catch (WhichDoctorSearchDaoException wse) {
        dataLogger.error("Error performing rotation search: " + wse.getMessage());
    }

    if (results != null) {
        for (Object objRotation : results.getSearchResults()) {
            RotationBean rotation = (RotationBean) objRotation;
            try {
                this.updateWorkplace(rotation, new ArrayList<Integer>(), "modify", user, privileges);
                dataLogger.error("Refreshed workplace for rotation: " + rotation.getGUID());
            } catch (WhichDoctorDaoException wde) {
                dataLogger.error("Error refreshing workplace for rotation:" + rotation.getGUID() + ": "
                        + wde.getMessage());
            }
        }
    }
}

From source file:com.sfs.whichdoctor.dao.PersonDAOImpl.java

/**
 * Load a PersonBean for a specified name using the load options provided.
 *
 * @param strPerson the str person//from w  w w .  ja v  a  2  s .co  m
 * @param loadDetails the load details
 *
 * @return the person bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final PersonBean load(final String strPerson, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

    dataLogger.info("Person Name: " + strPerson + " requested");

    int personGUID = 0;

    final String loadSQL = getSQL().getValue("person/loadName");

    try {
        personGUID = this.getJdbcTemplateReader().queryForInt(loadSQL, new Object[] { strPerson });
    } catch (DataAccessException de) {
        dataLogger.error("Error getting guid for supplied person: " + de.getMessage());
    }
    if (personGUID > 0) {
        return loadGUID(personGUID, loadDetails);
    } else {
        throw new WhichDoctorDaoException("Sorry no person matching those " + "details could be identified");
    }
}