From f9ddc38a39fe6baa835fb7418bd493c975b3aeb7 Mon Sep 17 00:00:00 2001 From: RajatGarg Date: Tue, 1 May 2018 14:24:25 +0530 Subject: [PATCH] BAEL-1734 move packages from libraries to libraries-data --- libraries-data/README.md | 4 + libraries-data/log4j.properties | 1 + libraries-data/myPersistence.xml | 26 +++ libraries-data/pom.xml | 73 ++++++ .../com/baeldung/hikaricp/DataSource.java | 0 .../java/com/baeldung/hikaricp/Employee.java | 0 .../com/baeldung/hikaricp/HikariCPDemo.java | 0 .../jcache/SimpleCacheEntryListener.java | 0 .../baeldung/jcache/SimpleCacheLoader.java | 0 .../baeldung/jcache/SimpleEntryProcessor.java | 0 .../java/com/baeldung/jdo/GuideToJDO.java | 0 .../main/java/com/baeldung/jdo/Product.java | 0 .../java/com/baeldung/jdo/ProductXML.java | 0 .../java/com/baeldung/jdo/query/MyApp.java | 192 ++++++++-------- .../com/baeldung/jdo/query/ProductItem.java | 140 ++++++------ .../com/baeldung/jdo/xml/AnnotadedPerson.java | 132 +++++------ .../main/java/com/baeldung/jdo/xml/MyApp.java | 210 +++++++++--------- .../java/com/baeldung/jdo/xml/Person.java | 116 +++++----- .../java/com/baeldung/jdo/xml/Product.java | 116 +++++----- .../src/main/resources/META-INF/BenchmarkList | 0 .../resources/META-INF/datanucleus.properties | 4 + .../src/main/resources/META-INF/jdoconfig.xml | 32 +-- .../src/main/resources/META-INF/package.jdo | 56 ++--- .../src/main/resources/db.sql | 0 .../hikaricp/HikariCPIntegrationTest.java | 0 .../com/baeldung/jcache/CacheLoaderTest.java | 0 .../jcache/EntryProcessorIntegrationTest.java | 0 .../jcache/EventListenerIntegrationTest.java | 0 .../jcache/JCacheIntegrationTest.java | 0 .../jdo/GuideToJDOIntegrationTest.java | 0 libraries/README.md | 4 - 31 files changed, 605 insertions(+), 501 deletions(-) create mode 100644 libraries-data/log4j.properties create mode 100644 libraries-data/myPersistence.xml rename {libraries => libraries-data}/src/main/java/com/baeldung/hikaricp/DataSource.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/hikaricp/Employee.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/hikaricp/HikariCPDemo.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jcache/SimpleCacheEntryListener.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jcache/SimpleCacheLoader.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jcache/SimpleEntryProcessor.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/GuideToJDO.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/Product.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/ProductXML.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/query/MyApp.java (97%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/query/ProductItem.java (95%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/xml/AnnotadedPerson.java (96%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/xml/MyApp.java (97%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/xml/Person.java (95%) rename {libraries => libraries-data}/src/main/java/com/baeldung/jdo/xml/Product.java (94%) create mode 100644 libraries-data/src/main/resources/META-INF/BenchmarkList create mode 100644 libraries-data/src/main/resources/META-INF/datanucleus.properties rename {libraries => libraries-data}/src/main/resources/META-INF/jdoconfig.xml (98%) rename {libraries => libraries-data}/src/main/resources/META-INF/package.jdo (97%) rename {libraries => libraries-data}/src/main/resources/db.sql (100%) rename {libraries => libraries-data}/src/test/java/com/baeldung/hikaricp/HikariCPIntegrationTest.java (100%) rename {libraries => libraries-data}/src/test/java/com/baeldung/jcache/CacheLoaderTest.java (100%) rename {libraries => libraries-data}/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java (100%) rename {libraries => libraries-data}/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java (100%) rename {libraries => libraries-data}/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java (100%) rename {libraries => libraries-data}/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java (100%) diff --git a/libraries-data/README.md b/libraries-data/README.md index 9e8d32fa44..afca20eb2a 100644 --- a/libraries-data/README.md +++ b/libraries-data/README.md @@ -3,3 +3,7 @@ - [Introduction to ORMLite](http://www.baeldung.com/ormlite) - [Introduction To Kryo](http://www.baeldung.com/kryo) - [Introduction to KafkaStreams in Java](http://www.baeldung.com/java-kafka-streams) +- [Guide to Java Data Objects](http://www.baeldung.com/jdo) +- [Intro to JDO Queries 2/2](http://www.baeldung.com/jdo-queries) +- [Introduction to HikariCP](http://www.baeldung.com/hikaricp) +- [Introduction to JCache](http://www.baeldung.com/jcache) diff --git a/libraries-data/log4j.properties b/libraries-data/log4j.properties new file mode 100644 index 0000000000..2173c5d96f --- /dev/null +++ b/libraries-data/log4j.properties @@ -0,0 +1 @@ +log4j.rootLogger=INFO, stdout diff --git a/libraries-data/myPersistence.xml b/libraries-data/myPersistence.xml new file mode 100644 index 0000000000..de2c250957 --- /dev/null +++ b/libraries-data/myPersistence.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index 55bf02ae16..6ea80f1c1f 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -85,6 +85,55 @@ gson ${gson.version} + + + com.zaxxer + HikariCP + 2.7.2 + compile + + + + org.datanucleus + javax.jdo + 3.2.0-m7 + + + org.datanucleus + datanucleus-core + 5.1.1 + + + org.datanucleus + datanucleus-api-jdo + 5.1.1 + + + org.datanucleus + datanucleus-rdbms + 5.1.1 + + + org.datanucleus + datanucleus-maven-plugin + 5.0.2 + + + org.datanucleus + datanucleus-xml + 5.0.0-release + + + org.datanucleus + datanucleus-jdo-query + 5.0.4 + + + + javax.cache + cache-api + ${cache.version} + @@ -184,6 +233,29 @@ + + + org.datanucleus + datanucleus-maven-plugin + 5.0.2 + + JDO + ${basedir}/datanucleus.properties + ${basedir}/log4j.properties + true + false + + + + + process-classes + + enhance + + + + + @@ -203,5 +275,6 @@ 1.0.0 2.3.0 2.8.2 + 1.0.0 \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/hikaricp/DataSource.java b/libraries-data/src/main/java/com/baeldung/hikaricp/DataSource.java similarity index 100% rename from libraries/src/main/java/com/baeldung/hikaricp/DataSource.java rename to libraries-data/src/main/java/com/baeldung/hikaricp/DataSource.java diff --git a/libraries/src/main/java/com/baeldung/hikaricp/Employee.java b/libraries-data/src/main/java/com/baeldung/hikaricp/Employee.java similarity index 100% rename from libraries/src/main/java/com/baeldung/hikaricp/Employee.java rename to libraries-data/src/main/java/com/baeldung/hikaricp/Employee.java diff --git a/libraries/src/main/java/com/baeldung/hikaricp/HikariCPDemo.java b/libraries-data/src/main/java/com/baeldung/hikaricp/HikariCPDemo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/hikaricp/HikariCPDemo.java rename to libraries-data/src/main/java/com/baeldung/hikaricp/HikariCPDemo.java diff --git a/libraries/src/main/java/com/baeldung/jcache/SimpleCacheEntryListener.java b/libraries-data/src/main/java/com/baeldung/jcache/SimpleCacheEntryListener.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jcache/SimpleCacheEntryListener.java rename to libraries-data/src/main/java/com/baeldung/jcache/SimpleCacheEntryListener.java diff --git a/libraries/src/main/java/com/baeldung/jcache/SimpleCacheLoader.java b/libraries-data/src/main/java/com/baeldung/jcache/SimpleCacheLoader.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jcache/SimpleCacheLoader.java rename to libraries-data/src/main/java/com/baeldung/jcache/SimpleCacheLoader.java diff --git a/libraries/src/main/java/com/baeldung/jcache/SimpleEntryProcessor.java b/libraries-data/src/main/java/com/baeldung/jcache/SimpleEntryProcessor.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jcache/SimpleEntryProcessor.java rename to libraries-data/src/main/java/com/baeldung/jcache/SimpleEntryProcessor.java diff --git a/libraries/src/main/java/com/baeldung/jdo/GuideToJDO.java b/libraries-data/src/main/java/com/baeldung/jdo/GuideToJDO.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdo/GuideToJDO.java rename to libraries-data/src/main/java/com/baeldung/jdo/GuideToJDO.java diff --git a/libraries/src/main/java/com/baeldung/jdo/Product.java b/libraries-data/src/main/java/com/baeldung/jdo/Product.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdo/Product.java rename to libraries-data/src/main/java/com/baeldung/jdo/Product.java diff --git a/libraries/src/main/java/com/baeldung/jdo/ProductXML.java b/libraries-data/src/main/java/com/baeldung/jdo/ProductXML.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdo/ProductXML.java rename to libraries-data/src/main/java/com/baeldung/jdo/ProductXML.java diff --git a/libraries/src/main/java/com/baeldung/jdo/query/MyApp.java b/libraries-data/src/main/java/com/baeldung/jdo/query/MyApp.java similarity index 97% rename from libraries/src/main/java/com/baeldung/jdo/query/MyApp.java rename to libraries-data/src/main/java/com/baeldung/jdo/query/MyApp.java index 235142d16e..30f019a79d 100644 --- a/libraries/src/main/java/com/baeldung/jdo/query/MyApp.java +++ b/libraries-data/src/main/java/com/baeldung/jdo/query/MyApp.java @@ -1,96 +1,96 @@ -package com.baeldung.jdo.query; - -import java.util.List; - -import javax.jdo.JDOQLTypedQuery; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import javax.jdo.Query; - -import org.datanucleus.api.jdo.JDOPersistenceManagerFactory; -import org.datanucleus.metadata.PersistenceUnitMetaData; - -public class MyApp { - - private static PersistenceManagerFactory pmf; - private static PersistenceManager pm; - - public static void main(String[] args) { - - defineDynamicPersistentUnit(); - createTestData(); - queryUsingJDOQL(); - queryUsingTypedJDOQL(); - queryUsingSQL(); - queryUsingJPQL(); - - } - - public static void createTestData() { - ProductItem item1 = new ProductItem("supportedItem", "price less than 10", "SoldOut", 5); - ProductItem item2 = new ProductItem("pro2", "price less than 10", "InStock", 8); - ProductItem item3 = new ProductItem("pro3", "price more than 10", "SoldOut", 15); - - if (pm != null) { - pm.makePersistent(item1); - pm.makePersistent(item2); - pm.makePersistent(item3); - } - } - - public static void defineDynamicPersistentUnit() { - - PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null); - pumd.addProperty("javax.jdo.option.ConnectionURL", "jdbc:mysql://localhost:3306/jdo_db"); - pumd.addProperty("javax.jdo.option.ConnectionUserName", "root"); - pumd.addProperty("javax.jdo.option.ConnectionPassword", "admin"); - pumd.addProperty("javax.jdo.option.ConnectionDriverName", "com.mysql.jdbc.Driver"); - pumd.addProperty("datanucleus.schema.autoCreateAll", "true"); - - pmf = new JDOPersistenceManagerFactory(pumd, null); - pm = pmf.getPersistenceManager(); - } - - public static void queryUsingJDOQL() { - - Query query = pm.newQuery("SELECT FROM com.baeldung.jdo.query.ProductItem " + "WHERE price < threshold PARAMETERS double threshold"); - List explicitParamResults = (List) query.execute(10); - - query = pm.newQuery("SELECT FROM " + "com.baeldung.jdo.query.ProductItem WHERE price < :threshold"); - query.setParameters("double threshold"); - List explicitParamResults2 = (List) query.execute(10); - - query = pm.newQuery("SELECT FROM " + "com.baeldung.jdo.query.ProductItem WHERE price < :threshold"); - List implicitParamResults = (List) query.execute(10); - - } - - public static void queryUsingTypedJDOQL() { - JDOQLTypedQuery tq = pm.newJDOQLTypedQuery(ProductItem.class); - QProductItem cand = QProductItem.candidate(); - tq = tq.filter(cand.price.lt(10).and(cand.name.startsWith("pro"))); - List results = tq.executeList(); - - } - - public static void queryUsingSQL() { - - Query query = pm.newQuery("javax.jdo.query.SQL", "select * from " + "product_item where price < ? and status = ?"); - query.setClass(ProductItem.class); - query.setParameters(10, "InStock"); - List results = query.executeList(); - - } - - public static void queryUsingJPQL() { - Query query = pm.newQuery("JPQL", "select i from " + "com.baeldung.jdo.query.ProductItem i where i.price < 10" + " and i.status = 'InStock'"); - List results = (List) query.execute(); - - } - - public static void namedQuery() { - Query query = pm.newNamedQuery(ProductItem.class, "PriceBelow10"); - List results = query.executeList(); - - } -} +package com.baeldung.jdo.query; + +import java.util.List; + +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Query; + +import org.datanucleus.api.jdo.JDOPersistenceManagerFactory; +import org.datanucleus.metadata.PersistenceUnitMetaData; + +public class MyApp { + + private static PersistenceManagerFactory pmf; + private static PersistenceManager pm; + + public static void main(String[] args) { + + defineDynamicPersistentUnit(); + createTestData(); + queryUsingJDOQL(); + queryUsingTypedJDOQL(); + queryUsingSQL(); + queryUsingJPQL(); + + } + + public static void createTestData() { + ProductItem item1 = new ProductItem("supportedItem", "price less than 10", "SoldOut", 5); + ProductItem item2 = new ProductItem("pro2", "price less than 10", "InStock", 8); + ProductItem item3 = new ProductItem("pro3", "price more than 10", "SoldOut", 15); + + if (pm != null) { + pm.makePersistent(item1); + pm.makePersistent(item2); + pm.makePersistent(item3); + } + } + + public static void defineDynamicPersistentUnit() { + + PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null); + pumd.addProperty("javax.jdo.option.ConnectionURL", "jdbc:mysql://localhost:3306/jdo_db"); + pumd.addProperty("javax.jdo.option.ConnectionUserName", "root"); + pumd.addProperty("javax.jdo.option.ConnectionPassword", "admin"); + pumd.addProperty("javax.jdo.option.ConnectionDriverName", "com.mysql.jdbc.Driver"); + pumd.addProperty("datanucleus.schema.autoCreateAll", "true"); + + pmf = new JDOPersistenceManagerFactory(pumd, null); + pm = pmf.getPersistenceManager(); + } + + public static void queryUsingJDOQL() { + + Query query = pm.newQuery("SELECT FROM com.baeldung.jdo.query.ProductItem " + "WHERE price < threshold PARAMETERS double threshold"); + List explicitParamResults = (List) query.execute(10); + + query = pm.newQuery("SELECT FROM " + "com.baeldung.jdo.query.ProductItem WHERE price < :threshold"); + query.setParameters("double threshold"); + List explicitParamResults2 = (List) query.execute(10); + + query = pm.newQuery("SELECT FROM " + "com.baeldung.jdo.query.ProductItem WHERE price < :threshold"); + List implicitParamResults = (List) query.execute(10); + + } + + public static void queryUsingTypedJDOQL() { + JDOQLTypedQuery tq = pm.newJDOQLTypedQuery(ProductItem.class); + QProductItem cand = QProductItem.candidate(); + tq = tq.filter(cand.price.lt(10).and(cand.name.startsWith("pro"))); + List results = tq.executeList(); + + } + + public static void queryUsingSQL() { + + Query query = pm.newQuery("javax.jdo.query.SQL", "select * from " + "product_item where price < ? and status = ?"); + query.setClass(ProductItem.class); + query.setParameters(10, "InStock"); + List results = query.executeList(); + + } + + public static void queryUsingJPQL() { + Query query = pm.newQuery("JPQL", "select i from " + "com.baeldung.jdo.query.ProductItem i where i.price < 10" + " and i.status = 'InStock'"); + List results = (List) query.execute(); + + } + + public static void namedQuery() { + Query query = pm.newNamedQuery(ProductItem.class, "PriceBelow10"); + List results = query.executeList(); + + } +} diff --git a/libraries/src/main/java/com/baeldung/jdo/query/ProductItem.java b/libraries-data/src/main/java/com/baeldung/jdo/query/ProductItem.java similarity index 95% rename from libraries/src/main/java/com/baeldung/jdo/query/ProductItem.java rename to libraries-data/src/main/java/com/baeldung/jdo/query/ProductItem.java index fbe999ba2a..25dd8bdb98 100644 --- a/libraries/src/main/java/com/baeldung/jdo/query/ProductItem.java +++ b/libraries-data/src/main/java/com/baeldung/jdo/query/ProductItem.java @@ -1,70 +1,70 @@ -package com.baeldung.jdo.query; - -import javax.jdo.annotations.IdGeneratorStrategy; -import javax.jdo.annotations.PersistenceCapable; -import javax.jdo.annotations.Persistent; -import javax.jdo.annotations.PrimaryKey; - -@PersistenceCapable(table = "product_item") -public class ProductItem { - - @PrimaryKey - @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT) - int id; - String name; - String description; - String status; - double price; - - public ProductItem() { - - } - - public ProductItem(String name, String description, String status, double price) { - this.name = name; - this.description = description; - this.status = status; - this.price = price; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public double getPrice() { - return price; - } - - public void setPrice(double price) { - this.price = price; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - -} +package com.baeldung.jdo.query; + +import javax.jdo.annotations.IdGeneratorStrategy; +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.Persistent; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable(table = "product_item") +public class ProductItem { + + @PrimaryKey + @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT) + int id; + String name; + String description; + String status; + double price; + + public ProductItem() { + + } + + public ProductItem(String name, String description, String status, double price) { + this.name = name; + this.description = description; + this.status = status; + this.price = price; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + +} diff --git a/libraries/src/main/java/com/baeldung/jdo/xml/AnnotadedPerson.java b/libraries-data/src/main/java/com/baeldung/jdo/xml/AnnotadedPerson.java similarity index 96% rename from libraries/src/main/java/com/baeldung/jdo/xml/AnnotadedPerson.java rename to libraries-data/src/main/java/com/baeldung/jdo/xml/AnnotadedPerson.java index acfc26627a..0673ff341c 100644 --- a/libraries/src/main/java/com/baeldung/jdo/xml/AnnotadedPerson.java +++ b/libraries-data/src/main/java/com/baeldung/jdo/xml/AnnotadedPerson.java @@ -1,66 +1,66 @@ -package com.baeldung.jdo.xml; - -import java.util.ArrayList; -import java.util.List; - -import javax.jdo.annotations.Element; -import javax.jdo.annotations.PersistenceCapable; -import javax.jdo.annotations.PrimaryKey; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; - -@PersistenceCapable(schema = "/myproduct/people", table = "person") -public class AnnotadedPerson { - @XmlAttribute - private long personNum; - - @PrimaryKey - private String firstName; - private String lastName; - - @XmlElementWrapper(name = "phone-numbers") - @XmlElement(name = "phone-number") - @Element(types = String.class) - private List phoneNumbers = new ArrayList(); - - public AnnotadedPerson(long personNum, String firstName, String lastName) { - super(); - this.personNum = personNum; - this.firstName = firstName; - this.lastName = lastName; - } - - public long getPersonNum() { - return personNum; - } - - public void setPersonNum(long personNum) { - this.personNum = personNum; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public List getPhoneNumbers() { - return phoneNumbers; - } - - public void setPhoneNumbers(List phoneNumbers) { - this.phoneNumbers = phoneNumbers; - } - -} +package com.baeldung.jdo.xml; + +import java.util.ArrayList; +import java.util.List; + +import javax.jdo.annotations.Element; +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.PrimaryKey; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; + +@PersistenceCapable(schema = "/myproduct/people", table = "person") +public class AnnotadedPerson { + @XmlAttribute + private long personNum; + + @PrimaryKey + private String firstName; + private String lastName; + + @XmlElementWrapper(name = "phone-numbers") + @XmlElement(name = "phone-number") + @Element(types = String.class) + private List phoneNumbers = new ArrayList(); + + public AnnotadedPerson(long personNum, String firstName, String lastName) { + super(); + this.personNum = personNum; + this.firstName = firstName; + this.lastName = lastName; + } + + public long getPersonNum() { + return personNum; + } + + public void setPersonNum(long personNum) { + this.personNum = personNum; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public List getPhoneNumbers() { + return phoneNumbers; + } + + public void setPhoneNumbers(List phoneNumbers) { + this.phoneNumbers = phoneNumbers; + } + +} diff --git a/libraries/src/main/java/com/baeldung/jdo/xml/MyApp.java b/libraries-data/src/main/java/com/baeldung/jdo/xml/MyApp.java similarity index 97% rename from libraries/src/main/java/com/baeldung/jdo/xml/MyApp.java rename to libraries-data/src/main/java/com/baeldung/jdo/xml/MyApp.java index c75d3695f7..b43b45f415 100644 --- a/libraries/src/main/java/com/baeldung/jdo/xml/MyApp.java +++ b/libraries-data/src/main/java/com/baeldung/jdo/xml/MyApp.java @@ -1,105 +1,105 @@ -package com.baeldung.jdo.xml; - -import java.util.List; - -import javax.jdo.JDOHelper; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import javax.jdo.Query; -import javax.jdo.Transaction; - -import org.datanucleus.api.jdo.JDOPersistenceManagerFactory; -import org.datanucleus.metadata.PersistenceUnitMetaData; - -public class MyApp { - - private static PersistenceUnitMetaData pumd; - private static PersistenceManagerFactory pmf; - private static PersistenceManager pm; - - public static void main(String[] args) { - - // persist product object using dynamic persistence unit - defineDynamicPersistentUnit(); - Product product = new Product("id1", "Sony Discman", "A standard discman from Sony", 49.99); - persistObject(product); - closePersistenceManager(); - - // persist AnnotatedPerson object using named pmf - defineNamedPersistenceManagerFactory("XmlDatastore"); - AnnotadedPerson annotatedPerson = new AnnotadedPerson(654320, "annotated", "person"); - annotatedPerson.getPhoneNumbers().add("999999999"); - annotatedPerson.getPhoneNumbers().add("000000000"); - persistObject(annotatedPerson); - queryAnnotatedPersonsInXML(); - closePersistenceManager(); - - // persist Person object using PMF created by properties file - definePersistenceManagerFactoryUsingPropertiesFile("META-INF\\datanucleus.properties"); - Person person = new Person(654321, "bealdung", "author"); - person.getPhoneNumbers().add("123456789"); - person.getPhoneNumbers().add("987654321"); - persistObject(person); - queryPersonsInXML(); - closePersistenceManager(); - } - - public static void defineDynamicPersistentUnit() { - - PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null); - pumd.addProperty("javax.jdo.option.ConnectionURL", "xml:file:myfile_dynamicPMF.xml"); - pumd.addProperty("datanucleus.schema.autoCreateAll", "true"); - pumd.addProperty("datanucleus.xml.indentSize", "4"); - - pmf = new JDOPersistenceManagerFactory(pumd, null); - pm = pmf.getPersistenceManager(); - } - - public static void defineNamedPersistenceManagerFactory(String pmfName) { - - pmf = JDOHelper.getPersistenceManagerFactory("XmlDatastore"); - pm = pmf.getPersistenceManager(); - } - - public static void definePersistenceManagerFactoryUsingPropertiesFile(String filePath) { - - pmf = JDOHelper.getPersistenceManagerFactory(filePath); - pm = pmf.getPersistenceManager(); - } - - public static void closePersistenceManager() { - - if (pm != null && !pm.isClosed()) { - pm.close(); - } - } - - public static void persistObject(Object obj) { - - Transaction tx = pm.currentTransaction(); - - try { - tx.begin(); - pm.makePersistent(obj); - tx.commit(); - } finally { - if (tx.isActive()) { - tx.rollback(); - } - } - } - - public static void queryPersonsInXML() { - - Query query = pm.newQuery(Person.class); - List result = query.executeList(); - System.out.println("name: " + result.get(0).getFirstName()); - } - - public static void queryAnnotatedPersonsInXML() { - - Query query = pm.newQuery(AnnotadedPerson.class); - List result = query.executeList(); - System.out.println("name: " + result.get(0).getFirstName()); - } -} +package com.baeldung.jdo.xml; + +import java.util.List; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Query; +import javax.jdo.Transaction; + +import org.datanucleus.api.jdo.JDOPersistenceManagerFactory; +import org.datanucleus.metadata.PersistenceUnitMetaData; + +public class MyApp { + + private static PersistenceUnitMetaData pumd; + private static PersistenceManagerFactory pmf; + private static PersistenceManager pm; + + public static void main(String[] args) { + + // persist product object using dynamic persistence unit + defineDynamicPersistentUnit(); + Product product = new Product("id1", "Sony Discman", "A standard discman from Sony", 49.99); + persistObject(product); + closePersistenceManager(); + + // persist AnnotatedPerson object using named pmf + defineNamedPersistenceManagerFactory("XmlDatastore"); + AnnotadedPerson annotatedPerson = new AnnotadedPerson(654320, "annotated", "person"); + annotatedPerson.getPhoneNumbers().add("999999999"); + annotatedPerson.getPhoneNumbers().add("000000000"); + persistObject(annotatedPerson); + queryAnnotatedPersonsInXML(); + closePersistenceManager(); + + // persist Person object using PMF created by properties file + definePersistenceManagerFactoryUsingPropertiesFile("META-INF\\datanucleus.properties"); + Person person = new Person(654321, "bealdung", "author"); + person.getPhoneNumbers().add("123456789"); + person.getPhoneNumbers().add("987654321"); + persistObject(person); + queryPersonsInXML(); + closePersistenceManager(); + } + + public static void defineDynamicPersistentUnit() { + + PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null); + pumd.addProperty("javax.jdo.option.ConnectionURL", "xml:file:myfile_dynamicPMF.xml"); + pumd.addProperty("datanucleus.schema.autoCreateAll", "true"); + pumd.addProperty("datanucleus.xml.indentSize", "4"); + + pmf = new JDOPersistenceManagerFactory(pumd, null); + pm = pmf.getPersistenceManager(); + } + + public static void defineNamedPersistenceManagerFactory(String pmfName) { + + pmf = JDOHelper.getPersistenceManagerFactory("XmlDatastore"); + pm = pmf.getPersistenceManager(); + } + + public static void definePersistenceManagerFactoryUsingPropertiesFile(String filePath) { + + pmf = JDOHelper.getPersistenceManagerFactory(filePath); + pm = pmf.getPersistenceManager(); + } + + public static void closePersistenceManager() { + + if (pm != null && !pm.isClosed()) { + pm.close(); + } + } + + public static void persistObject(Object obj) { + + Transaction tx = pm.currentTransaction(); + + try { + tx.begin(); + pm.makePersistent(obj); + tx.commit(); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + } + } + + public static void queryPersonsInXML() { + + Query query = pm.newQuery(Person.class); + List result = query.executeList(); + System.out.println("name: " + result.get(0).getFirstName()); + } + + public static void queryAnnotatedPersonsInXML() { + + Query query = pm.newQuery(AnnotadedPerson.class); + List result = query.executeList(); + System.out.println("name: " + result.get(0).getFirstName()); + } +} diff --git a/libraries/src/main/java/com/baeldung/jdo/xml/Person.java b/libraries-data/src/main/java/com/baeldung/jdo/xml/Person.java similarity index 95% rename from libraries/src/main/java/com/baeldung/jdo/xml/Person.java rename to libraries-data/src/main/java/com/baeldung/jdo/xml/Person.java index 0678201afd..4fbc81ee03 100644 --- a/libraries/src/main/java/com/baeldung/jdo/xml/Person.java +++ b/libraries-data/src/main/java/com/baeldung/jdo/xml/Person.java @@ -1,58 +1,58 @@ -package com.baeldung.jdo.xml; - -import java.util.ArrayList; -import java.util.List; - -import javax.jdo.annotations.PersistenceCapable; -import javax.jdo.annotations.PrimaryKey; - -@PersistenceCapable -public class Person { - private long personNum; - - @PrimaryKey - private String firstName; - private String lastName; - - private List phoneNumbers = new ArrayList(); - - public Person(long personNum, String firstName, String lastName) { - super(); - this.personNum = personNum; - this.firstName = firstName; - this.lastName = lastName; - } - - public long getPersonNum() { - return personNum; - } - - public void setPersonNum(long personNum) { - this.personNum = personNum; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public List getPhoneNumbers() { - return phoneNumbers; - } - - public void setPhoneNumbers(List phoneNumbers) { - this.phoneNumbers = phoneNumbers; - } - -} +package com.baeldung.jdo.xml; + +import java.util.ArrayList; +import java.util.List; + +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable +public class Person { + private long personNum; + + @PrimaryKey + private String firstName; + private String lastName; + + private List phoneNumbers = new ArrayList(); + + public Person(long personNum, String firstName, String lastName) { + super(); + this.personNum = personNum; + this.firstName = firstName; + this.lastName = lastName; + } + + public long getPersonNum() { + return personNum; + } + + public void setPersonNum(long personNum) { + this.personNum = personNum; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public List getPhoneNumbers() { + return phoneNumbers; + } + + public void setPhoneNumbers(List phoneNumbers) { + this.phoneNumbers = phoneNumbers; + } + +} diff --git a/libraries/src/main/java/com/baeldung/jdo/xml/Product.java b/libraries-data/src/main/java/com/baeldung/jdo/xml/Product.java similarity index 94% rename from libraries/src/main/java/com/baeldung/jdo/xml/Product.java rename to libraries-data/src/main/java/com/baeldung/jdo/xml/Product.java index 1e46f212cb..5aac05834d 100644 --- a/libraries/src/main/java/com/baeldung/jdo/xml/Product.java +++ b/libraries-data/src/main/java/com/baeldung/jdo/xml/Product.java @@ -1,58 +1,58 @@ -package com.baeldung.jdo.xml; - -import javax.jdo.annotations.PersistenceCapable; -import javax.jdo.annotations.PrimaryKey; - -@PersistenceCapable -public class Product { - - @PrimaryKey - String id; - String name; - String description; - double price; - - public Product() { - - } - - public Product(String id, String name, String description, double price) { - this.id = id; - this.name = name; - this.description = description; - this.price = price; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public double getPrice() { - return price; - } - - public void setPrice(double price) { - this.price = price; - } - -} +package com.baeldung.jdo.xml; + +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable +public class Product { + + @PrimaryKey + String id; + String name; + String description; + double price; + + public Product() { + + } + + public Product(String id, String name, String description, double price) { + this.id = id; + this.name = name; + this.description = description; + this.price = price; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + +} diff --git a/libraries-data/src/main/resources/META-INF/BenchmarkList b/libraries-data/src/main/resources/META-INF/BenchmarkList new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libraries-data/src/main/resources/META-INF/datanucleus.properties b/libraries-data/src/main/resources/META-INF/datanucleus.properties new file mode 100644 index 0000000000..7470a58d23 --- /dev/null +++ b/libraries-data/src/main/resources/META-INF/datanucleus.properties @@ -0,0 +1,4 @@ +javax.jdo.PersistenceManagerFactoryClass=org.datanucleus.api.jdo.JDOPersistenceManagerFactory +javax.jdo.option.ConnectionURL= xml:file:myfile-ds.xml +datanucleus.xml.indentSize=6 +datanucleus.schema.autoCreateAll=true \ No newline at end of file diff --git a/libraries/src/main/resources/META-INF/jdoconfig.xml b/libraries-data/src/main/resources/META-INF/jdoconfig.xml similarity index 98% rename from libraries/src/main/resources/META-INF/jdoconfig.xml rename to libraries-data/src/main/resources/META-INF/jdoconfig.xml index 77da460686..910f63cb9a 100644 --- a/libraries/src/main/resources/META-INF/jdoconfig.xml +++ b/libraries-data/src/main/resources/META-INF/jdoconfig.xml @@ -1,17 +1,17 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/libraries/src/main/resources/META-INF/package.jdo b/libraries-data/src/main/resources/META-INF/package.jdo similarity index 97% rename from libraries/src/main/resources/META-INF/package.jdo rename to libraries-data/src/main/resources/META-INF/package.jdo index d3cf501bb6..7f85bbbd58 100644 --- a/libraries/src/main/resources/META-INF/package.jdo +++ b/libraries-data/src/main/resources/META-INF/package.jdo @@ -1,29 +1,29 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libraries/src/main/resources/db.sql b/libraries-data/src/main/resources/db.sql similarity index 100% rename from libraries/src/main/resources/db.sql rename to libraries-data/src/main/resources/db.sql diff --git a/libraries/src/test/java/com/baeldung/hikaricp/HikariCPIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/hikaricp/HikariCPIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/hikaricp/HikariCPIntegrationTest.java rename to libraries-data/src/test/java/com/baeldung/hikaricp/HikariCPIntegrationTest.java diff --git a/libraries/src/test/java/com/baeldung/jcache/CacheLoaderTest.java b/libraries-data/src/test/java/com/baeldung/jcache/CacheLoaderTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/jcache/CacheLoaderTest.java rename to libraries-data/src/test/java/com/baeldung/jcache/CacheLoaderTest.java diff --git a/libraries/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java rename to libraries-data/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java diff --git a/libraries/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java rename to libraries-data/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java diff --git a/libraries/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java rename to libraries-data/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java diff --git a/libraries/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java rename to libraries-data/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java diff --git a/libraries/README.md b/libraries/README.md index 7c06aa88ca..ace2000d8d 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -17,9 +17,7 @@ - [Introduction to Quartz](http://www.baeldung.com/quartz) - [How to Warm Up the JVM](http://www.baeldung.com/java-jvm-warmup) - [Apache Commons Collections SetUtils](http://www.baeldung.com/apache-commons-setutils) -- [Guide to Java Data Objects](http://www.baeldung.com/jdo) - [Software Transactional Memory in Java Using Multiverse](http://www.baeldung.com/java-multiverse-stm) -- [Introduction to HikariCP](http://www.baeldung.com/hikaricp) - [Serenity BDD with Spring and JBehave](http://www.baeldung.com/serenity-spring-jbehave) - [Locality-Sensitive Hashing in Java Using Java-LSH](http://www.baeldung.com/locality-sensitive-hashing) - [Apache Commons Collections OrderedMap](http://www.baeldung.com/apache-commons-ordered-map) @@ -47,7 +45,6 @@ - [Guide to JDeferred](http://www.baeldung.com/jdeferred) - [Integrating Retrofit with RxJava](http://www.baeldung.com/retrofit-rxjava) - [Introduction to MBassador](http://www.baeldung.com/mbassador) -- [Introduction to JCache](http://www.baeldung.com/jcache) - [Introduction to Retrofit](http://www.baeldung.com/retrofit) - [Using Pairs in Java](http://www.baeldung.com/java-pairs) - [Apache Commons Collections Bag](http://www.baeldung.com/apache-commons-bag) @@ -56,7 +53,6 @@ - [Introduction To Docx4J](http://www.baeldung.com/docx4j) - [Introduction to StreamEx](http://www.baeldung.com/streamex) - [Introduction to BouncyCastle with Java](http://www.baeldung.com/java-bouncy-castle) -- [Intro to JDO Queries 2/2](http://www.baeldung.com/jdo-queries) - [Guide to google-http-client](http://www.baeldung.com/google-http-client) - [Interact with Google Sheets from Java](http://www.baeldung.com/google-sheets-java-client) - [Programatically Create, Configure, and Run a Tomcat Server] (http://www.baeldung.com/tomcat-programmatic-setup)