Dynamically set keyspace for entityMappers, not @Table

142 views
Skip to first unread message

robin.van...@jdriven.com

unread,
Jan 31, 2018, 4:37:57 AM1/31/18
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

I need to be able to get the keyspace-configuration from my configuration properties.


However, this is not possible due to the fact that I need to provide this statically to the @Table annotation.
I could bind the session to this keyspace, but this doesn't work if I have multiple tables in different keyspaces. Creating multiple session objects is not recommended in the manual:

Generally, the recommended approach is to use a single session with no keyspace, and prefix all your queries.


 I create a mapper with  new MappingManager(session).mapper(clazz)
This will automatically create a mapper +entityMapper  with the keyspace that is either from the session or from the Table annotation.
So, in order to comply to the recommendations, I should use the @Table.keyspace property. Unfortunately, it should be able to configure it dynamically trough properties, and not compile time.


Is there any workaround to make this more dynamic? i.e. not injecting the 'keyspace' through @Table. 
How should I make a 'feature request'? (am not able to log in on JIRA, and 'issues' is disabled on the repo)

Kind Regards,
Robin

Kevin Gallardo

unread,
Jan 31, 2018, 11:36:33 AM1/31/18
to java-dri...@lists.datastax.com
Hi, 

Support for dynamic keyspace in the Mapper was just recently added in the driver. You would use it as following:

MappingManager manager = new MappingManager(session);
Mapper<UserT> mapper = manager.mapper(userClass, mapperKeyspace);

The ticket was JAVA-1229 and has been released in the Java driver for Apache Cassandra 3.4.0 and the DSE driver 1.5.0.

Hope that helps.

Thanks.

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.



--
Kévin Gallardo.
Software Developer in Drivers and Tools Team,
DataStax.

Robin van den Berg

unread,
Feb 2, 2018, 10:06:05 AM2/2/18
to java-dri...@lists.datastax.com
Thanks!

Exactly what I needed. Upgraded. 

Virusvrij. www.avg.com

On 31 January 2018 at 17:36, Kevin Gallardo <kevin.g...@datastax.com> wrote:
Hi, 

Support for dynamic keyspace in the Mapper was just recently added in the driver. You would use it as following:

MappingManager manager = new MappingManager(session);
Mapper<UserT> mapper = manager.mapper(userClass, mapperKeyspace);

The ticket was JAVA-1229 and has been released in the Java driver for Apache Cassandra 3.4.0 and the DSE driver 1.5.0.

Hope that helps.

Thanks.



--

JDriven

JDriven BV
Robin van den Berg
 
| Consultant
e.  robin.van...@jdriven.com
t.   030 - 630 39 27
m. 06 - 485 625 15
Coltbaan 4d 3439 NG Nieuwegein 
www.jdriven.com | blog.jdriven.com

Reply all
Reply to author
Forward
0 new messages