Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Demo pull request#8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:dev
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package ai.codemaker.demo.dao; | ||
| import org.hibernate.HibernateException; | ||
| import org.hibernate.Session; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
| import java.util.ArrayList; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| public class OrderDao { | ||
| private final Session session; | ||
| private static final Logger logger = LoggerFactory.getLogger(OrderDao.class); | ||
| /** | ||
| * Constructor for OrderDao class. | ||
| * | ||
| * @param session The session to be used for the OrderDao. | ||
| */ | ||
| public OrderDao(Session session) { | ||
| this.session = session; | ||
| } | ||
| /** | ||
| * Saves the given {@link Order} in the database. | ||
| * | ||
| * @param order the {@link Order} to save | ||
| * @throws NullPointerException If the order object is null. | ||
| * @throws HibernateException if an error occurs while saving the order | ||
| */ | ||
| public void save(Order order) { | ||
| checkNotNull(order, "Order cannot be null"); | ||
| Transaction transaction = null; | ||
| try { | ||
| transaction = session.beginTransaction(); | ||
| session.save(order); | ||
| transaction.commit(); | ||
| logger.info("Order saved successfully"); | ||
| } catch (HibernateException e) { | ||
| if (transaction != null) { | ||
| transaction.rollback(); | ||
| } | ||
| logger.error("Error occurred while saving order", e); | ||
| throw e; | ||
| } | ||
| } | ||
| /** | ||
| * Updates the given Order object in the database. | ||
| * | ||
| * @param order The Order object to be updated. | ||
| * @throws NullPointerException If the order object is null. | ||
| * @throws HibernateException If an error occurs while updating the order. | ||
| */ | ||
| public void update(Order order) { | ||
| checkNotNull(order, "Order object cannot be null"); | ||
| try { | ||
| session.beginTransaction(); | ||
| session.update(order); | ||
| session.getTransaction().commit(); | ||
| } catch (HibernateException e) { | ||
| logger.error("Error occurred while updating order: " + e.getMessage()); | ||
| session.getTransaction().rollback(); | ||
| throw e; | ||
| } | ||
| } | ||
| /** | ||
| * Retrives the {@link Order} from the database transactionally. | ||
| * | ||
| * @param orderId the {@link Order} to update | ||
| * @throws NullPointerException If the orderId is null. | ||
| * @throws HibernateException if an error occurs while saving the order | ||
| */ | ||
| public void get(String orderId) { | ||
| checkNotNull(orderId, "orderId cannot be null"); | ||
| try { | ||
| session.beginTransaction(); | ||
| Order order = session.get(Order.class, orderId); | ||
| session.getTransaction().commit(); | ||
| return order; | ||
| } catch (HibernateException e) { | ||
| logger.error("Error retrieving order from database", e); | ||
| throw e; | ||
| } | ||
| } | ||
| /** | ||
| * Deletes the given order from the database. | ||
| * | ||
| * @param order the order to be deleted | ||
| * @throws NullPointerException if the order is null | ||
| * @throws HibernateException if an error occurs while deleting the order | ||
| */ | ||
| public void delete(Order order) { | ||
| checkNotNull(order, "Order cannot be null"); | ||
| try { | ||
| session.beginTransaction(); | ||
| session.delete(order); | ||
| session.getTransaction().commit(); | ||
| } catch (HibernateException e) { | ||
| logger.error("Error occurred while deleting order: {}", e.getMessage()); | ||
| session.getTransaction().rollback(); | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| public class PaymentDao { | ||
| private static final Logger logger = LoggerFactory.getLogger(PaymentDao.class); | ||
| private final Session session; | ||
| public PaymentDao(Session session) { | ||
| this.session = session; | ||
| } | ||
| /** | ||
| * Saves the given {@link Payment} in the database. | ||
| * | ||
| * @param payment the {@link Payment} to save | ||
| * @throws HibernateException if an error occurs while saving the payment | ||
codemakerai-dev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| * @throws IllegalArgumentException if payment is null | ||
| */ | ||
| public void save(Payment payment) { | ||
codemakerai-dev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. codemakerai-dev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (payment == null) { | ||
| throw new IllegalArgumentException("Payment cannot be null"); | ||
| } | ||
| try { | ||
| Transaction transaction = session.beginTransaction(); | ||
| session.save(payment); | ||
| transaction.commit(); | ||
| logger.info("Payment saved successfully"); | ||
| } catch (Exception e) { | ||
| logger.error("Error occurred while saving payment: " + e.getMessage()); | ||
| } | ||
| } | ||
| /** | ||
| * Updates the given Payment object in the database. | ||
| * | ||
| * @param payment The Payment object to be updated. | ||
| * @throws HibernateException If an error occurs while updating the payment. | ||
| */ | ||
| public void update(Payment payment) { | ||
codemakerai-dev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| try { | ||
| Transaction transaction = session.beginTransaction(); | ||
| session.update(payment); | ||
| transaction.commit(); | ||
| logger.info("Payment updated successfully"); | ||
| } catch (Exception e) { | ||
| logger.error("Error occurred while updating payment: " + e.getMessage()); | ||
| } | ||
| } | ||
| /** | ||
| * Retrives the {@link Payment} from the database transactionally. | ||
| * | ||
| * @param paymentId the {@link Payment} to update | ||
| * @throws HibernateException if an error occurs while saving the payment | ||
| */ | ||
| public Payment get(String id) { | ||
| } | ||
| /** | ||
| * Deletes the given {@link Payment} to the database. | ||
| * | ||
| * @param payment the {@link Payment} to update | ||
| * @throws HibernateException if an error occurs while saving the payment | ||
| */ | ||
| public void delete(Payment payment) { | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.