Skip to content

Commit

Permalink
Tested GitHub-hosted Maven repo
Browse files Browse the repository at this point in the history
  • Loading branch information
a-rog committed Jul 30, 2015
1 parent 4a58b04 commit 844cb5f
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Px100DataUserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The example below uses Ignite:
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="igniteConfig" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="gridName" value="acDataGrid"/>
<property name="gridName" value="myDataGrid"/>

<!-- Optional arbitrary "tags" to enumerate nodes, group them into cluster groups, etc. -->
<property name="userAttributes">
Expand Down Expand Up @@ -118,6 +118,7 @@ The example below uses Ignite:
<value>x.y.z</value>
</list>
</property>
<property name="backupDirectory" value="."/>
</bean>
</beans>
```
Expand All @@ -140,7 +141,7 @@ public class SomeClass {
...

public void hello(Long id) {
Transaction tx = ds.getTransaction(0);
Transaction tx = ds.transaction(0);
MyEntity bean = tx.get(MyEntity.class, id);
bean.setSomeStringProperty("Hello, Px100 Data!");
tx.update(bean, false);
Expand All @@ -152,12 +153,12 @@ public class SomeClass {
```

**Note:** Px100 Data uses "pseudo-transactions" for performance reasons: minimal locking. It means that no locking occurs when we call
ds.getTransaction(). If all we did, were get operations, we wouldn't even need to commit - however both read and write API is provided through
ds.transaction(). If all we did, were get operations, we wouldn't even need to commit - however both read and write API is provided through
Transaction only for consistency. Telling Transaction to update() simply puts the bean on the update list. Only when we call commit(),
the actual "real" transaction happens (simulated in Mongo anyway), as the framework goes through its lists of accumulated inserts, updates,
and deletes, locking the data units (Mongo collections, Hazelcast maps, or Ignite caches) and actually writing the data to them.

It also means you can (but shouldn't) have some complex long-running logic between ds.getTransaction() and tx.commit(), as the only "real"
It also means you can (but shouldn't) have some complex long-running logic between ds.transaction() and tx.commit(), as the only "real"
transaction happens inside commit(). And if you never call commit() - don't put it inside the finally block - e.g. when some exception occurs,
the pseudo-transaction is naturally rolled backed because nothing was even attempted to be written anyway: it did not reach that point.

Expand All @@ -174,7 +175,7 @@ Once committed, Transaction will not accept any operations, even read ones.
Sometimes you need to break a long transaction into "batches". It can be done like this:

```java
Transaction tx = ds.getTransaction(0);
Transaction tx = ds.transaction(0);

for (int i = 0, n = BATCH_SIZE; i < n; i++)
tx.insert(beans[i]);
Expand Down Expand Up @@ -522,7 +523,7 @@ Px100 Data only API to read and write data is Transaction. You obtain it via Dat
...

public void example() {
Transaction tx = ds.getTransaction(0);
Transaction tx = ds.transaction(0);

// do something
...
Expand All @@ -535,7 +536,7 @@ Px100 Data only API to read and write data is Transaction. You obtain it via Dat

### Inserts
```java
Transaction tx = ds.getTransaction(0);
Transaction tx = ds.transaction(0);

MedicalInsuranceApplication entity = new MedicalInsuranceApplication();
entity.setName("John Doe");
Expand All @@ -554,7 +555,7 @@ Px100 Data only API to read and write data is Transaction. You obtain it via Dat

### Update
```java
Transaction tx = ds.getTransaction(0);
Transaction tx = ds.transaction(0);

MedicalInsuranceApplication entity = tx.get(MedicalInsuranceApplication.class, 125L);
entity.setName("Ivan Petroff");
Expand All @@ -575,7 +576,7 @@ import static com.px100systems.data.core.Criteria.*;

...

Transaction tx = ds.getTransaction(0);
Transaction tx = ds.transaction(0);

MedicalInsuranceApplication entity = tx.get(MedicalInsuranceApplication.class, 125L);
tx.deleteWithDependents(entity);
Expand All @@ -595,7 +596,7 @@ import static com.px100systems.data.core.Criteria.*;

...

Transaction tx = ds.getTransaction(0);
Transaction tx = ds.transaction(0);

long applicationCount = tx.delete(MedicalInsuranceApplication.class, null);
long filteredApplicationCount = tx.delete(MedicalInsuranceApplication.class,
Expand Down Expand Up @@ -791,6 +792,7 @@ The configuration below uses a JDBC persister with MySQL. It is a typical develo
</property>

<property name="persistenceServer" ref="persistenceServer"/>
<property name="backupDirectory" value="/some-directory"/>
</bean>
</beans>
```
Expand Down
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,64 @@ No data migration when you add or remove fields and even entire entities - natur

Orthogonal and minimalistic API with criteria queries.

## Installation
Use the foolowing Maven repository *(temporary measure - until the project is added to Maven Central)*
```xml
<repositories>
<repository>
<id>Px100 Data GitHub Repo</id>
<url>https://github.com/a-rog/px100data/raw/master/releases</url>
</repository>
</repositories>
```

### Core Maven Dependencies
```xml
<dependency>
<groupId>com.px100systems</groupId>
<artifactId>px100-persistence</artifactId>
<version>0.3.0</version>
</dependency>
```

Add one of the following:

**Persistent Ignite**
```xml
<dependency>
<groupId>com.px100systems</groupId>
<artifactId>ignite-storage</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>com.px100systems</groupId>
<artifactId>in-memory-jdbc-persistence</artifactId>
<version>0.3.0</version>
</dependency>
```

**Persistent Hazelcast**
```xml
<dependency>
<groupId>com.px100systems</groupId>
<artifactId>hazelcast-storage</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>com.px100systems</groupId>
<artifactId>in-memory-jdbc-persistence</artifactId>
<version>0.3.0</version>
</dependency>
```

**Mongo**
```xml
<dependency>
<groupId>com.px100systems</groupId>
<artifactId>mongo-storage</artifactId>
<version>0.3.0</version>
</dependency>
```

## Learn Px100 Data
See the User Guide
90 changes: 90 additions & 0 deletions examples/Px100DataTest/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.t34</groupId>
<artifactId>Px100DataTest</artifactId>
<version>0.1.0</version>

<repositories>
<repository>
<id>Px100 Data GitHub Repo</id>
<url>https://github.com/a-rog/px100data/raw/master/releases</url>
</repository>
</repositories>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.springframework.version>4.1.3.RELEASE</org.springframework.version>
<java.target.version>1.8</java.target.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.target.version}</source>
<target>${java.target.version}</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.px100systems</groupId>
<artifactId>px100-persistence</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>com.px100systems</groupId>
<artifactId>ignite-storage</artifactId>
<version>0.3.0</version>
</dependency>
<!--dependency>
<groupId>com.px100systems</groupId>
<artifactId>in-memory-jdbc-persistence</artifactId>
<version>0.3.0</version>
</dependency-->

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependencies>
</project>
31 changes: 31 additions & 0 deletions examples/Px100DataTest/src/main/java/com/t34/test/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.t34.test;

import com.px100systems.data.core.DataStorageException;
import com.px100systems.data.core.DatabaseStorage;
import com.px100systems.data.core.Transaction;
import com.t34.test.entity.MyEntity;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.Date;
import static com.px100systems.data.core.Criteria.*;

public class Main {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:config.xml");
DatabaseStorage ds = context.getBean("dataStorage", DatabaseStorage.class);

try {
Transaction tx = ds.transaction(0);
MyEntity bean = new MyEntity();
bean.setDate(new Date());
bean.setText("Hello");
tx.insert(bean);
tx.commit();

tx = tx.transaction(0);
System.out.println(tx.findOne(MyEntity.class, not(isNull("id"))));
} catch (DataStorageException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.t34.test.entity;

import com.px100systems.data.core.Entity;
import com.px100systems.data.core.Index;
import com.px100systems.util.serialization.SerializationDefinition;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Date;

public class MyEntity extends Entity implements Externalizable {
private String text;
private Date date;

@Override
public void writeExternal(ObjectOutput out) throws IOException {
SerializationDefinition.get(getClass()).write(out, this);
}

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
SerializationDefinition.get(getClass()).read(in, this);
}

@Override
public String toString() {
return "MyEntity{" +
"date=" + date +
", text='" + text + '\'' +
'}';
}

@Index
public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}
}
Loading

0 comments on commit 844cb5f

Please sign in to comment.