@@ -167,48 +167,84 @@ public void setRowMovement(RowMovement rowMovement) {
167167 @ Override
168168 @ SuppressWarnings ({"PMD.CyclomaticComplexity" , "PMD.NPathComplexity" })
169169 public String toString () {
170- String sql ;
170+ StringBuilder b = new StringBuilder ();
171+ appendCreateClause (b );
172+ appendColumnDefinitions (b );
173+ appendTableOptions (b );
174+ appendTableProperties (b );
175+ return b .toString ();
176+ }
177+
178+ private void appendCreateClause (StringBuilder b ) {
171179 String createOps = PlainSelect .getStringList (createOptionsStrings , false , false );
172180
173- sql = "CREATE " + (unlogged ? "UNLOGGED " : "" )
174- + (!"" .equals (createOps ) ? createOps + " " : "" )
175- + (orReplace ? "OR REPLACE " : "" )
176- + "TABLE " + (ifNotExists ? "IF NOT EXISTS " : "" ) + table ;
181+ b .append ("CREATE " );
182+ if (unlogged ) {
183+ b .append ("UNLOGGED " );
184+ }
185+ if (!"" .equals (createOps )) {
186+ b .append (createOps ).append (" " );
187+ }
188+ if (orReplace ) {
189+ b .append ("OR REPLACE " );
190+ }
191+ b .append ("TABLE " );
192+ if (ifNotExists ) {
193+ b .append ("IF NOT EXISTS " );
194+ }
195+ b .append (table );
196+ }
177197
198+ private void appendColumnDefinitions (StringBuilder b ) {
178199 if (columns != null && !columns .isEmpty ()) {
179- sql += " " ;
180- sql += PlainSelect .getStringList (columns , true , true );
200+ b . append ( " " ) ;
201+ b . append ( PlainSelect .getStringList (columns , true , true ) );
181202 }
182203 if (columnDefinitions != null && !columnDefinitions .isEmpty ()) {
183- sql += " (" ;
184-
185- sql += PlainSelect .getStringList (columnDefinitions , true , false );
204+ b .append (" (" );
205+ b .append (PlainSelect .getStringList (columnDefinitions , true , false ));
186206 if (indexes != null && !indexes .isEmpty ()) {
187- sql += ", " ;
188- sql += PlainSelect .getStringList (indexes );
207+ b . append ( ", " ) ;
208+ b . append ( PlainSelect .getStringList (indexes ) );
189209 }
190- sql += ")" ;
210+ b . append ( ")" ) ;
191211 }
212+ }
213+
214+ private void appendTableOptions (StringBuilder b ) {
192215 String options = PlainSelect .getStringList (tableOptionsStrings , false , false );
193216 if (options != null && options .length () > 0 ) {
194- sql += " " + options ;
217+ b . append ( " " ). append ( options ) ;
195218 }
219+ }
196220
221+ private void appendTableProperties (StringBuilder b ) {
197222 if (rowMovement != null ) {
198- sql += " " + rowMovement .getMode (). toString () + " ROW MOVEMENT" ;
223+ b . append ( " " ). append ( rowMovement .getMode ()). append ( " ROW MOVEMENT" ) ;
199224 }
200225 if (select != null ) {
201- sql += " AS " + (selectParenthesis ? "(" : "" ) + select .toString ()
202- + (selectParenthesis ? ")" : "" );
226+ b .append (" AS " );
227+ if (selectParenthesis ) {
228+ b .append ("(" );
229+ }
230+ b .append (select );
231+ if (selectParenthesis ) {
232+ b .append (")" );
233+ }
203234 }
204235 if (likeTable != null ) {
205- sql += " LIKE " + (selectParenthesis ? "(" : "" ) + likeTable .toString ()
206- + (selectParenthesis ? ")" : "" );
236+ b .append (" LIKE " );
237+ if (selectParenthesis ) {
238+ b .append ("(" );
239+ }
240+ b .append (likeTable );
241+ if (selectParenthesis ) {
242+ b .append (")" );
243+ }
207244 }
208245 if (interleaveIn != null ) {
209- sql += ", " + interleaveIn ;
246+ b . append ( ", " ). append ( interleaveIn ) ;
210247 }
211- return sql ;
212248 }
213249
214250 public CreateTable withTable (Table table ) {
0 commit comments