Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Using SessionBroker for sharded DB
Using SessionBroker for sharded DB [message #1716741] Mon, 07 December 2015 22:11
Leena Kantawala is currently offline Leena KantawalaFriend
Messages: 1
Registered: December 2015
Junior Member
Hi,

I want to use EclipseLink's SessionBroker for a multi-tenant application. We have 2 shards and would like SessionBroker to fetch Data from 2 shards transparently.

Here is how EclipseLink suggests to connect to multiple datastore

Project p1 = ProjectReader.read(("C:\Test\Test1.project"));
Project p2 = ProjectReader.read(("C:\Test\Test2.project"));

/* modify the user name and password if they are not correct in the .project file */
p1.getLogin().setUserName("User1");
p1.getLogin().setPassword("password1");
p2.getLogin().setUserName("User2");
p2.getLogin().setPassword("password2");
DatabaseSession session1 = p1.createDatabaseSession();
DatabaseSession session2 = p2.createDatabaseSession();

SessionBroker broker = new SessionBroker();
broker.registerSession("broker1", session1);
broker.registerSession("broker2", session2);

broker.login();

Here is how I coded it.

Since I have a horizontal shard, my Project is the same. But Login is different.
SessionBroker sessionBroker = new SessionBroker();
for(BaseShard shard : shardGroup.getShards()) {
Project project = shardGroup.getPersistenceProjectClass().newInstance();
project.setLogin(shard.getDatabaseLogin());
Server serverSession = project.createServerSession();
sessionBroker.registerSession(shard.getShardName(), serverSession);
}
sessionBroker.login();

Session sesion = sessionBroker.acquireClientSessionBroker();
sesion.readAllObjects(Company.class)


When I try to read an entity from both the shards, I get data only from one of the shards.

My guess is that SessionBroker does not work with same "Project". It has to have different schemas. e.g. If one Datastore has Company entity and another datastore has Employee entity then SessionBroker will be able to work seamlessly. But, if there are company and employee entities on both the datastores, then it does not work correctly.

I concluded this based on the fact that SessionBroker has a member variable called sessionNamesByClass. sessionNamesByClass maintains map of entity and sessionName from where to get the data. Since the "value" is not a list of SessionName, I'm thinking it is not going to be possible for sessionBroker to fetch data from more than one session.

Does anyone has any more insight to this? Or is there any workaround this issue? Or Am I missing anything? Any help will be greatly appreciated.

Thanks in advance
Leena
Previous Topic:Query TimeOut Hints not working in Eclipse Link 2.6
Next Topic:JPA Criteria Query
Goto Forum:
  


Current Time: Fri Apr 26 19:52:02 GMT 2024

Powered by FUDForum. Page generated in 0.02773 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top