HHH-6189 Binding @Where on entiry level
This commit is contained in:
parent
e8bd7dfd66
commit
e2db59de70
|
@ -202,7 +202,7 @@ public class ConfiguredClassHierarchy implements Iterable<ConfiguredClass> {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for ( ClassInfo info : classes ) {
|
for ( ClassInfo info : classes ) {
|
||||||
builder.append( info.name().toString() );
|
builder.append( info.name().toString() );
|
||||||
if ( count < classes.size() ) {
|
if ( count < classes.size() - 1 ) {
|
||||||
builder.append( ", " );
|
builder.append( ", " );
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class EntityBinder {
|
||||||
EntityBinding entityBinding = new EntityBinding();
|
EntityBinding entityBinding = new EntityBinding();
|
||||||
bindJpaEntityAnnotation( entityBinding );
|
bindJpaEntityAnnotation( entityBinding );
|
||||||
bindHibernateEntityAnnotation( entityBinding ); // optional hibernate specific @org.hibernate.annotations.Entity
|
bindHibernateEntityAnnotation( entityBinding ); // optional hibernate specific @org.hibernate.annotations.Entity
|
||||||
|
bindWhereFilter( entityBinding );
|
||||||
schemaName = createSchemaName();
|
schemaName = createSchemaName();
|
||||||
bindTable( entityBinding );
|
bindTable( entityBinding );
|
||||||
|
|
||||||
|
@ -70,6 +71,17 @@ public class EntityBinder {
|
||||||
meta.addEntity( entityBinding );
|
meta.addEntity( entityBinding );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void bindWhereFilter(EntityBinding entityBinding) {
|
||||||
|
AnnotationInstance whereAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
|
configuredClass.getClassInfo(), HibernateDotNames.WHERE
|
||||||
|
);
|
||||||
|
if ( whereAnnotation != null ) {
|
||||||
|
// no null check needed, it is a required attribute
|
||||||
|
String clause = whereAnnotation.value( "clause" ).asString();
|
||||||
|
entityBinding.setWhereFilter( clause );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Schema.Name createSchemaName() {
|
private Schema.Name createSchemaName() {
|
||||||
String schema = null;
|
String schema = null;
|
||||||
String catalog = null;
|
String catalog = null;
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
|
import org.hibernate.service.ServiceRegistryBuilder;
|
||||||
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public class MiscAnnotationBindingTest extends BaseUnitTestCase {
|
||||||
|
@Test
|
||||||
|
public void testWhereFilter() {
|
||||||
|
|
||||||
|
|
||||||
|
MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
|
||||||
|
sources.addAnnotatedClass( Foo.class );
|
||||||
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
EntityBinding binding = metadata.getEntityBinding( MiscAnnotationBindingTest.class.getSimpleName() + "$" + Foo.class.getSimpleName() );
|
||||||
|
assertEquals( "Wrong where filter", "1=1", binding.getWhereFilter() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Where(clause = "1=1")
|
||||||
|
class Foo {
|
||||||
|
@Id
|
||||||
|
private long id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue