Skip to content

Commit 3dc5011

Browse files
committed
Documentation for custom rendering strategies
1 parent 3ab4104 commit 3dc5011

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles
99
### Added
1010

1111
- Added a general insert statement that does not require a separate record class to hold values for the insert. ([#201](https://github.com/mybatis/mybatis-dynamic-sql/issues/201))
12+
- Added the capability to specify a rendering strategy on a column to override the defaut rendering strategy for a statement. This will allow certain edge cases where a parameter marker needs to be formatted in a unique way (for example, "::jsonb" needs to be added to parameter markers for JSON fields in PostgreSQL) ([#200](https://github.com/mybatis/mybatis-dynamic-sql/issues/200))
1213

1314
## Release 1.1.4 - November 23, 2019
1415

src/site/markdown/docs/databaseObjects.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,18 @@ Whenever the table is referenced for rendering SQL, the name will be calculated
130130

131131
## Column Representation
132132

133-
The class `org.mybatis.dynamic.sql.SqlColumn` is used to represent a column in a table or view. An `SqlColumn` is always associated with a `SqlTable`. In it's most basic form, the `SqlColumn` class holds a name and a reference to the `SqlTable` it is associated with.
133+
The class `org.mybatis.dynamic.sql.SqlColumn` is used to represent a column in a table or view. An `SqlColumn` is always associated with a `SqlTable`. In it's most basic form, the `SqlColumn` class holds a name and a reference to the `SqlTable` it is associated with. The table reference is required so that table aliases can be applied to columns in the rendering phase.
134+
135+
The `SqlColumn` will be rendered in SQL based on the `RenderingStrategy` applied to the SQL statement. Typically the rendering strategy generates a string that represents a parameter marker in whatever SQL engine you are using. For example, MyBatis3 parameter markers are formatted as "#{some_attribute}". By default all columns are rendered with the same strategy. The library supplies rendering strategies that are appropriate for several SQL execution engines including MyBatis3 and Spring JDBC template.
136+
137+
In some cases it is necessary to override the rendering strategy for a particular column - so the `SqlColumn` class supports specifying a rendering strategy for a column that will override the rendering strategy applied to a statement. A good example of this use case is with PostgreSQL. In that database it is required to add the string "::jsonb" to a prepared statement parameter marker when inserting or updating JSON fields, but not for other fields. A column based rendering strategy enables this.
134138

135139
The `SqlColumn` class has additional optional attributes that are useful for SQL rendering - especially in MyBatis3. These include:
136140

137141
* The `java.sql.JDBCType` of the column. This will be rendered into the MyBatis3 compatible parameter marker - which helps with picking type handlers and also inserting or updating null capable fields
138142
* A String containing a type handler - either a type handler alias or the fully qualified type of a type handler. This will be rendered into the MyBatis3 compatible parameter marker
139143

140-
If you are not using MyBatis3, then you will not need to specify the JDBC Type or type handler.
144+
If you are not using MyBatis3, then you will not need to specify the JDBC Type or type handler as those attributes are ignored by other rendering strategies.
141145

142146
Finally, the `SqlColumn` class has methods to designate a column alias or sort order for use in different SQL statements.
143147

0 commit comments

Comments
 (0)