1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: EntityConverter.java,v 1.1 2008/02/07 17:12:27 mark Exp $ 7 */ 8 9package com.sleepycat.persist.evolve; 10 11import java.util.Collections; 12import java.util.HashSet; 13import 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 */ 31public 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, 42 int classVersion, 43 Conversion conversion, 44 Set<String> deletedKeys) { 45 super(entityClassName, classVersion, null, conversion); 46 47 /* Eclipse objects to assigning with a ternary operator. */ 48 if (deletedKeys != null) { 49 this.deletedKeys = new HashSet(deletedKeys); 50 } else { 51 this.deletedKeys = Collections.emptySet(); 52 } 53 } 54 55 /** 56 * Returns the set of key names that are to be deleted. 57 */ 58 public Set<String> getDeletedKeys() { 59 return Collections.unmodifiableSet(deletedKeys); 60 } 61 62 /** 63 * Returns true if the deleted and renamed keys are equal in this object 64 * and given object, and if the {@link Converter#equals} superclass method 65 * returns true. 66 */ 67 @Override 68 public boolean equals(Object other) { 69 if (other instanceof EntityConverter) { 70 EntityConverter o = (EntityConverter) other; 71 return deletedKeys.equals(o.deletedKeys) && 72 super.equals(other); 73 } else { 74 return false; 75 } 76 } 77 78 @Override 79 public int hashCode() { 80 return deletedKeys.hashCode() + super.hashCode(); 81 } 82 83 @Override 84 public String toString() { 85 return "[EntityConverter " + super.toString() + 86 " DeletedKeys: " + deletedKeys + ']'; 87 } 88} 89