diff --git a/.gitignore b/.gitignore
index e87e1c64..fd610ab8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
*.class
*.jar
classes/
+.*
diff --git a/java/HRWebApp/Readme.md b/java/HRWebApp/Readme.md
new file mode 100644
index 00000000..f603a356
--- /dev/null
+++ b/java/HRWebApp/Readme.md
@@ -0,0 +1,37 @@
+# Overview of the HR Web Application
+
+**HR Web Application** is the Java application that uses Oracle Java Database Connectivity (JDBC), Universal Connection Pool (UCP), and Oracle Java in the Database (OJVM) with Oracle Database 12c Release 2.
+
+It is a light weight web application that uses the MVC (Model, View, Controller) architecture and all the latest tools and technologies. The presentation layer uses HTML that internally uses JavaScript, JQuery, and CSS to display the results. The controller will be a servlet that talks to the Oracle Database through the Java Beans. Maven is used for building the application.
+
+This Java application leverages HR schema and Employees table of the Oracle Database 12c Release 2. It is intended to help the HR team of AnyCo Corporation to store the details of all the employees, add any new employee, update the employee details, delete any employee, or provide a salary hike to all employees. It has two users **HRStaff** and **HRAdmin** who have different roles and access to the application.
+
+The application has the following functionalities.
+
+
+* **About** :
+This page provides an overview of the HR Application and explains the various functionalities it offers.
+
+* **List All Employees** :
+Use this functionality to retrieve employees information. It lists the employee information such as Employee_ID, First_Name, Last_Name, Email, Phone_Number, Job_Id, and Salary.
+
+* **Search By Employee ID:** :
+Use Employee ID that is the primary key of Employees table to search for a particular employee.
+
+* **Update Employee Record:** :
+Search for a particular employee based on the name of the employee. You can then update employee details in the record, such as first_name, last_name, email, phone_number, job_id and salary using this function.
+
+* **Delete an Employee Record:** :
+Search for a particular employee record to be deleted using **Search by Employee ID** functionality and then, use the DELETE function to the delete the entire employee record.
+
+* **Increment Salary:** :
+Through this functionality, you can alter (increase or decrease) the percentage of the salary hike. A business logic to distribute this salary hike is executed through a stored procedure using Java in the database.
+
+
+
+
+
+
+
+
+
diff --git a/java/HRWebApp/pom.xml b/java/HRWebApp/pom.xml
new file mode 100644
index 00000000..26e4d6a5
--- /dev/null
+++ b/java/HRWebApp/pom.xml
@@ -0,0 +1,79 @@
+
+ 4.0.0
+ com.oracle.jdbc
+ JdbcWebSamples
+ war
+ 1.0-SNAPSHOT
+ JdbcWebSamples Maven Webapp
+ http://maven.apache.org
+
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+
+
+
+
+ com.google.code.gson
+ gson
+ 2.5
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+ com.oracle.jdbc
+ ojdbc8
+ 12.2.0.1
+
+
+
+ JdbcWebSamples
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.5.1
+
+ 1.8
+ 1.8
+
+
+
+
+
+
+
+ maven.oracle.com
+ oracle-maven-repo
+ https://maven.oracle.com
+ default
+
+ true
+ always
+
+
+
+
+
+
+ maven.oracle.com
+ oracle-maven-repo
+ https://maven.oracle.com
+ default
+
+ true
+ always
+
+
+
+
+
diff --git a/java/HRWebApp/settings-security.xml b/java/HRWebApp/settings-security.xml
new file mode 100644
index 00000000..7fee036a
--- /dev/null
+++ b/java/HRWebApp/settings-security.xml
@@ -0,0 +1,3 @@
+
+ {generate_master_password_and_add_here}
+
diff --git a/java/HRWebApp/settings.xml b/java/HRWebApp/settings.xml
new file mode 100644
index 00000000..0a924f16
--- /dev/null
+++ b/java/HRWebApp/settings.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+ maven.oracle.com
+ {Username registered on maven.oracle.com}
+ {Add_registered_password_here}
+
+
+ ANY
+ ANY
+ OAM 11g
+
+
+
+
+
+ http.protocol.allow-circular-redirects
+ %b,true
+
+
+
+
+
+
+
+
+
diff --git a/java/HRWebApp/src/conf/MANIFEST.MF b/java/HRWebApp/src/conf/MANIFEST.MF
new file mode 100644
index 00000000..59499bce
--- /dev/null
+++ b/java/HRWebApp/src/conf/MANIFEST.MF
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+
diff --git a/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/bean/JdbcBean.java b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/bean/JdbcBean.java
new file mode 100644
index 00000000..2dbd4af2
--- /dev/null
+++ b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/bean/JdbcBean.java
@@ -0,0 +1,50 @@
+/*
+ * 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.oracle.jdbc.samples.bean;
+
+import java.util.List;
+import com.oracle.jdbc.samples.entity.Employee;
+
+/**
+ *
+ * @author nirmala.sundarappa@oracle.com
+ */
+public interface JdbcBean {
+ /**
+ * Get a list of Employees
+ * @return List of employees
+ */
+ public List getEmployees();
+
+ /**
+ * Get List of employee based on empId. This will always return one row
+ * but returning a List to be make signatures consistent.
+ * @param empId
+ * @return
+ */
+ public List getEmployee(int empId);
+
+ /**
+ * Update employee based on employee-id. Returns the updated record.
+ * @param empId
+ * @return updated record.
+ */
+ public Employee updateEmployee(int empId);
+
+ /**
+ * Get List of employees by First Name pattern
+ * @param fn
+ * @return List of employees with given beginning pattern
+ */
+ public List getEmployeeByFn(String fn);
+
+ /**
+ * Increment salary by a percentage
+ * @param incrementPct percent increase
+ * @return List of employees with incremented salary
+ */
+ public List incrementSalary(int incrementPct);
+}
diff --git a/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/bean/JdbcBeanImpl.java b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/bean/JdbcBeanImpl.java
new file mode 100644
index 00000000..d7c3be77
--- /dev/null
+++ b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/bean/JdbcBeanImpl.java
@@ -0,0 +1,128 @@
+package com.oracle.jdbc.samples.bean;
+
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import com.oracle.jdbc.samples.entity.Employee;
+import oracle.jdbc.OracleTypes;
+
+
+import java.sql.PreparedStatement;
+import oracle.jdbc.OracleStatement;
+import oracle.jdbc.OracleConnection;
+
+import oracle.jdbc.driver.OracleDriver;
+
+/**
+ *
+ * @author nirmala.sundarappa@oracle.com
+ */
+public class JdbcBeanImpl implements JdbcBean {
+
+ public static Connection getConnection() throws SQLException {
+ DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
+ Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@//myorclhost:1521/myorcldbservice", "hr", "hr");
+
+ return connection;
+ }
+
+ @Override
+ public List getEmployees() {
+ List returnValue = new ArrayList<>();
+ try (Connection connection = getConnection()) {
+ try (Statement statement = connection.createStatement()) {
+ try (ResultSet resultSet = statement.executeQuery("SELECT Employee_Id, First_Name, Last_Name, Email, Phone_Number, Job_Id, Salary FROM EMPLOYEES")) {
+ while(resultSet.next()) {
+ returnValue.add(new Employee(resultSet));
+ }
+ }
+ }
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, null, ex);
+ ex.printStackTrace();
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * Returns the employee object for the given empId. Returns
+ * @param empId
+ * @return
+ */
+ @Override
+ public List getEmployee(int empId) {
+ List returnValue = new ArrayList<>();
+
+ try (Connection connection = getConnection()) {
+ try (PreparedStatement preparedStatement = connection.prepareStatement(
+ "SELECT Employee_Id, First_Name, Last_Name, Email, Phone_Number, Job_Id, Salary FROM EMPLOYEES WHERE Employee_Id = ?")) {
+ preparedStatement.setInt(1, empId);
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ if(resultSet.next()) {
+ returnValue.add(new Employee(resultSet));
+ }
+ }
+ }
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, null, ex);
+ ex.printStackTrace();
+ }
+
+ return returnValue;
+ }
+
+ @Override
+ public Employee updateEmployee(int empId) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public List getEmployeeByFn(String fn) {
+ List returnValue = new ArrayList<>();
+
+ try (Connection connection = getConnection()) {
+ try (PreparedStatement preparedStatement = connection.prepareStatement(
+ "SELECT Employee_Id, First_Name, Last_Name, Email, Phone_Number, Job_Id, Salary FROM EMPLOYEES WHERE First_Name LIKE ?")) {
+ preparedStatement.setString(1, fn + '%');
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ while(resultSet.next()) {
+ returnValue.add(new Employee(resultSet));
+ }
+ }
+ }
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, null, ex);
+ ex.printStackTrace();
+ }
+
+ return returnValue;
+ }
+
+ @Override
+ public List incrementSalary (int incrementPct) {
+ List returnValue = new ArrayList<>();
+
+ try (Connection connection = getConnection()) {
+ try (CallableStatement callableStatement = connection.prepareCall("begin ? := refcur_pkg.incrementsalary(?); end;")) {
+ callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
+ callableStatement.setInt(2, incrementPct);
+ callableStatement.execute();
+ try (ResultSet resultSet = (ResultSet) callableStatement.getObject(1)) {
+ while (resultSet.next()) {
+ returnValue.add(new Employee(resultSet));
+ }
+ }
+ }
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, null, ex);
+ ex.printStackTrace();
+ }
+
+ return returnValue;
+ }
+
+ static final Logger logger = Logger.getLogger("com.oracle.jdbc.samples.bean.JdbcBeanImpl");
+}
diff --git a/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/entity/Employee.java b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/entity/Employee.java
new file mode 100644
index 00000000..170a7b91
--- /dev/null
+++ b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/entity/Employee.java
@@ -0,0 +1,93 @@
+/*
+ * 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.oracle.jdbc.samples.entity;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+
+/**
+ *
+ * @author nirmala.sundarappa@oracle.com
+ */
+public class Employee {
+
+ private int Employee_Id;
+ private String First_Name;
+ private String Last_Name;
+ private String Email;
+ private String Phone_Number;
+ private String Job_Id;
+ private int Salary;
+
+ public Employee(ResultSet resultSet) throws SQLException {
+ this.Employee_Id = resultSet.getInt(1);
+ this.First_Name = resultSet.getString(2);
+ this.Last_Name = resultSet.getString(3);
+ this.Email = resultSet.getString(4);
+ this.Phone_Number = resultSet.getString(5);
+ this.Job_Id = resultSet.getString(6);
+ this.Salary = resultSet.getInt(7);
+ }
+
+ public int getEmployee_Id() {
+ return Employee_Id;
+ }
+
+ public void setEmployee_Id(int Employee_Id) {
+ this.Employee_Id = Employee_Id;
+ }
+
+ public String getFirst_Name() {
+ return First_Name;
+ }
+
+ public void setFirst_Name(String First_Name) {
+ this.First_Name = First_Name;
+ }
+
+ public String getLast_Name() {
+ return Last_Name;
+ }
+
+ public void setLast_Name(String Last_Name) {
+ this.Last_Name = Last_Name;
+ }
+
+ public String getEmail() {
+ return Email;
+ }
+
+ public void setEmail(String Email) {
+ this.Email = Email;
+ }
+
+ public String getPhone_Number() {
+ return Phone_Number;
+ }
+
+ public void setPhone_Number(String Phone_Number) {
+ this.Phone_Number = Phone_Number;
+ }
+
+ public String getJob_Id() {
+ return Job_Id;
+ }
+
+ public void setJob_Id(String Job_Id) {
+ this.Job_Id = Job_Id;
+ }
+
+ public int getSalary() {
+ return Salary;
+ }
+
+ public void setSalary(int Salary) {
+ this.Salary = Salary;
+ }
+
+
+}
diff --git a/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/web/GetRole.java b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/web/GetRole.java
new file mode 100644
index 00000000..289a1792
--- /dev/null
+++ b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/web/GetRole.java
@@ -0,0 +1,69 @@
+/*
+ * 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.oracle.jdbc.samples.web;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ *
+ * @author nirmala.sundarappa@oracle.com
+ */
+@WebServlet(name = "GetRole", urlPatterns = {"/getrole"})
+/*
+@ServletSecurity(
+ httpMethodConstraints = {
+ @HttpMethodConstraint(value = "GET", rolesAllowed = "staff"),
+ @HttpMethodConstraint(value = "GET", rolesAllowed = "manager"),
+ @HttpMethodConstraint(value = "POST", rolesAllowed = "manager",
+ transportGuarantee = NONE),
+ }
+)
+*/
+public class GetRole extends HttpServlet {
+
+ private static final String[] ROLES = {"manager", "staff" };
+
+ /**
+ * Handles the HTTP GET method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ response.setContentType("text/css");
+ String returnValue = "anonymous";
+ for (String role : ROLES) {
+ if(request.isUserInRole(role)) {
+ returnValue = role;
+ break;
+ }
+ }
+
+ response.getWriter().print(returnValue);
+ }
+
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "JdbcWebServlet: Reading Employees table using JDBC and transforming it as a JSON.\n Author: nirmala.sundarapp@oracle.com";
+ }//
+
+}
diff --git a/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/web/WebController.java b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/web/WebController.java
new file mode 100644
index 00000000..447cd723
--- /dev/null
+++ b/java/HRWebApp/src/main/java/com/oracle/jdbc/samples/web/WebController.java
@@ -0,0 +1,189 @@
+/*
+ * 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.oracle.jdbc.samples.web;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.oracle.jdbc.samples.bean.JdbcBean;
+import com.oracle.jdbc.samples.bean.JdbcBeanImpl;
+import com.oracle.jdbc.samples.entity.Employee;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.*;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ *
+ * @author nirmala.sundarappa@oracle.com
+ */
+@WebServlet(name = "WebController", urlPatterns = {"/WebController"})
+/*
+@ServletSecurity(
+ httpMethodConstraints = {
+ @HttpMethodConstraint(value = "GET", rolesAllowed = "staff"),
+ @HttpMethodConstraint(value = "GET", rolesAllowed = "manager"),
+ @HttpMethodConstraint(value = "POST", rolesAllowed = "manager",
+ transportGuarantee = NONE),
+ }
+)
+*/
+public class WebController extends HttpServlet {
+
+ private static final String INCREMENT_PCT = "incrementPct" ;
+ private static final String ID_KEY = "id";
+ private static final String FN_KEY = "firstName";
+ private static final String LOGOUT = "logout";
+
+ JdbcBean jdbcBean = new JdbcBeanImpl();
+
+ private void reportError(HttpServletResponse response, String message)
+ throws ServletException, IOException {
+ response.setContentType("text/html;charset=UTF-8");
+
+ try (PrintWriter out = response.getWriter()) {
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("Servlet WebController");
+ out.println("");
+ out.println("");
+ out.println("
" + message + "
");
+ out.println("");
+ out.println("");
+ }
+ }
+
+ /**
+ * Processes requests for both HTTP GET and POST
+ * methods.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ protected void processRequest(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ Gson gson = new Gson();
+
+ String value = null;
+ List employeeList = null;
+ if ((value = request.getParameter(ID_KEY)) != null) {
+ int empId = Integer.valueOf(value).intValue();
+ employeeList = jdbcBean.getEmployee(empId);
+ }
+ else if ((value = request.getParameter(FN_KEY)) != null) {
+ employeeList = jdbcBean.getEmployeeByFn(value);
+ }
+ else if ((value = request.getParameter(LOGOUT)) != null) {
+ // faking logoff
+ // response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ // return;
+ /* Getting session and then invalidating it */
+
+ HttpSession session = request.getSession(false);
+ if (request.isRequestedSessionIdValid() && session != null) {
+ session.invalidate();
+ }
+ handleLogOutResponse(request,response);
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ }
+ else {
+ employeeList = jdbcBean.getEmployees();
+ }
+
+ if(employeeList != null) {
+ response.setContentType("application/json");
+ gson.toJson(employeeList,
+ new TypeToken>() {
+ }.getType(),
+ response.getWriter());
+ }
+ else {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
+
+ }
+
+
+ /**
+ * This method would edit the cookie information and make JSESSIONID empty
+ * while responding to logout. This would further help in order to. This would help
+ * to avoid same cookie ID each time a person logs in.
+ * @param response
+ * @param request
+ */
+ private void handleLogOutResponse(HttpServletRequest request, HttpServletResponse response) {
+ Cookie[] cookies = request.getCookies();
+ for (Cookie cookie : cookies) {
+ cookie.setMaxAge(0);
+ cookie.setValue(null);
+ cookie.setPath("/");
+ response.addCookie(cookie);
+
+ }
+
+ }
+
+ //
+ /**
+ * Handles the HTTP GET method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ Map x = request.getParameterMap();
+ String value = null;
+ if ((value = request.getParameter(INCREMENT_PCT)) != null) {
+ Gson gson = new Gson();
+ response.setContentType("application/json");
+ List employeeList = jdbcBean.incrementSalary(Integer.valueOf(value));
+ gson.toJson(employeeList,
+ new TypeToken>() {
+ }.getType(),
+ response.getWriter());
+ }
+ else {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "JdbcWebServlet: Reading Employees table using JDBC and transforming it as a JSON.\n Author: nirmala.sundarapp@oracle.com";
+ }//
+
+}
diff --git a/java/HRWebApp/src/main/resources/SalaryHikeSP.java b/java/HRWebApp/src/main/resources/SalaryHikeSP.java
new file mode 100755
index 00000000..80b5dc2f
--- /dev/null
+++ b/java/HRWebApp/src/main/resources/SalaryHikeSP.java
@@ -0,0 +1,206 @@
+/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*/
+/*
+ DESCRIPTION
+ This is a Java class that invokes the SalaryHikeSP stored procedure.
+
+ Step 1: Connect to SQLPLUS using the database USER/PASSWORD.
+ Make sure to have SalaryHikeSP.sql accessible on the
+ client side to execute.
+ Step 2: Run the SQL file after connecting to DB "@SalaryHikeSP.sql"
+
+ NOTES
+ Use JDK 1.6 and above
+
+ MODIFIED (MM/DD/YY)
+ nbsundar 03/23/15 - Creation (kmensah - Contributor)
+ */
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+import oracle.jdbc.OracleStatement;
+import oracle.jdbc.OracleConnection;
+
+import oracle.jdbc.driver.OracleDriver;
+import oracle.jdbc.pool.OracleDataSource;
+
+
+public class SalaryHikeSP {
+ /*
+ * Increment the Salary
+ */
+ public static ResultSet incrementSalary (int percentIncrease) throws SQLException {
+ int updateCount = 0;
+ int totalemployees = 0;
+ int tier3emp = 0;
+ int tier2emp = 0;
+ int tier1emp = 0;
+ float totalsalary = 0.0f;
+ float minsalary = 0.0f;
+ float maxsalary = 0.0f;
+ float totalbudget = 0.0f;
+ float tier3hike = 0.0f;
+ float tier2hike = 0.0f;
+ float tier1hike = 0.0f;
+
+
+ // Percentage to divide the salary hike budget into
+ // three tiers based on the salary range
+ // Tier 1 salary range is 15,001 to 25,000
+ float tier1percent = 0.10f;
+ // Tier 2 salary range is 7,001 to 15,000
+ float tier2percent = 0.30f;
+ // Tier 3 salary range is 0 to 7,000
+ float tier3percent = 0.60f;
+
+ Connection connection = null;
+ ResultSet resultSet = null;
+ Statement statement = null;
+ PreparedStatement preparedStatement;
+ ResultSet rset = null;
+
+ System.out.println("==== Here ===== ");
+ String TOTAL_EMP = "SELECT count(EMPLOYEE_ID) from EMPLOYEES";
+ String TOTAL_SALARY = "SELECT sum(salary) from EMPLOYEES";
+ String MIN_SALARY = "SELECT min(salary) from EMPLOYEES";
+ String MAX_SALARY = "SELECT max(salary) from EMPLOYEES";
+ String UPDATE_SQL =
+ "UPDATE EMPLOYEES SET SALARY = 20000 WHERE EMPLOYEE_ID=100";
+ String TIER3_EMP = "SELECT COUNT(EMPLOYEE_ID) from EMPLOYEES WHERE " +
+ "salary >= ? and salary < 7000.00";
+ String TIER2_EMP = "SELECT count(EMPLOYEE_ID) from EMPLOYEES " +
+ " WHERE SALARY > 7001.00 and SALARY < 15000.00";
+ String TIER1_EMP ="SELECT count(EMPLOYEE_ID) from EMPLOYEES " +
+ " WHERE SALARY >15001.00 AND SALARY < ?";
+
+ String TIER3_UPDATE ="UPDATE EMPLOYEES SET SALARY = (SALARY + ?)" +
+ " WHERE salary > ? " +
+ " and salary < 7000.00";
+ String TIER2_UPDATE = "UPDATE EMPLOYEES SET SALARY = (SALARY + ? )" +
+ " WHERE SALARY > 7001.00 and SALARY < 15000.00 ";
+ String TIER1_UPDATE = "UPDATE EMPLOYEES SET SALARY = (SALARY + ?)" +
+ " WHERE SALARY > 15001.00 and SALARY < ? ";
+ if (percentIncrease <= 0) {
+ throw new
+ IllegalArgumentException("Invalid percentage provided: " +percentIncrease);
+ }
+ try {
+ connection = new OracleDriver().defaultConnection();
+ // Get the total number of employees
+ statement = connection.createStatement();
+ resultSet = statement.executeQuery(TOTAL_EMP);
+ while (resultSet.next()) {
+ totalemployees = resultSet.getInt(1);
+ System.out.println("Number of employees" + totalemployees);
+ }
+ // Get the total salary of all employees
+ resultSet = statement.executeQuery(TOTAL_SALARY);
+ while (resultSet.next()) {
+ totalsalary = resultSet.getFloat(1);
+ System.out.println("Total salary of all employees: " + totalsalary);
+ }
+ // Get the minimum salary of all employees
+ resultSet = statement.executeQuery(MIN_SALARY);
+ while (resultSet.next()) {
+ minsalary = resultSet.getFloat(1);
+ System.out.println("Minimum salary of all employees: " + minsalary);
+ }
+ // Get the maximum salary of all employees
+ resultSet = statement.executeQuery(MAX_SALARY);
+ while (resultSet.next()) {
+ maxsalary = resultSet.getFloat(1);
+ System.out.println("Maximum salary of all employees: " + maxsalary);
+ }
+ // Get the budget for the salary rise
+ totalbudget = (totalsalary * percentIncrease )/100;
+ System.out.println("Total budget for the rise: " + totalbudget);
+
+ // Get the salary increase for the tier3 employees
+ // 60% of the total budget is for tier3 employees
+ preparedStatement = connection.prepareStatement(TIER3_EMP);
+ preparedStatement.setFloat(1,minsalary);
+ resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next()) {
+ tier3emp = resultSet.getInt(1);
+ if ( tier3emp != 0 ) {
+ tier3hike = (float) Math.ceil(((totalbudget * tier3percent)/tier3emp));
+ }
+ System.out.println("Number of tier3 employees: " + tier3emp);
+ System.out.println("Hike for tier3 employees: " + tier3hike);
+ }
+
+ // Get the salary increase for the tier2 employees
+ // 30% of the total budget is for tier2 employees
+ statement = connection.createStatement();
+ resultSet = statement.executeQuery(TIER2_EMP);
+ while (resultSet.next()) {
+ tier2emp = resultSet.getInt(1);
+ if ( tier2emp != 0 ) {
+ tier2hike = (float) Math.ceil(((totalbudget * tier2percent)/tier2emp));
+ }
+ System.out.println("Number of tier2 employees: " + tier2emp);
+ System.out.println("Hike for tier2 employees: " + tier2hike);
+ }
+
+ // Get the salary increase for the tier1 employees
+ // 10% of the total budget is for tier1 employees
+ preparedStatement = connection.prepareStatement(TIER1_EMP);
+ preparedStatement.setFloat(1,maxsalary);
+ resultSet = preparedStatement.executeQuery();
+ while (resultSet.next()) {
+ tier1emp = resultSet.getInt(1);
+ if ( tier1emp != 0 ) {
+ tier1hike = (float) Math.ceil(((totalbudget * tier1percent)/tier1emp));
+ }
+ System.out.println("Number of tier1 employees: " + tier1emp);
+ System.out.println("Hike for tier1 employees: " + tier1hike);
+ }
+
+ // Give a salary hike to tier3 employees
+
+ preparedStatement = connection.prepareStatement(TIER3_UPDATE);
+ preparedStatement.setFloat(1, tier3hike);
+ preparedStatement.setFloat(2,minsalary);
+ preparedStatement.executeUpdate();
+
+ // Give a salary hike to tier2 employees
+ preparedStatement = connection.prepareStatement(TIER2_UPDATE);
+ preparedStatement.setFloat(1, tier2hike);
+ updateCount = preparedStatement.executeUpdate();
+
+ // Give a salary hike to tier1 employees
+ preparedStatement = connection.prepareStatement(TIER1_UPDATE);
+ preparedStatement.setFloat(1, tier1hike);
+ preparedStatement.setFloat(2,maxsalary);
+ preparedStatement.executeUpdate();
+
+ // Verifying if the update was successful.
+ // Get the salary of all employees using a ref cursor and print it.
+ ((OracleConnection)connection).setCreateStatementAsRefCursor(true);
+ Statement stmt = connection.createStatement();
+ ((OracleStatement)stmt).setRowPrefetch(1);
+ rset = stmt.executeQuery("SELECT Employee_Id, First_Name, Last_Name, Email, Phone_Number, Job_Id, Salary FROM EMPLOYEES");
+ // fetch one row
+ if (rset.next()) {
+ System.out.println("Ename = " + rset.getObject("FIRST_NAME") +
+ "-- Salary = " + rset.getObject("salary"));
+ }
+
+ // Verifying if the update was successful.
+ // Get the total salary of all employees after the salary increase
+ resultSet = statement.executeQuery(TOTAL_SALARY);
+ while (resultSet.next()) {
+ totalsalary = resultSet.getFloat(1);
+ System.out.println("Total salary of all employees after the"+
+ " salary increase: " + totalsalary);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return rset;
+ }
+}
+
+
diff --git a/java/HRWebApp/src/main/resources/SalaryHikeSP.sql b/java/HRWebApp/src/main/resources/SalaryHikeSP.sql
new file mode 100755
index 00000000..84ce2b11
--- /dev/null
+++ b/java/HRWebApp/src/main/resources/SalaryHikeSP.sql
@@ -0,0 +1,70 @@
+Rem SalaryHikeSP.sql
+Rem
+Rem Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+Rem
+Rem NAME
+Rem SalaryHikeSP.sql
+Rem
+Rem DESCRIPTION
+Rem SQL for invoking the method which gets a server side connection to
+Rem internal T2 Driver
+Rem
+Rem MODIFIED (MM/DD/YY)
+Rem nbsundar 03/23/15 - Created
+Rem kmensah 03/23/15 - Contributor
+
+REM Reads the content of the Java source from SalaryHikeSP.java
+REM then compiles it
+connect hr/hr
+
+CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED SalaryHikeSP_src AS
+@SalaryHikeSP.java
+/
+
+REM Check for errors
+show error
+
+REM Create a PL/SQL wrapper
+create or replace package refcur_pkg as
+ TYPE EmpCurTyp IS REF CURSOR;
+ function incrementsalary(percent IN NUMBER) return EmpCurTyp;
+end refcur_pkg;
+/
+show errors;
+
+create or replace package body refcur_pkg as
+function incrementsalary(percent IN NUMBER) return EmpCurTyp
+ as language java
+ name 'SalaryHikeSP.incrementSalary(int) returns java.sql.ResultSet';
+
+end refcur_pkg;
+/
+
+show error
+
+/
+
+-- Running the sample
+--- connect hr/hr
+--- set serveroutput on
+--- call dbms_java.set_output(50000);
+
+---declare
+ ---type EmpCur IS REF CURSOR;
+ ---rc EmpCur;
+ --employee employees%ROWTYPE;
+--begin
+ --rc := refcur_pkg.incrementsalary(5);
+ --LOOP
+ --fetch rc into employee;
+ --exit when rc%notfound;
+ --dbms_output.put_line(' Name = ' || employee.FIRST_NAME || ' Salary = ' || employee.SALARY);
+ --end loop;
+--close rc;
+--end;
+--/
+--show error;
+--/
+
+
+
diff --git a/java/HRWebApp/src/main/webapp/WEB-INF/web.xml b/java/HRWebApp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..87670ca7
--- /dev/null
+++ b/java/HRWebApp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,52 @@
+
+
+
+ Jdbc Web Sample
+
+
+ manager
+
+
+ staff
+
+
+
+
+ Wildcard means whole app requires authentication
+ /*
+ GET
+ POST
+
+
+ manager
+
+
+ NONE
+
+
+
+
+
+ Wildcard means whole app requires authentication
+ /*
+ GET
+
+
+ staff
+
+
+
+ NONE
+
+
+
+
+ FORM
+
+ /login.html
+ /login-failed.html
+
+
+
diff --git a/java/HRWebApp/src/main/webapp/about.html b/java/HRWebApp/src/main/webapp/about.html
new file mode 100644
index 00000000..f0aca087
--- /dev/null
+++ b/java/HRWebApp/src/main/webapp/about.html
@@ -0,0 +1,42 @@
+
+
+
+
+ About
+
+
+
HR Application for AnyCo Corporation
+
+HR Application for the company AnyCo Corporation is designed to show the various scenarios of using an HR application.
+
+HR Application is an web application that provides access to information of all employees in AnyCo Corporation.
+HRStaff and HRAdmin are the two users of this application with different roles and privileges.
+
+
+ HRAdmin is an admin user who has all kinds of access i.e., read, write, and delete access to records of employees.
+Some of the functionalities accessible to HRAdmin are:
+
+
List All Employees : This functionality is primarily used to retrieve all employees information. Employee information such as
+Employee_id, First_Name, Last_Name, Email, Phone_Number, Job_Id and Salary are displayed.
+
Search By Employee Id : Employee records can be searched using the primary key of employee Id.
+
Update Employee Record : This functionality is used by HRAdmin to update the employee records. HRAdmin can search based on the name of the employee and the results will get displayed on the screen. Later, HRAdmin can choose an employee record to either UPDATE or DELETE. UPDATE functionality offers to update any fields such as First_name, last_name, Email, Phone_number, Job_ID, and salary of an Employee record. DELETE will delete the entire employee record from the database.
+
Increment Salary :This functionality is designed to showcase the usage of "Java in the database". HRAdmin will input the percentage for the salary hike. The Salary Hike algorithm calculates the budget for the salary hike based on the input percentage. This salary hike budget is later used to provide a salary increase to employees based on the salary tier that they belong. Please refer to the Java 2 Day Developer's Guide for detailed explanation of the salary hike algorithm.
+
About : This page provides an overview of the HR Application and explains the functionalities that it offers.
+
+
+
+ HRStaff is a staff user who has only read only access. HRStaff can only view the employee records and he can search the records based on the employee Id. However, HRStaff does not have any update or delete access and hence, any update/delete functionalities are hidden to this user.
+
+Some of the functionalities accessible to HRStaff are:
+
+
List All Employees : This functionality is primarily used to retrieve all employees information. Employee information such as Employee_id, First_Name, Last_Name, Email, Phone_Number, and Job_Id are displayed.
+
Search By Employee Id : Employee records can be searched using the primary key of employee Id.
+
About : This page provides an overview of the HR Application and explains the functionalities that it offers.