@@ -73,24 +73,23 @@ public class DatabendPreparedStatement extends DatabendStatement implements Prep
73
73
static final DateTimeFormatter TIME_FORMATTER = DateTimeFormat .forPattern ("HH:mm:ss.SSS" );
74
74
static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormat .forPattern ("yyyy-MM-dd HH:mm:ss.SSS" );
75
75
private final DatabendParameterMetaData paramMetaData ;
76
- private static final java .time .format .DateTimeFormatter LOCAL_DATE_TIME_FORMATTER =
77
- new DateTimeFormatterBuilder ()
78
- .append (ISO_LOCAL_DATE )
79
- .appendLiteral (' ' )
80
- .append (ISO_LOCAL_TIME )
81
- .toFormatter ();
82
- private static final java .time .format .DateTimeFormatter OFFSET_TIME_FORMATTER =
83
- new DateTimeFormatterBuilder ()
84
- .append (ISO_LOCAL_TIME )
85
- .appendOffset ("+HH:mm" , "+00:00" )
86
- .toFormatter ();
76
+ private static final java .time .format .DateTimeFormatter LOCAL_DATE_TIME_FORMATTER = new DateTimeFormatterBuilder ()
77
+ .append (ISO_LOCAL_DATE )
78
+ .appendLiteral (' ' )
79
+ .append (ISO_LOCAL_TIME )
80
+ .toFormatter ();
81
+ private static final java .time .format .DateTimeFormatter OFFSET_TIME_FORMATTER = new DateTimeFormatterBuilder ()
82
+ .append (ISO_LOCAL_TIME )
83
+ .appendOffset ("+HH:mm" , "+00:00" )
84
+ .toFormatter ();
87
85
private final String originalSql ;
88
86
private final List <String []> batchValues ;
89
87
private final Optional <BatchInsertUtils > batchInsertUtils ;
90
88
private final String statementName ;
91
89
private int batchSize = 0 ;
92
90
93
- DatabendPreparedStatement (DatabendConnection connection , Consumer <DatabendStatement > onClose , String statementName , String sql ) {
91
+ DatabendPreparedStatement (DatabendConnection connection , Consumer <DatabendStatement > onClose , String statementName ,
92
+ String sql ) {
94
93
super (connection , onClose );
95
94
this .statementName = requireNonNull (statementName , "statementName is null" );
96
95
this .originalSql = requireNonNull (sql , "sql is null" );
@@ -142,13 +141,13 @@ private static String formatBigDecimalLiteral(BigDecimal x) {
142
141
return x .toString ();
143
142
}
144
143
145
-
146
144
private static String formatBytesLiteral (byte [] x ) {
147
145
return new String (x , StandardCharsets .UTF_8 );
148
146
}
149
147
150
148
static IllegalArgumentException invalidConversion (Object x , String toType ) {
151
- return new IllegalArgumentException (format ("Cannot convert instance of %s to %s" , x .getClass ().getName (), toType ));
149
+ return new IllegalArgumentException (
150
+ format ("Cannot convert instance of %s to %s" , x .getClass ().getName (), toType ));
152
151
}
153
152
154
153
@ Override
@@ -183,7 +182,9 @@ private DatabendCopyParams uploadBatchesForCopyInto() throws SQLException {
183
182
DatabendStage databendStage = DatabendStage .builder ().stageName (stageName ).path (stagePrefix ).build ();
184
183
List <String > files = new ArrayList <>();
185
184
files .add (fileName );
186
- DatabendCopyParams databendCopyParams = DatabendCopyParams .builder ().setFiles (files ).setCopyOptions (copyOptions ).setDatabaseTableName (batchInsertUtils .get ().getDatabaseTableName ()).setDatabendStage (databendStage ).build ();
185
+ DatabendCopyParams databendCopyParams = DatabendCopyParams .builder ().setFiles (files )
186
+ .setCopyOptions (copyOptions ).setDatabaseTableName (batchInsertUtils .get ().getDatabaseTableName ())
187
+ .setDatabendStage (databendStage ).build ();
187
188
return databendCopyParams ;
188
189
} catch (Exception e ) {
189
190
throw new SQLException (e );
@@ -235,11 +236,14 @@ private StageAttachment uploadBatches() throws SQLException {
235
236
}
236
237
237
238
/**
238
- * This method is used to build a StageAttachment object which represents a stage in Databend.
239
- * A stage in Databend is a temporary storage area where data files are stored before being loaded into the Databend database.
239
+ * This method is used to build a StageAttachment object which represents a
240
+ * stage in Databend.
241
+ * A stage in Databend is a temporary storage area where data files are stored
242
+ * before being loaded into the Databend database.
240
243
*
241
- * @param connection The DatabendConnection object which contains the connection details to the Databend database.
242
- * @param stagePath The path of the stage in the Databend database.
244
+ * @param connection The DatabendConnection object which contains the connection
245
+ * details to the Databend database.
246
+ * @param stagePath The path of the stage in the Databend database.
243
247
* @return A StageAttachment object which contains the details of the stage.
244
248
*/
245
249
public static StageAttachment buildStateAttachment (DatabendConnection connection , String stagePath ) {
@@ -291,18 +295,19 @@ private boolean dropStageAttachment(StageAttachment attachment) {
291
295
public int [] executeBatchByAttachment () throws SQLException {
292
296
int [] batchUpdateCounts = new int [batchValues .size ()];
293
297
if (!batchInsertUtils .isPresent () || batchValues == null || batchValues .isEmpty ()) {
294
- // super.execute(this.originalSql);
298
+ // super.execute(this.originalSql);
295
299
return batchUpdateCounts ;
296
300
}
297
301
StageAttachment attachment = uploadBatches ();
298
302
ResultSet r = null ;
299
303
if (attachment == null ) {
300
- // logger.fine("use normal execute instead of batch insert");
301
- // super.execute(batchInsertUtils.get().getSql());
304
+ // logger.fine("use normal execute instead of batch insert");
305
+ // super.execute(batchInsertUtils.get().getSql());
302
306
return batchUpdateCounts ;
303
307
}
304
308
try {
305
- logger .fine (String .format ("use batch insert instead of normal insert, attachment: %s, sql: %s" , attachment , batchInsertUtils .get ().getSql ()));
309
+ logger .fine (String .format ("use batch insert instead of normal insert, attachment: %s, sql: %s" , attachment ,
310
+ batchInsertUtils .get ().getSql ()));
306
311
super .internalExecute (batchInsertUtils .get ().getSql (), attachment );
307
312
r = getResultSet ();
308
313
while (r .next ()) {
@@ -347,7 +352,7 @@ public int[] executeBatchByCopyInto() throws SQLException {
347
352
348
353
public int [] executeBatchDelete () throws SQLException {
349
354
if (!batchInsertUtils .isPresent () || batchValues == null || batchValues .isEmpty ()) {
350
- return new int []{};
355
+ return new int [] {};
351
356
}
352
357
int [] batchUpdateCounts = new int [batchValues .size ()];
353
358
try {
@@ -382,7 +387,6 @@ public static String convertSQLWithBatchValues(String baseSql, List<String[]> ba
382
387
return convertedSqlBuilder .toString ();
383
388
}
384
389
385
-
386
390
@ Override
387
391
public int [] executeBatch () throws SQLException {
388
392
if (originalSql .toLowerCase ().contains ("delete from" )) {
@@ -449,7 +453,7 @@ protected void handleBatchInsert() throws SQLException {
449
453
@ Override
450
454
public int executeUpdate () throws SQLException {
451
455
this .execute (prepareSQL (batchInsertUtils .get ().getProvideParams ()));
452
- return batchInsertUtils . get (). getProvideParams (). size ();
456
+ return getUpdateCount ();
453
457
}
454
458
455
459
@ Override
@@ -519,7 +523,8 @@ public void setDouble(int i, double v)
519
523
public void setBigDecimal (int i , BigDecimal bigDecimal )
520
524
throws SQLException {
521
525
checkOpen ();
522
- batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , formatBigDecimalLiteral (bigDecimal )));
526
+ batchInsertUtils
527
+ .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , formatBigDecimalLiteral (bigDecimal )));
523
528
}
524
529
525
530
@ Override
@@ -535,7 +540,8 @@ public void setString(int i, String s)
535
540
s = s .replace ("'" , "\\ \' " );
536
541
}
537
542
String finalS = s ;
538
- batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , String .format ("%s%s%s" , "'" , finalS , "'" )));
543
+ batchInsertUtils .ifPresent (
544
+ insertUtils -> insertUtils .setPlaceHolderValue (i , String .format ("%s%s%s" , "'" , finalS , "'" )));
539
545
}
540
546
}
541
547
@@ -554,7 +560,8 @@ public void setDate(int i, Date date)
554
560
batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , null ));
555
561
} else {
556
562
if (originalSql .toLowerCase ().startsWith ("select" )) {
557
- batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , String .format ("%s%s%s" , "'" , date , "'" )));
563
+ batchInsertUtils .ifPresent (
564
+ insertUtils -> insertUtils .setPlaceHolderValue (i , String .format ("%s%s%s" , "'" , date , "'" )));
558
565
} else {
559
566
batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , toDateLiteral (date )));
560
567
}
@@ -569,7 +576,8 @@ public void setTime(int i, Time time)
569
576
batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , null ));
570
577
} else {
571
578
if (originalSql .toLowerCase ().startsWith ("select" )) {
572
- batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , String .format ("%s%s%s" , "'" , time , "'" )));
579
+ batchInsertUtils .ifPresent (
580
+ insertUtils -> insertUtils .setPlaceHolderValue (i , String .format ("%s%s%s" , "'" , time , "'" )));
573
581
} else {
574
582
batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , toTimeLiteral (time )));
575
583
}
@@ -584,9 +592,11 @@ public void setTimestamp(int i, Timestamp timestamp)
584
592
batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , null ));
585
593
} else {
586
594
if (originalSql .toLowerCase ().startsWith ("select" )) {
587
- batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , String .format ("%s%s%s" , "'" , timestamp , "'" )));
595
+ batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i ,
596
+ String .format ("%s%s%s" , "'" , timestamp , "'" )));
588
597
} else {
589
- batchInsertUtils .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , toTimestampLiteral (timestamp )));
598
+ batchInsertUtils
599
+ .ifPresent (insertUtils -> insertUtils .setPlaceHolderValue (i , toTimestampLiteral (timestamp )));
590
600
}
591
601
}
592
602
}
@@ -759,7 +769,6 @@ public static String convertArrayListToString(ArrayList<?> arrayList) {
759
769
return builder .toString ();
760
770
}
761
771
762
-
763
772
@ Override
764
773
public void addBatch ()
765
774
throws SQLException {
@@ -854,7 +863,8 @@ public void setURL(int i, URL url)
854
863
throw new SQLFeatureNotSupportedException ("PreparedStatement" , "setURL" );
855
864
}
856
865
857
- // If you want to use ps.getParameterMetaData().* methods, you need to use a valid sql such as
866
+ // If you want to use ps.getParameterMetaData().* methods, you need to use a
867
+ // valid sql such as
858
868
// insert into table_name (col1 type1, col2 typ2, col3 type3) values (?, ?, ?)
859
869
@ Override
860
870
public ParameterMetaData getParameterMetaData () throws SQLException {
@@ -1006,7 +1016,6 @@ public void setNClob(int i, Reader reader)
1006
1016
throw new SQLFeatureNotSupportedException ("PreparedStatement" , "setNClob" );
1007
1017
}
1008
1018
1009
-
1010
1019
private String toDateLiteral (Object value ) throws IllegalArgumentException {
1011
1020
requireNonNull (value , "value is null" );
1012
1021
if (value instanceof java .util .Date ) {
0 commit comments