HHH-6300 Adding support for @BatchSize and @RowId
This commit is contained in:
parent
24bd525693
commit
b6f9d9d5d7
|
@ -33,7 +33,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@java.lang.annotation.Target({TYPE})
|
||||
@java.lang.annotation.Target( { TYPE })
|
||||
@Retention(RUNTIME)
|
||||
public @interface RowId {
|
||||
/**
|
||||
|
|
|
@ -99,12 +99,15 @@ public class EntityBinder {
|
|||
|
||||
bindInheritance( entityBinding );
|
||||
|
||||
// bind entity level annotations
|
||||
bindWhereFilter( entityBindingState );
|
||||
bindJpaCaching( entityBindingState );
|
||||
bindHibernateCaching( entityBindingState );
|
||||
bindProxy( entityBindingState );
|
||||
bindSynchronize( entityBindingState );
|
||||
bindCustomSQL( entityBindingState );
|
||||
bindRowId( entityBindingState );
|
||||
bindBatchSize( entityBindingState );
|
||||
|
||||
// take care of the id, attributes and relations
|
||||
if ( configuredClass.isRoot() ) {
|
||||
|
@ -326,6 +329,26 @@ public class EntityBinder {
|
|||
);
|
||||
}
|
||||
|
||||
private void bindRowId(EntityBindingStateImpl entityBindingState) {
|
||||
AnnotationInstance rowIdAnnotation = JandexHelper.getSingleAnnotation(
|
||||
configuredClass.getClassInfo(), HibernateDotNames.ROW_ID
|
||||
);
|
||||
|
||||
if ( rowIdAnnotation != null ) {
|
||||
entityBindingState.setRowId( rowIdAnnotation.value().asString() );
|
||||
}
|
||||
}
|
||||
|
||||
private void bindBatchSize(EntityBindingStateImpl entityBindingState) {
|
||||
AnnotationInstance batchSizeAnnotation = JandexHelper.getSingleAnnotation(
|
||||
configuredClass.getClassInfo(), HibernateDotNames.BATCH_SIZE
|
||||
);
|
||||
|
||||
if ( batchSizeAnnotation != null ) {
|
||||
entityBindingState.setBatchSize( batchSizeAnnotation.value( "size" ).asInt() );
|
||||
}
|
||||
}
|
||||
|
||||
private Caching createCachingForCacheableAnnotation(EntityBindingStateImpl entityBindingState) {
|
||||
String region = entityBindingState.getEntityName();
|
||||
RegionFactory regionFactory = meta.getServiceRegistry().getService( RegionFactory.class );
|
||||
|
|
|
@ -44,7 +44,6 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
private String entityName;
|
||||
|
||||
private Caching caching;
|
||||
private MetaAttributeContext metaAttributeContext;
|
||||
|
||||
private boolean mutable;
|
||||
private boolean explicitPolymorphism;
|
||||
|
@ -59,7 +58,6 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
private OptimisticLockType optimisticLock;
|
||||
|
||||
private Class<?> persisterClass;
|
||||
private boolean isAbstract;
|
||||
|
||||
private boolean lazy;
|
||||
private String proxyInterfaceName;
|
||||
|
@ -74,12 +72,7 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
this.isRoot = configuredClass.isRoot();
|
||||
this.inheritanceType = configuredClass.getInheritanceType();
|
||||
this.synchronizedTableNames = new HashSet<String>();
|
||||
|
||||
// TODO: where do these values come from?
|
||||
this.metaAttributeContext = null;
|
||||
this.rowId = null;
|
||||
this.batchSize = -1;
|
||||
this.isAbstract = false;
|
||||
}
|
||||
|
||||
public void setEntityName(String entityName) {
|
||||
|
@ -134,6 +127,14 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
this.proxyInterfaceName = proxyInterfaceName;
|
||||
}
|
||||
|
||||
public void setRowId(String rowId) {
|
||||
this.rowId = rowId;
|
||||
}
|
||||
|
||||
public void setBatchSize(int batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public void addSynchronizedTableName(String tableName) {
|
||||
synchronizedTableNames.add( tableName );
|
||||
}
|
||||
|
@ -168,7 +169,8 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
|
||||
@Override
|
||||
public MetaAttributeContext getMetaAttributeContext() {
|
||||
return metaAttributeContext;
|
||||
// not needed for annotations!? (HF)
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,7 +235,8 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
|
||||
@Override
|
||||
public Boolean isAbstract() {
|
||||
return isAbstract;
|
||||
// no annotations equivalent
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.annotations.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.annotations.BatchSize;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@code o.h.a.BatchSize}.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class BatchSizeBindingTests extends BaseAnnotationBindingTestCase {
|
||||
@Test
|
||||
public void testNoBatchSize() {
|
||||
buildMetadataSources( NoBatchSizeEntity.class );
|
||||
EntityBinding binding = getEntityBinding( NoBatchSizeEntity.class );
|
||||
assertEquals( "Wrong batch size", -1, binding.getBatchSize() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchSize() {
|
||||
buildMetadataSources( BatchSizeEntity.class );
|
||||
EntityBinding binding = getEntityBinding( BatchSizeEntity.class );
|
||||
assertEquals( "Wrong batch size", 100, binding.getBatchSize() );
|
||||
}
|
||||
|
||||
@Entity
|
||||
class NoBatchSizeEntity {
|
||||
@Id
|
||||
private int id;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@BatchSize(size = 100)
|
||||
class BatchSizeEntity {
|
||||
@Id
|
||||
private int id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ import static junit.framework.Assert.assertNull;
|
|||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class CustomSQLTests extends BaseAnnotationBindingTestCase {
|
||||
public class CustomSQLBindingTests extends BaseAnnotationBindingTestCase {
|
||||
@Test
|
||||
public void testNoCustomSqlAnnotations() {
|
||||
buildMetadataSources( NoCustomSQLEntity.class );
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.annotations.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.annotations.RowId;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@code o.h.a.RowId}.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class RowIdBindingTests extends BaseAnnotationBindingTestCase {
|
||||
@Test
|
||||
public void testNoRowId() {
|
||||
buildMetadataSources( NoRowIdEntity.class );
|
||||
EntityBinding binding = getEntityBinding( NoRowIdEntity.class );
|
||||
assertEquals( "Wrong row id", null, binding.getRowId() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRowId() {
|
||||
buildMetadataSources( RowIdEntity.class );
|
||||
EntityBinding binding = getEntityBinding( RowIdEntity.class );
|
||||
assertEquals( "Wrong row id", "rowid", binding.getRowId() );
|
||||
}
|
||||
|
||||
@Entity
|
||||
class NoRowIdEntity {
|
||||
@Id
|
||||
private int id;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@RowId("rowid")
|
||||
class RowIdEntity {
|
||||
@Id
|
||||
private int id;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue