1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*
* Copyright 2006-2012 Amazon Technologies, Inc. or its affiliates.
* Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
* of Amazon Technologies, Inc. or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.amazon.carbonado.synthetic;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.SupportException;
/**
* A synthetic builder provides a mechanism for creating a user storable from scratch.
* The client creates the builder, decorates with properties and indexes on those
* properties, then builds.
*
* If additional, ad hoc decoration is desired, the partially constructed classfile
* can be retrieved and operated on directly via the ClassFileBuilder
* returned by {@link #prepare}.
*
* @author Don Schneider
* @author David Rosenstrauch
*/
public interface SyntheticBuilder {
/**
* @return {@link ClassFileBuilder} ready for further decoration or building
* @throws SupportException
*/
public ClassFileBuilder prepare() throws SupportException;
/**
* @return the generated class file for this builder. Note that
* proper operation requires that {@link #prepare()} already have been called
* prior to calling this method.
* @throws IllegalStateException if build has not yet been called.
*/
public Class<? extends Storable> getStorableClass() throws IllegalStateException;
/**
* Convenience method to generate the class.
* Build will always call {@link #prepare()} and return the result of
* generating the class from that classfile. If the caller does not
* wish to regenerate the class from scratch, use {@link #getStorableClass()} instead.
*/
public Class<? extends Storable> build() throws SupportException;
/**
* Add a property to the set managed by this builder.
* @param name of the property
* @param type of the property
* @return property specification which can be further refined
*/
public SyntheticProperty addProperty(String name, Class type);
/**
* Add an externally defined synthetic property to the list
* @param prop to add
* @return original synthetic property as a convenience
*/
public SyntheticProperty addProperty(SyntheticProperty prop);
/**
* Check to see if a particular property has already been added to the list of
* properties to generate
* @param name
*/
public boolean hasProperty(String name);
/**
* Add a primary key to be built.
* @return key to be decorated with property values defining the primary key
*/
public SyntheticKey addPrimaryKey();
/**
* Add an alternate key to be built.
* @return key to be decorated with property values defining the alternate key
* @since 1.2
*/
public SyntheticKey addAlternateKey();
/**
* Add an index to the set managed by this builder. All indexes added this
* way will be in addition to the primary and alternate key indexes.
* @return index to be decorated with property values defining the index
*/
public SyntheticIndex addIndex();
/**
* Returns true if a property with the version attribute has been addded
*/
public boolean isVersioned();
/**
* Interface used to get the name for the class to generate. This allows the
* client to apply different rules for classname generation.
*/
public interface ClassNameProvider {
public String getName();
/**
* SyntheticBuilder may choose to alter the class name to prevent a
* class name collision. When explicit is true, the class name must not
* be altered.
*/
public boolean isExplicit();
}
}
|