Skip to content

Commit e259dd3

Browse files
committed
prior to push
2 parents 242fb8a + af14e02 commit e259dd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+16296
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.class
33
*.jar
44
classes/
5+
.*
68.9 KB
Loading

java/HRWebApp/Readme.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Overview of the HR Web Application
2+
3+
**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.
4+
5+
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. The Architecture of the HR Web Application is depicted in the following figure.
6+
7+
![Architecture of HR Web Application](https://github.com/oracle/oracle-db-examples/blob/master/java/HRWebApp/HRWebApp_Architecture.jpg)
8+
9+
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. There are two users **HRStaff** and **HRAdmin** who have different privileges and access to the application.
10+
11+
**HRStaff** has read access to the application and do not have any privileges to update/delete an employee record. HRStaff has privileges to perform the following functions.
12+
13+
* **List All Employees** :
14+
This functionality retrieves information about the employees. It lists the employee information such as Employee_ID, First_Name, Last_Name, Email, Phone_Number, Job_Id, and Salary.
15+
16+
* **Search By Employee ID:** :
17+
Use Employee ID that is the primary key of Employees table to search for a particular employee.
18+
19+
**HRAdmin** has a full control on the application and has both read and update privileges. HRAdmin has access to all functionalities of the application. HRAdmin can do the following functions in addition everything that HRStaff can do.
20+
21+
* **Update Employee Record:** :
22+
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.
23+
24+
* **Delete an Employee Record:** :
25+
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.
26+
27+
* **Increment Salary:** :
28+
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.
29+
30+
31+
32+
33+
34+
35+
36+
37+

java/HRWebApp/pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.oracle.jdbc</groupId>
5+
<artifactId>JdbcWebSamples</artifactId>
6+
<packaging>war</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>JdbcWebSamples Maven Webapp</name>
9+
<url>http://maven.apache.org</url>
10+
<dependencies>
11+
<!-- http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
12+
<dependency>
13+
<groupId>javax.servlet</groupId>
14+
<artifactId>javax.servlet-api</artifactId>
15+
<version>3.1.0</version>
16+
</dependency>
17+
18+
<!-- http://mvnrepository.com/artifact/com.google.code.gson/gson -->
19+
<dependency>
20+
<groupId>com.google.code.gson</groupId>
21+
<artifactId>gson</artifactId>
22+
<version>2.5</version>
23+
</dependency>
24+
25+
26+
<dependency>
27+
<groupId>junit</groupId>
28+
<artifactId>junit</artifactId>
29+
<version>3.8.1</version>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.oracle.jdbc</groupId>
34+
<artifactId>ojdbc8</artifactId>
35+
<version>12.2.0.1</version>
36+
</dependency>
37+
</dependencies>
38+
<build>
39+
<finalName>JdbcWebSamples</finalName>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-compiler-plugin</artifactId>
44+
<version>3.5.1</version>
45+
<configuration>
46+
<source>1.8</source>
47+
<target>1.8</target>
48+
</configuration>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
53+
<repositories>
54+
<repository>
55+
<id>maven.oracle.com</id>
56+
<name>oracle-maven-repo</name>
57+
<url>https://maven.oracle.com</url>
58+
<layout>default</layout>
59+
<releases>
60+
<enabled>true</enabled>
61+
<updatePolicy>always</updatePolicy>
62+
</releases>
63+
</repository>
64+
</repositories>
65+
66+
<pluginRepositories>
67+
<pluginRepository>
68+
<id>maven.oracle.com</id>
69+
<name>oracle-maven-repo</name>
70+
<url>https://maven.oracle.com</url>
71+
<layout>default</layout>
72+
<releases>
73+
<enabled>true</enabled>
74+
<updatePolicy>always</updatePolicy>
75+
</releases>
76+
</pluginRepository>
77+
</pluginRepositories>
78+
79+
</project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<settingsSecurity>
2+
<master>{generate_master_password_and_add_here}</master>
3+
</settingsSecurity>

java/HRWebApp/settings.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<settings
2+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"
3+
xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
5+
<!--
6+
<proxies>
7+
<proxy>
8+
<active>true</active>
9+
<protocol>http</protocol>
10+
<host>adc-proxy.oracle.com</host>
11+
<port>80</port>
12+
<nonProxyHosts>maven-stage.oracle.com|www-portal-stage.oracle.com|login-stage.oracle.com|*.oraclecorp.com</nonProxyHosts>
13+
</proxy>
14+
</proxies>
15+
-->
16+
17+
<servers>
18+
<server>
19+
<id>maven.oracle.com</id>
20+
<username>{Username registered on maven.oracle.com}</username>
21+
<password>{Add_registered_password_here}</password>
22+
<configuration>
23+
<basicAuthScope>
24+
<host>ANY</host>
25+
<port>ANY</port>
26+
<realm>OAM 11g</realm>
27+
</basicAuthScope>
28+
<httpConfiguration>
29+
<all>
30+
<params>
31+
<property>
32+
<name>http.protocol.allow-circular-redirects</name>
33+
<value>%b,true</value>
34+
</property>
35+
</params>
36+
</all>
37+
</httpConfiguration>
38+
</configuration>
39+
</server>
40+
</servers>
41+
42+
</settings>

java/HRWebApp/src/conf/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.oracle.jdbc.samples.bean;
7+
8+
import java.util.List;
9+
import com.oracle.jdbc.samples.entity.Employee;
10+
11+
/**
12+
*
13+
* @author nirmala.sundarappa@oracle.com
14+
*/
15+
public interface JdbcBean {
16+
/**
17+
* Get a list of Employees
18+
* @return List of employees
19+
*/
20+
public List<Employee> getEmployees();
21+
22+
/**
23+
* Get List of employee based on empId. This will always return one row
24+
* but returning a List to be make signatures consistent.
25+
* @param empId
26+
* @return
27+
*/
28+
public List<Employee> getEmployee(int empId);
29+
30+
/**
31+
* Update employee based on employee-id. Returns the updated record.
32+
* @param empId
33+
* @return updated record.
34+
*/
35+
public Employee updateEmployee(int empId);
36+
37+
/**
38+
* Get List of employees by First Name pattern
39+
* @param fn
40+
* @return List of employees with given beginning pattern
41+
*/
42+
public List<Employee> getEmployeeByFn(String fn);
43+
44+
/**
45+
* Increment salary by a percentage
46+
* @param incrementPct percent increase
47+
* @return List of employees with incremented salary
48+
*/
49+
public List<Employee> incrementSalary(int incrementPct);
50+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package com.oracle.jdbc.samples.bean;
2+
3+
import java.sql.*;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.logging.Level;
7+
import java.util.logging.Logger;
8+
import com.oracle.jdbc.samples.entity.Employee;
9+
import oracle.jdbc.OracleTypes;
10+
11+
12+
import java.sql.PreparedStatement;
13+
import oracle.jdbc.OracleStatement;
14+
import oracle.jdbc.OracleConnection;
15+
16+
import oracle.jdbc.driver.OracleDriver;
17+
18+
/**
19+
*
20+
* @author nirmala.sundarappa@oracle.com
21+
*/
22+
public class JdbcBeanImpl implements JdbcBean {
23+
24+
public static Connection getConnection() throws SQLException {
25+
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
26+
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@//myorclhost:1521/myorcldbservice", "hr", "hr");
27+
28+
return connection;
29+
}
30+
31+
@Override
32+
public List<Employee> getEmployees() {
33+
List<Employee> returnValue = new ArrayList<>();
34+
try (Connection connection = getConnection()) {
35+
try (Statement statement = connection.createStatement()) {
36+
try (ResultSet resultSet = statement.executeQuery("SELECT Employee_Id, First_Name, Last_Name, Email, Phone_Number, Job_Id, Salary FROM EMPLOYEES")) {
37+
while(resultSet.next()) {
38+
returnValue.add(new Employee(resultSet));
39+
}
40+
}
41+
}
42+
} catch (SQLException ex) {
43+
logger.log(Level.SEVERE, null, ex);
44+
ex.printStackTrace();
45+
}
46+
47+
return returnValue;
48+
}
49+
50+
/**
51+
* Returns the employee object for the given empId. Returns
52+
* @param empId
53+
* @return
54+
*/
55+
@Override
56+
public List<Employee> getEmployee(int empId) {
57+
List<Employee> returnValue = new ArrayList<>();
58+
59+
try (Connection connection = getConnection()) {
60+
try (PreparedStatement preparedStatement = connection.prepareStatement(
61+
"SELECT Employee_Id, First_Name, Last_Name, Email, Phone_Number, Job_Id, Salary FROM EMPLOYEES WHERE Employee_Id = ?")) {
62+
preparedStatement.setInt(1, empId);
63+
try (ResultSet resultSet = preparedStatement.executeQuery()) {
64+
if(resultSet.next()) {
65+
returnValue.add(new Employee(resultSet));
66+
}
67+
}
68+
}
69+
} catch (SQLException ex) {
70+
logger.log(Level.SEVERE, null, ex);
71+
ex.printStackTrace();
72+
}
73+
74+
return returnValue;
75+
}
76+
77+
@Override
78+
public Employee updateEmployee(int empId) {
79+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
80+
}
81+
82+
@Override
83+
public List<Employee> getEmployeeByFn(String fn) {
84+
List<Employee> returnValue = new ArrayList<>();
85+
86+
try (Connection connection = getConnection()) {
87+
try (PreparedStatement preparedStatement = connection.prepareStatement(
88+
"SELECT Employee_Id, First_Name, Last_Name, Email, Phone_Number, Job_Id, Salary FROM EMPLOYEES WHERE First_Name LIKE ?")) {
89+
preparedStatement.setString(1, fn + '%');
90+
try (ResultSet resultSet = preparedStatement.executeQuery()) {
91+
while(resultSet.next()) {
92+
returnValue.add(new Employee(resultSet));
93+
}
94+
}
95+
}
96+
} catch (SQLException ex) {
97+
logger.log(Level.SEVERE, null, ex);
98+
ex.printStackTrace();
99+
}
100+
101+
return returnValue;
102+
}
103+
104+
@Override
105+
public List<Employee> incrementSalary (int incrementPct) {
106+
List<Employee> returnValue = new ArrayList<>();
107+
108+
try (Connection connection = getConnection()) {
109+
try (CallableStatement callableStatement = connection.prepareCall("begin ? := refcur_pkg.incrementsalary(?); end;")) {
110+
callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
111+
callableStatement.setInt(2, incrementPct);
112+
callableStatement.execute();
113+
try (ResultSet resultSet = (ResultSet) callableStatement.getObject(1)) {
114+
while (resultSet.next()) {
115+
returnValue.add(new Employee(resultSet));
116+
}
117+
}
118+
}
119+
} catch (SQLException ex) {
120+
logger.log(Level.SEVERE, null, ex);
121+
ex.printStackTrace();
122+
}
123+
124+
return returnValue;
125+
}
126+
127+
static final Logger logger = Logger.getLogger("com.oracle.jdbc.samples.bean.JdbcBeanImpl");
128+
}

0 commit comments

Comments
 (0)