use of net.petafuel.styx.core.persistence.PersistenceException in project styx by petafuel.
the class PersistentPayment method getByPaymentId.
public static PaymentEntry getByPaymentId(String paymentId) {
Connection connection = Persistence.getInstance().getConnection();
PaymentEntry paymentEntry = null;
try (PreparedStatement query = connection.prepareStatement("SELECT * FROM get_payment_by_payment_id(?)")) {
query.setString(1, paymentId);
try (ResultSet resultSet = query.executeQuery()) {
if (resultSet.next()) {
paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
if (resultSet.getString(COLUMN_CLIENT_TOKEN) != null) {
AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
paymentEntry.setClientToken(accessToken);
}
if (resultSet.getString(COLUMN_STATUS) != null) {
paymentEntry.setStatus(TransactionStatus.valueOf(resultSet.getString(COLUMN_STATUS)));
}
paymentEntry.setPaymentService(PaymentService.valueOf(resultSet.getString(COLUMN_SERVICE)));
paymentEntry.setPaymentProduct(PaymentProduct.valueOf(resultSet.getString(COLUMN_PRODUCT)));
}
}
} catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IntrospectionException e) {
LOG.error(ERROR_MODEL_MAPPING, e.getMessage());
throw new PersistenceException(e.getMessage(), e);
} catch (SQLException e) {
LOG.error("Error executing get_payment_by_payment_id() for payment_id={} state={} message={}", paymentId, e.getSQLState(), e.getMessage());
throw new PersistenceException(e.getMessage(), e);
}
return paymentEntry;
}
use of net.petafuel.styx.core.persistence.PersistenceException in project styx by petafuel.
the class PersistentPayment method updateStatusByPaymentId.
public static PaymentEntry updateStatusByPaymentId(String paymentId, TransactionStatus transactionStatus) {
Connection connection = Persistence.getInstance().getConnection();
PaymentEntry paymentEntry = null;
try (PreparedStatement query = connection.prepareStatement("SELECT * FROM update_payment_status_by_payment_id(?, ?)")) {
query.setString(1, paymentId);
query.setString(2, transactionStatus.name());
try (ResultSet resultSet = query.executeQuery()) {
if (resultSet.next()) {
paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
paymentEntry.setClientToken(accessToken);
paymentEntry.setStatus(TransactionStatus.valueOf(resultSet.getString(COLUMN_STATUS)));
paymentEntry.setPaymentService(PaymentService.valueOf(resultSet.getString(COLUMN_SERVICE)));
paymentEntry.setPaymentProduct(PaymentProduct.valueOf(resultSet.getString(COLUMN_PRODUCT)));
}
}
} catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IntrospectionException e) {
LOG.error(ERROR_MODEL_MAPPING, e.getMessage());
throw new PersistenceException(e.getMessage(), e);
} catch (SQLException e) {
LOG.error("Error executing update_payment_status_by_payment_id() for paymentId={} state={} message={}", paymentId, e.getSQLState(), e.getMessage());
throw new PersistenceException(e.getMessage(), e);
}
return paymentEntry;
}
use of net.petafuel.styx.core.persistence.PersistenceException in project styx by petafuel.
the class PersistentPayment method deleteByPaymentId.
public static PaymentEntry deleteByPaymentId(String paymentId) {
Connection connection = Persistence.getInstance().getConnection();
PaymentEntry paymentEntry = null;
try (PreparedStatement query = connection.prepareStatement("SELECT * FROM delete_payment_by_payment_id(?)")) {
query.setString(1, paymentId);
try (ResultSet resultSet = query.executeQuery()) {
if (resultSet.next()) {
paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
paymentEntry.setClientToken(accessToken);
paymentEntry.setStatus(TransactionStatus.valueOf(resultSet.getString(COLUMN_STATUS)));
paymentEntry.setPaymentService(PaymentService.valueOf(resultSet.getString(COLUMN_SERVICE)));
paymentEntry.setPaymentProduct(PaymentProduct.valueOf(resultSet.getString(COLUMN_PRODUCT)));
}
}
} catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IntrospectionException e) {
LOG.error(ERROR_MODEL_MAPPING, e.getMessage());
throw new PersistenceException(e.getMessage(), e);
} catch (SQLException e) {
LOG.error("Error executing delete_payment_by_payment_id() for paymentId={} state={} message={}", paymentId, e.getSQLState(), e.getMessage());
throw new PersistenceException(e.getMessage(), e);
}
return paymentEntry;
}
use of net.petafuel.styx.core.persistence.PersistenceException in project styx by petafuel.
the class PersistentPayment method updateById.
public static PaymentEntry updateById(String id, String clientToken, String bic, TransactionStatus transactionStatus) {
Connection connection = Persistence.getInstance().getConnection();
PaymentEntry paymentEntry = null;
try (PreparedStatement query = connection.prepareStatement("SELECT * FROM update_payment_by_id(?, ?, ?, ?)")) {
query.setString(1, id);
query.setString(2, clientToken);
query.setString(3, bic);
query.setString(4, transactionStatus.name());
try (ResultSet resultSet = query.executeQuery()) {
if (resultSet.next()) {
paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
paymentEntry.setClientToken(accessToken);
paymentEntry.setStatus(TransactionStatus.valueOf(resultSet.getString(COLUMN_STATUS)));
paymentEntry.setPaymentService(PaymentService.valueOf(resultSet.getString(COLUMN_SERVICE)));
paymentEntry.setPaymentProduct(PaymentProduct.valueOf(resultSet.getString(COLUMN_PRODUCT)));
}
}
} catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IntrospectionException e) {
LOG.error(ERROR_MODEL_MAPPING, e.getMessage());
throw new PersistenceException(e.getMessage(), e);
} catch (SQLException e) {
LOG.error("Error executing update_payment_by_id() for id={} bic={} state={} message={}", id, bic, e.getSQLState(), e.getMessage());
throw new PersistenceException(e.getMessage(), e);
}
return paymentEntry;
}
use of net.petafuel.styx.core.persistence.PersistenceException in project styx by petafuel.
the class PersistentPayment method getById.
public static PaymentEntry getById(String id) {
Connection connection = Persistence.getInstance().getConnection();
PaymentEntry paymentEntry = null;
try (PreparedStatement query = connection.prepareStatement("SELECT * FROM get_payment_by_id(?)")) {
query.setString(1, id);
try (ResultSet resultSet = query.executeQuery()) {
if (resultSet.next()) {
paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
if (resultSet.getString(COLUMN_CLIENT_TOKEN) != null) {
AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
paymentEntry.setClientToken(accessToken);
}
if (resultSet.getString(COLUMN_STATUS) != null) {
paymentEntry.setStatus(TransactionStatus.valueOf(resultSet.getString(COLUMN_STATUS)));
}
paymentEntry.setPaymentService(PaymentService.valueOf(resultSet.getString(COLUMN_SERVICE)));
paymentEntry.setPaymentProduct(PaymentProduct.valueOf(resultSet.getString(COLUMN_PRODUCT)));
}
}
} catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IntrospectionException e) {
LOG.error(ERROR_MODEL_MAPPING, e.getMessage());
throw new PersistenceException(e.getMessage(), e);
} catch (SQLException e) {
LOG.error("Error executing get_payment_by_id() for id={} state={} message={}", id, e.getSQLState(), e.getMessage());
throw new PersistenceException(e.getMessage(), e);
}
return paymentEntry;
}
Aggregations