move reladomo ex to librarie-data (#2485)
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.reladomo;
|
||||
|
||||
public class Department extends DepartmentAbstract {
|
||||
public Department() {
|
||||
super();
|
||||
// You must not modify this constructor. Mithra calls this internally.
|
||||
// You can call this constructor. You can also add new constructors.
|
||||
}
|
||||
|
||||
public Department(long id, String name) {
|
||||
super();
|
||||
this.setId(id);
|
||||
this.setName(name);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.baeldung.reladomo;
|
||||
public class DepartmentDatabaseObject extends DepartmentDatabaseObjectAbstract
|
||||
{
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.baeldung.reladomo;
|
||||
import com.gs.fw.finder.Operation;
|
||||
import java.util.*;
|
||||
public class DepartmentList extends DepartmentListAbstract
|
||||
{
|
||||
public DepartmentList()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public DepartmentList(int initialSize)
|
||||
{
|
||||
super(initialSize);
|
||||
}
|
||||
|
||||
public DepartmentList(Collection c)
|
||||
{
|
||||
super(c);
|
||||
}
|
||||
|
||||
public DepartmentList(Operation operation)
|
||||
{
|
||||
super(operation);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.baeldung.reladomo;
|
||||
public class Employee extends EmployeeAbstract
|
||||
{
|
||||
public Employee()
|
||||
{
|
||||
super();
|
||||
// You must not modify this constructor. Mithra calls this internally.
|
||||
// You can call this constructor. You can also add new constructors.
|
||||
}
|
||||
|
||||
public Employee(long id, String name){
|
||||
super();
|
||||
this.setId(id);
|
||||
this.setName(name);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.baeldung.reladomo;
|
||||
public class EmployeeDatabaseObject extends EmployeeDatabaseObjectAbstract
|
||||
{
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.baeldung.reladomo;
|
||||
import com.gs.fw.finder.Operation;
|
||||
import java.util.*;
|
||||
public class EmployeeList extends EmployeeListAbstract
|
||||
{
|
||||
public EmployeeList()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public EmployeeList(int initialSize)
|
||||
{
|
||||
super(initialSize);
|
||||
}
|
||||
|
||||
public EmployeeList(Collection c)
|
||||
{
|
||||
super(c);
|
||||
}
|
||||
|
||||
public EmployeeList(Operation operation)
|
||||
{
|
||||
super(operation);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.baeldung.reladomo;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.gs.fw.common.mithra.MithraManager;
|
||||
import com.gs.fw.common.mithra.MithraManagerProvider;
|
||||
|
||||
public class ReladomoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
ReladomoConnectionManager.getInstance().createTables();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
MithraManager mithraManager = MithraManagerProvider.getMithraManager();
|
||||
mithraManager.setTransactionTimeout(120);
|
||||
|
||||
try (InputStream is = ReladomoApplication.class.getClassLoader().getResourceAsStream("ReladomoRuntimeConfig.xml")) {
|
||||
MithraManagerProvider.getMithraManager().readConfiguration(is);
|
||||
|
||||
Department department = new Department(1, "IT");
|
||||
Employee employee = new Employee(1, "John");
|
||||
department.getEmployees().add(employee);
|
||||
department.cascadeInsert();
|
||||
|
||||
Department depFound = DepartmentFinder.findByPrimaryKey(1);
|
||||
System.out.println("Department Name:" + department.getName());
|
||||
|
||||
Employee empFound = EmployeeFinder.findOne(EmployeeFinder.name().eq("John"));
|
||||
System.out.println("Employee Id:" + empFound.getId());
|
||||
empFound.setName("Steven");
|
||||
empFound.delete();
|
||||
Department depDetached = DepartmentFinder.findByPrimaryKey(1).getDetachedCopy();
|
||||
|
||||
mithraManager.executeTransactionalCommand(tx -> {
|
||||
Department dep = new Department(2, "HR");
|
||||
Employee emp = new Employee(2, "Jim");
|
||||
dep.getEmployees().add(emp);
|
||||
dep.cascadeInsert();
|
||||
return null;
|
||||
});
|
||||
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.baeldung.reladomo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.TimeZone;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.h2.tools.RunScript;
|
||||
|
||||
import com.gs.fw.common.mithra.bulkloader.BulkLoader;
|
||||
import com.gs.fw.common.mithra.bulkloader.BulkLoaderException;
|
||||
import com.gs.fw.common.mithra.connectionmanager.SourcelessConnectionManager;
|
||||
import com.gs.fw.common.mithra.connectionmanager.XAConnectionManager;
|
||||
import com.gs.fw.common.mithra.databasetype.DatabaseType;
|
||||
import com.gs.fw.common.mithra.databasetype.H2DatabaseType;
|
||||
|
||||
public class ReladomoConnectionManager implements SourcelessConnectionManager {
|
||||
|
||||
private static ReladomoConnectionManager instance;
|
||||
|
||||
private XAConnectionManager xaConnectionManager;
|
||||
|
||||
private final String databaseName = "myDb";
|
||||
|
||||
public static synchronized ReladomoConnectionManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ReladomoConnectionManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ReladomoConnectionManager() {
|
||||
this.createConnectionManager();
|
||||
}
|
||||
|
||||
private XAConnectionManager createConnectionManager() {
|
||||
xaConnectionManager = new XAConnectionManager();
|
||||
xaConnectionManager.setDriverClassName("org.h2.Driver");
|
||||
xaConnectionManager.setJdbcConnectionString("jdbc:h2:mem:" + databaseName);
|
||||
xaConnectionManager.setJdbcUser("sa");
|
||||
xaConnectionManager.setJdbcPassword("");
|
||||
xaConnectionManager.setPoolName("My Connection Pool");
|
||||
xaConnectionManager.setInitialSize(1);
|
||||
xaConnectionManager.setPoolSize(10);
|
||||
xaConnectionManager.initialisePool();
|
||||
return xaConnectionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BulkLoader createBulkLoader() throws BulkLoaderException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return xaConnectionManager.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseType getDatabaseType() {
|
||||
return H2DatabaseType.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZone getDatabaseTimeZone() {
|
||||
return TimeZone.getDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDatabaseIdentifier() {
|
||||
return databaseName;
|
||||
}
|
||||
|
||||
public void createTables() throws Exception {
|
||||
Path ddlPath = Paths.get(ClassLoader.getSystemResource("sql").toURI());
|
||||
|
||||
try (Connection conn = xaConnectionManager.getConnection(); Stream<Path> list = Files.list(ddlPath);) {
|
||||
list.forEach(path -> {
|
||||
try {
|
||||
RunScript.execute(conn, Files.newBufferedReader(path));
|
||||
} catch (SQLException | IOException exc) {
|
||||
exc.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user