com.matel.pg.dao.impl.CustomerDAOImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.matel.pg.dao.impl.CustomerDAOImpl.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matel.pg.dao.impl;

import com.matel.domain.Product;
import com.matel.domain.UserProfile;
import com.matel.pg.dao.CustomerDAO;
import com.matel.pg.mock.domain.Customer;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Repository
@Component("customerDAO")
public class CustomerDAOImpl implements CustomerDAO {

    @Autowired
    SessionFactory sessionFactory;

    @Override
    public void save(Set<Customer> customersToSave) {
        if (customersToSave.toArray().length > 0) {
            System.out.println(((Customer) (customersToSave.toArray()[0])).getQboId());
        }
        //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void saveUsers(Set<UserProfile> customersToSave) {
        for (UserProfile profile : customersToSave) {
            System.out.println(".............. QBOID: " + profile.getQboUserProfile().getQboId());
            try {
                Session session = sessionFactory.getCurrentSession();
                session.saveOrUpdate(profile.getQboUserProfile());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}