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.IsbEntityDAOImpl.java

/**
 * Update the IsbEntityBean.//from  w  w w.  java2 s. com
 *
 * @param entity the entity
 * @param status the status
 * @param internalCreation the internal creation
 * @param internalModification the internal modification
 *
 * @return true, if successful
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private boolean update(final IsbEntityBean entity, final boolean status, final boolean internalCreation,
        final boolean internalModification) throws WhichDoctorDaoException {

    boolean success = false;

    // Get the ISB Target Type
    int isbTypeId = 0;
    try {
        ObjectTypeBean object = this.getObjectTypeDAO().load("ISB Target", "", entity.getTarget());
        isbTypeId = object.getObjectTypeId();
    } catch (Exception e) {
        throw new WhichDoctorDaoException("Error loading ISB target type: " + e.getMessage());
    }

    // Get the WhichDoctor object Type
    int objectTypeId = 0;
    try {
        ObjectTypeBean object = this.getObjectTypeDAO().load("WhichDoctor", "", entity.getObjectType());
        objectTypeId = object.getObjectTypeId();
    } catch (Exception e) {
        throw new WhichDoctorDaoException("Error loading WhichDoctor object type: " + e.getMessage());
    }

    // Set the timestamp values
    Timestamp creationTimeStamp = null;
    Timestamp updateTimeStamp = null;
    Timestamp exportTimeStamp = null;

    // Set the default values of the timestamps
    try {
        creationTimeStamp = new Timestamp(entity.getCreatedDate().getTime());
    } catch (Exception e) {
        dataLogger.debug("Creation timestamp could not be created: " + e.getMessage());
    }
    try {
        updateTimeStamp = new Timestamp(entity.getModifiedDate().getTime());
    } catch (Exception e) {
        dataLogger.debug("Update timestamp could not be created: " + e.getMessage());
    }
    try {
        exportTimeStamp = new Timestamp(entity.getExportedDate().getTime());
    } catch (Exception e) {
        dataLogger.debug("Export timestamp could not be created: " + e.getMessage());
    }

    if (internalCreation) {
        // The record has been created (added) to the ISB
        try {
            creationTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());
        } catch (Exception e) {
            dataLogger.debug("Creation timestamp could not be created: " + e.getMessage());
        }
    } else {
        if (internalModification) {
            try {
                updateTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());
            } catch (Exception e) {
                dataLogger.debug("Update timestamp could not be created: " + e.getMessage());
            }
        } else {
            try {
                exportTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());
            } catch (Exception e) {
                dataLogger.debug("Export timestamp could not be created: " + e.getMessage());
            }
        }
    }

    try {
        final int updateCount = this.getJdbcTemplateWriter().update(this.getSQL().getValue("isbentity/update"),
                new Object[] { entity.getGUID(), isbTypeId, objectTypeId, entity.getIdentifier(),
                        entity.getName(), creationTimeStamp, updateTimeStamp, exportTimeStamp, status,
                        entity.getIdentifier(), entity.getName(), creationTimeStamp, updateTimeStamp,
                        exportTimeStamp, status });

        if (updateCount > 0) {
            success = true;
        }

    } catch (DataAccessException de) {
        dataLogger.error("Error updating ISB entity: " + de.getMessage());
    }

    checkRelationships(entity);

    return success;
}

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

/**
 * Creates the address verification bean.
 *
 * @param address the address//from   w  ww .j  a  va 2 s  .  c o  m
 * @return the int
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final int create(final AddressBean address) throws WhichDoctorDaoException {

    if (address == null) {
        throw new WhichDoctorDaoException("The address cannot be null");
    }
    if (address.getGUID() < 1) {
        throw new WhichDoctorDaoException("The address requires a valid GUID");
    }
    if (StringUtils.isBlank(address.getCountry())) {
        throw new WhichDoctorDaoException("A valid country is required");
    }
    if (StringUtils.isBlank(address.getAddressField(0))) {
        throw new WhichDoctorDaoException("An address requires at least one line");
    }

    // The message for any unprocessed records
    String processedMessage = "Address verification request superceeded by " + "a WhichDoctor change";

    // Load the parent person or organisation
    int personIdentifier = 0;
    String personName = "";
    String organisationName = "";

    boolean parentFound = false;

    try {
        PersonBean person = this.personDAO.loadGUID(address.getReferenceGUID());
        if (person != null) {
            personIdentifier = person.getPersonIdentifier();
            personName = person.getPreferredName() + " " + person.getLastName();
            parentFound = true;
        }
    } catch (WhichDoctorDaoException wde) {
        dataLogger.info("No person found for the address: " + wde.getMessage());
    }

    if (!parentFound) {
        try {
            OrganisationBean org = this.organisationDAO.loadGUID(address.getReferenceGUID());
            if (org != null) {
                organisationName = org.getName();
                parentFound = true;
            }
        } catch (WhichDoctorDaoException wde) {
            dataLogger.info("No organisation found for the address: " + wde.getMessage());
        }
    }

    if (!parentFound) {
        throw new WhichDoctorDaoException(
                "No valid person or organisation is " + "associated with this address");
    }

    /* Identify the pending and processed ProcessStatusId */
    int pendingProcessStatusId = 0;
    int processedProcessStatusId = 0;

    try {
        ObjectTypeBean object = this.getObjectTypeDAO().load("Address Verification Process Status", "",
                PENDING);
        pendingProcessStatusId = object.getObjectTypeId();
    } catch (SFSDaoException sfe) {
        dataLogger.error("Error loading address verification process status: " + sfe.getMessage());
        throw new WhichDoctorDaoException("A valid address verification process status is required");
    }

    try {
        ObjectTypeBean object = this.getObjectTypeDAO().load("Address Verification Process Status", "",
                PROCESSED);
        processedProcessStatusId = object.getObjectTypeId();
    } catch (SFSDaoException sfe) {
        dataLogger.error("Error loading address verification process status: " + sfe.getMessage());
        throw new WhichDoctorDaoException("A valid address verification process status is required");
    }

    int addressVerificationId = 0;
    int createCount = 0;

    // Create the new record
    Timestamp sqlTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());

    TreeMap<Integer, String> addressMap = new TreeMap<Integer, String>();
    addressMap.put(0, address.getAddressField(0));
    addressMap.put(1, address.getAddressField(1));
    addressMap.put(2, address.getAddressField(2));
    addressMap.put(3, address.getAddressField(3));
    addressMap.put(4, address.getAddressField(4));
    addressMap.put(5, address.getAddressField(5));

    // Remove the suburb and city values from the map
    addressMap.put(address.getAddressFieldCount() - 1, "");
    addressMap.put(address.getAddressFieldCount() - 2, "");

    try {
        createCount = this.getJdbcTemplateWriter().update(this.getSQL().getValue("addressVerification/create"),
                new Object[] { address.getGUID(), address.getReferenceGUID(), personIdentifier, personName,
                        organisationName, pendingProcessStatusId, sqlTimeStamp, addressMap.get(0),
                        addressMap.get(1), addressMap.get(2), addressMap.get(3), addressMap.get(4),
                        addressMap.get(5), address.getSuburb(), address.getCity(),
                        address.getStateAbbreviation(), address.getCountry(), address.getPostCode() });

    } catch (DataAccessException de) {
        dataLogger.error("Error creating address verification record: " + de.getMessage());
        throw new WhichDoctorDaoException(
                "Error creating address verification " + "record: " + de.getMessage());
    }

    if (createCount > 0) {
        // Find the maximum address verification id
        addressVerificationId = this.getJdbcTemplateReader()
                .queryForInt(this.getSQL().getValue("addressVerification/findMax"));

        // Set the processed flag to true for any pending address
        // verification records for this address guid
        this.getJdbcTemplateWriter().update(this.getSQL().getValue("addressVerification/updateProcess"),
                new Object[] { processedProcessStatusId, processedMessage, address.getGUID(),
                        addressVerificationId, pendingProcessStatusId });

        // Update the address verification status
        this.addressDAO.updateVerificationStatus("Pending verification", address.getGUID());
    }

    return addressVerificationId;
}

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

/**
 * Used to get a OrganisationBean for a specified name with the load details
 * provided./*from   w  ww  .ja v a  2s  .  c om*/
 *
 * @param strOrganisation the str organisation
 * @param loadDetails the load details
 *
 * @return the organisation bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final OrganisationBean load(final String strOrganisation, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

    dataLogger.info("Organisation Name: " + strOrganisation + " requested");

    int organisationGUID = 0;

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

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

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

/**
 * Update the financial summary.//from  w  ww .ja  v a  2 s  .  c o  m
 *
 * @param action the action
 * @param debit the debit
 * @param typeId the type id
 * @param issued the issued
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private void updateFinancialSummary(final String action, final DebitBean debit, final int typeId,
        final Date issued) throws WhichDoctorDaoException {

    try {
        if (StringUtils.equals(action, "delete")) {
            this.getJdbcTemplateWriter().update(this.getSQL().getValue("debit/deleteSummary"),
                    new Object[] { debit.getGUID() });
        } else {
            /* Create or modify the financial summary */
            this.getJdbcTemplateWriter().update(this.getSQL().getValue("debit/editSummary"),
                    new Object[] { debit.getGUID(), typeId, debit.getNumber(), debit.getDescription(),
                            debit.getValue(), debit.getNetValue(), debit.getCancelled(), issued,
                            debit.getPersonId(), debit.getOrganisationId(),

                            typeId, debit.getNumber(), debit.getDescription(), debit.getValue(),
                            debit.getNetValue(), debit.getCancelled(), issued, debit.getPersonId(),
                            debit.getOrganisationId() });
        }
    } catch (DataAccessException dae) {
        dataLogger.error("Failed to modify the financial summary: " + dae.getMessage());
        throw new WhichDoctorDaoException("Failed to modify the financial summary: " + dae.getMessage());
    }
}

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

/**
 * A private function that refreshes the calculated debit values
 * (credit/outstanding) for the supplied debit object.
 *
 * @param debit the debit/*from  w ww .  ja v  a  2  s . co m*/
 */
private void refreshDebitValues(final DebitBean debit) {
    try {
        Double[] calculatedValues = getCalculatedValues(debit);

        final double creditValue = calculatedValues[0];
        final double outstandingValue = calculatedValues[1];

        /* Modify the financial summary */
        this.getJdbcTemplateWriter().update(this.getSQL().getValue("debit/updateValues"),
                new Object[] { creditValue, outstandingValue, debit.getGUID() });
    } catch (DataAccessException dae) {
        dataLogger.error(
                "Failed to update calculated values for GUID " + debit.getGUID() + ": " + dae.getMessage());
    }
}

From source file:com.hp.avmon.discovery.service.DiscoveryService.java

/**
 * MIB/* w  ww  .ja v a 2 s  .  c  o m*/
 * 
 * @param request
 * @return
 * @throws IOException
 */
public String importMibFile(HttpServletRequest request) throws IOException {

    String result = StringUtil.EMPTY;
    HashMap<String, ArrayList<Map<String, String>>> resultMap = new HashMap<String, ArrayList<Map<String, String>>>();
    ArrayList<Map<String, String>> files = new ArrayList<Map<String, String>>();
    String typeId = request.getParameter("typeId");
    String deviceName = request.getParameter("deviceName");
    String deviceDesc = request.getParameter("deviceDesc");
    String factory = request.getParameter("factory");
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;

    // ?
    String templatePath = Config.getInstance().getMibfilesUploadPath();
    File dirPath = new File(templatePath);
    if (!dirPath.exists()) {
        dirPath.mkdirs();
    }
    Map<String, String> fileMap;
    for (Iterator<String> it = multipartRequest.getFileNames(); it.hasNext();) {
        String fileName = (String) it.next();
        fileMap = new HashMap<String, String>();
        CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile(fileName);
        if (file != null && file.getSize() != 0) {
            String sep = System.getProperty("file.separator");
            File uploadedFile = new File(dirPath + sep + file.getOriginalFilename());
            FileCopyUtils.copy(file.getBytes(), uploadedFile);

            try {
                insertMibFileTb(file.getOriginalFilename(), typeId, deviceName, deviceDesc, factory);
                MibFileParserDB mibFileParser = new MibFileParserDB(dirPath + sep + file.getOriginalFilename());
                mibFileParser.parseMib(jdbcTemplate);
            } catch (MibLoaderException e) {
                fileMap.put("error", "Mib");
                logger.error(e.getMessage());

            } catch (DataAccessException e1) {
                logger.error(e1.getMessage());
                fileMap.put("error", "??,?");
            } catch (Exception e2) {
                logger.error(this.getClass().getName() + e2.getMessage());
                fileMap.put("error", ",?");
            }
        }

        fileMap.put("url", "");
        fileMap.put("thumbnailUrl", "");
        fileMap.put("name", file.getOriginalFilename());
        fileMap.put("type", "image/jpeg");
        fileMap.put("size", file.getSize() + "");
        fileMap.put("deleteUrl", "");
        fileMap.put("deleteType", "DELETE");
        files.add(fileMap);
    }

    resultMap.put("files", files);
    result = JackJson.fromObjectToJson(resultMap);
    logger.debug(result);
    return result;
}

From source file:com.pontecultural.flashcards.ReadSpreadsheet.java

public void endElement(String uri, String localName, String qName) throws SAXException {
    if (qName.equals(TAG_FOR_TEXT)) {
        if (inSrcLang == true) {
            inSrcLang = false;/* ww w  . ja v  a  2  s. co  m*/
            srcColumnSetP = true;
        } else if (inDestLang == true) {
            inDestLang = false;
            srcColumnSetP = false;
        }
    } else if (qName.equals(TAG_FOR_CARD)) {
        if (!(srcPhrase.isEmpty() && destPhrase.isEmpty())) {
            if (inDescription) {
                logger.debug("deck name: " + deckName + " - " + destPhrase + "\n");
                Deck d = new Deck(deckName, destPhrase);
                try {
                    this.deckId = this.jdbcFlashcardsDao.insert(d);
                } catch (DataAccessException e) {
                    SQLException sqle = (SQLException) e.getCause();
                    logger.error(e.getCause().getMessage());
                    logger.error("Error code: " + sqle.getErrorCode());
                    logger.error("SQL state: " + sqle.getSQLState());
                }

                testCountDecks++;
            } else {
                Card c = new Card(srcPhrase, destPhrase, deckId);
                try {
                    this.jdbcFlashcardsDao.insert(c);
                } catch (DataAccessException e) {
                    SQLException sqle = (SQLException) e.getCause();
                    logger.error(e.getCause().getMessage());
                    logger.error("Error code: " + sqle.getErrorCode());
                    logger.error("SQL state: " + sqle.getSQLState());
                } catch (Exception e) {
                    logger.error("hmm..what happened here: " + e.getMessage());
                }
                logger.debug("card completed");
                logger.debug("\t en: " + srcPhrase);
                logger.debug("\t pt: " + destPhrase);
                testCountCards++;
            }
            this.initializeCardState();
        }
    } else if (qName.equals(TAG_FOR_DECK)) {
        logger.debug("deck completed.");
    }
}

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

/**
 * Gets the state based on the supplied city and country values.
 *
 * @param city the city/*from www  .j  a  v  a 2 s . co m*/
 * @param country the country
 * @return the state
 */
public final String getState(final String city, final String country) {

    String state = "";

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

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

/**
 * Gets the region based on the supplied city, state and country values.
 *
 * @param city the city//from  ww  w  . j  ava2 s .  c  o m
 * @param state the state
 * @param country the country
 * @return the region
 */
public final String getRegion(final String city, final String state, final String country) {

    // By default the region is outside New Zealand
    String region = "Outside N.Z.";

    if (StringUtils.equalsIgnoreCase(country, "New Zealand")) {
        region = "Unknown";
        try {
            region = this.getJdbcTemplateReader().queryForObject(this.getSQL().getValue("address/findRegion"),
                    new Object[] { city, state, country }, String.class);
        } catch (DataAccessException dae) {
            dataLogger.error("Error loading region: " + dae.getMessage());
        }
    }
    return region;
}

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

/**
 * Gets the state based on the supplied state abbreviation.
 *
 * @param stateAbbreviation the state abbreviation
 * @return the state/*w  w  w.j  a  v a 2 s .c  o  m*/
 */
public final String getStateFromAbbreviation(final String stateAbbreviation) {

    String state = "";

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

        if (StringUtils.isBlank(state)) {
            state = stateAbbreviation;
        }
    }
    return state;
}