-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/homihq/db2rest/rest/read/helper/TableUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.homihq.db2rest.rest.read.helper; | ||
|
||
import com.homihq.db2rest.rest.read.model.DbAlias; | ||
import com.homihq.db2rest.rest.read.model.DbColumn; | ||
import com.homihq.db2rest.rest.read.model.DbTable; | ||
|
||
public abstract class TableUtil { | ||
|
||
private TableUtil() {} | ||
|
||
public static DbTable getTable(String tableName) { | ||
//check if table contains schema name | ||
|
||
String [] tableParts = tableName.split("!."); | ||
|
||
if(tableParts.length == 2) { | ||
String table = tableParts[1]; | ||
DbAlias alias = getAlias(table); | ||
return new DbTable(tableParts[0], alias.name(), alias.alias()); | ||
} | ||
else{ | ||
String table = tableParts[0]; | ||
DbAlias alias = getAlias(table); | ||
return new DbTable(null, alias.name(), alias.alias()); | ||
} | ||
} | ||
|
||
public static DbColumn getColumn(String columName) { | ||
//check if table contains schema name | ||
|
||
String [] columnParts = columName.split("!."); | ||
|
||
if(columnParts.length == 2) { | ||
String col = columnParts[1]; | ||
DbAlias alias = getAlias(col); | ||
return new DbColumn(columnParts[0], alias.name(), alias.alias()); | ||
} | ||
else{ | ||
String col = columnParts[0]; | ||
DbAlias alias = getAlias(col); | ||
return new DbColumn(null, alias.name(), alias.alias()); | ||
} | ||
} | ||
|
||
public static DbAlias getAlias(String name) { | ||
String [] aliasParts = name.split(":"); | ||
|
||
if(aliasParts.length == 2) { | ||
return new DbAlias(aliasParts[0], aliasParts[1]); | ||
} | ||
else { | ||
return new DbAlias(aliasParts[0], null); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/com/homihq/db2rest/rest/read/model/DbAlias.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.homihq.db2rest.rest.read.model; | ||
|
||
public record DbAlias(String name, String alias) { } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/homihq/db2rest/rest/read/model/DbColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.homihq.db2rest.rest.read.model; | ||
|
||
|
||
public record DbColumn(String tableName, String name, String alias) { | ||
|
||
|
||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/com/homihq/db2rest/rest/read/model/DbTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.homihq.db2rest.rest.read.model; | ||
|
||
public record DbTable(String schema, String name, String alias) { } |