Created
May 7, 2016 21:40
-
-
Save bytestree/10ab745dc7e73be6f5e14d21e55a7ac9 to your computer and use it in GitHub Desktop.
Generic DAO in Hibernate - Application class
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
package com.bytestree; | |
import java.util.List; | |
import org.apache.log4j.Logger; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Component; | |
import com.bytestree.model.Employee; | |
import com.bytestree.service.EmployeeService; | |
@Component | |
public class MyApplication { | |
final static Logger logger = Logger.getLogger(MyApplication.class); | |
@Autowired | |
private EmployeeService employeeService; | |
public void performDbTasks() | |
{ | |
// Get all employees | |
List<Employee> employeeList = employeeService.getAllEmployees(); | |
printEmployees(employeeList); | |
Employee empNew = new Employee("Bytes", "Tree", "Senior Developer", 2000); | |
// Save new employee | |
employeeService.addNewEmployee(empNew); | |
// Get all employees - to check added employee | |
employeeList = employeeService.getAllEmployees(); | |
printEmployees(employeeList); | |
Integer maxSalary = employeeService.getMaxSalary(); | |
logger.debug("Maximum salary given to employee is: " + maxSalary); | |
} | |
private void printEmployees(List<Employee> emplist) { | |
if (emplist != null) { | |
logger.debug("Found total " + emplist.size() + " records."); | |
for (Employee employee : emplist) { | |
logger.debug(employee.toString()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refer Generic DAO in Hibernate for complete example