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