HHH-7527 - OSGI manifests for hibernate-orm : clean up org.hibernate.engine.spi package duplication between hem and core
This commit is contained in:
parent
52336f4150
commit
6b5a428b3f
|
@ -29,7 +29,7 @@ import org.hibernate.EntityMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.PropertyValueException;
|
import org.hibernate.PropertyValueException;
|
||||||
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
|
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.type.CollectionType;
|
import org.hibernate.type.CollectionType;
|
||||||
|
@ -151,7 +151,7 @@ public final class Nullability {
|
||||||
//check for all components values in the collection
|
//check for all components values in the collection
|
||||||
|
|
||||||
CompositeType componentType = (CompositeType) collectionElementType;
|
CompositeType componentType = (CompositeType) collectionElementType;
|
||||||
Iterator iter = CascadingAction.getLoadedElementsIterator( session, collectionType, value );
|
Iterator iter = CascadingActions.getLoadedElementsIterator( session, collectionType, value );
|
||||||
while ( iter.hasNext() ) {
|
while ( iter.hasNext() ) {
|
||||||
Object compValue = iter.next();
|
Object compValue = iter.next();
|
||||||
if (compValue != null) {
|
if (compValue != null) {
|
||||||
|
|
|
@ -24,20 +24,16 @@
|
||||||
package org.hibernate.engine.spi;
|
package org.hibernate.engine.spi;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A contract for defining the aspects of cascading various persistence actions.
|
* A contract for defining the aspects of cascading various persistence actions.
|
||||||
*
|
*
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*
|
||||||
* @see CascadingAction
|
* @see CascadingAction
|
||||||
*/
|
*/
|
||||||
public abstract class CascadeStyle implements Serializable {
|
public interface CascadeStyle extends Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For this style, should the given action be cascaded?
|
* For this style, should the given action be cascaded?
|
||||||
*
|
*
|
||||||
|
@ -45,7 +41,7 @@ public abstract class CascadeStyle implements Serializable {
|
||||||
*
|
*
|
||||||
* @return True if the action should be cascaded under this style; false otherwise.
|
* @return True if the action should be cascaded under this style; false otherwise.
|
||||||
*/
|
*/
|
||||||
public abstract boolean doCascade(CascadingAction action);
|
public boolean doCascade(CascadingAction action);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Probably more aptly named something like doCascadeToCollectionElements(); it is
|
* Probably more aptly named something like doCascadeToCollectionElements(); it is
|
||||||
|
@ -61,9 +57,7 @@ public abstract class CascadeStyle implements Serializable {
|
||||||
* @return True if the action should be really cascaded under this style;
|
* @return True if the action should be really cascaded under this style;
|
||||||
* false otherwise.
|
* false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean reallyDoCascade(CascadingAction action) {
|
public boolean reallyDoCascade(CascadingAction action);
|
||||||
return doCascade( action );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do we need to delete orphaned collection elements?
|
* Do we need to delete orphaned collection elements?
|
||||||
|
@ -71,252 +65,5 @@ public abstract class CascadeStyle implements Serializable {
|
||||||
* @return True if this style need to account for orphan delete
|
* @return True if this style need to account for orphan delete
|
||||||
* operations; false otherwise.
|
* operations; false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasOrphanDelete() {
|
public boolean hasOrphanDelete();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class MultipleCascadeStyle extends CascadeStyle {
|
|
||||||
private final CascadeStyle[] styles;
|
|
||||||
|
|
||||||
public MultipleCascadeStyle(CascadeStyle[] styles) {
|
|
||||||
this.styles = styles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
for ( CascadeStyle style : styles ) {
|
|
||||||
if ( style.doCascade( action ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean reallyDoCascade(CascadingAction action) {
|
|
||||||
for ( CascadeStyle style : styles ) {
|
|
||||||
if ( style.reallyDoCascade( action ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasOrphanDelete() {
|
|
||||||
for ( CascadeStyle style : styles ) {
|
|
||||||
if ( style.hasOrphanDelete() ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return ArrayHelper.toString( styles );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* save / delete / update / evict / lock / replicate / merge / persist + delete orphans
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle ALL_DELETE_ORPHAN = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasOrphanDelete() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_ALL_DELETE_ORPHAN";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* save / delete / update / evict / lock / replicate / merge / persist
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle ALL = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_ALL";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* save / update
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle UPDATE = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.SAVE_UPDATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_SAVE_UPDATE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* lock
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle LOCK = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.LOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_LOCK";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* refresh
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle REFRESH = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.REFRESH;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_REFRESH";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* evict
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle EVICT = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.EVICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_EVICT";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* replicate
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle REPLICATE = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.REPLICATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_REPLICATE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* merge
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle MERGE = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.MERGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_MERGE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle PERSIST = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.PERSIST
|
|
||||||
|| action == CascadingAction.PERSIST_ON_FLUSH;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_PERSIST";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delete
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle DELETE = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.DELETE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_DELETE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delete + delete orphans
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle DELETE_ORPHAN = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.DELETE || action == CascadingAction.SAVE_UPDATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean reallyDoCascade(CascadingAction action) {
|
|
||||||
return action == CascadingAction.DELETE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasOrphanDelete() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_DELETE_ORPHAN";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* no cascades
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle NONE = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_NONE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public CascadeStyle() {
|
|
||||||
}
|
|
||||||
|
|
||||||
static final Map<String, CascadeStyle> STYLES = new HashMap<String, CascadeStyle>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
STYLES.put( "all", ALL );
|
|
||||||
STYLES.put( "all-delete-orphan", ALL_DELETE_ORPHAN );
|
|
||||||
STYLES.put( "save-update", UPDATE );
|
|
||||||
STYLES.put( "persist", PERSIST );
|
|
||||||
STYLES.put( "merge", MERGE );
|
|
||||||
STYLES.put( "lock", LOCK );
|
|
||||||
STYLES.put( "refresh", REFRESH );
|
|
||||||
STYLES.put( "replicate", REPLICATE );
|
|
||||||
STYLES.put( "evict", EVICT );
|
|
||||||
STYLES.put( "delete", DELETE );
|
|
||||||
STYLES.put( "remove", DELETE ); // adds remove as a sort-of alias for delete...
|
|
||||||
STYLES.put( "delete-orphan", DELETE_ORPHAN );
|
|
||||||
STYLES.put( "none", NONE );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method for obtaining named cascade styles
|
|
||||||
*
|
|
||||||
* @param cascade The named cascade style name.
|
|
||||||
*
|
|
||||||
* @return The appropriate CascadeStyle
|
|
||||||
*/
|
|
||||||
public static CascadeStyle getCascadeStyle(String cascade) {
|
|
||||||
CascadeStyle style = STYLES.get( cascade );
|
|
||||||
if ( style == null ) {
|
|
||||||
throw new MappingException( "Unsupported cascade style: " + cascade );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,348 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, 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.engine.spi;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class CascadeStyles {
|
||||||
|
private static final Logger log = Logger.getLogger( CascadeStyles.class );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disallow instantiation
|
||||||
|
*/
|
||||||
|
private CascadeStyles() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save / delete / update / evict / lock / replicate / merge / persist + delete orphans
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle ALL_DELETE_ORPHAN = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasOrphanDelete() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_ALL_DELETE_ORPHAN";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save / delete / update / evict / lock / replicate / merge / persist
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle ALL = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_ALL";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save / update
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle UPDATE = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.SAVE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_SAVE_UPDATE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lock
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle LOCK = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.LOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_LOCK";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* refresh
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle REFRESH = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.REFRESH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_REFRESH";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* evict
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle EVICT = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.EVICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_EVICT";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* replicate
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle REPLICATE = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.REPLICATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_REPLICATE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* merge
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle MERGE = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.MERGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_MERGE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle PERSIST = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.PERSIST
|
||||||
|
|| action == CascadingActions.PERSIST_ON_FLUSH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_PERSIST";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle DELETE = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.DELETE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_DELETE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete + delete orphans
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle DELETE_ORPHAN = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.DELETE || action == CascadingActions.SAVE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean reallyDoCascade(CascadingAction action) {
|
||||||
|
return action == CascadingActions.DELETE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasOrphanDelete() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_DELETE_ORPHAN";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* no cascades
|
||||||
|
*/
|
||||||
|
public static final CascadeStyle NONE = new BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_NONE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Map<String, CascadeStyle> STYLES = buildBaseCascadeStyleMap();
|
||||||
|
|
||||||
|
private static Map<String, CascadeStyle> buildBaseCascadeStyleMap() {
|
||||||
|
final HashMap<String, CascadeStyle> base = new HashMap<String, CascadeStyle>();
|
||||||
|
|
||||||
|
base.put( "all", ALL );
|
||||||
|
base.put( "all-delete-orphan", ALL_DELETE_ORPHAN );
|
||||||
|
base.put( "save-update", UPDATE );
|
||||||
|
base.put( "persist", PERSIST );
|
||||||
|
base.put( "merge", MERGE );
|
||||||
|
base.put( "lock", LOCK );
|
||||||
|
base.put( "refresh", REFRESH );
|
||||||
|
base.put( "replicate", REPLICATE );
|
||||||
|
base.put( "evict", EVICT );
|
||||||
|
base.put( "delete", DELETE );
|
||||||
|
base.put( "remove", DELETE ); // adds remove as a sort-of alias for delete...
|
||||||
|
base.put( "delete-orphan", DELETE_ORPHAN );
|
||||||
|
base.put( "none", NONE );
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method for obtaining named cascade styles
|
||||||
|
*
|
||||||
|
* @param cascade The named cascade style name.
|
||||||
|
*
|
||||||
|
* @return The appropriate CascadeStyle
|
||||||
|
*/
|
||||||
|
public static CascadeStyle getCascadeStyle(String cascade) {
|
||||||
|
CascadeStyle style = STYLES.get( cascade );
|
||||||
|
if ( style == null ) {
|
||||||
|
throw new MappingException( "Unsupported cascade style: " + cascade );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerCascadeStyle(String name, BaseCascadeStyle cascadeStyle) {
|
||||||
|
log.tracef( "Registering external cascade style [%s : %s]", name, cascadeStyle );
|
||||||
|
final CascadeStyle old = STYLES.put( name, cascadeStyle );
|
||||||
|
if ( old != null ) {
|
||||||
|
log.debugf(
|
||||||
|
"External cascade style regsitration [%s : %s] overrode base registration [%s]",
|
||||||
|
name,
|
||||||
|
cascadeStyle,
|
||||||
|
old
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class BaseCascadeStyle implements CascadeStyle {
|
||||||
|
@Override
|
||||||
|
public boolean reallyDoCascade(CascadingAction action) {
|
||||||
|
return doCascade( action );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasOrphanDelete() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class MultipleCascadeStyle extends BaseCascadeStyle {
|
||||||
|
private final CascadeStyle[] styles;
|
||||||
|
|
||||||
|
public MultipleCascadeStyle(CascadeStyle[] styles) {
|
||||||
|
this.styles = styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
for ( CascadeStyle style : styles ) {
|
||||||
|
if ( style.doCascade( action ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean reallyDoCascade(CascadingAction action) {
|
||||||
|
for ( CascadeStyle style : styles ) {
|
||||||
|
if ( style.reallyDoCascade( action ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasOrphanDelete() {
|
||||||
|
for ( CascadeStyle style : styles ) {
|
||||||
|
if ( style.hasOrphanDelete() ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ArrayHelper.toString( styles );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,40 +24,19 @@
|
||||||
package org.hibernate.engine.spi;
|
package org.hibernate.engine.spi;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.LockMode;
|
|
||||||
import org.hibernate.LockOptions;
|
|
||||||
import org.hibernate.ReplicationMode;
|
|
||||||
import org.hibernate.TransientPropertyValueException;
|
|
||||||
import org.hibernate.collection.spi.PersistentCollection;
|
|
||||||
import org.hibernate.engine.internal.ForeignKeys;
|
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
|
||||||
import org.hibernate.type.CollectionType;
|
import org.hibernate.type.CollectionType;
|
||||||
import org.hibernate.type.EntityType;
|
|
||||||
import org.hibernate.type.Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A session action that may be cascaded from parent entity to its children
|
* A session action that may be cascaded from parent entity to its children
|
||||||
*
|
*
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public abstract class CascadingAction {
|
public interface CascadingAction {
|
||||||
|
|
||||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, CascadingAction.class.getName());
|
|
||||||
|
|
||||||
|
|
||||||
// the CascadingAction contract ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
public CascadingAction() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cascade the action to the child object.
|
* Cascade the action to the child object.
|
||||||
|
@ -70,7 +49,7 @@ public abstract class CascadingAction {
|
||||||
* @param isCascadeDeleteEnabled Are cascading deletes enabled.
|
* @param isCascadeDeleteEnabled Are cascading deletes enabled.
|
||||||
* @throws HibernateException
|
* @throws HibernateException
|
||||||
*/
|
*/
|
||||||
public abstract void cascade(
|
public void cascade(
|
||||||
EventSource session,
|
EventSource session,
|
||||||
Object child,
|
Object child,
|
||||||
String entityName,
|
String entityName,
|
||||||
|
@ -86,7 +65,7 @@ public abstract class CascadingAction {
|
||||||
* @param collection The collection instance.
|
* @param collection The collection instance.
|
||||||
* @return The children iterator.
|
* @return The children iterator.
|
||||||
*/
|
*/
|
||||||
public abstract Iterator getCascadableChildrenIterator(
|
public Iterator getCascadableChildrenIterator(
|
||||||
EventSource session,
|
EventSource session,
|
||||||
CollectionType collectionType,
|
CollectionType collectionType,
|
||||||
Object collection);
|
Object collection);
|
||||||
|
@ -96,7 +75,7 @@ public abstract class CascadingAction {
|
||||||
*
|
*
|
||||||
* @return True if this action can lead to deletions of orphans.
|
* @return True if this action can lead to deletions of orphans.
|
||||||
*/
|
*/
|
||||||
public abstract boolean deleteOrphans();
|
public boolean deleteOrphans();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,9 +83,7 @@ public abstract class CascadingAction {
|
||||||
*
|
*
|
||||||
* @return True if this action requires no-cascade verification; false otherwise.
|
* @return True if this action requires no-cascade verification; false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean requiresNoCascadeChecking() {
|
public boolean requiresNoCascadeChecking();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called (in the case of {@link #requiresNoCascadeChecking} returning true) to validate
|
* Called (in the case of {@link #requiresNoCascadeChecking} returning true) to validate
|
||||||
|
@ -118,357 +95,10 @@ public abstract class CascadingAction {
|
||||||
* @param persister The entity persister for the owner
|
* @param persister The entity persister for the owner
|
||||||
* @param propertyIndex The index of the property within the owner.
|
* @param propertyIndex The index of the property within the owner.
|
||||||
*/
|
*/
|
||||||
public void noCascade(EventSource session, Object child, Object parent, EntityPersister persister, int propertyIndex) {
|
public void noCascade(EventSource session, Object child, Object parent, EntityPersister persister, int propertyIndex);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should this action be performed (or noCascade consulted) in the case of lazy properties.
|
* Should this action be performed (or noCascade consulted) in the case of lazy properties.
|
||||||
*/
|
*/
|
||||||
public boolean performOnLazyProperty() {
|
public boolean performOnLazyProperty();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// the CascadingAction implementations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#delete(Object)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction DELETE = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to delete: {0}", entityName );
|
|
||||||
session.delete( entityName, child, isCascadeDeleteEnabled, ( Set ) anything );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// delete does cascade to uninitialized collections
|
|
||||||
return CascadingAction.getAllElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
// orphans should be deleted during delete
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_DELETE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#lock(Object, LockMode)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction LOCK = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to lock: {0}", entityName );
|
|
||||||
LockMode lockMode = LockMode.NONE;
|
|
||||||
LockOptions lr = new LockOptions();
|
|
||||||
if ( anything instanceof LockOptions) {
|
|
||||||
LockOptions lockOptions = (LockOptions)anything;
|
|
||||||
lr.setTimeOut(lockOptions.getTimeOut());
|
|
||||||
lr.setScope( lockOptions.getScope());
|
|
||||||
if ( lockOptions.getScope() == true ) // cascade specified lockMode
|
|
||||||
lockMode = lockOptions.getLockMode();
|
|
||||||
}
|
|
||||||
lr.setLockMode(lockMode);
|
|
||||||
session.buildLockRequest(lr).lock(entityName, child);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// lock doesn't cascade to uninitialized collections
|
|
||||||
return getLoadedElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
//TODO: should orphans really be deleted during lock???
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_LOCK";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#refresh(Object)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction REFRESH = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to refresh: {0}", entityName );
|
|
||||||
session.refresh( child, (Map) anything );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// refresh doesn't cascade to uninitialized collections
|
|
||||||
return getLoadedElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_REFRESH";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#evict(Object)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction EVICT = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to evict: {0}", entityName );
|
|
||||||
session.evict(child);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// evicts don't cascade to uninitialized collections
|
|
||||||
return getLoadedElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean performOnLazyProperty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_EVICT";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#saveOrUpdate(Object)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction SAVE_UPDATE = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to save or update: {0}", entityName );
|
|
||||||
session.saveOrUpdate(entityName, child);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// saves / updates don't cascade to uninitialized collections
|
|
||||||
return getLoadedElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
// orphans should be deleted during save/update
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean performOnLazyProperty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_SAVE_UPDATE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#merge(Object)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction MERGE = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to merge: {0}", entityName );
|
|
||||||
session.merge( entityName, child, (Map) anything );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// merges don't cascade to uninitialized collections
|
|
||||||
// //TODO: perhaps this does need to cascade after all....
|
|
||||||
return getLoadedElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
// orphans should not be deleted during merge??
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_MERGE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#persist(Object)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction PERSIST = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to persist: {0}" + entityName );
|
|
||||||
session.persist( entityName, child, (Map) anything );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// persists don't cascade to uninitialized collections
|
|
||||||
return CascadingAction.getAllElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean performOnLazyProperty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_PERSIST";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute persist during flush time
|
|
||||||
*
|
|
||||||
* @see org.hibernate.Session#persist(Object)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction PERSIST_ON_FLUSH = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to persist on flush: {0}", entityName );
|
|
||||||
session.persistOnFlush( entityName, child, (Map) anything );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// persists don't cascade to uninitialized collections
|
|
||||||
return CascadingAction.getLoadedElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean requiresNoCascadeChecking() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void noCascade(
|
|
||||||
EventSource session,
|
|
||||||
Object child,
|
|
||||||
Object parent,
|
|
||||||
EntityPersister persister,
|
|
||||||
int propertyIndex) {
|
|
||||||
if ( child == null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Type type = persister.getPropertyTypes()[propertyIndex];
|
|
||||||
if ( type.isEntityType() ) {
|
|
||||||
String childEntityName = ( ( EntityType ) type ).getAssociatedEntityName( session.getFactory() );
|
|
||||||
|
|
||||||
if ( ! isInManagedState( child, session )
|
|
||||||
&& ! ( child instanceof HibernateProxy ) //a proxy cannot be transient and it breaks ForeignKeys.isTransient
|
|
||||||
&& ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
|
|
||||||
String parentEntiytName = persister.getEntityName();
|
|
||||||
String propertyName = persister.getPropertyNames()[propertyIndex];
|
|
||||||
throw new TransientPropertyValueException(
|
|
||||||
"object references an unsaved transient instance - save the transient instance before flushing",
|
|
||||||
childEntityName,
|
|
||||||
parentEntiytName,
|
|
||||||
propertyName
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean performOnLazyProperty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInManagedState(Object child, EventSource session) {
|
|
||||||
EntityEntry entry = session.getPersistenceContext().getEntry( child );
|
|
||||||
return entry != null &&
|
|
||||||
(
|
|
||||||
entry.getStatus() == Status.MANAGED ||
|
|
||||||
entry.getStatus() == Status.READ_ONLY ||
|
|
||||||
entry.getStatus() == Status.SAVING
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_PERSIST_ON_FLUSH";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#replicate(Object, org.hibernate.ReplicationMode)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction REPLICATE = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.tracev( "Cascading to replicate: {0}", entityName );
|
|
||||||
session.replicate( entityName, child, (ReplicationMode) anything );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// replicate does cascade to uninitialized collections
|
|
||||||
return getLoadedElementsIterator(session, collectionType, collection);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
return false; //I suppose?
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_REPLICATE";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// static helper methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Given a collection, get an iterator of all its children, loading them
|
|
||||||
* from the database if necessary.
|
|
||||||
*
|
|
||||||
* @param session The session within which the cascade is occuring.
|
|
||||||
* @param collectionType The mapping type of the collection.
|
|
||||||
* @param collection The collection instance.
|
|
||||||
* @return The children iterator.
|
|
||||||
*/
|
|
||||||
private static Iterator getAllElementsIterator(
|
|
||||||
EventSource session,
|
|
||||||
CollectionType collectionType,
|
|
||||||
Object collection) {
|
|
||||||
return collectionType.getElementsIterator( collection, session );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterate just the elements of the collection that are already there. Don't load
|
|
||||||
* any new elements from the database.
|
|
||||||
*/
|
|
||||||
public static Iterator getLoadedElementsIterator(SessionImplementor session, CollectionType collectionType, Object collection) {
|
|
||||||
if ( collectionIsInitialized(collection) ) {
|
|
||||||
// handles arrays and newly instantiated collections
|
|
||||||
return collectionType.getElementsIterator(collection, session);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// does not handle arrays (thats ok, cos they can't be lazy)
|
|
||||||
// or newly instantiated collections, so we can do the cast
|
|
||||||
return ( (PersistentCollection) collection ).queuedAdditionIterator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean collectionIsInitialized(Object collection) {
|
|
||||||
return !(collection instanceof PersistentCollection) || ( (PersistentCollection) collection ).wasInitialized();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,521 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, 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.engine.spi;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.LockMode;
|
||||||
|
import org.hibernate.LockOptions;
|
||||||
|
import org.hibernate.ReplicationMode;
|
||||||
|
import org.hibernate.TransientPropertyValueException;
|
||||||
|
import org.hibernate.collection.spi.PersistentCollection;
|
||||||
|
import org.hibernate.engine.internal.ForeignKeys;
|
||||||
|
import org.hibernate.event.spi.EventSource;
|
||||||
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
import org.hibernate.type.CollectionType;
|
||||||
|
import org.hibernate.type.EntityType;
|
||||||
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class CascadingActions {
|
||||||
|
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||||
|
CoreMessageLogger.class,
|
||||||
|
CascadingAction.class.getName()
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disallow instantiation
|
||||||
|
*/
|
||||||
|
private CascadingActions() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.Session#delete(Object)
|
||||||
|
*/
|
||||||
|
public static final CascadingAction DELETE = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled) {
|
||||||
|
LOG.tracev( "Cascading to delete: {0}", entityName );
|
||||||
|
session.delete( entityName, child, isCascadeDeleteEnabled, (Set) anything );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// delete does cascade to uninitialized collections
|
||||||
|
return getAllElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
// orphans should be deleted during delete
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_DELETE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.Session#lock(Object, org.hibernate.LockMode)
|
||||||
|
*/
|
||||||
|
public static final CascadingAction LOCK = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled) {
|
||||||
|
LOG.tracev( "Cascading to lock: {0}", entityName );
|
||||||
|
LockMode lockMode = LockMode.NONE;
|
||||||
|
LockOptions lr = new LockOptions();
|
||||||
|
if ( anything instanceof LockOptions ) {
|
||||||
|
LockOptions lockOptions = (LockOptions) anything;
|
||||||
|
lr.setTimeOut( lockOptions.getTimeOut() );
|
||||||
|
lr.setScope( lockOptions.getScope() );
|
||||||
|
if ( lockOptions.getScope() ) {
|
||||||
|
lockMode = lockOptions.getLockMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lr.setLockMode( lockMode );
|
||||||
|
session.buildLockRequest( lr ).lock( entityName, child );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// lock doesn't cascade to uninitialized collections
|
||||||
|
return getLoadedElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
//TODO: should orphans really be deleted during lock???
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_LOCK";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.Session#refresh(Object)
|
||||||
|
*/
|
||||||
|
public static final CascadingAction REFRESH = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled)
|
||||||
|
throws HibernateException {
|
||||||
|
LOG.tracev( "Cascading to refresh: {0}", entityName );
|
||||||
|
session.refresh( child, (Map) anything );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// refresh doesn't cascade to uninitialized collections
|
||||||
|
return getLoadedElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_REFRESH";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.Session#evict(Object)
|
||||||
|
*/
|
||||||
|
public static final CascadingAction EVICT = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled)
|
||||||
|
throws HibernateException {
|
||||||
|
LOG.tracev( "Cascading to evict: {0}", entityName );
|
||||||
|
session.evict( child );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// evicts don't cascade to uninitialized collections
|
||||||
|
return getLoadedElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean performOnLazyProperty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_EVICT";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.Session#saveOrUpdate(Object)
|
||||||
|
*/
|
||||||
|
public static final CascadingAction SAVE_UPDATE = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled)
|
||||||
|
throws HibernateException {
|
||||||
|
LOG.tracev( "Cascading to save or update: {0}", entityName );
|
||||||
|
session.saveOrUpdate( entityName, child );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// saves / updates don't cascade to uninitialized collections
|
||||||
|
return getLoadedElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
// orphans should be deleted during save/update
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean performOnLazyProperty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_SAVE_UPDATE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.Session#merge(Object)
|
||||||
|
*/
|
||||||
|
public static final CascadingAction MERGE = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled)
|
||||||
|
throws HibernateException {
|
||||||
|
LOG.tracev( "Cascading to merge: {0}", entityName );
|
||||||
|
session.merge( entityName, child, (Map) anything );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// merges don't cascade to uninitialized collections
|
||||||
|
return getLoadedElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
// orphans should not be deleted during merge??
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_MERGE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.Session#persist(Object)
|
||||||
|
*/
|
||||||
|
public static final CascadingAction PERSIST = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled)
|
||||||
|
throws HibernateException {
|
||||||
|
LOG.tracev( "Cascading to persist: {0}" + entityName );
|
||||||
|
session.persist( entityName, child, (Map) anything );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// persists don't cascade to uninitialized collections
|
||||||
|
return getAllElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean performOnLazyProperty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_PERSIST";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute persist during flush time
|
||||||
|
*
|
||||||
|
* @see org.hibernate.Session#persist(Object)
|
||||||
|
*/
|
||||||
|
public static final CascadingAction PERSIST_ON_FLUSH = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled)
|
||||||
|
throws HibernateException {
|
||||||
|
LOG.tracev( "Cascading to persist on flush: {0}", entityName );
|
||||||
|
session.persistOnFlush( entityName, child, (Map) anything );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// persists don't cascade to uninitialized collections
|
||||||
|
return getLoadedElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresNoCascadeChecking() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void noCascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
Object parent,
|
||||||
|
EntityPersister persister,
|
||||||
|
int propertyIndex) {
|
||||||
|
if ( child == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Type type = persister.getPropertyTypes()[propertyIndex];
|
||||||
|
if ( type.isEntityType() ) {
|
||||||
|
String childEntityName = ((EntityType) type).getAssociatedEntityName( session.getFactory() );
|
||||||
|
|
||||||
|
if ( !isInManagedState( child, session )
|
||||||
|
&& !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient
|
||||||
|
&& ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
|
||||||
|
String parentEntiytName = persister.getEntityName();
|
||||||
|
String propertyName = persister.getPropertyNames()[propertyIndex];
|
||||||
|
throw new TransientPropertyValueException(
|
||||||
|
"object references an unsaved transient instance - save the transient instance before flushing",
|
||||||
|
childEntityName,
|
||||||
|
parentEntiytName,
|
||||||
|
propertyName
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean performOnLazyProperty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInManagedState(Object child, EventSource session) {
|
||||||
|
EntityEntry entry = session.getPersistenceContext().getEntry( child );
|
||||||
|
return entry != null &&
|
||||||
|
(
|
||||||
|
entry.getStatus() == Status.MANAGED ||
|
||||||
|
entry.getStatus() == Status.READ_ONLY ||
|
||||||
|
entry.getStatus() == Status.SAVING
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_PERSIST_ON_FLUSH";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.hibernate.Session#replicate
|
||||||
|
*/
|
||||||
|
public static final CascadingAction REPLICATE = new BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(
|
||||||
|
EventSource session,
|
||||||
|
Object child,
|
||||||
|
String entityName,
|
||||||
|
Object anything,
|
||||||
|
boolean isCascadeDeleteEnabled)
|
||||||
|
throws HibernateException {
|
||||||
|
LOG.tracev( "Cascading to replicate: {0}", entityName );
|
||||||
|
session.replicate( entityName, child, (ReplicationMode) anything );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
// replicate does cascade to uninitialized collections
|
||||||
|
return getLoadedElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
return false; //I suppose?
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_REPLICATE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public abstract static class BaseCascadingAction implements CascadingAction {
|
||||||
|
@Override
|
||||||
|
public boolean requiresNoCascadeChecking() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void noCascade(EventSource session, Object child, Object parent, EntityPersister persister, int propertyIndex) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean performOnLazyProperty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a collection, get an iterator of all its children, loading them
|
||||||
|
* from the database if necessary.
|
||||||
|
*
|
||||||
|
* @param session The session within which the cascade is occuring.
|
||||||
|
* @param collectionType The mapping type of the collection.
|
||||||
|
* @param collection The collection instance.
|
||||||
|
*
|
||||||
|
* @return The children iterator.
|
||||||
|
*/
|
||||||
|
private static Iterator getAllElementsIterator(
|
||||||
|
EventSource session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
return collectionType.getElementsIterator( collection, session );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate just the elements of the collection that are already there. Don't load
|
||||||
|
* any new elements from the database.
|
||||||
|
*/
|
||||||
|
public static Iterator getLoadedElementsIterator(
|
||||||
|
SessionImplementor session,
|
||||||
|
CollectionType collectionType,
|
||||||
|
Object collection) {
|
||||||
|
if ( collectionIsInitialized( collection ) ) {
|
||||||
|
// handles arrays and newly instantiated collections
|
||||||
|
return collectionType.getElementsIterator( collection, session );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// does not handle arrays (thats ok, cos they can't be lazy)
|
||||||
|
// or newly instantiated collections, so we can do the cast
|
||||||
|
return ((PersistentCollection) collection).queuedAdditionIterator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean collectionIsInitialized(Object collection) {
|
||||||
|
return !(collection instanceof PersistentCollection) || ((PersistentCollection) collection).wasInitialized();
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,7 @@ import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.internal.Collections;
|
import org.hibernate.engine.internal.Collections;
|
||||||
import org.hibernate.engine.spi.ActionQueue;
|
import org.hibernate.engine.spi.ActionQueue;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.CollectionEntry;
|
import org.hibernate.engine.spi.CollectionEntry;
|
||||||
import org.hibernate.engine.spi.CollectionKey;
|
import org.hibernate.engine.spi.CollectionKey;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
|
@ -168,7 +169,7 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
||||||
protected Object getAnything() { return null; }
|
protected Object getAnything() { return null; }
|
||||||
|
|
||||||
protected CascadingAction getCascadingAction() {
|
protected CascadingAction getCascadingAction() {
|
||||||
return CascadingAction.SAVE_UPDATE;
|
return CascadingActions.SAVE_UPDATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.hibernate.classic.Lifecycle;
|
||||||
import org.hibernate.engine.internal.Cascade;
|
import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.internal.ForeignKeys;
|
import org.hibernate.engine.internal.ForeignKeys;
|
||||||
import org.hibernate.engine.internal.Nullability;
|
import org.hibernate.engine.internal.Nullability;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
import org.hibernate.engine.spi.PersistenceContext;
|
import org.hibernate.engine.spi.PersistenceContext;
|
||||||
|
@ -321,7 +321,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
||||||
session.getPersistenceContext().incrementCascadeLevel();
|
session.getPersistenceContext().incrementCascadeLevel();
|
||||||
try {
|
try {
|
||||||
// cascade-delete to collections BEFORE the collection owner is deleted
|
// cascade-delete to collections BEFORE the collection owner is deleted
|
||||||
new Cascade( CascadingAction.DELETE, Cascade.AFTER_INSERT_BEFORE_DELETE, session )
|
new Cascade( CascadingActions.DELETE, Cascade.AFTER_INSERT_BEFORE_DELETE, session )
|
||||||
.cascade( persister, entity, transientEntities );
|
.cascade( persister, entity, transientEntities );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -341,7 +341,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
||||||
session.getPersistenceContext().incrementCascadeLevel();
|
session.getPersistenceContext().incrementCascadeLevel();
|
||||||
try {
|
try {
|
||||||
// cascade-delete to many-to-one AFTER the parent was deleted
|
// cascade-delete to many-to-one AFTER the parent was deleted
|
||||||
new Cascade( CascadingAction.DELETE, Cascade.BEFORE_INSERT_AFTER_DELETE, session )
|
new Cascade( CascadingActions.DELETE, Cascade.BEFORE_INSERT_AFTER_DELETE, session )
|
||||||
.cascade( persister, entity, transientEntities );
|
.cascade( persister, entity, transientEntities );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.internal.Cascade;
|
import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
import org.hibernate.engine.spi.PersistenceContext;
|
import org.hibernate.engine.spi.PersistenceContext;
|
||||||
|
@ -117,7 +117,7 @@ public class DefaultEvictEventListener implements EvictEventListener {
|
||||||
// This is now handled by removeEntity()
|
// This is now handled by removeEntity()
|
||||||
//session.getPersistenceContext().removeDatabaseSnapshot(key);
|
//session.getPersistenceContext().removeDatabaseSnapshot(key);
|
||||||
|
|
||||||
new Cascade( CascadingAction.EVICT, Cascade.AFTER_EVICT, session )
|
new Cascade( CascadingActions.EVICT, Cascade.AFTER_EVICT, session )
|
||||||
.cascade( persister, object );
|
.cascade( persister, object );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.hibernate.LockMode;
|
||||||
import org.hibernate.TransientObjectException;
|
import org.hibernate.TransientObjectException;
|
||||||
import org.hibernate.engine.internal.Cascade;
|
import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.internal.ForeignKeys;
|
import org.hibernate.engine.internal.ForeignKeys;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
|
@ -89,7 +89,7 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
|
||||||
EventSource source = event.getSession();
|
EventSource source = event.getSession();
|
||||||
source.getPersistenceContext().incrementCascadeLevel();
|
source.getPersistenceContext().incrementCascadeLevel();
|
||||||
try {
|
try {
|
||||||
new Cascade(CascadingAction.LOCK, Cascade.AFTER_LOCK, source)
|
new Cascade( CascadingActions.LOCK, Cascade.AFTER_LOCK, source)
|
||||||
.cascade( persister, entity, event.getLockOptions() );
|
.cascade( persister, entity, event.getLockOptions() );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.WrongClassException;
|
||||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||||
import org.hibernate.engine.internal.Cascade;
|
import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
|
@ -447,7 +448,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadeAction() {
|
protected CascadingAction getCascadeAction() {
|
||||||
return CascadingAction.MERGE;
|
return CascadingActions.MERGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.ObjectDeletedException;
|
import org.hibernate.ObjectDeletedException;
|
||||||
import org.hibernate.PersistentObjectException;
|
import org.hibernate.PersistentObjectException;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.engine.spi.Status;
|
import org.hibernate.engine.spi.Status;
|
||||||
|
@ -60,7 +61,7 @@ public class DefaultPersistEventListener extends AbstractSaveEventListener imple
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadeAction() {
|
protected CascadingAction getCascadeAction() {
|
||||||
return CascadingAction.PERSIST;
|
return CascadingActions.PERSIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
package org.hibernate.event.internal;
|
package org.hibernate.event.internal;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When persist is used as the cascade action, persistOnFlush should be used
|
* When persist is used as the cascade action, persistOnFlush should be used
|
||||||
|
@ -31,6 +32,6 @@ import org.hibernate.engine.spi.CascadingAction;
|
||||||
*/
|
*/
|
||||||
public class DefaultPersistOnFlushEventListener extends DefaultPersistEventListener {
|
public class DefaultPersistOnFlushEventListener extends DefaultPersistEventListener {
|
||||||
protected CascadingAction getCascadeAction() {
|
protected CascadingAction getCascadeAction() {
|
||||||
return CascadingAction.PERSIST_ON_FLUSH;
|
return CascadingActions.PERSIST_ON_FLUSH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.hibernate.PersistentObjectException;
|
||||||
import org.hibernate.UnresolvableObjectException;
|
import org.hibernate.UnresolvableObjectException;
|
||||||
import org.hibernate.cache.spi.CacheKey;
|
import org.hibernate.cache.spi.CacheKey;
|
||||||
import org.hibernate.engine.internal.Cascade;
|
import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
@ -119,7 +119,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
||||||
|
|
||||||
// cascade the refresh prior to refreshing this entity
|
// cascade the refresh prior to refreshing this entity
|
||||||
refreshedAlready.put(object, object);
|
refreshedAlready.put(object, object);
|
||||||
new Cascade( CascadingAction.REFRESH, Cascade.BEFORE_REFRESH, source)
|
new Cascade( CascadingActions.REFRESH, Cascade.BEFORE_REFRESH, source)
|
||||||
.cascade( persister, object, refreshedAlready );
|
.cascade( persister, object, refreshedAlready );
|
||||||
|
|
||||||
if ( e != null ) {
|
if ( e != null ) {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.hibernate.ReplicationMode;
|
||||||
import org.hibernate.TransientObjectException;
|
import org.hibernate.TransientObjectException;
|
||||||
import org.hibernate.engine.internal.Cascade;
|
import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.engine.spi.Status;
|
import org.hibernate.engine.spi.Status;
|
||||||
|
@ -207,7 +208,7 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
||||||
EventSource source) {
|
EventSource source) {
|
||||||
source.getPersistenceContext().incrementCascadeLevel();
|
source.getPersistenceContext().incrementCascadeLevel();
|
||||||
try {
|
try {
|
||||||
new Cascade( CascadingAction.REPLICATE, Cascade.AFTER_UPDATE, source )
|
new Cascade( CascadingActions.REPLICATE, Cascade.AFTER_UPDATE, source )
|
||||||
.cascade( persister, entity, replicationMode );
|
.cascade( persister, entity, replicationMode );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -217,6 +218,6 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadeAction() {
|
protected CascadingAction getCascadeAction() {
|
||||||
return CascadingAction.REPLICATE;
|
return CascadingActions.REPLICATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.TransientObjectException;
|
||||||
import org.hibernate.classic.Lifecycle;
|
import org.hibernate.classic.Lifecycle;
|
||||||
import org.hibernate.engine.internal.Cascade;
|
import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
@ -358,7 +359,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
||||||
EventSource source = event.getSession();
|
EventSource source = event.getSession();
|
||||||
source.getPersistenceContext().incrementCascadeLevel();
|
source.getPersistenceContext().incrementCascadeLevel();
|
||||||
try {
|
try {
|
||||||
new Cascade( CascadingAction.SAVE_UPDATE, Cascade.AFTER_UPDATE, source )
|
new Cascade( CascadingActions.SAVE_UPDATE, Cascade.AFTER_UPDATE, source )
|
||||||
.cascade( persister, entity );
|
.cascade( persister, entity );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -368,6 +369,6 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadeAction() {
|
protected CascadingAction getCascadeAction() {
|
||||||
return CascadingAction.SAVE_UPDATE;
|
return CascadingActions.SAVE_UPDATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.EntityMode;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.PropertyNotFoundException;
|
import org.hibernate.PropertyNotFoundException;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
import org.hibernate.property.Getter;
|
import org.hibernate.property.Getter;
|
||||||
|
@ -124,8 +125,8 @@ public class Property implements Serializable, MetaAttributable {
|
||||||
}
|
}
|
||||||
int length = compositeType.getSubtypes().length;
|
int length = compositeType.getSubtypes().length;
|
||||||
for ( int i=0; i<length; i++ ) {
|
for ( int i=0; i<length; i++ ) {
|
||||||
if ( compositeType.getCascadeStyle(i) != CascadeStyle.NONE ) {
|
if ( compositeType.getCascadeStyle(i) != CascadeStyles.NONE ) {
|
||||||
return CascadeStyle.ALL;
|
return CascadeStyles.ALL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getCascadeStyle( cascade );
|
return getCascadeStyle( cascade );
|
||||||
|
@ -142,16 +143,16 @@ public class Property implements Serializable, MetaAttributable {
|
||||||
|
|
||||||
private static CascadeStyle getCascadeStyle(String cascade) {
|
private static CascadeStyle getCascadeStyle(String cascade) {
|
||||||
if ( cascade==null || cascade.equals("none") ) {
|
if ( cascade==null || cascade.equals("none") ) {
|
||||||
return CascadeStyle.NONE;
|
return CascadeStyles.NONE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StringTokenizer tokens = new StringTokenizer(cascade, ", ");
|
StringTokenizer tokens = new StringTokenizer(cascade, ", ");
|
||||||
CascadeStyle[] styles = new CascadeStyle[ tokens.countTokens() ] ;
|
CascadeStyle[] styles = new CascadeStyle[ tokens.countTokens() ] ;
|
||||||
int i=0;
|
int i=0;
|
||||||
while ( tokens.hasMoreTokens() ) {
|
while ( tokens.hasMoreTokens() ) {
|
||||||
styles[i++] = CascadeStyle.getCascadeStyle( tokens.nextToken() );
|
styles[i++] = CascadeStyles.getCascadeStyle( tokens.nextToken() );
|
||||||
}
|
}
|
||||||
return new CascadeStyle.MultipleCascadeStyle(styles);
|
return new CascadeStyles.MultipleCascadeStyle(styles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.FetchMode;
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||||
import org.hibernate.metamodel.relational.Table;
|
import org.hibernate.metamodel.relational.Table;
|
||||||
import org.hibernate.metamodel.relational.TableSpecification;
|
import org.hibernate.metamodel.relational.TableSpecification;
|
||||||
|
@ -187,23 +188,23 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
|
||||||
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles) {
|
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles) {
|
||||||
List<CascadeStyle> cascadeStyleList = new ArrayList<CascadeStyle>();
|
List<CascadeStyle> cascadeStyleList = new ArrayList<CascadeStyle>();
|
||||||
for ( CascadeStyle style : cascadeStyles ) {
|
for ( CascadeStyle style : cascadeStyles ) {
|
||||||
if ( style != CascadeStyle.NONE ) {
|
if ( style != CascadeStyles.NONE ) {
|
||||||
cascadeStyleList.add( style );
|
cascadeStyleList.add( style );
|
||||||
}
|
}
|
||||||
if ( style == CascadeStyle.DELETE_ORPHAN ||
|
if ( style == CascadeStyles.DELETE_ORPHAN ||
|
||||||
style == CascadeStyle.ALL_DELETE_ORPHAN ) {
|
style == CascadeStyles.ALL_DELETE_ORPHAN ) {
|
||||||
orphanDelete = true;
|
orphanDelete = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( cascadeStyleList.isEmpty() ) {
|
if ( cascadeStyleList.isEmpty() ) {
|
||||||
cascadeStyle = CascadeStyle.NONE;
|
cascadeStyle = CascadeStyles.NONE;
|
||||||
}
|
}
|
||||||
else if ( cascadeStyleList.size() == 1 ) {
|
else if ( cascadeStyleList.size() == 1 ) {
|
||||||
cascadeStyle = cascadeStyleList.get( 0 );
|
cascadeStyle = cascadeStyleList.get( 0 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cascadeStyle = new CascadeStyle.MultipleCascadeStyle(
|
cascadeStyle = new CascadeStyles.MultipleCascadeStyle(
|
||||||
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
|
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,18 +126,18 @@ public enum CascadeType {
|
||||||
|
|
||||||
private static final Map<CascadeType, CascadeStyle> cascadeTypeToCascadeStyle = new HashMap<CascadeType, CascadeStyle>();
|
private static final Map<CascadeType, CascadeStyle> cascadeTypeToCascadeStyle = new HashMap<CascadeType, CascadeStyle>();
|
||||||
static {
|
static {
|
||||||
cascadeTypeToCascadeStyle.put( ALL, CascadeStyle.ALL );
|
cascadeTypeToCascadeStyle.put( ALL, CascadeStyles.ALL );
|
||||||
cascadeTypeToCascadeStyle.put( ALL_DELETE_ORPHAN, CascadeStyle.ALL_DELETE_ORPHAN );
|
cascadeTypeToCascadeStyle.put( ALL_DELETE_ORPHAN, CascadeStyles.ALL_DELETE_ORPHAN );
|
||||||
cascadeTypeToCascadeStyle.put( UPDATE, CascadeStyle.UPDATE );
|
cascadeTypeToCascadeStyle.put( UPDATE, CascadeStyles.UPDATE );
|
||||||
cascadeTypeToCascadeStyle.put( PERSIST, CascadeStyle.PERSIST );
|
cascadeTypeToCascadeStyle.put( PERSIST, CascadeStyles.PERSIST );
|
||||||
cascadeTypeToCascadeStyle.put( MERGE, CascadeStyle.MERGE );
|
cascadeTypeToCascadeStyle.put( MERGE, CascadeStyles.MERGE );
|
||||||
cascadeTypeToCascadeStyle.put( LOCK, CascadeStyle.LOCK );
|
cascadeTypeToCascadeStyle.put( LOCK, CascadeStyles.LOCK );
|
||||||
cascadeTypeToCascadeStyle.put( REFRESH, CascadeStyle.REFRESH );
|
cascadeTypeToCascadeStyle.put( REFRESH, CascadeStyles.REFRESH );
|
||||||
cascadeTypeToCascadeStyle.put( REPLICATE, CascadeStyle.REPLICATE );
|
cascadeTypeToCascadeStyle.put( REPLICATE, CascadeStyles.REPLICATE );
|
||||||
cascadeTypeToCascadeStyle.put( EVICT, CascadeStyle.EVICT );
|
cascadeTypeToCascadeStyle.put( EVICT, CascadeStyles.EVICT );
|
||||||
cascadeTypeToCascadeStyle.put( DELETE, CascadeStyle.DELETE );
|
cascadeTypeToCascadeStyle.put( DELETE, CascadeStyles.DELETE );
|
||||||
cascadeTypeToCascadeStyle.put( DELETE_ORPHAN, CascadeStyle.DELETE_ORPHAN );
|
cascadeTypeToCascadeStyle.put( DELETE_ORPHAN, CascadeStyles.DELETE_ORPHAN );
|
||||||
cascadeTypeToCascadeStyle.put( NONE, CascadeStyle.NONE );
|
cascadeTypeToCascadeStyle.put( NONE, CascadeStyles.NONE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.FetchMode;
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,18 +95,18 @@ public class ManyToOneAttributeBinding extends BasicAttributeBinding implements
|
||||||
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles) {
|
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles) {
|
||||||
List<CascadeStyle> cascadeStyleList = new ArrayList<CascadeStyle>();
|
List<CascadeStyle> cascadeStyleList = new ArrayList<CascadeStyle>();
|
||||||
for ( CascadeStyle style : cascadeStyles ) {
|
for ( CascadeStyle style : cascadeStyles ) {
|
||||||
if ( style != CascadeStyle.NONE ) {
|
if ( style != CascadeStyles.NONE ) {
|
||||||
cascadeStyleList.add( style );
|
cascadeStyleList.add( style );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( cascadeStyleList.isEmpty() ) {
|
if ( cascadeStyleList.isEmpty() ) {
|
||||||
cascadeStyle = CascadeStyle.NONE;
|
cascadeStyle = CascadeStyles.NONE;
|
||||||
}
|
}
|
||||||
else if ( cascadeStyleList.size() == 1 ) {
|
else if ( cascadeStyleList.size() == 1 ) {
|
||||||
cascadeStyle = cascadeStyleList.get( 0 );
|
cascadeStyle = cascadeStyleList.get( 0 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cascadeStyle = new CascadeStyle.MultipleCascadeStyle(
|
cascadeStyle = new CascadeStyles.MultipleCascadeStyle(
|
||||||
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
|
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import javax.persistence.GenerationType;
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.id.MultipleHiLoPerTableGenerator;
|
import org.hibernate.id.MultipleHiLoPerTableGenerator;
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
|
|
||||||
|
@ -67,22 +68,22 @@ public class EnumConversionHelper {
|
||||||
public static CascadeStyle cascadeTypeToCascadeStyle(CascadeType cascadeType) {
|
public static CascadeStyle cascadeTypeToCascadeStyle(CascadeType cascadeType) {
|
||||||
switch ( cascadeType ) {
|
switch ( cascadeType ) {
|
||||||
case ALL: {
|
case ALL: {
|
||||||
return CascadeStyle.ALL;
|
return CascadeStyles.ALL;
|
||||||
}
|
}
|
||||||
case PERSIST: {
|
case PERSIST: {
|
||||||
return CascadeStyle.PERSIST;
|
return CascadeStyles.PERSIST;
|
||||||
}
|
}
|
||||||
case MERGE: {
|
case MERGE: {
|
||||||
return CascadeStyle.MERGE;
|
return CascadeStyles.MERGE;
|
||||||
}
|
}
|
||||||
case REMOVE: {
|
case REMOVE: {
|
||||||
return CascadeStyle.DELETE;
|
return CascadeStyles.DELETE;
|
||||||
}
|
}
|
||||||
case REFRESH: {
|
case REFRESH: {
|
||||||
return CascadeStyle.REFRESH;
|
return CascadeStyles.REFRESH;
|
||||||
}
|
}
|
||||||
case DETACH: {
|
case DETACH: {
|
||||||
return CascadeStyle.EVICT;
|
return CascadeStyles.EVICT;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new AssertionFailure( "Unknown cascade type" );
|
throw new AssertionFailure( "Unknown cascade type" );
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||||
import org.hibernate.internal.jaxb.mapping.hbm.CustomSqlElement;
|
import org.hibernate.internal.jaxb.mapping.hbm.CustomSqlElement;
|
||||||
import org.hibernate.internal.jaxb.mapping.hbm.EntityElement;
|
import org.hibernate.internal.jaxb.mapping.hbm.EntityElement;
|
||||||
|
@ -189,7 +190,7 @@ public class Helper {
|
||||||
cascades = bindingContext.getMappingDefaults().getCascadeStyle();
|
cascades = bindingContext.getMappingDefaults().getCascadeStyle();
|
||||||
}
|
}
|
||||||
for ( String cascade : StringHelper.split( ",", cascades ) ) {
|
for ( String cascade : StringHelper.split( ",", cascades ) ) {
|
||||||
cascadeStyles.add( CascadeStyle.getCascadeStyle( cascade ) );
|
cascadeStyles.add( CascadeStyles.getCascadeStyle( cascade ) );
|
||||||
}
|
}
|
||||||
return cascadeStyles;
|
return cascadeStyles;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.PropertyAccessException;
|
|
||||||
import org.hibernate.QueryException;
|
import org.hibernate.QueryException;
|
||||||
import org.hibernate.StaleObjectStateException;
|
import org.hibernate.StaleObjectStateException;
|
||||||
import org.hibernate.StaleStateException;
|
import org.hibernate.StaleStateException;
|
||||||
|
@ -65,7 +64,8 @@ import org.hibernate.engine.internal.Versioning;
|
||||||
import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey;
|
import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey;
|
||||||
import org.hibernate.engine.spi.CachedNaturalIdValueSource;
|
import org.hibernate.engine.spi.CachedNaturalIdValueSource;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||||
|
@ -1054,7 +1054,7 @@ public abstract class AbstractEntityPersister
|
||||||
joinedFetchesList.add( associationAttributeBinding.getFetchMode() );
|
joinedFetchesList.add( associationAttributeBinding.getFetchMode() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cascades.add( CascadeStyle.NONE );
|
cascades.add( CascadeStyles.NONE );
|
||||||
joinedFetchesList.add( FetchMode.SELECT );
|
joinedFetchesList.add( FetchMode.SELECT );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3784,11 +3784,11 @@ public abstract class AbstractEntityPersister
|
||||||
|
|
||||||
loaders.put(
|
loaders.put(
|
||||||
"merge",
|
"merge",
|
||||||
new CascadeEntityLoader( this, CascadingAction.MERGE, getFactory() )
|
new CascadeEntityLoader( this, CascadingActions.MERGE, getFactory() )
|
||||||
);
|
);
|
||||||
loaders.put(
|
loaders.put(
|
||||||
"refresh",
|
"refresh",
|
||||||
new CascadeEntityLoader( this, CascadingAction.REFRESH, getFactory() )
|
new CascadeEntityLoader( this, CascadingActions.REFRESH, getFactory() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.hibernate.EntityMode;
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
import org.hibernate.engine.internal.UnsavedValueFactory;
|
import org.hibernate.engine.internal.UnsavedValueFactory;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.engine.spi.IdentifierValue;
|
import org.hibernate.engine.spi.IdentifierValue;
|
||||||
import org.hibernate.engine.spi.VersionValue;
|
import org.hibernate.engine.spi.VersionValue;
|
||||||
import org.hibernate.id.IdentifierGenerator;
|
import org.hibernate.id.IdentifierGenerator;
|
||||||
|
@ -207,7 +208,7 @@ public class PropertyFactory {
|
||||||
|
|
||||||
final CascadeStyle cascadeStyle = property.isAssociation()
|
final CascadeStyle cascadeStyle = property.isAssociation()
|
||||||
? ( (AssociationAttributeBinding) property ).getCascadeStyle()
|
? ( (AssociationAttributeBinding) property ).getCascadeStyle()
|
||||||
: CascadeStyle.NONE;
|
: CascadeStyles.NONE;
|
||||||
|
|
||||||
return new VersionProperty(
|
return new VersionProperty(
|
||||||
property.getAttribute().getName(),
|
property.getAttribute().getName(),
|
||||||
|
@ -291,7 +292,7 @@ public class PropertyFactory {
|
||||||
final SingularAttributeBinding singularAttributeBinding = ( SingularAttributeBinding ) property;
|
final SingularAttributeBinding singularAttributeBinding = ( SingularAttributeBinding ) property;
|
||||||
final CascadeStyle cascadeStyle = singularAttributeBinding.isAssociation()
|
final CascadeStyle cascadeStyle = singularAttributeBinding.isAssociation()
|
||||||
? ( (AssociationAttributeBinding) singularAttributeBinding ).getCascadeStyle()
|
? ( (AssociationAttributeBinding) singularAttributeBinding ).getCascadeStyle()
|
||||||
: CascadeStyle.NONE;
|
: CascadeStyles.NONE;
|
||||||
final FetchMode fetchMode = singularAttributeBinding.isAssociation()
|
final FetchMode fetchMode = singularAttributeBinding.isAssociation()
|
||||||
? ( (AssociationAttributeBinding) singularAttributeBinding ).getFetchMode()
|
? ( (AssociationAttributeBinding) singularAttributeBinding ).getFetchMode()
|
||||||
: FetchMode.DEFAULT;
|
: FetchMode.DEFAULT;
|
||||||
|
@ -317,7 +318,7 @@ public class PropertyFactory {
|
||||||
final AbstractPluralAttributeBinding pluralAttributeBinding = (AbstractPluralAttributeBinding) property;
|
final AbstractPluralAttributeBinding pluralAttributeBinding = (AbstractPluralAttributeBinding) property;
|
||||||
final CascadeStyle cascadeStyle = pluralAttributeBinding.isAssociation()
|
final CascadeStyle cascadeStyle = pluralAttributeBinding.isAssociation()
|
||||||
? pluralAttributeBinding.getCascadeStyle()
|
? pluralAttributeBinding.getCascadeStyle()
|
||||||
: CascadeStyle.NONE;
|
: CascadeStyles.NONE;
|
||||||
final FetchMode fetchMode = pluralAttributeBinding.isAssociation()
|
final FetchMode fetchMode = pluralAttributeBinding.isAssociation()
|
||||||
? pluralAttributeBinding.getFetchMode()
|
? pluralAttributeBinding.getFetchMode()
|
||||||
: FetchMode.DEFAULT;
|
: FetchMode.DEFAULT;
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.engine.OptimisticLockStyle;
|
import org.hibernate.engine.OptimisticLockStyle;
|
||||||
import org.hibernate.engine.internal.Versioning;
|
import org.hibernate.engine.internal.Versioning;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.ValueInclusion;
|
import org.hibernate.engine.spi.ValueInclusion;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
@ -231,7 +232,7 @@ public class EntityMetamodel implements Serializable {
|
||||||
hasLazy = true;
|
hasLazy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( properties[i].getCascadeStyle() != CascadeStyle.NONE ) {
|
if ( properties[i].getCascadeStyle() != CascadeStyles.NONE ) {
|
||||||
foundCascade = true;
|
foundCascade = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,7 +479,7 @@ public class EntityMetamodel implements Serializable {
|
||||||
hasLazy = true;
|
hasLazy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( properties[i].getCascadeStyle() != CascadeStyle.NONE ) {
|
if ( properties[i].getCascadeStyle() != CascadeStyles.NONE ) {
|
||||||
foundCascade = true;
|
foundCascade = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.TransientObjectException;
|
import org.hibernate.TransientObjectException;
|
||||||
import org.hibernate.engine.internal.ForeignKeys;
|
import org.hibernate.engine.internal.ForeignKeys;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
|
@ -270,7 +271,7 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public CascadeStyle getCascadeStyle(int i) {
|
public CascadeStyle getCascadeStyle(int i) {
|
||||||
return CascadeStyle.NONE;
|
return CascadeStyles.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FetchMode getFetchMode(int i) {
|
public FetchMode getFetchMode(int i) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.hibernate.FetchMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
|
@ -121,7 +122,7 @@ public class CompositeCustomType extends AbstractType implements CompositeType,
|
||||||
}
|
}
|
||||||
|
|
||||||
public CascadeStyle getCascadeStyle(int i) {
|
public CascadeStyle getCascadeStyle(int i) {
|
||||||
return CascadeStyle.NONE;
|
return CascadeStyles.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FetchMode getFetchMode(int i) {
|
public FetchMode getFetchMode(int i) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import javax.persistence.EntityNotFoundException;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.event.internal.DefaultAutoFlushEventListener;
|
import org.hibernate.event.internal.DefaultAutoFlushEventListener;
|
||||||
import org.hibernate.event.internal.DefaultFlushEntityEventListener;
|
import org.hibernate.event.internal.DefaultFlushEntityEventListener;
|
||||||
|
@ -151,7 +152,7 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
|
||||||
public static class JPAPersistOnFlushEventListener extends JPAPersistEventListener {
|
public static class JPAPersistOnFlushEventListener extends JPAPersistEventListener {
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadeAction() {
|
protected CascadingAction getCascadeAction() {
|
||||||
return CascadingAction.PERSIST_ON_FLUSH;
|
return CascadingActions.PERSIST_ON_FLUSH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +162,7 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadingAction() {
|
protected CascadingAction getCascadingAction() {
|
||||||
return CascadingAction.PERSIST_ON_FLUSH;
|
return CascadingActions.PERSIST_ON_FLUSH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -176,7 +177,7 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadingAction() {
|
protected CascadingAction getCascadingAction() {
|
||||||
return CascadingAction.PERSIST_ON_FLUSH;
|
return CascadingActions.PERSIST_ON_FLUSH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2009-2012, 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.engine.spi;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Because CascadeStyle is not opened and package protected,
|
|
||||||
* I need to subclass and override the persist alias
|
|
||||||
*
|
|
||||||
* Note that This class has to be triggered by JpaPersistEventListener at class loading time
|
|
||||||
*
|
|
||||||
* TODO get rid of it for 3.3
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
*/
|
|
||||||
public abstract class JpaCascadeStyle extends CascadeStyle {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cascade using JpaCascadingAction
|
|
||||||
*/
|
|
||||||
public static final CascadeStyle PERSIST_JPA = new CascadeStyle() {
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action== JpaCascadingAction.PERSIST_SKIPLAZY
|
|
||||||
|| action==CascadingAction.PERSIST_ON_FLUSH;
|
|
||||||
}
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_PERSIST_SKIPLAZY";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static {
|
|
||||||
STYLES.put( "persist", PERSIST_JPA );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
|
|
||||||
*
|
|
||||||
* 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.engine.spi;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.event.spi.EventSource;
|
|
||||||
import org.hibernate.type.CollectionType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Because of CascadingAction constructor visibility
|
|
||||||
* I need a packaged friendly subclass
|
|
||||||
* TODO Get rid of it for 3.3
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
*/
|
|
||||||
public abstract class JpaCascadingAction extends CascadingAction {
|
|
||||||
private static final Logger LOG = Logger.getLogger( JpaCascadingAction.class.getName() );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.hibernate.Session#persist(Object)
|
|
||||||
*/
|
|
||||||
public static final CascadingAction PERSIST_SKIPLAZY = new CascadingAction() {
|
|
||||||
@Override
|
|
||||||
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
|
||||||
throws HibernateException {
|
|
||||||
LOG.trace("Cascading to persist: " + entityName);
|
|
||||||
session.persist( entityName, child, (Map) anything );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
|
||||||
// persists don't cascade to uninitialized collections
|
|
||||||
return CascadingAction.getLoadedElementsIterator( session, collectionType, collection );
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteOrphans() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean performOnLazyProperty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ACTION_PERSIST_SKIPLAZY";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.jpa.internal.event;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.event.internal.DefaultAutoFlushEventListener;
|
import org.hibernate.event.internal.DefaultAutoFlushEventListener;
|
||||||
import org.hibernate.event.spi.AutoFlushEventListener;
|
import org.hibernate.event.spi.AutoFlushEventListener;
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ public class JpaAutoFlushEventListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadingAction() {
|
protected CascadingAction getCascadingAction() {
|
||||||
return CascadingAction.PERSIST_ON_FLUSH;
|
return CascadingActions.PERSIST_ON_FLUSH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.jpa.internal.event;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.event.internal.DefaultFlushEventListener;
|
import org.hibernate.event.internal.DefaultFlushEventListener;
|
||||||
import org.hibernate.event.spi.FlushEventListener;
|
import org.hibernate.event.spi.FlushEventListener;
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ public class JpaFlushEventListener extends DefaultFlushEventListener implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadingAction() {
|
protected CascadingAction getCascadingAction() {
|
||||||
return CascadingAction.PERSIST_ON_FLUSH;
|
return CascadingActions.PERSIST_ON_FLUSH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,13 +31,16 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.engine.spi.CascadeStyles;
|
||||||
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.event.service.spi.DuplicationStrategy;
|
import org.hibernate.event.service.spi.DuplicationStrategy;
|
||||||
import org.hibernate.event.service.spi.EventListenerGroup;
|
import org.hibernate.event.service.spi.EventListenerGroup;
|
||||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||||
import org.hibernate.event.spi.EventType;
|
import org.hibernate.event.spi.EventType;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
|
import org.hibernate.jpa.AvailableSettings;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||||
|
@ -89,6 +92,24 @@ public class JpaIntegrator implements Integrator {
|
||||||
Configuration configuration,
|
Configuration configuration,
|
||||||
SessionFactoryImplementor sessionFactory,
|
SessionFactoryImplementor sessionFactory,
|
||||||
SessionFactoryServiceRegistry serviceRegistry) {
|
SessionFactoryServiceRegistry serviceRegistry) {
|
||||||
|
// first, register the JPA-specific persist cascade style
|
||||||
|
CascadeStyles.registerCascadeStyle(
|
||||||
|
"persist",
|
||||||
|
new CascadeStyles.BaseCascadeStyle() {
|
||||||
|
@Override
|
||||||
|
public boolean doCascade(CascadingAction action) {
|
||||||
|
return action == JpaPersistEventListener.PERSIST_SKIPLAZY
|
||||||
|
|| action == CascadingActions.PERSIST_ON_FLUSH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "STYLE_PERSIST_SKIPLAZY";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// then prepare listeners
|
||||||
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
||||||
|
|
||||||
boolean isSecurityEnabled = configuration.getProperties().containsKey( AvailableSettings.JACC_ENABLED );
|
boolean isSecurityEnabled = configuration.getProperties().containsKey( AvailableSettings.JACC_ENABLED );
|
||||||
|
@ -233,7 +254,8 @@ public class JpaIntegrator implements Integrator {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
callbackHandler.add(classLoaderSvc.classForName(name), classLoaderSvc, binding);
|
callbackHandler.add(classLoaderSvc.classForName(name), classLoaderSvc, binding);
|
||||||
} catch (ClassLoadingException error) {
|
}
|
||||||
|
catch (ClassLoadingException error) {
|
||||||
throw new MappingException( "entity class not found: " + name, error );
|
throw new MappingException( "entity class not found: " + name, error );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,17 @@
|
||||||
package org.hibernate.jpa.internal.event;
|
package org.hibernate.jpa.internal.event;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
import org.hibernate.engine.spi.JpaCascadeStyle;
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
import org.hibernate.engine.spi.JpaCascadingAction;
|
|
||||||
import org.hibernate.event.internal.DefaultPersistEventListener;
|
import org.hibernate.event.internal.DefaultPersistEventListener;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
|
import org.hibernate.type.CollectionType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides the LifeCycle OnSave call to call the PrePersist operation
|
* Overrides the LifeCycle OnSave call to call the PrePersist operation
|
||||||
|
@ -37,9 +42,7 @@ import org.hibernate.event.spi.EventSource;
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class JpaPersistEventListener extends DefaultPersistEventListener implements CallbackHandlerConsumer {
|
public class JpaPersistEventListener extends DefaultPersistEventListener implements CallbackHandlerConsumer {
|
||||||
static {
|
private static final Logger log = Logger.getLogger( JpaPersistEventListener.class );
|
||||||
JpaCascadeStyle.PERSIST_JPA.hasOrphanDelete(); //triggers class loading to override persist with PERSIST_JPA
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityCallbackHandler callbackHandler;
|
private EntityCallbackHandler callbackHandler;
|
||||||
|
|
||||||
|
@ -81,6 +84,32 @@ public class JpaPersistEventListener extends DefaultPersistEventListener impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadeAction() {
|
protected CascadingAction getCascadeAction() {
|
||||||
return JpaCascadingAction.PERSIST_SKIPLAZY;
|
return PERSIST_SKIPLAZY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final CascadingAction PERSIST_SKIPLAZY = new CascadingActions.BaseCascadingAction() {
|
||||||
|
@Override
|
||||||
|
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
|
||||||
|
throws HibernateException {
|
||||||
|
log.trace( "Cascading persist to : " + entityName );
|
||||||
|
session.persist( entityName, child, (Map) anything );
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
|
||||||
|
// persists don't cascade to uninitialized collections
|
||||||
|
return CascadingActions.getLoadedElementsIterator( session, collectionType, collection );
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean deleteOrphans() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean performOnLazyProperty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ACTION_PERSIST_SKIPLAZY";
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
package org.hibernate.jpa.internal.event;
|
package org.hibernate.jpa.internal.event;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
|
import org.hibernate.engine.spi.CascadingActions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -31,6 +32,6 @@ import org.hibernate.engine.spi.CascadingAction;
|
||||||
public class JpaPersistOnFlushEventListener extends JpaPersistEventListener {
|
public class JpaPersistOnFlushEventListener extends JpaPersistEventListener {
|
||||||
@Override
|
@Override
|
||||||
protected CascadingAction getCascadeAction() {
|
protected CascadingAction getCascadeAction() {
|
||||||
return CascadingAction.PERSIST_ON_FLUSH;
|
return CascadingActions.PERSIST_ON_FLUSH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue