HHH-6300 Adding support for @Synchronize annotation
This commit is contained in:
parent
5b4e976972
commit
002779dffb
|
@ -23,10 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -86,7 +84,7 @@ public class EntityBinding {
|
|||
private CustomSQL customUpdate;
|
||||
private CustomSQL customDelete;
|
||||
|
||||
private List<String> synchronizedTableNames;
|
||||
private Set<String> synchronizedTableNames = new HashSet<String>();
|
||||
|
||||
public EntityBinding initialize(EntityBindingState state) {
|
||||
this.isRoot = state.isRoot();
|
||||
|
@ -318,13 +316,13 @@ public class EntityBinding {
|
|||
return isAbstract;
|
||||
}
|
||||
|
||||
protected void addSynchronizedTable(String tablename) {
|
||||
if ( synchronizedTableNames == null ) {
|
||||
synchronizedTableNames = new ArrayList<String>();
|
||||
}
|
||||
synchronizedTableNames.add( tablename );
|
||||
protected void addSynchronizedTable(String tableName) {
|
||||
synchronizedTableNames.add( tableName );
|
||||
}
|
||||
|
||||
public Set<String> getSynchronizedTableNames() {
|
||||
return synchronizedTableNames;
|
||||
}
|
||||
|
||||
// Custom SQL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding.state;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.metamodel.binding.Caching;
|
||||
import org.hibernate.metamodel.binding.CustomSQL;
|
||||
|
@ -74,5 +74,5 @@ public interface EntityBindingState {
|
|||
|
||||
CustomSQL getCustomDelete();
|
||||
|
||||
List<String> getSynchronizedTableNames();
|
||||
Set<String> getSynchronizedTableNames();
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ public class EntityBinder {
|
|||
bindJpaCaching( entityBindingState );
|
||||
bindHibernateCaching( entityBindingState );
|
||||
bindProxy( entityBindingState );
|
||||
bindSynchronize( entityBindingState );
|
||||
|
||||
// take care of the id, attributes and relations
|
||||
if ( configuredClass.isRoot() ) {
|
||||
|
@ -259,6 +260,19 @@ public class EntityBinder {
|
|||
entityBindingState.setProxyInterfaceName( proxyInterfaceClass );
|
||||
}
|
||||
|
||||
private void bindSynchronize(EntityBindingStateImpl entityBindingState) {
|
||||
AnnotationInstance synchronizeAnnotation = JandexHelper.getSingleAnnotation(
|
||||
configuredClass.getClassInfo(), HibernateDotNames.SYNCHRONIZE
|
||||
);
|
||||
|
||||
if ( synchronizeAnnotation != null ) {
|
||||
String[] tableNames = synchronizeAnnotation.value().asStringArray();
|
||||
for ( String tableName : tableNames ) {
|
||||
entityBindingState.addSynchronizedTableName( tableName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Caching createCachingForCacheableAnnotation(EntityBindingStateImpl entityBindingState) {
|
||||
String region = entityBindingState.getEntityName();
|
||||
RegionFactory regionFactory = meta.getServiceRegistry().getService( RegionFactory.class );
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.source.annotations.entity.state.binding;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.annotations.OptimisticLockType;
|
||||
import org.hibernate.metamodel.binding.Caching;
|
||||
|
@ -67,11 +68,12 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
private CustomSQL customUpdate;
|
||||
private CustomSQL customDelete;
|
||||
|
||||
private List<String> synchronizedTableNames;
|
||||
private Set<String> synchronizedTableNames;
|
||||
|
||||
public EntityBindingStateImpl(ConfiguredClass configuredClass) {
|
||||
this.isRoot = configuredClass.isRoot();
|
||||
this.inheritanceType = configuredClass.getInheritanceType();
|
||||
this.synchronizedTableNames = new HashSet<String>();
|
||||
|
||||
// TODO: where do these values come from?
|
||||
this.metaAttributeContext = null;
|
||||
|
@ -81,7 +83,6 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
this.customInsert = null;
|
||||
this.customUpdate = null;
|
||||
this.customDelete = null;
|
||||
this.synchronizedTableNames = null;
|
||||
}
|
||||
|
||||
public void setEntityName(String entityName) {
|
||||
|
@ -136,6 +137,10 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
this.proxyInterfaceName = proxyInterfaceName;
|
||||
}
|
||||
|
||||
public void addSynchronizedTableName(String tableName) {
|
||||
synchronizedTableNames.add( tableName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot() {
|
||||
return isRoot;
|
||||
|
@ -238,7 +243,7 @@ public class EntityBindingStateImpl implements EntityBindingState {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSynchronizedTableNames() {
|
||||
public Set<String> getSynchronizedTableNames() {
|
||||
return synchronizedTableNames;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
|
@ -74,7 +74,7 @@ public class HbmEntityBindingState implements EntityBindingState {
|
|||
private final CustomSQL customUpdate;
|
||||
private final CustomSQL customDelete;
|
||||
|
||||
private final List<String> synchronizedTableNames;
|
||||
private final Set<String> synchronizedTableNames;
|
||||
|
||||
public HbmEntityBindingState(
|
||||
boolean isRoot,
|
||||
|
@ -84,7 +84,7 @@ public class HbmEntityBindingState implements EntityBindingState {
|
|||
this.isRoot = isRoot;
|
||||
this.entityInheritanceType = inheritanceType;
|
||||
|
||||
this.caching = createCaching( entityClazz, bindingContext.extractEntityName( entityClazz ) );
|
||||
this.caching = createCaching( entityClazz, bindingContext.extractEntityName( entityClazz ) );
|
||||
|
||||
metaAttributeContext = HbmHelper.extractMetaAttributeContext(
|
||||
entityClazz.getMeta(), true, bindingContext.getMetaAttributeContext()
|
||||
|
@ -150,7 +150,7 @@ public class HbmEntityBindingState implements EntityBindingState {
|
|||
}
|
||||
|
||||
if ( entityClazz.getSynchronize() != null ) {
|
||||
synchronizedTableNames = new ArrayList<String>( entityClazz.getSynchronize().size() );
|
||||
synchronizedTableNames = new HashSet<String>( entityClazz.getSynchronize().size() );
|
||||
for ( XMLSynchronizeElement synchronize : entityClazz.getSynchronize() ) {
|
||||
synchronizedTableNames.add( synchronize.getTable() );
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ public class HbmEntityBindingState implements EntityBindingState {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSynchronizedTableNames() {
|
||||
public Set<String> getSynchronizedTableNames() {
|
||||
return synchronizedTableNames;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import static junit.framework.Assert.assertTrue;
|
|||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class InheritanceTypeTest extends BaseAnnotationBindingTestCase {
|
||||
public class InheritanceBindingTest extends BaseAnnotationBindingTestCase {
|
||||
@Test
|
||||
public void testNoInheritance() {
|
||||
buildMetadataSources( SingleEntity.class );
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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 java.util.Set;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.annotations.Synchronize;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@code o.h.a.Synchronize}.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class SynchronizeBindingTests extends BaseAnnotationBindingTestCase {
|
||||
@Test
|
||||
public void testSynchronizeAnnotation() {
|
||||
buildMetadataSources( TestEntityWithSynchronizeAnnotation.class );
|
||||
EntityBinding binding = getEntityBinding( TestEntityWithSynchronizeAnnotation.class );
|
||||
Set<String> synchronizedTableNames = binding.getSynchronizedTableNames();
|
||||
assertEquals( "Wrong number of synced tables", 2, synchronizedTableNames.size() );
|
||||
assertTrue( "Table name missing", synchronizedTableNames.contains( "Foo" ) );
|
||||
assertTrue( "Table name missing", synchronizedTableNames.contains( "Bar" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSynchronizeAnnotation() {
|
||||
buildMetadataSources( TestEntity.class );
|
||||
EntityBinding binding = getEntityBinding( TestEntity.class );
|
||||
assertTrue( "There should be no cache binding", binding.getSynchronizedTableNames().size() == 0 );
|
||||
}
|
||||
|
||||
@Entity
|
||||
class TestEntity {
|
||||
@Id
|
||||
private int id;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Synchronize( { "Foo", "Bar" })
|
||||
class TestEntityWithSynchronizeAnnotation {
|
||||
@Id
|
||||
private int id;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue