3333 * the {@link SqlTable} the column is a part of.
3434 *
3535 * <p>The class can be extended if you wish to associate additional attributes with a column for your
36- * own purposes. Extending the class is a bit more challenging than you might expect because you will need to
36+ * own purposes. Extending the class is a bit more challenging than you might expect because you may need to
3737 * handle the covariant types for many methods in {@code SqlColumn}. Additionally, many methods in {@code SqlColumn}
3838 * create new instances of the class in keeping with the library's primary strategy of immutability. You will also
3939 * need to ensure that these methods create instances of your extended class, rather than the base {@code SqlColumn}
4444 * <li>Create a class that extends {@link SqlColumn}</li>
4545 * <li>In your extended class, create a static builder class that extends {@link SqlColumn.AbstractBuilder}</li>
4646 * <li>Add your desired attributes to the class and the builder</li>
47- * <li>In your extended class, override the {@link SqlColumn#copyBuilder()} method and return a new instance of
48- * your builder with all attributes set. You should call the
47+ * <li>You MUST override the {@link SqlColumn#copyBuilder()} method and return a new instance of
48+ * your builder with all attributes set. In the overridden method you should call the superclass
4949 * {@link SqlColumn#populateBaseBuilder(AbstractBuilder)} method
50- * to set the attributes from {@code SqlColumn}, then populate your extended attributes.
50+ * to set the attributes from the base {@code SqlColumn}, then populate your extended attributes. During normal
51+ * usage, the library may create additional instances of your class. If you do not override the
52+ * {@link SqlColumn#copyBuilder()} method properly, then your extended attributes will be lost.
5153 * </li>
52- * <li>You MUST override the following methods. These methods are used with regular operations in the library.
53- * If you do not override these methods, it is likely that your extended attributes will be lost during
54- * regular usage. For example, if you do not override the {@code as} method and a user calls the method to
55- * apply an alias, then the base {@code SqlColumn} class would create a new instance of {@code SqlColumn}, NOT
56- * your extended class .
54+ * <li>You MAY override the following methods. These methods are used with regular operations in the library and
55+ * create new instances of the class. However, these methods are not typically chained, so losing the specific
56+ * type may not be a problem. If you want to preserve the type, then you can override these methods
57+ * to specify the covariant return type. See below for usage of the {@link SqlColumn#cast(SqlColumn)} method
58+ * to make it easier to override these methods .
5759 * <ul>
5860 * <li>{@link SqlColumn#as(String)}</li>
5961 * <li>{@link SqlColumn#asCamelCase()}</li>
6365 * </li>
6466 * <li>You SHOULD override the following methods. These methods can be used to add additional attributes to a
6567 * column by creating a new instance with a specified attribute set. These methods are used during the
66- * construction of columns. If you do not override these methods, and a user calls them, then a new
67- * {@code SqlColumn} will be created that does not contain your extended attributes.
68+ * construction of columns. If you do not override these methods, and a user calls them, then the specific type
69+ * will be lost. If you want to preserve the type, then you can override these methods
70+ * to specify the covariant return type. See below for usage of the {@link SqlColumn#cast(SqlColumn)} method
71+ * to make it easier to override these methods.
6872 * <ul>
6973 * <li>{@link SqlColumn#withJavaProperty(String)}</li>
7074 * <li>{@link SqlColumn#withRenderingStrategy(RenderingStrategy)}</li>
8892 * }
8993 * </pre>
9094 *
91- * <p>The test code for this library contains an example of a proper extension of this class.
95+ * <p>The test code for this library contains an example of a fully executed extension of this class.
9296 *
9397 * @param <T> the Java type associated with the column
9498 */
@@ -164,7 +168,7 @@ public Optional<String> javaProperty() {
164168 */
165169 @ Override
166170 public SqlColumn <T > descending () {
167- return cast ( copyBuilder ().withDescendingPhrase (" DESC" ).build () ); //$NON-NLS-1$
171+ return copyBuilder ().withDescendingPhrase (" DESC" ).build (); //$NON-NLS-1$
168172 }
169173
170174 /**
@@ -177,7 +181,7 @@ public SqlColumn<T> descending() {
177181 */
178182 @ Override
179183 public SqlColumn <T > as (String alias ) {
180- return cast ( copyBuilder ().withAlias (alias ).build () );
184+ return copyBuilder ().withAlias (alias ).build ();
181185 }
182186
183187 /**
@@ -188,7 +192,7 @@ public SqlColumn<T> as(String alias) {
188192 * @return a new column that will be rendered with the specified table qualifier
189193 */
190194 public SqlColumn <T > qualifiedWith (String tableQualifier ) {
191- return cast ( copyBuilder ().withTableQualifier (tableQualifier ).build () );
195+ return copyBuilder ().withTableQualifier (tableQualifier ).build ();
192196 }
193197
194198 /**
@@ -203,9 +207,9 @@ public SqlColumn<T> qualifiedWith(String tableQualifier) {
203207 * @return a new column aliased with a camel case version of the column name
204208 */
205209 public SqlColumn <T > asCamelCase () {
206- return cast ( copyBuilder ()
210+ return copyBuilder ()
207211 .withAlias ("\" " + StringUtilities .toCamelCase (name ) + "\" " ) //$NON-NLS-1$ //$NON-NLS-2$
208- .build ()) ;
212+ .build ();
209213 }
210214
211215 @ Override
@@ -318,6 +322,14 @@ public <S> SqlColumn<S> withJavaProperty(String javaProperty) {
318322 return cast (copyBuilder ().withJavaProperty (javaProperty ).build ());
319323 }
320324
325+ /**
326+ * Create a new Builder, then populate all attributes in the builder with current values.
327+ *
328+ * <p>This method is used to create copies of the class during normal operations (e.g. when calling the
329+ * {@link SqlColumn#as(String)} method). Any subclass of {@code SqlColumn} MUST override this method.
330+ *
331+ * @return a new Builder instance with all current values populated
332+ */
321333 protected AbstractBuilder <T , ?, ?> copyBuilder () {
322334 return populateBaseBuilder (new Builder <>());
323335 }
0 commit comments