-
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
Open
codemakerai-dev
wants to merge
2
commits into
dev
Choose a base branch
from
demo-pull-request
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Show resolved
Hide resolved
|
||
| * @throws IllegalArgumentException if payment is null | ||
| */ | ||
| public void save(Payment payment) { | ||
codemakerai-dev marked this conversation as resolved.
Show resolved
Hide resolved
codemakerai-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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.
Show resolved
Hide resolved
|
||
| 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) { | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.