From c52c52b3ab088a30f2f3d6996e0bff1b9e4b92bb Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 27 Oct 2025 14:08:34 -0400 Subject: [PATCH] Update docs for extending SqlColumn --- .../org/mybatis/dynamic/sql/SqlColumn.java | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/mybatis/dynamic/sql/SqlColumn.java b/src/main/java/org/mybatis/dynamic/sql/SqlColumn.java index b3dcf9513..d8f9dc56e 100644 --- a/src/main/java/org/mybatis/dynamic/sql/SqlColumn.java +++ b/src/main/java/org/mybatis/dynamic/sql/SqlColumn.java @@ -33,7 +33,7 @@ * the {@link SqlTable} the column is a part of. * *

The class can be extended if you wish to associate additional attributes with a column for your - * own purposes. Extending the class is a bit more challenging than you might expect because you will need to + * own purposes. Extending the class is a bit more challenging than you might expect because you may need to * handle the covariant types for many methods in {@code SqlColumn}. Additionally, many methods in {@code SqlColumn} * create new instances of the class in keeping with the library's primary strategy of immutability. You will also * need to ensure that these methods create instances of your extended class, rather than the base {@code SqlColumn} @@ -44,16 +44,18 @@ *

  • Create a class that extends {@link SqlColumn}
  • *
  • In your extended class, create a static builder class that extends {@link SqlColumn.AbstractBuilder}
  • *
  • Add your desired attributes to the class and the builder
  • - *
  • In your extended class, override the {@link SqlColumn#copyBuilder()} method and return a new instance of - * your builder with all attributes set. You should call the + *
  • You MUST override the {@link SqlColumn#copyBuilder()} method and return a new instance of + * your builder with all attributes set. In the overridden method you should call the superclass * {@link SqlColumn#populateBaseBuilder(AbstractBuilder)} method - * to set the attributes from {@code SqlColumn}, then populate your extended attributes. + * to set the attributes from the base {@code SqlColumn}, then populate your extended attributes. During normal + * usage, the library may create additional instances of your class. If you do not override the + * {@link SqlColumn#copyBuilder()} method properly, then your extended attributes will be lost. *
  • - *
  • You MUST override the following methods. These methods are used with regular operations in the library. - * If you do not override these methods, it is likely that your extended attributes will be lost during - * regular usage. For example, if you do not override the {@code as} method and a user calls the method to - * apply an alias, then the base {@code SqlColumn} class would create a new instance of {@code SqlColumn}, NOT - * your extended class. + *
  • You MAY override the following methods. These methods are used with regular operations in the library and + * create new instances of the class. However, these methods are not typically chained, so losing the specific + * type may not be a problem. If you want to preserve the type, then you can override these methods + * to specify the covariant return type. See below for usage of the {@link SqlColumn#cast(SqlColumn)} method + * to make it easier to override these methods. *