java - Play framework, using JPA and Morphia , conflicts if applying to same model -


i have location model class. have abstract class, persister. have 2 implementations of abstract class: mysqlpersister , mongodbpersister. reasoning can switch between using mysql or mongodb whenever have to. note not using both @ same time. more flexibility.

problem location model class extends model, mysql have import play.db.jpa.model. mongodb import play.modules.morphia.model. becomes problem because every time want switch, not have change location model class, have change code in implementations of persister due 2 libraries having different methods model.

for example, if want change using jpa morphia, have comment out code in mysqlpersister. model.find().fetch() returns iterable in jpa, , model.find().filter().aslist() in morphia doesn't exist when import jpa.

how overcome problem? don't want create generic model class , 2 more identical model classes import each database - that's duplication.

basically find design of play-morphia , play-jpa unflexible:

jpa                             playmorphia play.db.jpa.model           >   play.modules.morphia.model javax.persistence.entity    >   com.google.code.morphia.annotations.entity 

it have been better if both play.db.jpa.model , play.modules.morphia.model extended more generalized model class. way don't have go changing models if wanted implement both databases.

thanks! let me know if explanation isn't clear.

i try using abstraction layer on top of persistence layer. abstract layer should provide implementation-independent methods needs application , layer should delegate calls actual, framework-dependent, persistence layer implementation (e.g. jpa.model or morphia.model).

this not duplication, use case object oriented programming :)


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -