📄 cascades.java
字号:
if ( styles[i].doCascade(action) ) return true; } return false; } boolean reallyDoCascade(CascadingAction action) { for (int i=0; i<styles.length; i++) { if ( styles[i].reallyDoCascade(action) ) return true; } return false; } boolean hasOrphanDelete() { for (int i=0; i<styles.length; i++) { if ( styles[i].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 STYLE_ALL_DELETE_ORPHAN = new CascadeStyle() { boolean doCascade(CascadingAction action) { return true; } boolean hasOrphanDelete() { return true; } public String toString() { return "STYLE_ALL_DELETE_ORPHAN"; } }; /** * save / delete / update / evict / lock / replicate / merge / persist */ public static final CascadeStyle STYLE_ALL = new CascadeStyle() { boolean doCascade(CascadingAction action) { return true; } public String toString() { return "STYLE_ALL"; } }; /** * save / update */ public static final CascadeStyle STYLE_SAVE_UPDATE = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_SAVE_UPDATE || action==ACTION_SAVE_UPDATE_COPY; } public String toString() { return "STYLE_SAVE_UPDATE"; } }; /** * lock */ public static final CascadeStyle STYLE_LOCK = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_LOCK; } public String toString() { return "STYLE_LOCK"; } }; /** * refresh */ public static final CascadeStyle STYLE_REFRESH = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_REFRESH; } public String toString() { return "STYLE_REFRESH"; } }; /** * evict */ public static final CascadeStyle STYLE_EVICT = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_EVICT; } public String toString() { return "STYLE_EVICT"; } }; /** * replicate */ public static final CascadeStyle STYLE_REPLICATE = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_REPLICATE; } public String toString() { return "STYLE_REPLICATE"; } }; /** * merge */ public static final CascadeStyle STYLE_MERGE = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_MERGE; } public String toString() { return "STYLE_MERGE"; } }; /** * create */ public static final CascadeStyle STYLE_PERSIST = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_PERSIST; } public String toString() { return "STYLE_PERSIST"; } }; /** * delete */ public static final CascadeStyle STYLE_DELETE = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_DELETE; } public String toString() { return "STYLE_DELETE"; } }; /** * delete + delete orphans */ public static final CascadeStyle STYLE_DELETE_ORPHAN = new CascadeStyle() { boolean doCascade(CascadingAction action) { return action==ACTION_DELETE || action==ACTION_SAVE_UPDATE; } boolean reallyDoCascade(CascadingAction action) { return action==ACTION_DELETE; } boolean hasOrphanDelete() { return true; } public String toString() { return "STYLE_DELETE_ORPHAN"; } }; /** * no cascades */ public static final CascadeStyle STYLE_NONE = new CascadeStyle() { boolean doCascade(CascadingAction action) { return false; } public String toString() { return "STYLE_NONE"; } }; // The allowable unsaved-value settings: /** * A strategy for determining if an identifier value is an identifier of * a new transient instance or a previously persistent transient instance. * The strategy is determined by the <tt>unsaved-value</tt> attribute in * the mapping file. */ public static class IdentifierValue { private final Serializable value; protected IdentifierValue() { this.value = null; } /** * Assume the transient instance is newly instantiated if * its identifier is null or equal to <tt>value</tt> */ public IdentifierValue(Serializable value) { this.value = value; } /** * Does the given identifier belong to a new instance? */ public Boolean isUnsaved(Serializable id) { if ( log.isTraceEnabled() ) log.trace("id unsaved-value: " + value); return id==null || id.equals(value) ? Boolean.TRUE : Boolean.FALSE; } public Serializable getDefaultValue(Serializable currentValue) { return value; } public String toString() { return "identifier unsaved-value: " + value; } } /** * Always assume the transient instance is newly instantiated */ public static final IdentifierValue SAVE_ANY = new IdentifierValue() { public final Boolean isUnsaved(Serializable id) { log.trace("id unsaved-value strategy ANY"); return Boolean.TRUE; } public Serializable getDefaultValue(Serializable currentValue) { return currentValue; } public String toString() { return "SAVE_ANY"; } }; /** * Never assume the transient instance is newly instantiated */ public static final IdentifierValue SAVE_NONE = new IdentifierValue() { public final Boolean isUnsaved(Serializable id) { log.trace("id unsaved-value strategy NONE"); return Boolean.FALSE; } public Serializable getDefaultValue(Serializable currentValue) { return currentValue; } public String toString() { return "SAVE_NONE"; } }; /** * Assume the transient instance is newly instantiated if the identifier * is null. */ public static final IdentifierValue SAVE_NULL = new IdentifierValue() { public final Boolean isUnsaved(Serializable id) { log.trace("id unsaved-value strategy NULL"); return id==null ? Boolean.TRUE : Boolean.FALSE; } public Serializable getDefaultValue(Serializable currentValue) { return null; } public String toString() { return "SAVE_NULL"; } }; public static final IdentifierValue UNDEFINED = new IdentifierValue() { public final Boolean isUnsaved(Serializable id) { log.trace("id unsaved-value strategy UNDEFINED"); return null; } public Serializable getDefaultValue(Serializable currentValue) { return null; } public String toString() { return "UNDEFINED"; } }; /** * A strategy for determining if a version value is an version of * a new transient instance or a previously persistent transient instance. * The strategy is determined by the <tt>unsaved-value</tt> attribute in * the mapping file. */ public static class VersionValue { private final Object value; protected VersionValue() { this.value = null; } /** * Assume the transient instance is newly instantiated if * its version is null or equal to <tt>value</tt> * @param value value to compare to */ public VersionValue(Object value) { this.value = value; } /** * Does the given version belong to a new instance? * * @param version version to check * @return true is unsaved, false is saved, null is undefined */ public Boolean isUnsaved(Object version) throws MappingException { if ( log.isTraceEnabled() ) log.trace("version unsaved-value: " + value); return version==null || version.equals(value) ? Boolean.TRUE : Boolean.FALSE; } public Object getDefaultValue(Object currentValue) { return value; } public String toString() { return "version unsaved-value: " + value; } } /** * Assume the transient instance is newly instantiated if the version * is null, otherwise assume it is a detached instance. */ public static final VersionValue VERSION_SAVE_NULL = new VersionValue() { public final Boolean isUnsaved(Object version) { log.trace("version unsaved-value strategy NULL"); return version==null ? Boolean.TRUE : Boolean.FALSE; } public Object getDefaultValue(Object currentValue) { return null; } public String toString() { return "VERSION_SAVE_NULL"; } }; /** * Assume the transient instance is newly instantiated if the version * is null, otherwise defer to the identifier unsaved-value. */ public static final VersionValue VERSION_UNDEFINED = new VersionValue() { public final Boolean isUnsaved(Object version) { log.trace("version unsaved-value strategy UNDEFINED"); return version==null ? Boolean.TRUE : null; } public Object getDefaultValue(Object currentValue) { return currentValue; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -