01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: EntityConverter.java,v 1.8.2.3 2008/01/07 15:14:19 cwl Exp $
07: */
08:
09: package com.sleepycat.persist.evolve;
10:
11: import java.util.Collections;
12: import java.util.HashSet;
13: import java.util.Set;
14:
15: /**
16: * A subclass of Converter that allows specifying keys to be deleted.
17: *
18: * <p>When a Converter is used with an entity class, secondary keys cannot be
19: * automatically deleted based on field deletion, because field Deleter objects
20: * are not used in conjunction with a Converter mutation. The EntityConverter
21: * can be used instead of a plain Converter to specify the key names to be
22: * deleted.</p>
23: *
24: * <p>It is not currently possible to rename or insert secondary keys when
25: * using a Converter mutation with an entity class.</p>
26: *
27: * @see Converter
28: * @see com.sleepycat.persist.evolve Class Evolution
29: * @author Mark Hayes
30: */
31: public class EntityConverter extends Converter {
32:
33: private static final long serialVersionUID = -988428985370593743L;
34:
35: private Set<String> deletedKeys;
36:
37: /**
38: * Creates a mutation for converting all instances of the given entity
39: * class version to the current version of the class.
40: */
41: public EntityConverter(String entityClassName, int classVersion,
42: Conversion conversion, Set<String> deletedKeys) {
43: super (entityClassName, classVersion, null, conversion);
44:
45: /* Eclipse objects to assigning with a ternary operator. */
46: if (deletedKeys != null) {
47: this .deletedKeys = new HashSet(deletedKeys);
48: } else {
49: this .deletedKeys = Collections.emptySet();
50: }
51: }
52:
53: /**
54: * Returns the set of key names that are to be deleted.
55: */
56: public Set<String> getDeletedKeys() {
57: return Collections.unmodifiableSet(deletedKeys);
58: }
59:
60: /**
61: * Returns true if the deleted and renamed keys are equal in this object
62: * and given object, and if the {@link Converter#equals} superclass method
63: * returns true.
64: */
65: @Override
66: public boolean equals(Object other) {
67: if (other instanceof EntityConverter) {
68: EntityConverter o = (EntityConverter) other;
69: return deletedKeys.equals(o.deletedKeys)
70: && super .equals(other);
71: } else {
72: return false;
73: }
74: }
75:
76: @Override
77: public int hashCode() {
78: return deletedKeys.hashCode() + super .hashCode();
79: }
80:
81: @Override
82: public String toString() {
83: return "[EntityConverter " + super .toString()
84: + " DeletedKeys: " + deletedKeys + ']';
85: }
86: }
|