BAEL-1734 move packages from libraries to libraries-data

This commit is contained in:
RajatGarg 2018-05-01 14:24:25 +05:30
parent 7140229ca0
commit f9ddc38a39
31 changed files with 605 additions and 501 deletions

View File

@ -3,3 +3,7 @@
- [Introduction to ORMLite](http://www.baeldung.com/ormlite) - [Introduction to ORMLite](http://www.baeldung.com/ormlite)
- [Introduction To Kryo](http://www.baeldung.com/kryo) - [Introduction To Kryo](http://www.baeldung.com/kryo)
- [Introduction to KafkaStreams in Java](http://www.baeldung.com/java-kafka-streams) - [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)

View File

@ -0,0 +1 @@
log4j.rootLogger=INFO, stdout

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?><root>
</root>

View File

@ -85,6 +85,55 @@
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
<version>${gson.version}</version> <version>${gson.version}</version>
</dependency> </dependency>
<!-- Hikari CP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.2</version>
<scope>compile</scope>
</dependency>
<!-- JDO -->
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>javax.jdo</artifactId>
<version>3.2.0-m7</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-xml</artifactId>
<version>5.0.0-release</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-jdo-query</artifactId>
<version>5.0.4</version>
</dependency>
<!-- Jcache -->
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>${cache.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -184,6 +233,29 @@
</plugin> </plugin>
<!-- /Reladomo--> <!-- /Reladomo-->
<!-- JDO Plugin -->
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>5.0.2</version>
<configuration>
<api>JDO</api>
<props>${basedir}/datanucleus.properties</props>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
<fork>false</fork>
<!-- Solve windows line too long error -->
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
@ -203,5 +275,6 @@
<kafka.version>1.0.0</kafka.version> <kafka.version>1.0.0</kafka.version>
<ignite.version>2.3.0</ignite.version> <ignite.version>2.3.0</ignite.version>
<gson.version>2.8.2</gson.version> <gson.version>2.8.2</gson.version>
<cache.version>1.0.0</cache.version>
</properties> </properties>
</project> </project>

View File

@ -1,96 +1,96 @@
package com.baeldung.jdo.query; package com.baeldung.jdo.query;
import java.util.List; import java.util.List;
import javax.jdo.JDOQLTypedQuery; import javax.jdo.JDOQLTypedQuery;
import javax.jdo.PersistenceManager; import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory; import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query; import javax.jdo.Query;
import org.datanucleus.api.jdo.JDOPersistenceManagerFactory; import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
import org.datanucleus.metadata.PersistenceUnitMetaData; import org.datanucleus.metadata.PersistenceUnitMetaData;
public class MyApp { public class MyApp {
private static PersistenceManagerFactory pmf; private static PersistenceManagerFactory pmf;
private static PersistenceManager pm; private static PersistenceManager pm;
public static void main(String[] args) { public static void main(String[] args) {
defineDynamicPersistentUnit(); defineDynamicPersistentUnit();
createTestData(); createTestData();
queryUsingJDOQL(); queryUsingJDOQL();
queryUsingTypedJDOQL(); queryUsingTypedJDOQL();
queryUsingSQL(); queryUsingSQL();
queryUsingJPQL(); queryUsingJPQL();
} }
public static void createTestData() { public static void createTestData() {
ProductItem item1 = new ProductItem("supportedItem", "price less than 10", "SoldOut", 5); ProductItem item1 = new ProductItem("supportedItem", "price less than 10", "SoldOut", 5);
ProductItem item2 = new ProductItem("pro2", "price less than 10", "InStock", 8); ProductItem item2 = new ProductItem("pro2", "price less than 10", "InStock", 8);
ProductItem item3 = new ProductItem("pro3", "price more than 10", "SoldOut", 15); ProductItem item3 = new ProductItem("pro3", "price more than 10", "SoldOut", 15);
if (pm != null) { if (pm != null) {
pm.makePersistent(item1); pm.makePersistent(item1);
pm.makePersistent(item2); pm.makePersistent(item2);
pm.makePersistent(item3); pm.makePersistent(item3);
} }
} }
public static void defineDynamicPersistentUnit() { public static void defineDynamicPersistentUnit() {
PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null); 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.ConnectionURL", "jdbc:mysql://localhost:3306/jdo_db");
pumd.addProperty("javax.jdo.option.ConnectionUserName", "root"); pumd.addProperty("javax.jdo.option.ConnectionUserName", "root");
pumd.addProperty("javax.jdo.option.ConnectionPassword", "admin"); pumd.addProperty("javax.jdo.option.ConnectionPassword", "admin");
pumd.addProperty("javax.jdo.option.ConnectionDriverName", "com.mysql.jdbc.Driver"); pumd.addProperty("javax.jdo.option.ConnectionDriverName", "com.mysql.jdbc.Driver");
pumd.addProperty("datanucleus.schema.autoCreateAll", "true"); pumd.addProperty("datanucleus.schema.autoCreateAll", "true");
pmf = new JDOPersistenceManagerFactory(pumd, null); pmf = new JDOPersistenceManagerFactory(pumd, null);
pm = pmf.getPersistenceManager(); pm = pmf.getPersistenceManager();
} }
public static void queryUsingJDOQL() { public static void queryUsingJDOQL() {
Query query = pm.newQuery("SELECT FROM com.baeldung.jdo.query.ProductItem " + "WHERE price < threshold PARAMETERS double threshold"); Query query = pm.newQuery("SELECT FROM com.baeldung.jdo.query.ProductItem " + "WHERE price < threshold PARAMETERS double threshold");
List<ProductItem> explicitParamResults = (List<ProductItem>) query.execute(10); List<ProductItem> explicitParamResults = (List<ProductItem>) query.execute(10);
query = pm.newQuery("SELECT FROM " + "com.baeldung.jdo.query.ProductItem WHERE price < :threshold"); query = pm.newQuery("SELECT FROM " + "com.baeldung.jdo.query.ProductItem WHERE price < :threshold");
query.setParameters("double threshold"); query.setParameters("double threshold");
List<ProductItem> explicitParamResults2 = (List<ProductItem>) query.execute(10); List<ProductItem> explicitParamResults2 = (List<ProductItem>) query.execute(10);
query = pm.newQuery("SELECT FROM " + "com.baeldung.jdo.query.ProductItem WHERE price < :threshold"); query = pm.newQuery("SELECT FROM " + "com.baeldung.jdo.query.ProductItem WHERE price < :threshold");
List<ProductItem> implicitParamResults = (List<ProductItem>) query.execute(10); List<ProductItem> implicitParamResults = (List<ProductItem>) query.execute(10);
} }
public static void queryUsingTypedJDOQL() { public static void queryUsingTypedJDOQL() {
JDOQLTypedQuery<ProductItem> tq = pm.newJDOQLTypedQuery(ProductItem.class); JDOQLTypedQuery<ProductItem> tq = pm.newJDOQLTypedQuery(ProductItem.class);
QProductItem cand = QProductItem.candidate(); QProductItem cand = QProductItem.candidate();
tq = tq.filter(cand.price.lt(10).and(cand.name.startsWith("pro"))); tq = tq.filter(cand.price.lt(10).and(cand.name.startsWith("pro")));
List<ProductItem> results = tq.executeList(); List<ProductItem> results = tq.executeList();
} }
public static void queryUsingSQL() { public static void queryUsingSQL() {
Query query = pm.newQuery("javax.jdo.query.SQL", "select * from " + "product_item where price < ? and status = ?"); Query query = pm.newQuery("javax.jdo.query.SQL", "select * from " + "product_item where price < ? and status = ?");
query.setClass(ProductItem.class); query.setClass(ProductItem.class);
query.setParameters(10, "InStock"); query.setParameters(10, "InStock");
List<ProductItem> results = query.executeList(); List<ProductItem> results = query.executeList();
} }
public static void queryUsingJPQL() { 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'"); Query query = pm.newQuery("JPQL", "select i from " + "com.baeldung.jdo.query.ProductItem i where i.price < 10" + " and i.status = 'InStock'");
List<ProductItem> results = (List<ProductItem>) query.execute(); List<ProductItem> results = (List<ProductItem>) query.execute();
} }
public static void namedQuery() { public static void namedQuery() {
Query<ProductItem> query = pm.newNamedQuery(ProductItem.class, "PriceBelow10"); Query<ProductItem> query = pm.newNamedQuery(ProductItem.class, "PriceBelow10");
List<ProductItem> results = query.executeList(); List<ProductItem> results = query.executeList();
} }
} }

View File

@ -1,70 +1,70 @@
package com.baeldung.jdo.query; package com.baeldung.jdo.query;
import javax.jdo.annotations.IdGeneratorStrategy; import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable; import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent; import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey; import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable(table = "product_item") @PersistenceCapable(table = "product_item")
public class ProductItem { public class ProductItem {
@PrimaryKey @PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT) @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT)
int id; int id;
String name; String name;
String description; String description;
String status; String status;
double price; double price;
public ProductItem() { public ProductItem() {
} }
public ProductItem(String name, String description, String status, double price) { public ProductItem(String name, String description, String status, double price) {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.status = status; this.status = status;
this.price = price; this.price = price;
} }
public int getId() { public int getId() {
return id; return id;
} }
public void setId(int id) { public void setId(int id) {
this.id = id; this.id = id;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public double getPrice() { public double getPrice() {
return price; return price;
} }
public void setPrice(double price) { public void setPrice(double price) {
this.price = price; this.price = price;
} }
public String getStatus() { public String getStatus() {
return status; return status;
} }
public void setStatus(String status) { public void setStatus(String status) {
this.status = status; this.status = status;
} }
} }

View File

@ -1,66 +1,66 @@
package com.baeldung.jdo.xml; package com.baeldung.jdo.xml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.jdo.annotations.Element; import javax.jdo.annotations.Element;
import javax.jdo.annotations.PersistenceCapable; import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.PrimaryKey; import javax.jdo.annotations.PrimaryKey;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
@PersistenceCapable(schema = "/myproduct/people", table = "person") @PersistenceCapable(schema = "/myproduct/people", table = "person")
public class AnnotadedPerson { public class AnnotadedPerson {
@XmlAttribute @XmlAttribute
private long personNum; private long personNum;
@PrimaryKey @PrimaryKey
private String firstName; private String firstName;
private String lastName; private String lastName;
@XmlElementWrapper(name = "phone-numbers") @XmlElementWrapper(name = "phone-numbers")
@XmlElement(name = "phone-number") @XmlElement(name = "phone-number")
@Element(types = String.class) @Element(types = String.class)
private List phoneNumbers = new ArrayList(); private List phoneNumbers = new ArrayList();
public AnnotadedPerson(long personNum, String firstName, String lastName) { public AnnotadedPerson(long personNum, String firstName, String lastName) {
super(); super();
this.personNum = personNum; this.personNum = personNum;
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
} }
public long getPersonNum() { public long getPersonNum() {
return personNum; return personNum;
} }
public void setPersonNum(long personNum) { public void setPersonNum(long personNum) {
this.personNum = personNum; this.personNum = personNum;
} }
public String getFirstName() { public String getFirstName() {
return firstName; return firstName;
} }
public void setFirstName(String firstName) { public void setFirstName(String firstName) {
this.firstName = firstName; this.firstName = firstName;
} }
public String getLastName() { public String getLastName() {
return lastName; return lastName;
} }
public void setLastName(String lastName) { public void setLastName(String lastName) {
this.lastName = lastName; this.lastName = lastName;
} }
public List getPhoneNumbers() { public List getPhoneNumbers() {
return phoneNumbers; return phoneNumbers;
} }
public void setPhoneNumbers(List phoneNumbers) { public void setPhoneNumbers(List phoneNumbers) {
this.phoneNumbers = phoneNumbers; this.phoneNumbers = phoneNumbers;
} }
} }

View File

@ -1,105 +1,105 @@
package com.baeldung.jdo.xml; package com.baeldung.jdo.xml;
import java.util.List; import java.util.List;
import javax.jdo.JDOHelper; import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager; import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory; import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query; import javax.jdo.Query;
import javax.jdo.Transaction; import javax.jdo.Transaction;
import org.datanucleus.api.jdo.JDOPersistenceManagerFactory; import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
import org.datanucleus.metadata.PersistenceUnitMetaData; import org.datanucleus.metadata.PersistenceUnitMetaData;
public class MyApp { public class MyApp {
private static PersistenceUnitMetaData pumd; private static PersistenceUnitMetaData pumd;
private static PersistenceManagerFactory pmf; private static PersistenceManagerFactory pmf;
private static PersistenceManager pm; private static PersistenceManager pm;
public static void main(String[] args) { public static void main(String[] args) {
// persist product object using dynamic persistence unit // persist product object using dynamic persistence unit
defineDynamicPersistentUnit(); defineDynamicPersistentUnit();
Product product = new Product("id1", "Sony Discman", "A standard discman from Sony", 49.99); Product product = new Product("id1", "Sony Discman", "A standard discman from Sony", 49.99);
persistObject(product); persistObject(product);
closePersistenceManager(); closePersistenceManager();
// persist AnnotatedPerson object using named pmf // persist AnnotatedPerson object using named pmf
defineNamedPersistenceManagerFactory("XmlDatastore"); defineNamedPersistenceManagerFactory("XmlDatastore");
AnnotadedPerson annotatedPerson = new AnnotadedPerson(654320, "annotated", "person"); AnnotadedPerson annotatedPerson = new AnnotadedPerson(654320, "annotated", "person");
annotatedPerson.getPhoneNumbers().add("999999999"); annotatedPerson.getPhoneNumbers().add("999999999");
annotatedPerson.getPhoneNumbers().add("000000000"); annotatedPerson.getPhoneNumbers().add("000000000");
persistObject(annotatedPerson); persistObject(annotatedPerson);
queryAnnotatedPersonsInXML(); queryAnnotatedPersonsInXML();
closePersistenceManager(); closePersistenceManager();
// persist Person object using PMF created by properties file // persist Person object using PMF created by properties file
definePersistenceManagerFactoryUsingPropertiesFile("META-INF\\datanucleus.properties"); definePersistenceManagerFactoryUsingPropertiesFile("META-INF\\datanucleus.properties");
Person person = new Person(654321, "bealdung", "author"); Person person = new Person(654321, "bealdung", "author");
person.getPhoneNumbers().add("123456789"); person.getPhoneNumbers().add("123456789");
person.getPhoneNumbers().add("987654321"); person.getPhoneNumbers().add("987654321");
persistObject(person); persistObject(person);
queryPersonsInXML(); queryPersonsInXML();
closePersistenceManager(); closePersistenceManager();
} }
public static void defineDynamicPersistentUnit() { public static void defineDynamicPersistentUnit() {
PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null); PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null);
pumd.addProperty("javax.jdo.option.ConnectionURL", "xml:file:myfile_dynamicPMF.xml"); pumd.addProperty("javax.jdo.option.ConnectionURL", "xml:file:myfile_dynamicPMF.xml");
pumd.addProperty("datanucleus.schema.autoCreateAll", "true"); pumd.addProperty("datanucleus.schema.autoCreateAll", "true");
pumd.addProperty("datanucleus.xml.indentSize", "4"); pumd.addProperty("datanucleus.xml.indentSize", "4");
pmf = new JDOPersistenceManagerFactory(pumd, null); pmf = new JDOPersistenceManagerFactory(pumd, null);
pm = pmf.getPersistenceManager(); pm = pmf.getPersistenceManager();
} }
public static void defineNamedPersistenceManagerFactory(String pmfName) { public static void defineNamedPersistenceManagerFactory(String pmfName) {
pmf = JDOHelper.getPersistenceManagerFactory("XmlDatastore"); pmf = JDOHelper.getPersistenceManagerFactory("XmlDatastore");
pm = pmf.getPersistenceManager(); pm = pmf.getPersistenceManager();
} }
public static void definePersistenceManagerFactoryUsingPropertiesFile(String filePath) { public static void definePersistenceManagerFactoryUsingPropertiesFile(String filePath) {
pmf = JDOHelper.getPersistenceManagerFactory(filePath); pmf = JDOHelper.getPersistenceManagerFactory(filePath);
pm = pmf.getPersistenceManager(); pm = pmf.getPersistenceManager();
} }
public static void closePersistenceManager() { public static void closePersistenceManager() {
if (pm != null && !pm.isClosed()) { if (pm != null && !pm.isClosed()) {
pm.close(); pm.close();
} }
} }
public static void persistObject(Object obj) { public static void persistObject(Object obj) {
Transaction tx = pm.currentTransaction(); Transaction tx = pm.currentTransaction();
try { try {
tx.begin(); tx.begin();
pm.makePersistent(obj); pm.makePersistent(obj);
tx.commit(); tx.commit();
} finally { } finally {
if (tx.isActive()) { if (tx.isActive()) {
tx.rollback(); tx.rollback();
} }
} }
} }
public static void queryPersonsInXML() { public static void queryPersonsInXML() {
Query<Person> query = pm.newQuery(Person.class); Query<Person> query = pm.newQuery(Person.class);
List<Person> result = query.executeList(); List<Person> result = query.executeList();
System.out.println("name: " + result.get(0).getFirstName()); System.out.println("name: " + result.get(0).getFirstName());
} }
public static void queryAnnotatedPersonsInXML() { public static void queryAnnotatedPersonsInXML() {
Query<AnnotadedPerson> query = pm.newQuery(AnnotadedPerson.class); Query<AnnotadedPerson> query = pm.newQuery(AnnotadedPerson.class);
List<AnnotadedPerson> result = query.executeList(); List<AnnotadedPerson> result = query.executeList();
System.out.println("name: " + result.get(0).getFirstName()); System.out.println("name: " + result.get(0).getFirstName());
} }
} }

View File

@ -1,58 +1,58 @@
package com.baeldung.jdo.xml; package com.baeldung.jdo.xml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.jdo.annotations.PersistenceCapable; import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.PrimaryKey; import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable @PersistenceCapable
public class Person { public class Person {
private long personNum; private long personNum;
@PrimaryKey @PrimaryKey
private String firstName; private String firstName;
private String lastName; private String lastName;
private List phoneNumbers = new ArrayList(); private List phoneNumbers = new ArrayList();
public Person(long personNum, String firstName, String lastName) { public Person(long personNum, String firstName, String lastName) {
super(); super();
this.personNum = personNum; this.personNum = personNum;
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
} }
public long getPersonNum() { public long getPersonNum() {
return personNum; return personNum;
} }
public void setPersonNum(long personNum) { public void setPersonNum(long personNum) {
this.personNum = personNum; this.personNum = personNum;
} }
public String getFirstName() { public String getFirstName() {
return firstName; return firstName;
} }
public void setFirstName(String firstName) { public void setFirstName(String firstName) {
this.firstName = firstName; this.firstName = firstName;
} }
public String getLastName() { public String getLastName() {
return lastName; return lastName;
} }
public void setLastName(String lastName) { public void setLastName(String lastName) {
this.lastName = lastName; this.lastName = lastName;
} }
public List getPhoneNumbers() { public List getPhoneNumbers() {
return phoneNumbers; return phoneNumbers;
} }
public void setPhoneNumbers(List phoneNumbers) { public void setPhoneNumbers(List phoneNumbers) {
this.phoneNumbers = phoneNumbers; this.phoneNumbers = phoneNumbers;
} }
} }

View File

@ -1,58 +1,58 @@
package com.baeldung.jdo.xml; package com.baeldung.jdo.xml;
import javax.jdo.annotations.PersistenceCapable; import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.PrimaryKey; import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable @PersistenceCapable
public class Product { public class Product {
@PrimaryKey @PrimaryKey
String id; String id;
String name; String name;
String description; String description;
double price; double price;
public Product() { public Product() {
} }
public Product(String id, String name, String description, double price) { public Product(String id, String name, String description, double price) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.price = price; this.price = price;
} }
public String getId() { public String getId() {
return id; return id;
} }
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public double getPrice() { public double getPrice() {
return price; return price;
} }
public void setPrice(double price) { public void setPrice(double price) {
this.price = price; this.price = price;
} }
} }

View File

@ -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

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<jdoconfig xmlns="http://xmlns.jcp.org/xml/ns/jdo/jdoconfig" <jdoconfig xmlns="http://xmlns.jcp.org/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/jdo/jdoconfig xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/jdo/jdoconfig
http://xmlns.jcp.org/xml/ns/jdo/jdoconfig_3_2.xsd" http://xmlns.jcp.org/xml/ns/jdo/jdoconfig_3_2.xsd"
version="3.2"> version="3.2">
<!-- Datastore Txn PMF --> <!-- Datastore Txn PMF -->
<persistence-manager-factory name="XmlDatastore"> <persistence-manager-factory name="XmlDatastore">
<property name="javax.jdo.PersistenceManagerFactoryClass" <property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" /> value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
<property name="javax.jdo.option.ConnectionURL" value="xml:file:namedPMF-ds.xml" /> <property name="javax.jdo.option.ConnectionURL" value="xml:file:namedPMF-ds.xml" />
<property name="datanucleus.xml.indentSize" value="6" /> <property name="datanucleus.xml.indentSize" value="6" />
<property name="datanucleus.schema.autoCreateAll" <property name="datanucleus.schema.autoCreateAll"
value="true" /> value="true" />
</persistence-manager-factory> </persistence-manager-factory>
</jdoconfig> </jdoconfig>

View File

@ -1,29 +1,29 @@
<jdo xmlns="http://xmlns.jcp.org/xml/ns/jdo/jdo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <jdo xmlns="http://xmlns.jcp.org/xml/ns/jdo/jdo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/jdo/jdo http://xmlns.jcp.org/xml/ns/jdo/jdo_3_1.xsd" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/jdo/jdo http://xmlns.jcp.org/xml/ns/jdo/jdo_3_1.xsd"
version="3.1"> version="3.1">
<package name="com.baeldung.jdo.xml"> <package name="com.baeldung.jdo.xml">
<class name="Person" detachable="true" schema="/myproduct/people" <class name="Person" detachable="true" schema="/myproduct/people"
table="person"> table="person">
<field name="personNum"> <field name="personNum">
<extension vendor-name="datanucleus" key="XmlAttribute" <extension vendor-name="datanucleus" key="XmlAttribute"
value="true" /> value="true" />
</field> </field>
<field name="firstName" primary-key="true" /> <!-- PK since JAXB requires String --> <field name="firstName" primary-key="true" /> <!-- PK since JAXB requires String -->
<field name="lastName" /> <field name="lastName" />
<field name="phoneNumbers"> <field name="phoneNumbers">
<collection element-type="java.lang.String" /> <collection element-type="java.lang.String" />
<element column="phoneNumber" /> <element column="phoneNumber" />
</field> </field>
</class> </class>
</package> </package>
<package name="com.baeldung.jdo.query"> <package name="com.baeldung.jdo.query">
<class name="ProductItem" detachable="true" table="product_item"> <class name="ProductItem" detachable="true" table="product_item">
<query name="PriceBelow10" language="javax.jdo.query.SQL"> <query name="PriceBelow10" language="javax.jdo.query.SQL">
<![CDATA[SELECT * FROM PRODUCT_ITEM WHERE PRICE < 10 <![CDATA[SELECT * FROM PRODUCT_ITEM WHERE PRICE < 10
]]></query> ]]></query>
</class> </class>
</package> </package>
</jdo> </jdo>

View File

@ -17,9 +17,7 @@
- [Introduction to Quartz](http://www.baeldung.com/quartz) - [Introduction to Quartz](http://www.baeldung.com/quartz)
- [How to Warm Up the JVM](http://www.baeldung.com/java-jvm-warmup) - [How to Warm Up the JVM](http://www.baeldung.com/java-jvm-warmup)
- [Apache Commons Collections SetUtils](http://www.baeldung.com/apache-commons-setutils) - [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) - [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) - [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) - [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) - [Apache Commons Collections OrderedMap](http://www.baeldung.com/apache-commons-ordered-map)
@ -47,7 +45,6 @@
- [Guide to JDeferred](http://www.baeldung.com/jdeferred) - [Guide to JDeferred](http://www.baeldung.com/jdeferred)
- [Integrating Retrofit with RxJava](http://www.baeldung.com/retrofit-rxjava) - [Integrating Retrofit with RxJava](http://www.baeldung.com/retrofit-rxjava)
- [Introduction to MBassador](http://www.baeldung.com/mbassador) - [Introduction to MBassador](http://www.baeldung.com/mbassador)
- [Introduction to JCache](http://www.baeldung.com/jcache)
- [Introduction to Retrofit](http://www.baeldung.com/retrofit) - [Introduction to Retrofit](http://www.baeldung.com/retrofit)
- [Using Pairs in Java](http://www.baeldung.com/java-pairs) - [Using Pairs in Java](http://www.baeldung.com/java-pairs)
- [Apache Commons Collections Bag](http://www.baeldung.com/apache-commons-bag) - [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 Docx4J](http://www.baeldung.com/docx4j)
- [Introduction to StreamEx](http://www.baeldung.com/streamex) - [Introduction to StreamEx](http://www.baeldung.com/streamex)
- [Introduction to BouncyCastle with Java](http://www.baeldung.com/java-bouncy-castle) - [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) - [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) - [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) - [Programatically Create, Configure, and Run a Tomcat Server] (http://www.baeldung.com/tomcat-programmatic-setup)