add Berkeley DB entities
This commit is contained in:
@@ -36,6 +36,10 @@
|
|||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sleepycat</groupId>
|
||||||
|
<artifactId>je</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|||||||
55
core/src/main/java/ru/trader/store/berkeley/BDBStore.java
Normal file
55
core/src/main/java/ru/trader/store/berkeley/BDBStore.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package ru.trader.store.berkeley;
|
||||||
|
|
||||||
|
import com.sleepycat.je.Database;
|
||||||
|
import com.sleepycat.je.DatabaseConfig;
|
||||||
|
import com.sleepycat.je.DatabaseException;
|
||||||
|
import com.sleepycat.je.Environment;
|
||||||
|
import com.sleepycat.je.EnvironmentConfig;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class BDBStore {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(BDBStore.class);
|
||||||
|
|
||||||
|
private final Environment dbEnvironment;
|
||||||
|
private final Database db;
|
||||||
|
|
||||||
|
public BDBStore(String path){
|
||||||
|
EnvironmentConfig envConfig = new EnvironmentConfig();
|
||||||
|
envConfig.setAllowCreate(true);
|
||||||
|
envConfig.setSharedCache(true);
|
||||||
|
envConfig.setTransactional(true);
|
||||||
|
dbEnvironment = new Environment(new File(path), envConfig);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DatabaseConfig dbConfig = new DatabaseConfig();
|
||||||
|
dbConfig.setAllowCreate(true);
|
||||||
|
db = dbEnvironment.openDatabase(null, "Trader", dbConfig);
|
||||||
|
} catch (DatabaseException e){
|
||||||
|
LOG.error("Error on open DB, path {}", path);
|
||||||
|
LOG.error("",e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void close(){
|
||||||
|
if (db != null) {
|
||||||
|
try {
|
||||||
|
db.close();
|
||||||
|
} catch (DatabaseException e){
|
||||||
|
LOG.error("Error on close DB", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dbEnvironment != null) {
|
||||||
|
try {
|
||||||
|
dbEnvironment.cleanLog();
|
||||||
|
dbEnvironment.close();
|
||||||
|
} catch (DatabaseException e){
|
||||||
|
LOG.error("Error on close DB environment", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package ru.trader.store.berkeley.entities;
|
||||||
|
|
||||||
|
import com.sleepycat.persist.model.Entity;
|
||||||
|
import com.sleepycat.persist.model.PrimaryKey;
|
||||||
|
import ru.trader.core.GROUP_TYPE;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Group {
|
||||||
|
@PrimaryKey
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private GROUP_TYPE type;
|
||||||
|
|
||||||
|
private Group() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group(String name, GROUP_TYPE type) {
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package ru.trader.store.berkeley.entities;
|
||||||
|
|
||||||
|
import com.sleepycat.persist.model.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Item {
|
||||||
|
@PrimaryKey(sequence="I_ID")
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@SecondaryKey(relate = Relationship.MANY_TO_ONE,
|
||||||
|
relatedEntity = Group.class,
|
||||||
|
onRelatedEntityDelete = DeleteAction.CASCADE)
|
||||||
|
private String groupId;
|
||||||
|
|
||||||
|
private Item() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package ru.trader.store.berkeley.entities;
|
||||||
|
|
||||||
|
import com.sleepycat.persist.model.*;
|
||||||
|
import ru.trader.core.OFFER_TYPE;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Offer {
|
||||||
|
|
||||||
|
@PrimaryKey(sequence = "O_ID")
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@SecondaryKey(relate = Relationship.MANY_TO_ONE,
|
||||||
|
relatedEntity = Item.class,
|
||||||
|
onRelatedEntityDelete = DeleteAction.NULLIFY)
|
||||||
|
private long itemId;
|
||||||
|
|
||||||
|
@SecondaryKey(relate = Relationship.MANY_TO_ONE,
|
||||||
|
relatedEntity = Vendor.class,
|
||||||
|
onRelatedEntityDelete = DeleteAction.NULLIFY)
|
||||||
|
private long vendorId;
|
||||||
|
|
||||||
|
@SecondaryKey(relate = Relationship.ONE_TO_ONE)
|
||||||
|
private OFFER_TYPE type;
|
||||||
|
|
||||||
|
private double price;
|
||||||
|
|
||||||
|
public Offer(Item item, OFFER_TYPE type, double price) {
|
||||||
|
this.itemId = item.getId();
|
||||||
|
this.type = type;
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package ru.trader.store.berkeley.entities;
|
||||||
|
|
||||||
|
import com.sleepycat.persist.model.Entity;
|
||||||
|
import com.sleepycat.persist.model.PrimaryKey;
|
||||||
|
import com.sleepycat.persist.model.Relationship;
|
||||||
|
import com.sleepycat.persist.model.SecondaryKey;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Vendor {
|
||||||
|
|
||||||
|
@PrimaryKey(sequence = "V_ID")
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@SecondaryKey(relate = Relationship.ONE_TO_ONE)
|
||||||
|
private double x;
|
||||||
|
@SecondaryKey(relate = Relationship.ONE_TO_ONE)
|
||||||
|
private double y;
|
||||||
|
@SecondaryKey(relate = Relationship.ONE_TO_ONE)
|
||||||
|
private double z;
|
||||||
|
|
||||||
|
private Vendor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vendor(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
pom.xml
14
pom.xml
@@ -74,9 +74,23 @@
|
|||||||
<artifactId>controlsfx</artifactId>
|
<artifactId>controlsfx</artifactId>
|
||||||
<version>8.0.6</version>
|
<version>8.0.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sleepycat</groupId>
|
||||||
|
<artifactId>je</artifactId>
|
||||||
|
<version>6.1.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>oracleReleases</id>
|
||||||
|
<name>Oracle Released Java Packages</name>
|
||||||
|
<url>http://download.oracle.com/maven</url>
|
||||||
|
<layout>default</layout>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user