1
1
package com .datastax .cdm .schema ;
2
2
3
- import com .datastax .oss .driver .api .core .type .DataType ;
4
3
import com .datastax .cdm .data .CqlConversion ;
4
+ import com .datastax .cdm .properties .IPropertyHelper ;
5
5
import com .datastax .cdm .properties .KnownProperties ;
6
- import com .datastax .cdm .properties .PropertyHelper ;
6
+ import com .datastax .oss .driver .api .core .type .DataType ;
7
+ import org .apache .commons .lang3 .StringUtils ;
7
8
9
+ import javax .validation .constraints .NotNull ;
8
10
import java .util .List ;
9
11
10
12
public class BaseTable implements Table {
11
- protected final PropertyHelper propertyHelper ;
13
+ protected final IPropertyHelper propertyHelper ;
12
14
protected final boolean isOrigin ;
13
-
14
15
protected String keyspaceName ;
15
16
protected String tableName ;
16
17
protected List <String > columnNames ;
17
18
protected List <DataType > columnCqlTypes ;
18
19
protected List <CqlConversion > cqlConversions ;
19
20
20
- public BaseTable (PropertyHelper propertyHelper , boolean isOrigin ) {
21
+ public BaseTable (IPropertyHelper propertyHelper , boolean isOrigin ) {
21
22
this .propertyHelper = propertyHelper ;
22
23
this .isOrigin = isOrigin ;
23
24
24
- String keyspaceTableString = ( this . isOrigin ? propertyHelper . getString ( KnownProperties . ORIGIN_KEYSPACE_TABLE ) : propertyHelper . getString ( KnownProperties . TARGET_KEYSPACE_TABLE )). trim ( );
25
+ String keyspaceTableString = getKeyspaceTableAsString ( propertyHelper , isOrigin );
25
26
if (keyspaceTableString .contains ("." )) {
26
27
String [] keyspaceTable = keyspaceTableString .split ("\\ ." );
27
28
this .keyspaceName = keyspaceTable [0 ];
@@ -32,11 +33,47 @@ public BaseTable(PropertyHelper propertyHelper, boolean isOrigin) {
32
33
}
33
34
}
34
35
35
- public String getKeyspaceName () {return this .keyspaceName ;}
36
- public String getTableName () {return this .tableName ;}
37
- public String getKeyspaceTable () {return this .keyspaceName + "." + this .tableName ;}
38
- public List <String > getColumnNames (boolean format ) { return this .columnNames ; }
39
- public List <DataType > getColumnCqlTypes () {return this .columnCqlTypes ;}
40
- public List <CqlConversion > getConversions () {return this .cqlConversions ;}
41
- public boolean isOrigin () {return this .isOrigin ;}
42
- }
36
+ @ NotNull
37
+ private String getKeyspaceTableAsString (IPropertyHelper propertyHelper , boolean isOrigin ) {
38
+ String keyspaceTableString = (isOrigin ? propertyHelper .getString (KnownProperties .ORIGIN_KEYSPACE_TABLE ) :
39
+ propertyHelper .getString (KnownProperties .TARGET_KEYSPACE_TABLE ));
40
+
41
+ // Use origin keyspaceTable property if target not specified
42
+ if (!isOrigin && StringUtils .isBlank (keyspaceTableString )) {
43
+ keyspaceTableString = propertyHelper .getString (KnownProperties .ORIGIN_KEYSPACE_TABLE );
44
+ }
45
+ if (StringUtils .isBlank (keyspaceTableString )) {
46
+ throw new RuntimeException ("Value for required property " + KnownProperties .ORIGIN_KEYSPACE_TABLE + " not provided!!" );
47
+ }
48
+
49
+ return keyspaceTableString .trim ();
50
+ }
51
+
52
+ public String getKeyspaceName () {
53
+ return this .keyspaceName ;
54
+ }
55
+
56
+ public String getTableName () {
57
+ return this .tableName ;
58
+ }
59
+
60
+ public String getKeyspaceTable () {
61
+ return this .keyspaceName + "." + this .tableName ;
62
+ }
63
+
64
+ public List <String > getColumnNames (boolean format ) {
65
+ return this .columnNames ;
66
+ }
67
+
68
+ public List <DataType > getColumnCqlTypes () {
69
+ return this .columnCqlTypes ;
70
+ }
71
+
72
+ public List <CqlConversion > getConversions () {
73
+ return this .cqlConversions ;
74
+ }
75
+
76
+ public boolean isOrigin () {
77
+ return this .isOrigin ;
78
+ }
79
+ }
0 commit comments