21
21
import java .sql .ResultSet ;
22
22
import java .sql .DatabaseMetaData ;
23
23
import java .sql .SQLException ;
24
+ import java .util .Optional ;
25
+ import java .util .function .Supplier ;
24
26
25
27
import org .embulk .spi .util .RetryExecutor ;
26
28
import org .embulk .spi .util .RetryExecutor .RetryGiveupException ;
31
33
import com .fasterxml .jackson .annotation .JsonCreator ;
32
34
import com .fasterxml .jackson .annotation .JsonValue ;
33
35
import com .fasterxml .jackson .annotation .JsonProperty ;
34
- import com .google .common .base .Optional ;
35
36
import com .google .common .base .Function ;
36
- import com .google .common .base .Supplier ;
37
37
import com .google .common .base .Throwables ;
38
38
import com .google .common .collect .Lists ;
39
39
import com .google .common .collect .ImmutableList ;
@@ -549,12 +549,12 @@ protected void doBegin(JdbcOutputConnection con,
549
549
550
550
Optional <JdbcSchema > initialTargetTableSchema =
551
551
mode .ignoreTargetTableSchema () ?
552
- Optional .<JdbcSchema >absent () :
552
+ Optional .<JdbcSchema >empty () :
553
553
newJdbcSchemaFromTableIfExists (con , task .getActualTable ());
554
554
555
555
// TODO get CREATE TABLE statement from task if set
556
556
JdbcSchema newTableSchema = applyColumnOptionsToNewTableSchema (
557
- initialTargetTableSchema .or (new Supplier <JdbcSchema >() {
557
+ initialTargetTableSchema .orElseGet (new Supplier <JdbcSchema >() {
558
558
public JdbcSchema get ()
559
559
{
560
560
return newJdbcSchemaForNewTable (schema );
@@ -568,7 +568,7 @@ public JdbcSchema get()
568
568
task .setIntermediateTables (Optional .<List <TableIdentifier >>of (createIntermediateTables (con , task , taskCount , newTableSchema )));
569
569
} else {
570
570
// direct modify mode doesn't need intermediate tables.
571
- task .setIntermediateTables (Optional .<List <TableIdentifier >>absent ());
571
+ task .setIntermediateTables (Optional .<List <TableIdentifier >>empty ());
572
572
if (task .getBeforeLoad ().isPresent ()) {
573
573
con .executeSql (task .getBeforeLoad ().get ());
574
574
}
@@ -578,7 +578,7 @@ public JdbcSchema get()
578
578
JdbcSchema targetTableSchema ;
579
579
if (initialTargetTableSchema .isPresent ()) {
580
580
targetTableSchema = initialTargetTableSchema .get ();
581
- task .setNewTableSchema (Optional .<JdbcSchema >absent ());
581
+ task .setNewTableSchema (Optional .<JdbcSchema >empty ());
582
582
} else if (task .getIntermediateTables ().isPresent () && !task .getIntermediateTables ().get ().isEmpty ()) {
583
583
TableIdentifier firstItermTable = task .getIntermediateTables ().get ().get (0 );
584
584
targetTableSchema = newJdbcSchemaFromTableIfExists (con , firstItermTable ).get ();
@@ -588,7 +588,7 @@ public JdbcSchema get()
588
588
// CREATE TABLE IF NOT EXISTS xyz
589
589
con .createTableIfNotExists (task .getActualTable (), newTableSchema , task .getCreateTableConstraint (), task .getCreateTableOption ());
590
590
targetTableSchema = newJdbcSchemaFromTableIfExists (con , task .getActualTable ()).get ();
591
- task .setNewTableSchema (Optional .<JdbcSchema >absent ());
591
+ task .setNewTableSchema (Optional .<JdbcSchema >empty ());
592
592
}
593
593
task .setTargetTableSchema (matchSchemaByColumnNames (schema , targetTableSchema ));
594
594
@@ -629,7 +629,7 @@ public JdbcSchema get()
629
629
}
630
630
logger .info ("Using merge keys: {}" , task .getMergeKeys ().get ());
631
631
} else {
632
- task .setMergeKeys (Optional .<List <String >>absent ());
632
+ task .setMergeKeys (Optional .<List <String >>empty ());
633
633
}
634
634
}
635
635
@@ -793,7 +793,7 @@ protected static List<ColumnSetter> newColumnSetters(ColumnSetterFactory factory
793
793
794
794
private static JdbcColumnOption columnOptionOf (Map <String , JdbcColumnOption > columnOptions , String columnName )
795
795
{
796
- return Optional .fromNullable (columnOptions .get (columnName )).or (
796
+ return Optional .ofNullable (columnOptions .get (columnName )).orElseGet (
797
797
// default column option
798
798
new Supplier <JdbcColumnOption >()
799
799
{
@@ -927,7 +927,7 @@ public Optional<JdbcSchema> newJdbcSchemaFromTableIfExists(JdbcOutputConnection
927
927
{
928
928
if (!connection .tableExists (table )) {
929
929
// DatabaseMetaData.getPrimaryKeys fails if table does not exist
930
- return Optional .absent ();
930
+ return Optional .empty ();
931
931
}
932
932
933
933
DatabaseMetaData dbm = connection .getMetaData ();
@@ -974,7 +974,7 @@ public Optional<JdbcSchema> newJdbcSchemaFromTableIfExists(JdbcOutputConnection
974
974
}
975
975
List <JdbcColumn > columns = builder .build ();
976
976
if (columns .isEmpty ()) {
977
- return Optional .absent ();
977
+ return Optional .empty ();
978
978
} else {
979
979
return Optional .of (new JdbcSchema (columns ));
980
980
}
@@ -986,7 +986,7 @@ private JdbcSchema matchSchemaByColumnNames(Schema inputSchema, JdbcSchema targe
986
986
987
987
for (Column column : inputSchema .getColumns ()) {
988
988
Optional <JdbcColumn > c = targetTableSchema .findColumn (column .getName ());
989
- jdbcColumns .add (c .or (JdbcColumn .skipColumn ()));
989
+ jdbcColumns .add (c .orElse (JdbcColumn .skipColumn ()));
990
990
}
991
991
992
992
return new JdbcSchema (jdbcColumns .build ());
@@ -1000,7 +1000,7 @@ public TransactionalPageOutput open(TaskSource taskSource, Schema schema, final
1000
1000
// instantiate BatchInsert without table name
1001
1001
BatchInsert batch = null ;
1002
1002
try {
1003
- Optional <MergeConfig > config = Optional .absent ();
1003
+ Optional <MergeConfig > config = Optional .empty ();
1004
1004
if (task .getMode () == Mode .MERGE_DIRECT ) {
1005
1005
config = Optional .of (new MergeConfig (task .getMergeKeys ().get (), task .getMergeRule ()));
1006
1006
}
0 commit comments