Example usage for org.springframework.orm.jpa JpaSystemException getLocalizedMessage

List of usage examples for org.springframework.orm.jpa JpaSystemException getLocalizedMessage

Introduction

In this page you can find the example usage for org.springframework.orm.jpa JpaSystemException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.mothsoft.alexis.engine.textual.ParseResponseMessageListener.java

private Term findOrCreateTerm(final String value, final PartOfSpeech partOfSpeech) {
    final int maxTries = 20;
    int retryCount = maxTries;

    Term term = null;/*w w  w  .  j a v a2 s  . c  o  m*/
    while (term == null && retryCount > 0) {
        retryCount--;

        try {
            term = this.transactionTemplate.execute(new TransactionCallback<Term>() {
                public Term doInTransaction(TransactionStatus status) {
                    try {
                        Term term = ParseResponseMessageListener.this.termDao.find(value, partOfSpeech);
                        if (term == null) {
                            term = new Term(value, partOfSpeech);
                            ParseResponseMessageListener.this.termDao.add(term);
                        }
                        return term;
                    } catch (JpaSystemException e) {
                        throw new TransactionSystemException(e.getLocalizedMessage());
                    }
                }
            });
        } catch (TransactionException e) {
            if (retryCount == 0) {
                logger.error("Retried transaction " + maxTries + " times; failed every time!" + e, e);
                throw e;
            } else {
                logger.warn("Experienced transaction failure: " + e.getLocalizedMessage() + "; will retry!");
                continue;
            }
        }
    }

    return term;
}