1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002, 2014 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 import com.sleepycat.persist.EntityStore;
15 
16 /**
17  * Configuration properties for eager conversion of unevolved objects.  This
18  * configuration is used with {@link EntityStore#evolve EntityStore.evolve}.
19  *
20  * @see com.sleepycat.persist.evolve Class Evolution
21  * @author Mark Hayes
22  */
23 public class EvolveConfig implements Cloneable {
24 
25     private Set<String> classesToEvolve;
26     private EvolveListener evolveListener;
27 
28     /**
29      * Creates an evolve configuration with default properties.
30      */
EvolveConfig()31     public EvolveConfig() {
32         classesToEvolve = new HashSet<String>();
33     }
34 
35     /**
36      * Returns a shallow copy of the configuration.
37      *
38      * @deprecated As of JE 4.0.13, replaced by {@link
39      * EvolveConfig#clone()}.</p>
40      */
cloneConfig()41     public EvolveConfig cloneConfig() {
42         try {
43             return (EvolveConfig) super.clone();
44         } catch (CloneNotSupportedException cannotHappen) {
45             return null;
46         }
47     }
48 
49     /**
50      * Returns a shallow copy of the configuration.
51      */
52     @Override
clone()53     public EvolveConfig clone() {
54         try {
55             return (EvolveConfig) super.clone();
56         } catch (CloneNotSupportedException cannotHappen) {
57             return null;
58         }
59     }
60 
61     /**
62      * Adds an entity class for a primary index to be converted.  If no classes
63      * are added, all indexes that require evolution will be converted.
64      */
addClassToEvolve(String entityClass)65     public EvolveConfig addClassToEvolve(String entityClass) {
66         classesToEvolve.add(entityClass);
67         return this;
68     }
69 
70     /**
71      * Returns an unmodifiable set of the entity classes to be evolved.
72      */
getClassesToEvolve()73     public Set<String> getClassesToEvolve() {
74         return Collections.unmodifiableSet(classesToEvolve);
75     }
76 
77     /**
78      * Sets a progress listener that is notified each time an entity is read.
79      */
setEvolveListener(EvolveListener listener)80     public EvolveConfig setEvolveListener(EvolveListener listener) {
81         setEvolveListenerVoid(listener);
82         return this;
83     }
84 
85     /**
86      * <!-- begin JE only -->
87      * @hidden
88      * <!-- end JE only -->
89      * The void return setter for use by Bean editors.
90      */
setEvolveListenerVoid(EvolveListener listener)91     public void setEvolveListenerVoid(EvolveListener listener) {
92         this.evolveListener = listener;
93     }
94 
95     /**
96      * Returns the progress listener that is notified each time an entity is
97      * read.
98      */
getEvolveListener()99     public EvolveListener getEvolveListener() {
100         return evolveListener;
101     }
102 }
103