-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow additional persistent bean registration outside of the actual b…
…ean types (if you want to use the bean types in some API)
- Loading branch information
Showing
9 changed files
with
218 additions
and
37 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
ojcms-persistence/src/main/java/de/adito/ojcms/persistence/AdditionalPersist.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,49 @@ | ||
package de.adito.ojcms.persistence; | ||
|
||
import de.adito.ojcms.beans.IBean; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* Allows to register an additional persistent bean. | ||
* | ||
* @author Simon Danner, 09.05.2020 | ||
* @see AdditionalPersistConfiguration | ||
*/ | ||
@Repeatable(AdditionalPersist.Multiple.class) | ||
@Documented | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface AdditionalPersist | ||
{ | ||
/** | ||
* The type of the persistent bean. | ||
*/ | ||
Class<? extends IBean> beanType(); | ||
|
||
/** | ||
* The id of the container in that the bean/beans are stored. | ||
* | ||
* @return the container id | ||
*/ | ||
String containerId(); | ||
|
||
/** | ||
* The mode in which the beans should be persisted. | ||
* Default: they will be stored in a container. | ||
* | ||
* @return the persistence mode to use | ||
*/ | ||
EPersistenceMode mode() default EPersistenceMode.CONTAINER; | ||
|
||
/** | ||
* Required to repeat this annotation. | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@interface Multiple | ||
{ | ||
AdditionalPersist[] value(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
ojcms-persistence/src/main/java/de/adito/ojcms/persistence/AdditionalPersistAsBaseType.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,49 @@ | ||
package de.adito.ojcms.persistence; | ||
|
||
import de.adito.ojcms.beans.IBean; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* Allows to register an additional persistent bean for some sub types. | ||
* | ||
* @author Simon Danner, 09.05.2020 | ||
* @see AdditionalPersistConfiguration | ||
*/ | ||
@Repeatable(AdditionalPersistAsBaseType.Multiple.class) | ||
@Documented | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface AdditionalPersistAsBaseType | ||
{ | ||
/** | ||
* The base type of the persistent bean. | ||
*/ | ||
Class<? extends IBean> baseType(); | ||
|
||
/** | ||
* The container id of the element, in which the bean/beans are stored. | ||
* | ||
* @return the container id | ||
*/ | ||
String containerId(); | ||
|
||
/** | ||
* All sub types the base type container is for. The base type itself can be included if it is not abstract. | ||
* At least two types must be provided. The given types must be assignable from the base bean type. | ||
* | ||
* @return an array of bean sub types the base container should be for | ||
*/ | ||
Class<? extends IBean>[] forSubTypes(); | ||
|
||
/** | ||
* Required to repeat this annotation. | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@interface Multiple | ||
{ | ||
AdditionalPersistAsBaseType[] value(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...-persistence/src/main/java/de/adito/ojcms/persistence/AdditionalPersistConfiguration.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,12 @@ | ||
package de.adito.ojcms.persistence; | ||
|
||
/** | ||
* Marks a class to provide additional registrations for persistent beans. | ||
* Use {@link AdditionalPersist} or {@link AdditionalPersistAsBaseType} to define additional persistent beans. | ||
* This is useful if you want to use bean types in some API modules and also want to use them as persistent beans in the server module. | ||
* | ||
* @author Simon Danner, 09.05.2020 | ||
*/ | ||
public interface AdditionalPersistConfiguration | ||
{ | ||
} |
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
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
19 changes: 19 additions & 0 deletions
19
...rest-server/src/test/java/de/adito/ojcms/rest/testapplication/SomeAdditionalTestBean.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,19 @@ | ||
package de.adito.ojcms.rest.testapplication; | ||
|
||
import de.adito.ojcms.beans.*; | ||
import de.adito.ojcms.beans.literals.fields.types.TextField; | ||
|
||
/** | ||
* Some business bean for test. | ||
* | ||
* @author Simon Danner, 09.05.2020 | ||
*/ | ||
public class SomeAdditionalTestBean extends OJBean | ||
{ | ||
public static final TextField SOME_FIELD = OJFields.create(SomeAdditionalTestBean.class); | ||
|
||
public SomeAdditionalTestBean() | ||
{ | ||
setValue(SOME_FIELD, "someValue"); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ojcms-rest-server/src/test/java/de/adito/ojcms/rest/testapplication/SomeTestBusiness.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,25 @@ | ||
package de.adito.ojcms.rest.testapplication; | ||
|
||
import de.adito.ojcms.beans.IBeanContainer; | ||
import de.adito.ojcms.transactions.annotations.Transactional; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
/** | ||
* Test business to test the additionally added persistent bean type. | ||
* | ||
* @author Simon Danner, 09.05.2020 | ||
*/ | ||
@ApplicationScoped | ||
class SomeTestBusiness | ||
{ | ||
@Inject | ||
private IBeanContainer<SomeAdditionalTestBean> additionalBeans; | ||
|
||
@Transactional | ||
void doIt() | ||
{ | ||
additionalBeans.addBean(new SomeAdditionalTestBean()); | ||
} | ||
} |