Hi Andrey,
I am happy to report that I am not getting that message after refactoring -
I don't understand why but that is ok :)
One issue was that I had not registered the classes so the query was
throwing an "not serializable" exception. Wish I had got a more meaning
message from Orientdb.
I am attaching the refactored classes. I would still like to know what was
the problem with the earlier CustomerTest3 class.
Thanks
Arvind
On Saturday, September 27, 2014 2:01:24 PM UTC-4, Andrey Lomakin wrote:
>
> Hi,
> Ok I will try meanwhile I noticed that you reused the same instance of db
> for every thread. db instance is like connection to data storage and you
> need to have new instance for each thread.
> I will try to repeat your test, meanwhile coudl you try to change code I
> suggested and try it too ?
>
> On Fri, Sep 26, 2014 at 5:20 PM, <[email protected] <javascript:>> wrote:
>
>> Sorry Andrey, no maven project, just playing with Orientdb.
>> But I am attaching the 4 java files that I used to get that bug, hope
>> that helps.
>>
>> On Friday, September 26, 2014 7:43:20 AM UTC-4, Andrey Lomakin wrote:
>>>
>>> Hi,
>>> Could you provide test which I can run, in form of may be maven project ?
>>>
>>> On Thu, Sep 25, 2014 at 7:41 AM, Andrey Lomakin <[email protected]>
>>> wrote:
>>>
>>>> Hi,
>>>> You should follow https://github.com/orientechnologies/orientdb/
>>>> issues/2840
>>>>
>>>> On Wed, Sep 24, 2014 at 10:57 PM, <[email protected]> wrote:
>>>>
>>>>> Hi,
>>>>> I get this error - any help on this?
>>>>> This is the code that is causing the exception:
>>>>>
>>>>> package test;
>>>>> import java.text.SimpleDateFormat;
>>>>> import java.util.Date;
>>>>> import java.util.List;
>>>>> import java.util.concurrent.*;
>>>>> import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
>>>>> import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
>>>>> public class CustomerTest3 {
>>>>>
>>>>> int corePoolSize = 2;
>>>>> int maxPoolSize = 3;
>>>>> long keepAliveTime = 500;
>>>>> public OObjectDatabaseTx db = new OObjectDatabaseTx(
>>>>> "plocal:c:/java/dbs/person").open("admin", "admin");
>>>>> public ExecutorService threadPoolExecutor = new ThreadPoolExecutor(
>>>>> corePoolSize,
>>>>> maxPoolSize,
>>>>> keepAliveTime,
>>>>> TimeUnit.MILLISECONDS,
>>>>> new LinkedBlockingQueue<Runnable>()
>>>>> );
>>>>>
>>>>>
>>>>>
>>>>> public CustomerTest3() {
>>>>>
>>>>>
>>>>> }
>>>>> public static void main(String[] args) {
>>>>>
>>>>>
>>>>> CustomerTest3 ct3 = new CustomerTest3();
>>>>>
>>>>> ct3.db.getEntityManager().registerEntityClasses("test");
>>>>> Future f1 = ct3.threadPoolExecutor.submit(new FutureTask<String>(
>>>>> new Callable<String>()
>>>>> {
>>>>> public String call() {
>>>>> ct3.updateCust3();
>>>>> return "done";
>>>>> }
>>>>> }));
>>>>>
>>>>> Future f2 = ct3.threadPoolExecutor.submit(new FutureTask<String>(
>>>>> new Callable<String>()
>>>>> {
>>>>> public String call() {
>>>>> ct3.updateCust4();
>>>>> return "done";
>>>>> }
>>>>> }));
>>>>>
>>>>>
>>>>> // try {
>>>>> // if (f1.get().equals("done") && f1.get().equals("done"))
>>>>> // ct3.db.close();
>>>>> // } catch (InterruptedException e) {
>>>>> // // TODO Auto-generated catch block
>>>>> // e.printStackTrace();
>>>>> // } catch (ExecutionException e) {
>>>>> // // TODO Auto-generated catch block
>>>>> // e.printStackTrace();
>>>>> // }
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>> private void updateCust3() {
>>>>> List<Customer> result = db.query(new OSQLSynchQuery<Customer>(
>>>>> "select * from Customer where address.city like '%98%'"));
>>>>>
>>>>> SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy
>>>>> HH:mm");
>>>>>
>>>>>
>>>>>
>>>>> for (Customer p : result) {
>>>>> //db.begin();
>>>>>
>>>>> p.setName("updated name " + sdf.format(new
>>>>> Date(System.currentTimeMillis())));
>>>>>
>>>>> System.out.println(sdf.format(new
>>>>> Date(System.currentTimeMillis())));
>>>>>
>>>>> System.out.println(p.getAddress().getCity());
>>>>> System.out.println(p.getName());
>>>>> db.save(p);
>>>>> try {
>>>>> Thread.sleep(5000);
>>>>> } catch (InterruptedException e) {
>>>>> // TODO Auto-generated catch block
>>>>> e.printStackTrace();
>>>>> }
>>>>>
>>>>> //db.commit();
>>>>> }
>>>>> }
>>>>>
>>>>> private void updateCust4() {
>>>>> List<Customer> result = db.query(new OSQLSynchQuery<Customer>(
>>>>> "select * from Customer where address.city like '%99%'"));
>>>>>
>>>>> SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy
>>>>> HH:mm");
>>>>>
>>>>>
>>>>>
>>>>> for (Customer p : result) {
>>>>>
>>>>>
>>>>> p.setName("updated name " + sdf.format(new
>>>>> Date(System.currentTimeMillis())));
>>>>>
>>>>> System.out.println(sdf.format(new
>>>>> Date(System.currentTimeMillis())));
>>>>>
>>>>> System.out.println(p.getAddress().getCity());
>>>>> System.out.println(p.getName());
>>>>>
>>>>> try {
>>>>> Thread.sleep(1000);
>>>>> } catch (InterruptedException e) {
>>>>> // TODO Auto-generated catch block
>>>>> e.printStackTrace();
>>>>> }
>>>>> //db.begin();
>>>>> db.save(p);
>>>>> //db.commit();
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> /////////////////////////////////////////////////////////////////
>>>>>
>>>>> Sep 24, 2014 3:48:31 PM com.orientechnologies.common.log.OLogManager
>>>>> log
>>>>> SEVERE: Error on fetching record during browsing. The record has been
>>>>> skipped
>>>>> com.orientechnologies.orient.core.exception.ODatabaseException: Error
>>>>> on retrieving record #10:0 (cluster: customer)
>>>>> at com.orientechnologies.orient.core.db.raw.ODatabaseRaw.read(
>>>>> ODatabaseRaw.java:288)
>>>>> at com.orientechnologies.orient.core.db.record.
>>>>> ODatabaseRecordAbstract.executeReadRecord(
>>>>> ODatabaseRecordAbstract.java:905)
>>>>> at com.orientechnologies.orient.core.tx.OTransactionNoTx.
>>>>> loadRecord(OTransactionNoTx.java:70)
>>>>> at com.orientechnologies.orient.core.db.record.
>>>>> ODatabaseRecordTx.load(ODatabaseRecordTx.java:274)
>>>>> at com.orientechnologies.orient.core.db.record.
>>>>> ODatabaseRecordTx.load(ODatabaseRecordTx.java:40)
>>>>> at com.orientechnologies.orient.core.iterator.OIdentifiableIterator.
>>>>> readCurrentRecord(OIdentifiableIterator.java:285)
>>>>> at com.orientechnologies.orient.core.iterator.
>>>>> ORecordIteratorClusters.begin(ORecordIteratorClusters.java:287)
>>>>> at com.orientechnologies.orient.core.iterator.
>>>>> ORecordIteratorClusters.config(ORecordIteratorClusters.java:376)
>>>>> at com.orientechnologies.orient.core.iterator.
>>>>> ORecordIteratorClass.<init>(ORecordIteratorClass.java:72)
>>>>> at com.orientechnologies.orient.core.sql.
>>>>> OCommandExecutorSQLResultsetAbstract.searchInClasses(
>>>>> OCommandExecutorSQLResultsetAbstract.java:368)
>>>>> at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.
>>>>> searchInClasses(OCommandExecutorSQLSelect.java:657)
>>>>> at com.orientechnologies.orient.core.sql.
>>>>> OCommandExecutorSQLResultsetAbstract.assignTarget(
>>>>> OCommandExecutorSQLResultsetAbstract.java:128)
>>>>> at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.
>>>>> assignTarget(OCommandExecutorSQLSelect.java:398)
>>>>> at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.
>>>>> executeSearch(OCommandExecutorSQLSelect.java:382)
>>>>> at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.
>>>>> execute(OCommandExecutorSQLSelect.java:349)
>>>>> at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.
>>>>> execute(OCommandExecutorSQLDelegate.java:60)
>>>>> at com.orientechnologies.orient.core.storage.OStorageEmbedded.
>>>>> executeCommand(OStorageEmbedded.java:82)
>>>>> at com.orientechnologies.orient.core.storage.OStorageEmbedded.
>>>>> command(OStorageEmbedded.java:71)
>>>>> at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(
>>>>> OSQLQuery.java:69)
>>>>> at com.orientechnologies.orient.core.sql.query.OSQLSynchQuery.
>>>>> run(OSQLSynchQuery.java:80)
>>>>> at com.orientechnologies.orient.core.query.OQueryAbstract.
>>>>> execute(OQueryAbstract.java:29)
>>>>> at com.orientechnologies.orient.core.db.record.
>>>>> ODatabaseRecordAbstract.query(ODatabaseRecordAbstract.java:664)
>>>>> at com.orientechnologies.orient.core.db.
>>>>> ODatabaseRecordWrapperAbstract.query(ODatabaseRecordWrapperAbstract
>>>>> .java:192)
>>>>> at com.orientechnologies.orient.object.db.
>>>>> ODatabasePojoAbstract.query(ODatabasePojoAbstract.java:238)
>>>>> at test.CustomerTest3.updateCust3(CustomerTest3.java:75)
>>>>> at test.CustomerTest3.access$0(CustomerTest3.java:73)
>>>>> at test.CustomerTest3$1.call(CustomerTest3.java:43)
>>>>> at test.CustomerTest3$1.call(CustomerTest3.java:1)
>>>>> at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>>>>> at java.util.concurrent.Executors$RunnableAdapter.
>>>>> call(Executors.java:511)
>>>>> at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>>>>> at java.util.concurrent.ThreadPoolExecutor.runWorker(
>>>>> ThreadPoolExecutor.java:1142)
>>>>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(
>>>>> ThreadPoolExecutor.java:617)
>>>>> at java.lang.Thread.run(Thread.java:744)
>>>>> Caused by: com.orientechnologies.common.concur.lock.OLockException:
>>>>> Cannot unlock a never acquired lock
>>>>> at com.orientechnologies.orient.core.tx.OTransactionAbstract.
>>>>> unlockRecord(OTransactionAbstract.java:119)
>>>>> at com.orientechnologies.orient.core.id.ORecordId.unlock(
>>>>> ORecordId.java:272)
>>>>> at com.orientechnologies.orient.core.storage.impl.local.
>>>>> OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.
>>>>> java:1304)
>>>>> at com.orientechnologies.orient.core.storage.impl.local.
>>>>> OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.
>>>>> java:661)
>>>>> at com.orientechnologies.orient.core.db.raw.ODatabaseRaw.read(
>>>>> ODatabaseRaw.java:282)
>>>>> ... 33 more
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "OrientDB" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Best regards,
>>>> Andrey Lomakin.
>>>>
>>>> Orient Technologies
>>>> the Company behind OrientDB
>>>>
>>>>
>>>
>>>
>>> --
>>> Best regards,
>>> Andrey Lomakin.
>>>
>>> Orient Technologies
>>> the Company behind OrientDB
>>>
>>> --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "OrientDB" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Best regards,
> Andrey Lomakin.
>
> Orient Technologies
> the Company behind OrientDB
>
>
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
package test.concurrent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import test.Customer;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
public class CustomerDAO2 implements Runnable {
public void run() {
OObjectDatabaseTx db = new OObjectDatabaseTx(
"plocal:c:/java/dbs/person").open("admin", "admin");
db.getEntityManager().registerEntityClasses("test");
System.out.println("updateCust4 query start");
List<Customer> result = db.query(new OSQLSynchQuery<Customer>(
"select * from Customer where address.city like '%9%'"));
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
for (Customer p : result) {
db.begin();
// System.out.println("updateCust4");
p.setName("updated name "
+ sdf.format(new Date(System.currentTimeMillis())));
db.save(p);
System.out.println(p.getAddress().getCity());
System.out.println(p.getName());
db.commit();
}
System.out.println("updateCust4 query done");
}
}
package test.concurrent;
public class ConcurrentTest1 {
public static void main(String[] args) {
Thread t1 = new Thread(new CustomerDAO1());
Thread t2 = new Thread(new CustomerDAO2());
t1.start();
t2.start();
}
}
package test.concurrent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import test.Customer;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
public class CustomerDAO1 implements Runnable {
public void run() {
OObjectDatabaseTx db = new OObjectDatabaseTx(
"plocal:c:/java/dbs/person").open("admin", "admin");
db.getEntityManager().registerEntityClasses("test");
System.out.println("updateCust3 query start");
List<Customer> result = db.query(new OSQLSynchQuery<Customer>(
"select * from Customer where address.city like '%8%'"));
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss");
for (Customer p : result) {
db.begin();
p.setName("updated name "
+ sdf.format(new Date(System.currentTimeMillis())));
db.save(p);
System.out.println(p.getAddress().getCity());
System.out.println(p.getName());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
db.commit();
}
System.out.println("updateCust3 query doen ");
}
}package test;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
public class CustomerTest1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
OObjectDatabaseTx db = null;
// OPEN THE DATABASE
try { db = new OObjectDatabaseTx ("plocal:c:/java/dbs/person").open("admin", "admin"); }
catch(com.orientechnologies.orient.core.exception.OStorageException e) {
db = new OObjectDatabaseTx("plocal:c:/java/dbs/person").create();
}
// REGISTER THE CLASS ONLY ONCE AFTER THE DB IS OPEN/CREATED
db.getEntityManager().registerEntityClasses("test");
OClass custClass = db.getMetadata().getSchema().getClass("Customer");
custClass.createProperty("age", OType.INTEGER);
custClass.createIndex("age", OClass.INDEX_TYPE.UNIQUE, "age");
OClass addressClass = db.getMetadata().getSchema().getClass("Address");
addressClass.createProperty("street", OType.STRING);
addressClass.createIndex("street", OClass.INDEX_TYPE.FULLTEXT, "street");
custClass = db.getMetadata().getSchema().getClass("Customer");
custClass.createProperty("name", OType.STRING);
custClass.createIndex("name", OClass.INDEX_TYPE.UNIQUE, "name");
db.declareIntent( new OIntentMassiveInsert() );
for (int i = 0; i < 10; i++) {
// CREATE A NEW PROXIED OBJECT AND FILL IT
Customer cust = db.newInstance(Customer.class);
cust.setName( "Name " + i);
cust.setAge(i);
Address add = new Address();
add.setCity("City " + i );
add.setStreet(i + "Street");
add.setZip(i);
cust.setAddress(add);
cust.getRelativesAddresses().add(add);
db.save( cust );
}
db.declareIntent( null );
db.close();
}
}