0

I am developing a data service using Spring Data and Gemfire. There is an annotation

@Region("<region name>")

to specify which Gemfire region the POJO is going to be stored in.

It requires the name of the configured Gemfire region. I feel like hard-coding the name of the region is a bad practice, since the Gemfire cluster is going to be managed by a separate team and I believe the region name should be totally configurable.

Is there any better practice to avoid hard coding the region name?

Dmitry Trofimov
  • 503
  • 4
  • 10

3 Answers3

1

The region name must be shared by all processes that access the region. This is analogous to a table name in a relational database. In this sense, it is no different than JPA or Hibernate annotations that declare the table name in which the POJO will be stored. IIRC, using Spring Data Repositories, if @Region is not present it will get it from the class name. But either way, the corresponding region must exist. If your application is a client to the GemFire grid, you must also configure a client region with the same name as the corresponding region on the server. If it's a peer than you must create the region (either a partition or a replica). These things may be done with Spring configuration or native GemFire configuration, but in any event, the shared region name must be known in advance and if it changes, it must change everywhere.

dturanski
  • 1,723
  • 1
  • 13
  • 8
  • Not sure if it answers my question. I would like to be able to load the region name from properties file at least. Don't like the idea of hard-coded name in the source code. – Dmitry Trofimov Feb 07 '14 at 09:37
1

Could you use Spring Expression Language to inject the name of the Region?

We inject a value from a config bean, which itself is based on an XML file, into a @Value annotation e.g:

@Value("#{config.dataSourceConfig.dbMainUsername}")

Where "config" is the name of the config bean.

Not sure is this works with all annotations tho...

Lawrence Tierney
  • 856
  • 1
  • 12
  • 30
  • Do you have some reading material on this please? I need to avoid to hardcode the value passed in in an annotation. Tnx – Gabe Jul 27 '16 at 16:35
0

In general, I do not think it is necessarily bad practice to specify the Region's name/path in the @Region annotation on the application domain object; it is certainly a lot more explicit.

However, I can understand the need to make such things configurable, perhaps as you promote from 1 env (e.g. DEV) to another (e.g. PROD). As such, see the recent change...

SGF-261 - allowing an application domain object/entity to be persisted to multiple Regions in a GemFire Cache

As well as this proposed, future change...

SGF-262.

John Blum
  • 7,381
  • 1
  • 20
  • 30