diff --git a/pom.xml b/pom.xml index 584a881..4f49153 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ - + + 4.0.0 org.pratap.sb sb-ex-pom @@ -7,5 +7,6 @@ 1.0-SNAPSHOT hello-world - - + spring-boot-data-jpa-oracle + + \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/.gitignore b/spring-boot-data-jpa-oracle/.gitignore new file mode 100644 index 0000000..854b05d --- /dev/null +++ b/spring-boot-data-jpa-oracle/.gitignore @@ -0,0 +1,11 @@ +-#Intellij +-.idea/ +-*.iml +- +-### Maven ### +-target/ +- +-#Eclipse project files# +-.settings* +-.classpath +-.project diff --git a/spring-boot-data-jpa-oracle/.idea/compiler.xml b/spring-boot-data-jpa-oracle/.idea/compiler.xml new file mode 100644 index 0000000..dd1a3da --- /dev/null +++ b/spring-boot-data-jpa-oracle/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/.idea/libraries/Maven__junit_junit_3_8_1.xml b/spring-boot-data-jpa-oracle/.idea/libraries/Maven__junit_junit_3_8_1.xml new file mode 100644 index 0000000..71b2993 --- /dev/null +++ b/spring-boot-data-jpa-oracle/.idea/libraries/Maven__junit_junit_3_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/.idea/misc.xml b/spring-boot-data-jpa-oracle/.idea/misc.xml new file mode 100644 index 0000000..df553a4 --- /dev/null +++ b/spring-boot-data-jpa-oracle/.idea/misc.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/.idea/modules.xml b/spring-boot-data-jpa-oracle/.idea/modules.xml new file mode 100644 index 0000000..0ccba2d --- /dev/null +++ b/spring-boot-data-jpa-oracle/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/.idea/workspace.xml b/spring-boot-data-jpa-oracle/.idea/workspace.xml new file mode 100644 index 0000000..8b53857 --- /dev/null +++ b/spring-boot-data-jpa-oracle/.idea/workspace.xml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1495801710826 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/pom.xml b/spring-boot-data-jpa-oracle/pom.xml new file mode 100644 index 0000000..0115160 --- /dev/null +++ b/spring-boot-data-jpa-oracle/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + org.pratap.sb + spring-boot-data-jpa-oracle + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-parent + 1.5.1.RELEASE + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.apache.tomcat + tomcat-jdbc + + + + + + + + + + + com.github.noraui + ojdbc7 + 12.1.0.2 + + + + + + com.zaxxer + HikariCP + 2.6.0 + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + diff --git a/spring-boot-data-jpa-oracle/spring-boot-data-jpa-oracle.iml b/spring-boot-data-jpa-oracle/spring-boot-data-jpa-oracle.iml new file mode 100644 index 0000000..30b296e --- /dev/null +++ b/spring-boot-data-jpa-oracle/spring-boot-data-jpa-oracle.iml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/Application.java b/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/Application.java new file mode 100644 index 0000000..968247a --- /dev/null +++ b/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/Application.java @@ -0,0 +1,68 @@ +package org.pratap.sb.demo.jpa; + +import org.pratap.sb.demo.jpa.model.Customer; +import org.pratap.sb.demo.jpa.repository.CustomerRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.transaction.annotation.Transactional; + +import javax.sql.DataSource; +import java.text.SimpleDateFormat; +import java.util.stream.Stream; + +import static java.lang.System.exit; +/** + * Created by orgpratap on 5/26/17. + */ + + +@SpringBootApplication +public class Application implements CommandLineRunner { + + private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + @Autowired + DataSource dataSource; + + @Autowired + CustomerRepository customerRepository; + + public static void main(String[] args) throws Exception { + SpringApplication.run(Application.class, args); + } + + @Transactional(readOnly = true) + @Override + public void run(String... args) throws Exception { + + System.out.println("DATASOURCE = " + dataSource); + + System.out.println("\n1.findAll()..."); + for (Customer customer : customerRepository.findAll()) { + System.out.println(customer); + } + + System.out.println("\n2.findByEmail(String email)..."); + for (Customer customer : customerRepository.findByEmail("222@yahoo.com")) { + System.out.println(customer); + } + + System.out.println("\n3.findByDate(Date date)..."); + for (Customer customer : customerRepository.findByDate(sdf.parse("2017-02-12"))) { + System.out.println(customer); + } + + // For Stream, need @Transactional + System.out.println("\n4.findByEmailReturnStream(@Param(\"email\") String email)..."); + try (Stream stream = customerRepository.findByEmailReturnStream("333@yahoo.com")) { + stream.forEach(x -> System.out.println(x)); + } + + System.out.println("Done!"); + + exit(0); + } + +} \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/model/Customer.java b/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/model/Customer.java new file mode 100644 index 0000000..0fab767 --- /dev/null +++ b/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/model/Customer.java @@ -0,0 +1,68 @@ +package org.pratap.sb.demo.jpa.model; + +import javax.persistence.*; +import java.util.Date; +/** + * Created by orgpratap on 5/26/17. + */ +@Entity +public class Customer { + + // "customer_seq" is Oracle sequence name. + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CUST_SEQ") + @SequenceGenerator(sequenceName = "customer_seq", allocationSize = 1, name = "CUST_SEQ") + Long id; + + String name; + + String email; + + @Column(name = "CREATED_DATE") + Date date; + + //getters and setters, contructors + + + public Customer() { + } + + public Customer(Long id, String name, String email, Date date) { + this.id = id; + this.name = name; + this.email = email; + this.date = date; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } +} \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/repository/CustomerRepository.java b/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/repository/CustomerRepository.java new file mode 100644 index 0000000..411a58f --- /dev/null +++ b/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/repository/CustomerRepository.java @@ -0,0 +1,25 @@ +package org.pratap.sb.demo.jpa.repository; + +import org.pratap.sb.demo.jpa.model.Customer; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; + +import java.util.Date; +import java.util.List; +import java.util.stream.Stream; + +/** + * Created by orgpratap on 5/26/17. + */ +public interface CustomerRepository extends CrudRepository { + + List findByEmail(String email); + + List findByDate(Date date); + + // custom query example and return a stream + @Query("select c from Customer c where c.email = :email") + Stream findByEmailReturnStream(@Param("email") String email); + +} \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/src/main/resources/application.properties b/spring-boot-data-jpa-oracle/src/main/resources/application.properties new file mode 100644 index 0000000..60b99bd --- /dev/null +++ b/spring-boot-data-jpa-oracle/src/main/resources/application.properties @@ -0,0 +1,22 @@ +spring.main.banner-mode=off + +# create and drop tables and sequences, loads import.sql +spring.jpa.hibernate.ddl-auto=create-drop + +# Oracle settings +spring.datasource.url=jdbc:oracle:thin:@10.42.45.66:1521:xe +spring.datasource.username=system +spring.datasource.password=root +spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver + +# HikariCP settings +# spring.datasource.hikari.* + +spring.datasource.hikari.connection-timeout=60000 +spring.datasource.hikari.maximum-pool-size=5 + +# logging +logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n +logging.level.org.hibernate.SQL=debug +#logging.level.org.hibernate.type.descriptor.sql=trace +logging.level.=error \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/src/main/resources/import.sql b/spring-boot-data-jpa-oracle/src/main/resources/import.sql new file mode 100644 index 0000000..1811cc3 --- /dev/null +++ b/spring-boot-data-jpa-oracle/src/main/resources/import.sql @@ -0,0 +1,3 @@ +INSERT INTO "CUSTOMER" (ID, NAME, EMAIL, CREATED_DATE) VALUES(1, 'mkyong','111@yahoo.com', TO_DATE('2017-02-11', 'yyyy-mm-dd')); +INSERT INTO "CUSTOMER" (ID, NAME, EMAIL, CREATED_DATE) VALUES(2, 'yflow','222@yahoo.com', TO_DATE('2017-02-12', 'yyyy-mm-dd')); +INSERT INTO "CUSTOMER" (ID, NAME, EMAIL, CREATED_DATE) VALUES(3, 'zilap','333@yahoo.com', TO_DATE('2017-02-13', 'yyyy-mm-dd')); \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/target/classes/application.properties b/spring-boot-data-jpa-oracle/target/classes/application.properties new file mode 100644 index 0000000..60b99bd --- /dev/null +++ b/spring-boot-data-jpa-oracle/target/classes/application.properties @@ -0,0 +1,22 @@ +spring.main.banner-mode=off + +# create and drop tables and sequences, loads import.sql +spring.jpa.hibernate.ddl-auto=create-drop + +# Oracle settings +spring.datasource.url=jdbc:oracle:thin:@10.42.45.66:1521:xe +spring.datasource.username=system +spring.datasource.password=root +spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver + +# HikariCP settings +# spring.datasource.hikari.* + +spring.datasource.hikari.connection-timeout=60000 +spring.datasource.hikari.maximum-pool-size=5 + +# logging +logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n +logging.level.org.hibernate.SQL=debug +#logging.level.org.hibernate.type.descriptor.sql=trace +logging.level.=error \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/target/classes/import.sql b/spring-boot-data-jpa-oracle/target/classes/import.sql new file mode 100644 index 0000000..1811cc3 --- /dev/null +++ b/spring-boot-data-jpa-oracle/target/classes/import.sql @@ -0,0 +1,3 @@ +INSERT INTO "CUSTOMER" (ID, NAME, EMAIL, CREATED_DATE) VALUES(1, 'mkyong','111@yahoo.com', TO_DATE('2017-02-11', 'yyyy-mm-dd')); +INSERT INTO "CUSTOMER" (ID, NAME, EMAIL, CREATED_DATE) VALUES(2, 'yflow','222@yahoo.com', TO_DATE('2017-02-12', 'yyyy-mm-dd')); +INSERT INTO "CUSTOMER" (ID, NAME, EMAIL, CREATED_DATE) VALUES(3, 'zilap','333@yahoo.com', TO_DATE('2017-02-13', 'yyyy-mm-dd')); \ No newline at end of file diff --git a/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/Application.class b/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/Application.class new file mode 100644 index 0000000..cbd2d64 Binary files /dev/null and b/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/Application.class differ diff --git a/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/model/Customer.class b/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/model/Customer.class new file mode 100644 index 0000000..7425655 Binary files /dev/null and b/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/model/Customer.class differ diff --git a/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/repository/CustomerRepository.class b/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/repository/CustomerRepository.class new file mode 100644 index 0000000..7ef89f8 Binary files /dev/null and b/spring-boot-data-jpa-oracle/target/classes/org/pratap/sb/demo/jpa/repository/CustomerRepository.class differ diff --git a/spring-boot-data-jpa-oracle/target/maven-archiver/pom.properties b/spring-boot-data-jpa-oracle/target/maven-archiver/pom.properties new file mode 100644 index 0000000..0d9cab3 --- /dev/null +++ b/spring-boot-data-jpa-oracle/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Apache Maven +#Fri May 26 20:29:50 IST 2017 +version=1.0-SNAPSHOT +groupId=org.pratap.sb +artifactId=spring-boot-data-jpa-oracle diff --git a/spring-boot-data-jpa-oracle/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/spring-boot-data-jpa-oracle/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..3a6df06 --- /dev/null +++ b/spring-boot-data-jpa-oracle/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +org/pratap/sb/demo/jpa/Application.class +org/pratap/sb/demo/jpa/repository/CustomerRepository.class +org/pratap/sb/demo/jpa/model/Customer.class diff --git a/spring-boot-data-jpa-oracle/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/spring-boot-data-jpa-oracle/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..d8f4ed3 --- /dev/null +++ b/spring-boot-data-jpa-oracle/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +/home/orgpratap/Desktop/skill-enhancement-workspace/sb-ex-root/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/Application.java +/home/orgpratap/Desktop/skill-enhancement-workspace/sb-ex-root/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/repository/CustomerRepository.java +/home/orgpratap/Desktop/skill-enhancement-workspace/sb-ex-root/spring-boot-data-jpa-oracle/src/main/java/org/pratap/sb/demo/jpa/model/Customer.java diff --git a/spring-boot-data-jpa-oracle/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/spring-boot-data-jpa-oracle/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/spring-boot-data-jpa-oracle/target/spring-boot-data-jpa-oracle-1.0-SNAPSHOT.jar b/spring-boot-data-jpa-oracle/target/spring-boot-data-jpa-oracle-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..8d0d9b1 Binary files /dev/null and b/spring-boot-data-jpa-oracle/target/spring-boot-data-jpa-oracle-1.0-SNAPSHOT.jar differ diff --git a/spring-boot-data-jpa-oracle/target/spring-boot-data-jpa-oracle-1.0-SNAPSHOT.jar.original b/spring-boot-data-jpa-oracle/target/spring-boot-data-jpa-oracle-1.0-SNAPSHOT.jar.original new file mode 100644 index 0000000..5a08b4a Binary files /dev/null and b/spring-boot-data-jpa-oracle/target/spring-boot-data-jpa-oracle-1.0-SNAPSHOT.jar.original differ