Search in sources :

Example 1 with Transaction

use of com.infiniteskills.data.entities.Transaction in project microservices by pwillhan.

the class HibernateApplication method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    SessionFactory factory = null;
    Session session = null;
    org.hibernate.Transaction tx = null;
    try {
        factory = HibernateUtil.getSessionFactory();
        session = factory.openSession();
        tx = session.beginTransaction();
        List<Transaction> transactions = session.createCriteria(Transaction.class).addOrder(Order.desc("title")).list();
        for (Transaction t : transactions) {
            System.out.println(t.getTitle());
        }
        tx.commit();
    } catch (Exception e) {
        e.printStackTrace();
        tx.rollback();
    } finally {
        session.close();
        factory.close();
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Transaction(com.infiniteskills.data.entities.Transaction) Session(org.hibernate.Session)

Example 2 with Transaction

use of com.infiniteskills.data.entities.Transaction in project microservices by pwillhan.

the class JpaApplication method main.

public static void main(String[] args) {
    EntityManagerFactory factory = null;
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        factory = Persistence.createEntityManagerFactory("infinite-finances");
        em = factory.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        // select t from transaction t
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Transaction> criteriaQuery = cb.createQuery(Transaction.class);
        Root<Transaction> root = criteriaQuery.from(Transaction.class);
        criteriaQuery.select(root);
        TypedQuery<Transaction> query = em.createQuery(criteriaQuery);
        List<Transaction> transactions = query.getResultList();
        for (Transaction t : transactions) {
            System.out.println(t.getTitle());
        }
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        e.printStackTrace();
    } finally {
        em.close();
        factory.close();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) Transaction(com.infiniteskills.data.entities.Transaction) EntityTransaction(javax.persistence.EntityTransaction) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 3 with Transaction

use of com.infiniteskills.data.entities.Transaction in project microservices by pwillhan.

the class Application method createNewBeltPurchase.

private static Transaction createNewBeltPurchase(Account account) {
    Transaction beltPurchase = new Transaction();
    beltPurchase.setAccount(account);
    beltPurchase.setTitle("Dress Belt");
    beltPurchase.setAmount(new BigDecimal("50.00"));
    beltPurchase.setClosingBalance(new BigDecimal("0.00"));
    beltPurchase.setCreatedBy("Kevin Bowersox");
    beltPurchase.setCreatedDate(new Date());
    beltPurchase.setInitialBalance(new BigDecimal("0.00"));
    beltPurchase.setLastUpdatedBy("Kevin Bowersox");
    beltPurchase.setLastUpdatedDate(new Date());
    beltPurchase.setNotes("New Dress Belt");
    beltPurchase.setTransactionType("Debit");
    return beltPurchase;
}
Also used : Transaction(com.infiniteskills.data.entities.Transaction) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 4 with Transaction

use of com.infiniteskills.data.entities.Transaction in project microservices by pwillhan.

the class Application method createShoePurchase.

private static Transaction createShoePurchase(Account account) {
    Transaction shoePurchase = new Transaction();
    shoePurchase.setAccount(account);
    shoePurchase.setTitle("Work Shoes");
    shoePurchase.setAmount(new BigDecimal("100.00"));
    shoePurchase.setClosingBalance(new BigDecimal("0.00"));
    shoePurchase.setCreatedBy("Kevin Bowersox");
    shoePurchase.setCreatedDate(new Date());
    shoePurchase.setInitialBalance(new BigDecimal("0.00"));
    shoePurchase.setLastUpdatedBy("Kevin Bowersox");
    shoePurchase.setLastUpdatedDate(new Date());
    shoePurchase.setNotes("Nice Pair of Shoes");
    shoePurchase.setTransactionType("Debit");
    return shoePurchase;
}
Also used : Transaction(com.infiniteskills.data.entities.Transaction) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 5 with Transaction

use of com.infiniteskills.data.entities.Transaction in project microservices by pwillhan.

the class Application method createShoePurchase.

private static Transaction createShoePurchase() {
    Transaction shoePurchase = new Transaction();
    shoePurchase.setTitle("Work Shoes");
    shoePurchase.setAmount(new BigDecimal("100.00"));
    shoePurchase.setClosingBalance(new BigDecimal("0.00"));
    shoePurchase.setCreatedBy("Kevin Bowersox");
    shoePurchase.setCreatedDate(new Date());
    shoePurchase.setInitialBalance(new BigDecimal("0.00"));
    shoePurchase.setLastUpdatedBy("Kevin Bowersox");
    shoePurchase.setLastUpdatedDate(new Date());
    shoePurchase.setNotes("Nice Pair of Shoes");
    shoePurchase.setTransactionType("Debit");
    return shoePurchase;
}
Also used : Transaction(com.infiniteskills.data.entities.Transaction) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Aggregations

Transaction (com.infiniteskills.data.entities.Transaction)8 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 EntityManager (javax.persistence.EntityManager)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 EntityTransaction (javax.persistence.EntityTransaction)2 Session (org.hibernate.Session)2 SessionFactory (org.hibernate.SessionFactory)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Query (org.hibernate.Query)1