Skip to content

Commit 9a8ad8b

Browse files
first commit
0 parents  commit 9a8ad8b

File tree

104 files changed

+902
-0
lines changed

Some content is hidden

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

104 files changed

+902
-0
lines changed

MySQL script/customer-tracker.sql

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
CREATE DATABASE IF NOT EXISTS `web_customer_tracker` /*!40100 DEFAULT CHARACTER SET latin1 */;
2+
USE `web_customer_tracker`;
3+
-- MySQL dump 10.13 Distrib 5.6.13, for osx10.6 (i386)
4+
--
5+
-- Host: 127.0.0.1 Database: web_customer_tracker
6+
-- ------------------------------------------------------
7+
-- Server version 5.6.16
8+
9+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
10+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
11+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
12+
/*!40101 SET NAMES utf8 */;
13+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
14+
/*!40103 SET TIME_ZONE='+00:00' */;
15+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
16+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
17+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
18+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
19+
20+
--
21+
-- Table structure for table `customer`
22+
--
23+
24+
DROP TABLE IF EXISTS `customer`;
25+
/*!40101 SET @saved_cs_client = @@character_set_client */;
26+
/*!40101 SET character_set_client = utf8 */;
27+
CREATE TABLE `customer` (
28+
`id` int(11) NOT NULL AUTO_INCREMENT,
29+
`first_name` varchar(45) DEFAULT NULL,
30+
`last_name` varchar(45) DEFAULT NULL,
31+
`email` varchar(45) DEFAULT NULL,
32+
PRIMARY KEY (`id`)
33+
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
34+
/*!40101 SET character_set_client = @saved_cs_client */;
35+
36+
--
37+
-- Dumping data for table `customer`
38+
--
39+
40+
LOCK TABLES `customer` WRITE;
41+
/*!40000 ALTER TABLE `customer` DISABLE KEYS */;
42+
43+
INSERT INTO `customer` VALUES
44+
(1,'David','Adams','[email protected]'),
45+
(2,'John','Doe','[email protected]'),
46+
(3,'Ajay','Rao','[email protected]'),
47+
(4,'Mary','Public','[email protected]'),
48+
(5,'Maxwell','Dixon','[email protected]');
49+
50+
/*!40000 ALTER TABLE `customer` ENABLE KEYS */;
51+
UNLOCK TABLES;
52+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
53+
54+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
55+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
56+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
57+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
58+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
59+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
60+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
61+
62+
-- Dump completed on 2016-09-24 21:50:59

nb-configuration.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-shared-configuration>
3+
<!--
4+
This file contains additional configuration written by modules in the NetBeans IDE.
5+
The configuration is intended to be shared among all the users of project and
6+
therefore it is assumed to be part of version control checkout.
7+
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
8+
-->
9+
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
10+
<!--
11+
Properties that influence various parts of the IDE, especially code formatting and the like.
12+
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
13+
That way multiple projects can share the same settings (useful for formatting rules for example).
14+
Any value defined here will override the pom.xml file value but is only applicable to the current project.
15+
-->
16+
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
17+
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
18+
</properties>
19+
</project-shared-configuration>

pom.xml

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.mycompany</groupId>
6+
<artifactId>SpringREST</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>war</packaging>
9+
10+
<name>SpringREST</name>
11+
12+
<properties>
13+
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>javax</groupId>
20+
<artifactId>javaee-web-api</artifactId>
21+
<version>7.0</version>
22+
<scope>provided</scope>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.springframework</groupId>
27+
<artifactId>spring-webmvc</artifactId>
28+
<version>5.2.4.RELEASE</version>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.springframework</groupId>
33+
<artifactId>spring-tx</artifactId>
34+
<version>5.2.4.RELEASE</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-orm</artifactId>
40+
<version>5.2.4.RELEASE</version>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>com.fasterxml.jackson.core</groupId>
45+
<artifactId>jackson-databind</artifactId>
46+
<version>2.10.3</version>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.hibernate</groupId>
51+
<artifactId>hibernate-core</artifactId>
52+
<version>6.0.0.Alpha4</version>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>mysql</groupId>
57+
<artifactId>mysql-connector-java</artifactId>
58+
<version>8.0.19</version>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>com.mchange</groupId>
63+
<artifactId>c3p0</artifactId>
64+
<version>0.9.5.5</version>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>javax.servlet</groupId>
69+
<artifactId>javax.servlet-api</artifactId>
70+
<version>4.0.1</version>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>javax.servlet.jsp</groupId>
75+
<artifactId>javax.servlet.jsp-api</artifactId>
76+
<version>2.3.3</version>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>javax.xml.bind</groupId>
81+
<artifactId>jaxb-api</artifactId>
82+
<version>2.4.0-b180830.0359</version>
83+
</dependency>
84+
</dependencies>
85+
86+
<build>
87+
<plugins>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-compiler-plugin</artifactId>
91+
<version>3.1</version>
92+
<configuration>
93+
<source>1.7</source>
94+
<target>1.7</target>
95+
<compilerArguments>
96+
<endorseddirs>${endorsed.dir}</endorseddirs>
97+
</compilerArguments>
98+
</configuration>
99+
</plugin>
100+
<plugin>
101+
<groupId>org.apache.maven.plugins</groupId>
102+
<artifactId>maven-war-plugin</artifactId>
103+
<version>2.3</version>
104+
<configuration>
105+
<failOnMissingWebXml>false</failOnMissingWebXml>
106+
</configuration>
107+
</plugin>
108+
<plugin>
109+
<groupId>org.apache.maven.plugins</groupId>
110+
<artifactId>maven-dependency-plugin</artifactId>
111+
<version>2.6</version>
112+
<executions>
113+
<execution>
114+
<phase>validate</phase>
115+
<goals>
116+
<goal>copy</goal>
117+
</goals>
118+
<configuration>
119+
<outputDirectory>${endorsed.dir}</outputDirectory>
120+
<silent>true</silent>
121+
<artifactItems>
122+
<artifactItem>
123+
<groupId>javax</groupId>
124+
<artifactId>javaee-endorsed-api</artifactId>
125+
<version>7.0</version>
126+
<type>jar</type>
127+
</artifactItem>
128+
</artifactItems>
129+
</configuration>
130+
</execution>
131+
</executions>
132+
</plugin>
133+
</plugins>
134+
</build>
135+
136+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package springrest.config;
2+
3+
import java.beans.PropertyVetoException;
4+
import java.util.Properties;
5+
import java.util.logging.Logger;
6+
7+
import javax.sql.DataSource;
8+
9+
import org.hibernate.SessionFactory;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.ComponentScan;
13+
import org.springframework.context.annotation.Configuration;
14+
import org.springframework.context.annotation.PropertySource;
15+
import org.springframework.core.env.Environment;
16+
import org.springframework.orm.hibernate5.HibernateTransactionManager;
17+
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
18+
import org.springframework.transaction.annotation.EnableTransactionManagement;
19+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
20+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
21+
22+
import com.mchange.v2.c3p0.ComboPooledDataSource;
23+
24+
@Configuration
25+
@EnableWebMvc
26+
@EnableTransactionManagement
27+
@ComponentScan("springrest")
28+
@PropertySource({ "classpath:persistence-mysql.properties" })
29+
public class DemoAppConfig implements WebMvcConfigurer {
30+
31+
@Autowired
32+
private Environment env;
33+
34+
private Logger logger = Logger.getLogger(getClass().getName());
35+
36+
@Bean
37+
public DataSource myDataSource() {
38+
39+
// create connection pool
40+
ComboPooledDataSource myDataSource = new ComboPooledDataSource();
41+
42+
// set the jdbc driver
43+
try {
44+
myDataSource.setDriverClass("com.mysql.jdbc.Driver");
45+
}
46+
catch (PropertyVetoException exc) {
47+
throw new RuntimeException(exc);
48+
}
49+
50+
// for sanity's sake, let's log url and user ... just to make sure we are reading the data
51+
logger.info("jdbc.url=" + env.getProperty("jdbc.url"));
52+
logger.info("jdbc.user=" + env.getProperty("jdbc.user"));
53+
54+
// set database connection props
55+
myDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
56+
myDataSource.setUser(env.getProperty("jdbc.user"));
57+
myDataSource.setPassword(env.getProperty("jdbc.password"));
58+
59+
// set connection pool props
60+
myDataSource.setInitialPoolSize(getIntProperty("connection.pool.initialPoolSize"));
61+
myDataSource.setMinPoolSize(getIntProperty("connection.pool.minPoolSize"));
62+
myDataSource.setMaxPoolSize(getIntProperty("connection.pool.maxPoolSize"));
63+
myDataSource.setMaxIdleTime(getIntProperty("connection.pool.maxIdleTime"));
64+
65+
return myDataSource;
66+
}
67+
68+
private Properties getHibernateProperties() {
69+
70+
// set hibernate properties
71+
Properties props = new Properties();
72+
73+
props.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
74+
props.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
75+
76+
return props;
77+
}
78+
79+
// need a helper method
80+
// read environment property and convert to int
81+
private int getIntProperty(String propName) {
82+
83+
String propVal = env.getProperty(propName);
84+
85+
// now convert to int
86+
int intPropVal = Integer.parseInt(propVal);
87+
88+
return intPropVal;
89+
}
90+
91+
@Bean
92+
public LocalSessionFactoryBean sessionFactory(){
93+
94+
// create session factorys
95+
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
96+
97+
// set the properties
98+
sessionFactory.setDataSource(myDataSource());
99+
sessionFactory.setPackagesToScan(env.getProperty("hibernate.packagesToScan"));
100+
sessionFactory.setHibernateProperties(getHibernateProperties());
101+
102+
return sessionFactory;
103+
}
104+
105+
@Bean
106+
@Autowired
107+
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
108+
109+
// setup transaction manager based on session factory
110+
HibernateTransactionManager txManager = new HibernateTransactionManager();
111+
txManager.setSessionFactory(sessionFactory);
112+
113+
return txManager;
114+
}
115+
116+
}
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package springrest.config;
2+
3+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
4+
5+
public class MySpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer
6+
{
7+
@Override
8+
protected Class<?>[] getRootConfigClasses()
9+
{
10+
return null;
11+
}
12+
13+
@Override
14+
protected Class<?>[] getServletConfigClasses()
15+
{
16+
return new Class[] { DemoAppConfig.class };
17+
}
18+
19+
@Override
20+
protected String[] getServletMappings()
21+
{
22+
return new String[] { "/" };
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package springrest.dao;
2+
3+
import java.util.List;
4+
5+
import springrest.entity.Customer;
6+
7+
public interface CustomerDAO {
8+
9+
public List<Customer> getCustomers();
10+
11+
public void saveCustomer(Customer theCustomer);
12+
13+
public Customer getCustomer(int theId);
14+
15+
public void deleteCustomer(int theId);
16+
17+
}
18+

0 commit comments

Comments
 (0)