You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by lpezet <lp...@gmail.com> on 2013/05/07 23:31:49 UTC

Custom data store implementation guidelines

Hi!

I'm trying to understand how OpenJPA works to be able to create say a
different data store.
I created my own BrokerFactory, Store, StoreManager, StoreQuery and
ResultObjectProvider.
Right now the code is just pass-through and only logs the method being
called.

I have a simple test as well:
/Map<String, String> oProps = new HashMap<String, String>();
oProps.put("openjpa.BrokerFactory", "org.fluke.jpa.BrokerFactory");
EntityManagerFactory factory =
OpenJPAPersistence.createEntityManagerFactory("hellojpa",
"org/fluke/jpa/persistence.xml", oProps);

EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
em.persist(new Message("Hello Persistence!"));
em.getTransaction().commit();
em.close();

EntityManager em2 = factory.createEntityManager();
Query q = em2.createQuery("select m from Message m");
for (Message m : (List<Message>) q.getResultList()) {
	System.out.println(m.getMessage()
		+ " (created on: " + m.getCreated() + ")"); 
}
em2.close();
factory.close();/


Here's what I get in the logs:
/
14:56:45.922 [main] ERROR o.f.jpa.StoreManager - setContext()
14:56:45.923 [main] ERROR o.f.jpa.StoreManager - newFetchConfiguration()
14:56:45.926 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
setContext()
14:56:45.954 [main] ERROR o.f.jpa.StoreManager - beginOptimistic()
14:56:46.031 [main] ERROR o.f.jpa.StoreManager - beforeStateChange()
14:56:46.033 [main] ERROR o.f.jpa.StoreManager - assignObjectId()
14:56:46.033 [main] ERROR o.f.jpa.StoreManager - retainConnection()
14:56:46.033 [main] ERROR o.f.jpa.StoreManager - begin()
14:56:46.037 [main] ERROR o.f.jpa.StoreManager - flush()
14:56:46.037 [main] ERROR o.f.jpa.StoreManager - commit()
14:56:46.037 [main] ERROR o.f.jpa.StoreManager - releaseConnection()
14:56:46.037 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
setReadLockLevel()
14:56:46.037 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
setWriteLockLevel()
14:56:46.037 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
lockTimeout()
14:56:46.038 [main] ERROR o.f.jpa.StoreManager - beforeStateChange()
14:56:46.046 [main] ERROR o.f.jpa.StoreManager - beforeStateChange()
14:56:46.046 [main] ERROR o.f.jpa.StoreManager - close()
14:56:46.047 [main] ERROR o.f.jpa.BrokerFactory - #########
newStoreManager() !!!
14:56:46.047 [main] ERROR o.f.jpa.StoreManager - setContext()
14:56:46.047 [main] ERROR o.f.jpa.StoreManager - newFetchConfiguration()
14:56:46.047 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
setContext()
14:56:46.047 [main] ERROR o.f.jpa.StoreManager -
newQuery(javax.persistence.JPQL)
14:56:46.135 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
getFetchBatchSize()
14:56:46.135 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
getFetchBatchSize()
14:56:46.135 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
getFetchBatchSize()
14:56:46.138 [main] ERROR o.f.jpa.StoreManager - executeExtent()
14:56:46.139 [main] ERROR o.f.jpa.ResultObjectProviderImpl - open()
14:56:46.139 [main] ERROR o.f.jpa.ResultObjectProviderImpl - next()
14:56:46.139 [main] ERROR o.f.jpa.ResultObjectProviderImpl - close()
14:56:46.145 [main] ERROR o.f.j.StoreManager$FetchConfigurationImpl -
newResultList()
/

I think I understand how the entities are loaded and JDBCStoreManager seems
to have everything for it (like executeIntent() and createStoreQuery()).
But I don't understand where the code leading to say an "INSERT INTO..." is
called based on the flow logged here.
I checked begin() and flush() and commit() in (many) classes of OpenJPA but
I see nothing that would ultimately lead to an "INSERT INTO..." at some
point. And the JDBCStoreManager looks more like a SELECT/LOAD manager than
anything else...I'm clueless :-P

Could someone please help me understand...how it works?
I looks like OpenJPA has a very good architecture and I should be able to
create my own data store...am I wrong?


Thank you for you help!
Luc.



--
View this message in context: http://openjpa.208410.n2.nabble.com/Custom-data-store-implementation-guidelines-tp7583851.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Custom data store implementation guidelines

Posted by Krzysztof <ya...@gmail.com>.
Hi,
I agree that clear architectural picture and dataflow would help to
understand how to extend and how to deal with its bugs and inefficiencies
(doable=>worth investing time/not-doable).

You might want to check specific HandlerStrategy from
org.apache.openjpa.meta.strats, i.e. HandlerFieldStrategy.insert() which
sets the values for prepared statement
and then Row implementation that actually generates prepared statement's
SQL: org.apache.openjpa.jdbc.sql.RowImpl::getSQL(DBDictionary) 
and actually filling it with data:
org.apache.openjpa.jdbc.sql.RowImpl::flush(..) 

This is called through through flush of suitable UpdateManager
(AbstractUpdateManager usually).

Not seeing the whole picture the architecture does seem quite convoluted
just by looking at the stack depth - I have considered adding some fast-path
capability for inserts for specific DB (COPY interface of Postgres) but not
sure if it's really doable without changing openjpa kernel.

Cheers
Chris

PS. Also changing generated sql for bit more complicated models is not
trivial (look for issues related to  PARALLEL queries in JIRA) - another
place some kind of data flow or functional diagram would be helpful.





--
View this message in context: http://openjpa.208410.n2.nabble.com/Custom-data-store-implementation-guidelines-tp7583851p7584074.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.