forked from hibernate/hibernate-orm
-
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.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
hibernate-core/src/test/java/org/hibernate/orm/test/mapping/attributebinder/Foo.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,27 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.orm.test.mapping.attributebinder; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import org.hibernate.annotations.AttributeBinderType; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* Dummy annotation to verify binders are called only once. | ||
* | ||
* @author Yanming Zhou | ||
*/ | ||
@Target({METHOD,FIELD}) | ||
@Retention(RUNTIME) | ||
@AttributeBinderType( binder = FooBinder.class ) | ||
public @interface Foo { | ||
} |
38 changes: 38 additions & 0 deletions
38
hibernate-core/src/test/java/org/hibernate/orm/test/mapping/attributebinder/FooBinder.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,38 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.orm.test.mapping.attributebinder; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.hibernate.binder.AttributeBinder; | ||
import org.hibernate.boot.spi.MetadataBuildingContext; | ||
import org.hibernate.mapping.PersistentClass; | ||
import org.hibernate.mapping.Property; | ||
|
||
/** | ||
* The binder to verify binders are called only once. | ||
* | ||
* @author Yanming Zhou | ||
*/ | ||
public class FooBinder implements AttributeBinder<Foo> { | ||
|
||
private static final Map<String, Foo> map = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void bind( | ||
Foo annotation, | ||
MetadataBuildingContext buildingContext, | ||
PersistentClass persistentClass, | ||
Property property) { | ||
String key = persistentClass.getClassName() + "." + property.getName(); | ||
Foo existing = map.putIfAbsent( key, annotation ); | ||
if ( existing == annotation ) { | ||
throw new IllegalStateException( "AttributeBinder is called twice" ); | ||
} | ||
} | ||
} |
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