1
//$Id: ReplicationMode.java 5060 2004-12-24 03:11:05Z oneovthafew $
4
import java.io.Serializable;
5
import java.util.HashMap;
8
import org.hibernate.type.VersionType;
11
* Represents a replication strategy.
13
* @see Session#replicate(Object, ReplicationMode)
16
public abstract class ReplicationMode implements Serializable {
17
private final String name;
18
private static final Map INSTANCES = new HashMap();
20
public ReplicationMode(String name) {
23
public String toString() {
26
public abstract boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType);
28
* Throw an exception when a row already exists.
30
public static final ReplicationMode EXCEPTION = new ReplicationMode("EXCEPTION") {
31
public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) {
32
throw new AssertionFailure("should not be called");
36
* Ignore replicated entities when a row already exists.
38
public static final ReplicationMode IGNORE = new ReplicationMode("IGNORE") {
39
public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) {
44
* Overwrite existing rows when a row already exists.
46
public static final ReplicationMode OVERWRITE = new ReplicationMode("OVERWRITE") {
47
public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) {
52
* When a row already exists, choose the latest version.
54
public static final ReplicationMode LATEST_VERSION = new ReplicationMode("LATEST_VERSION") {
55
public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) {
56
if (versionType==null) return true; //always overwrite nonversioned data
57
return versionType.getComparator().compare(currentVersion, newVersion) <= 0;
62
INSTANCES.put( LATEST_VERSION.name, LATEST_VERSION );
63
INSTANCES.put( IGNORE.name, IGNORE );
64
INSTANCES.put( OVERWRITE.name, OVERWRITE );
65
INSTANCES.put( EXCEPTION.name, EXCEPTION );
68
private Object readResolve() {
69
return INSTANCES.get(name);