You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is Issue 113 moved from a Google Code project.
Added by 2010-09-18T07:28:17.000Z by jani.laa...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-Medium, v0.9.23
Original description
If I use ODatabaseObjectPool to acquire multiple simultaneous connections in multiple threads I still need to register my entities for every pool. I'd hope registering entities once in Java process is the correct pattern.
Example here:
package com.janilaakso;
import com.janilaakso.domain.Company;
import com.janilaakso.domain.Person;
import com.orientechnologies.orient.core.db.object.ODatabaseObjectPool;
import com.orientechnologies.orient.core.db.object.ODatabaseObjectTx;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
public class ClientTest extends Thread {
private static int THREAD_COUNT = 10;
private static String dbUrl = "local:/tmp/orient-database-test/foo";
private ODatabaseObjectTx db;
@Override
public void run() {
log("THREAD START");
try {
db = ODatabaseObjectPool.global().acquire(dbUrl, "admin", "admin");
// ISSUE: This should work through main method (define entities
// once). We are on same Java process.
db.getEntityManager()
.registerEntityClasses("com.janilaakso.domain");
db.begin(TXTYPE.OPTIMISTIC);
for (int i = 0; i < 1000; i++) {
Company company = new Company();
company.setName("Vaadin Ltd " + i);
Person person = new Person();
person.setFirstname("Jani " + i);
person.setCompany(company);
db.save(person);
}
db.commit();
log(showElements());
log("THREAD END");
} catch (Exception e) {
log("THREAD FAILED: " + e.getMessage());
} finally {
if (db != null && !db.isClosed())
db.close();
}
}
private String showElements() {
StringBuffer desc = new StringBuffer();
for (String name : db.getClusterNames()) {
desc.append(name).append("=").append(db.countClusterElements(name))
.append(", ");
}
return desc.toString();
}
public static void main(String[] args) {
// ISSUE: all the same if I try to use
// db = ODatabaseObjectPool.global().acquire(dbUrl, "admin", "admin");
// here
ODatabaseObjectTx db = new ODatabaseObjectTx(dbUrl);
// Registering entities do no work here when threads afterwards acquire
// connections using ODatabaseObjectPool object.
// acquire. This should be enough to do once in here:
// db.getEntityManager().registerEntityClasses("com.janilaakso.domain");
try {
if (!db.exists()) {
log("Creating new database");
db.create();
}
} finally {
if (db != null && !db.isClosed())
db.close();
}
// Create threads and start them right away
for (int i = 0; i < THREAD_COUNT; i++) {
new ClientTest().start();
}
}
public static void log(String msg) {
System.err.println(Thread.currentThread() + ": " + msg);
}
}
The text was updated successfully, but these errors were encountered:
This is Issue 113 moved from a Google Code project.
Added by 2010-09-18T07:28:17.000Z by jani.laa...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-Medium, v0.9.23
Original description
The text was updated successfully, but these errors were encountered: