Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7b2094d
Creating HRWebApp
Apr 13, 2017
9460fa3
Create Readme.md
nsundara Apr 13, 2017
1a862f0
Creating Readme.md
Apr 13, 2017
e4e464b
Delete Readme.md
nsundara Apr 13, 2017
53acc81
Creating Readme.md
Apr 13, 2017
66138ec
Create Readme.md
nsundara Apr 13, 2017
f37654f
Delete ._.DS_Store
nsundara Apr 13, 2017
481d32c
Delete ._conf
nsundara Apr 13, 2017
be04609
Delete ._main
nsundara Apr 13, 2017
53c719b
Delete ._MANIFEST.MF
nsundara Apr 13, 2017
53569cc
Delete ._.DS_Store
nsundara Apr 13, 2017
d5acfc7
Delete ._java
nsundara Apr 13, 2017
2314e41
Delete ._resources
nsundara Apr 13, 2017
9c4b5a3
Delete ._webapp
nsundara Apr 13, 2017
f43283a
Update Readme.md
nsundara Apr 13, 2017
befc4d9
Update Readme.md
nsundara Apr 13, 2017
13cb153
Delete ._WEB-INF
nsundara Apr 17, 2017
63da74a
Merge branch 'HRWebApp' of https://github.com/oracle/oracle-db-exampl…
Apr 19, 2017
98e0129
Delete ._bean
nsundara Apr 19, 2017
1f264cd
Delete ._entity
nsundara Apr 19, 2017
8885133
Delete ._web
nsundara Apr 19, 2017
28b6876
Delete ._Employee.java
nsundara Apr 19, 2017
7cf1c4d
Delete ._samples
nsundara Apr 19, 2017
51cc097
Delete ._jdbc
nsundara Apr 19, 2017
c811d4e
Delete ._com
nsundara Apr 19, 2017
6283143
Delete ._oracle
nsundara Apr 19, 2017
66a11ab
Delete ._about.html
nsundara Apr 19, 2017
b538760
Delete ._css
nsundara Apr 19, 2017
2cd121b
Delete ._listAll.html
nsundara Apr 19, 2017
1bc449c
Delete ._listById.html
nsundara Apr 19, 2017
abf7f6d
Delete ._listByName.html
nsundara Apr 19, 2017
48de271
Delete ._app.css
nsundara Apr 19, 2017
9e3145e
Update .gitignore
nsundara Apr 19, 2017
60f2108
Update Readme.md
nsundara Apr 19, 2017
c98b724
Update Readme.md
nsundara Apr 19, 2017
0d5a778
Update Readme.md
nsundara Apr 19, 2017
afdddf4
Update SalaryHikeSP.java
nsundara Apr 19, 2017
1704138
Modified pom.xml
Apr 21, 2017
bb682ae
Updating pom.xml with Oracle maven repo
Apr 21, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.class
*.jar
classes/
.*
37 changes: 37 additions & 0 deletions java/HRWebApp/Readme.md
Original file line number Diff line number Diff line change
@@ -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.









79 changes: 79 additions & 0 deletions java/HRWebApp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.oracle.jdbc</groupId>
<artifactId>JdbcWebSamples</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>JdbcWebSamples Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>

<!-- http://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
</dependencies>
<build>
<finalName>JdbcWebSamples</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>maven.oracle.com</id>
<name>oracle-maven-repo</name>
<url>https://maven.oracle.com</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>maven.oracle.com</id>
<name>oracle-maven-repo</name>
<url>https://maven.oracle.com</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>

</project>
3 changes: 3 additions & 0 deletions java/HRWebApp/settings-security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<settingsSecurity>
<master>{generate_master_password_and_add_here}</master>
</settingsSecurity>
42 changes: 42 additions & 0 deletions java/HRWebApp/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<settings
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"
xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<!--
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>adc-proxy.oracle.com</host>
<port>80</port>
<nonProxyHosts>maven-stage.oracle.com|www-portal-stage.oracle.com|login-stage.oracle.com|*.oraclecorp.com</nonProxyHosts>
</proxy>
</proxies>
-->

<servers>
<server>
<id>maven.oracle.com</id>
<username>{Username registered on maven.oracle.com}</username>
<password>{Add_registered_password_here}</password>
<configuration>
<basicAuthScope>
<host>ANY</host>
<port>ANY</port>
<realm>OAM 11g</realm>
</basicAuthScope>
<httpConfiguration>
<all>
<params>
<property>
<name>http.protocol.allow-circular-redirects</name>
<value>%b,true</value>
</property>
</params>
</all>
</httpConfiguration>
</configuration>
</server>
</servers>

</settings>
2 changes: 2 additions & 0 deletions java/HRWebApp/src/conf/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

Original file line number Diff line number Diff line change
@@ -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<Employee> 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<Employee> 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<Employee> getEmployeeByFn(String fn);

/**
* Increment salary by a percentage
* @param incrementPct percent increase
* @return List of employees with incremented salary
*/
public List<Employee> incrementSalary(int incrementPct);
}
Original file line number Diff line number Diff line change
@@ -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<Employee> getEmployees() {
List<Employee> 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<Employee> getEmployee(int empId) {
List<Employee> 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<Employee> getEmployeeByFn(String fn) {
List<Employee> 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<Employee> incrementSalary (int incrementPct) {
List<Employee> 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");
}
Loading