forked from devonfw/devon4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devonfw#14: decoupling from mmm-util-entity (mmm-util-core is still u…
…sed for exception/I18N stuff) oasp/oasp4j#684: replaced AbstractJsonDeserializer with JacksonUtil
- Loading branch information
Showing
75 changed files
with
885 additions
and
625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
= devon4jJava | ||
= devon4j | ||
|
||
The Java stack of http://devonfw.com[devonfw]. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
modules/basic/src/main/java/com/devonfw/module/basic/common/api/entity/GenericEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.devonfw.module.basic.common.api.entity; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* This is the interface for an entity, which is an object that is potentially stored in a persistent store (typically a | ||
* database via JPA). Every non-abstract implementation of this interface is simply called an <em>entity</em>. It is | ||
* supposed to be a simple java bean. <br> | ||
* This interface makes the following assumptions: | ||
* <ul> | ||
* <li>A {@link GenericEntity} is identified by a {@link #getId() primary key}.</li> | ||
* <li>A {@link GenericEntity} has a {@link #getModificationCounter() modification counter} for optimistic locking (even | ||
* though not strictly required - you could statically return 0).</li> | ||
* </ul> | ||
* <b>ATTENTION:</b><br> | ||
* An instance of this interface is typically one of the following: | ||
* <ul> | ||
* <li>a <b>JPA {@link javax.persistence.Entity}</b><br> | ||
* <li>a <b>{@link com.devonfw.module.basic.common.api.to.AbstractEto entity transfer-object}</b><br> | ||
* </ul> | ||
* In order to distinguish the above cases an application has an architecture that organizes the code in technical | ||
* layers (see <a href="http://en.wikipedia.org/wiki/Multilayered_architecture">multilayered architecture</a>) and | ||
* business oriented slices (business components). Therefore within the persistence layer instances should always be | ||
* {@link javax.persistence.Entity persistence entities}. On the other hand the higher layers always need to use | ||
* {@link com.devonfw.module.basic.common.api.to.AbstractTo transfer-objects}. Our recommendation is to map between | ||
* these two in the logic-layer using the {@code BeanMapper} component from the {@code devon4j-beanmapping} module. | ||
* | ||
* @see javax.persistence.Entity | ||
* | ||
* @param <ID> is the type of the {@link #getId() primary key}. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
public interface GenericEntity<ID> extends Serializable { | ||
|
||
/** | ||
* @return the primary key (unique identifier) of this entity. May be {@code null} if this entity is transient (not | ||
* yet {@link javax.persistence.EntityManager#persist(Object) saved} in the database). While this method is | ||
* initially defined in a generic way, it is strongly recommended to use {@link Long} as datatype for IDs. | ||
* <br> | ||
* Even if you want to have a {@link String}-based business-oriented identifier it is best practice to use a | ||
* {@link Long} as primary key and add the business identifier as additional field (with a unique constraint). | ||
* This way references to the entity will be a lot more compact and improve your performance in JOINs or the | ||
* like. However, there may be reasons to use other datatypes for the ID. In any case the unique ID should be | ||
* an immutable java-object that can be rebuild from its {@link Object#toString() string-representation}. <br> | ||
* Please note that if your ID has a specific syntax, semantic, formatting rules, etc. you should create a | ||
* custom datatype for it. If it can easily be mapped to a {@link Long} value you can still use {@link Long} | ||
* here and provide a transient getter method that returns the your custom datatype from the {@link Long}. | ||
* @see javax.persistence.Id | ||
*/ | ||
ID getId(); | ||
|
||
/** | ||
* @param id the new {@link #getId() primary key}. This method shall typically only be used by technical frameworks | ||
* such as hibernate. | ||
*/ | ||
void setId(ID id); | ||
|
||
/** | ||
* This method gets the current modification-counter of this entity. Whenever the object gets modified and | ||
* {@link javax.persistence.EntityManager#persist(Object) persisted}, this counter will be increased (typically after | ||
* the transaction is closed). The initial value after construction is {@code 0}. <br> | ||
* This property is often simply called {@link javax.persistence.Version version}. However, as this sometimes causes | ||
* confusion or may conflict with a business property "version", we use the more technical and self-explanatory name | ||
* {@code modificationCounter}.<br> | ||
* If this feature is NOT supported for some reason, this method should always return {@code 0}. | ||
* | ||
* @see javax.persistence.Version | ||
* | ||
* @return the current modification-counter. | ||
* @see javax.persistence.Version | ||
*/ | ||
int getModificationCounter(); | ||
|
||
/** | ||
* @param modificationCounter the new {@link #getModificationCounter() modification counter}. This method shall | ||
* typically only be used by technical frameworks such as hibernate. | ||
*/ | ||
void setModificationCounter(int modificationCounter); | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
modules/basic/src/main/java/com/devonfw/module/basic/common/api/entity/RevisionedEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.devonfw.module.basic.common.api.entity; | ||
|
||
/** | ||
* This is the interface for a {@link GenericEntity} that is (potentially) revision-controlled. Frameworks like | ||
* {@code hibernate-envers} (look for {@code @Audited} annotation on {@link javax.persistence.Entity JPA entities}) or | ||
* {@code bi-temporal} can manage such entities so all changes are stored in the database as a revision history. An | ||
* instance of this interface represents the {@link #getRevision() revision} of the {@link GenericEntity entity}. There | ||
* are two cases to distinguish: | ||
* <ul> | ||
* <li><b>{@link #LATEST_REVISION latest revision}</b><br> | ||
* A {@link RevisionedEntity} pointing to {@link #LATEST_REVISION} ({@code null}) represents the latest state of the | ||
* entity and can be modified.</li> | ||
* <li><b>historic {@link #getRevision() revision}</b><br> | ||
* If the object is {@link #getRevision() revision controlled}, it has a history of modifications. A | ||
* {@link RevisionedEntity} can represent a historic {@link #getRevision() revision} out of this history. It therefore | ||
* is immutable so operations to modify the {@link RevisionedEntity} will typically fail.</li> | ||
* </ul> | ||
* | ||
* @param <ID> is the type of the {@link #getId() primary key}. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
public interface RevisionedEntity<ID> extends GenericEntity<ID> { | ||
|
||
/** | ||
* The latest {@link #getRevision() revision} of an {@link GenericEntity entity}. | ||
*/ | ||
Number LATEST_REVISION = null; | ||
|
||
/** | ||
* This method gets the revision of this entity. The {@link RevisionedEntity#LATEST_REVISION latest revision} of an | ||
* entity will always return {@code null}. Otherwise this object is a <em>historic entity</em> and it will be | ||
* read-only so modifications are NOT permitted. | ||
* | ||
* @return the revision or {@link #LATEST_REVISION} ({@code null}) if this is the latest revision. | ||
*/ | ||
Number getRevision(); | ||
|
||
/** | ||
* This method sets the {@link #getRevision() revision} of this entity. <br> | ||
* <b>ATTENTION:</b><br> | ||
* This operation should only be used in specific cases and if you are aware of what you are doing as this attribute | ||
* is managed by the persistence. However, for final freedom we decided to add this method to the API (e.g. to copy | ||
* from transfer-object to persistent-entity and vice-versa). | ||
* | ||
* @param revision is the new value of {@link #getRevision()}. | ||
*/ | ||
void setRevision(Number revision); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
modules/basic/src/main/java/com/devonfw/module/basic/common/api/reference/IdRef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
modules/basic/src/main/java/com/devonfw/module/basic/common/api/reference/Ref.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 4 additions & 7 deletions
11
modules/basic/src/main/java/com/devonfw/module/basic/common/api/to/AbstractCto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.