Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA and the Decorator Pattern

I am trying to create an application which will be partially dependent on the Census Department TIGER/Lines data Shapefiles, which have a record layout defined here:

http://www.census.gov/geo/www/tiger/tgrshp2010/TGRSHP10AA.pdf

My idea is to use the Decorator pattern to have a base Feature class with the fields common to all the data types, then extend it via the decorator pattern for the individual feature types (States, Counties, Congressional Districts, etc). However, I plan to use Google App Engine for hosting, so I have to do this via either JDO or JPA. I would much prefer JPA.

Can I map a decorated object? My idea is that the base feature class would be annotated with @Entity, then the extensions would contain the mapped fields specific to the decorated object. Since the GAE datastore is NOT an RDBMS, I'm thinking I can get away with it.

like image 612
Jason Avatar asked Mar 18 '11 21:03

Jason


People also ask

Which design pattern is used in JPA?

The JPA, short for Java Persistence API, is part of the Java EE 5 specification and has been implemented by Hibernate, TopLink, EclipseLink, OpenJPA, and a number of other object-relational mapping (ORM) frameworks.

What is a decorator pattern in Java?

Decorator patterns allow a user to add new functionality to an existing object without altering its structure. So, there is no change to the original class. The decorator design pattern is a structural pattern, which provides a wrapper to the existing class.

What does the decorator pattern do?

In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class.

What is spring boot decorator?

FlowerBouquetDecorator. ): Is an abstract class that extends Component and acts as the base class for concrete decorator classes.


1 Answers

If you use the Decorator pattern, it means that you use the composition. So what you can do is just mark the class you want to decorate as Embeddable and in your decorator, mark your decorated class as Embedded.

If you prefer to use the inheritance, your base class is not an entity since is just something you want to inherit and not store itself is the DB. To create a base classe which will be inherited from other real entities, there is an annotation for that : @MappedSuperclass

According the GAE docs, both are supported.

Hope it helps!

like image 138
tibo Avatar answered Sep 27 '22 21:09

tibo