-
Notifications
You must be signed in to change notification settings - Fork 19
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
577 additions
and
563 deletions.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
.../main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDK1007Adapter.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,136 @@ | ||
package com.databasepreservation.modules.siard.common.adapters; | ||
|
||
import java.math.BigInteger; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.databasepreservation.modules.siard.constants.SIARDDKConstants; | ||
|
||
import dk.sa.xmlns.diark._1_0.tableindex.ColumnType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.ColumnsType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeyType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeysType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.FunctionalDescriptionType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.PrimaryKeyType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.ReferenceType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.SiardDiark; | ||
import dk.sa.xmlns.diark._1_0.tableindex.TableType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.TablesType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.ViewType; | ||
import dk.sa.xmlns.diark._1_0.tableindex.ViewsType; | ||
|
||
/** | ||
* @author Gabriel Barros <gbarros@keep.pt> | ||
*/ | ||
public class SIARDDK1007Adapter implements SIARDDKAdapter { | ||
private final SiardDiark siardDiark; | ||
private final TablesType tablesType; | ||
private final ViewsType viewsType; | ||
|
||
public SIARDDK1007Adapter() { | ||
siardDiark = new SiardDiark(); | ||
tablesType = new TablesType(); | ||
viewsType = new ViewsType(); | ||
|
||
siardDiark.setTables(tablesType); | ||
siardDiark.setViews(viewsType); | ||
} | ||
|
||
@Override | ||
public void setVersion(String value) { | ||
siardDiark.setVersion(value); | ||
} | ||
|
||
@Override | ||
public void setDbName(String dbOriginalName) { | ||
siardDiark.setDbName(dbOriginalName); | ||
} | ||
|
||
@Override | ||
public void setDatabaseProduct(String productName) { | ||
siardDiark.setDatabaseProduct(productName); | ||
} | ||
|
||
@Override | ||
public void addTable(String tableName, String tableFolder, String tableDescription) { | ||
TableType tableType = new TableType(); | ||
tableType.setName(tableName); | ||
tableType.setFolder(tableFolder); | ||
tableType.setDescription(tableDescription); | ||
tableType.setColumns(new ColumnsType()); | ||
tablesType.getTable().add(tableType); | ||
} | ||
|
||
@Override | ||
public void addColumnForTable(String tableName, String columnName, String columnID, String columType, | ||
String columnOriginalType, String columnDefaultValue, Boolean columnStructureNillable, String columnDescription, | ||
String lobType) { | ||
ColumnType columnType = new ColumnType(); | ||
columnType.setName(columnName); | ||
columnType.setColumnID(columnID); | ||
columnType.setType(columType); | ||
columnType.setTypeOriginal(columnOriginalType); | ||
columnType.setDefaultValue(columnDefaultValue); | ||
columnType.setNullable(columnStructureNillable); | ||
columnType.setDescription(columnDescription); | ||
|
||
if (lobType != null) { | ||
if (lobType.equals(SIARDDKConstants.BINARY_LARGE_OBJECT)) { | ||
FunctionalDescriptionType functionalDescriptionType = FunctionalDescriptionType.DOKUMENTIDENTIFIKATION; | ||
columnType.getFunctionalDescription().add(functionalDescriptionType); | ||
} | ||
} | ||
tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get().getColumns() | ||
.getColumn().add(columnType); | ||
} | ||
|
||
@Override | ||
public Object getSIARDDK() { | ||
return siardDiark; | ||
} | ||
|
||
@Override | ||
public void addPrimaryKeyForTable(String tableName, String primaryKeyName, List<String> escapedColumnNames) { | ||
PrimaryKeyType primaryKeyType = new PrimaryKeyType(); | ||
primaryKeyType.setName(primaryKeyName); | ||
primaryKeyType.getColumn().addAll(escapedColumnNames); | ||
tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get() | ||
.setPrimaryKey(primaryKeyType); | ||
} | ||
|
||
@Override | ||
public void addForeignKeyForTable(String tableName, String foreignKeyName, String foreignKeyReferencedTable, | ||
Map<String, String> escapedReferencedColumns) { | ||
TableType tableType = tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst() | ||
.get(); | ||
if (tableType.getForeignKeys() == null) { | ||
tableType.setForeignKeys(new ForeignKeysType()); | ||
} | ||
ForeignKeyType foreignKeyType = new ForeignKeyType(); | ||
foreignKeyType.setName(foreignKeyName); | ||
foreignKeyType.setReferencedTable(foreignKeyReferencedTable); | ||
escapedReferencedColumns.forEach((column, ref) -> { | ||
ReferenceType referenceType = new ReferenceType(); | ||
referenceType.setColumn(column); | ||
referenceType.setReferenced(ref); | ||
foreignKeyType.getReference().add(referenceType); | ||
}); | ||
tableType.getForeignKeys().getForeignKey().add(foreignKeyType); | ||
} | ||
|
||
@Override | ||
public void setRowsForTable(String tableName, BigInteger bigInteger) { | ||
tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get() | ||
.setRows(bigInteger); | ||
} | ||
|
||
@Override | ||
public void addView(String viewName, String viewQueryOriginal, String viewDescription) { | ||
ViewType viewType = new ViewType(); | ||
viewType.setName(viewName); | ||
viewType.setQueryOriginal(viewQueryOriginal); | ||
viewType.setDescription(viewDescription); | ||
viewsType.getView().add(viewType); | ||
} | ||
|
||
} |
134 changes: 134 additions & 0 deletions
134
...c/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDK128Adapter.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,134 @@ | ||
package com.databasepreservation.modules.siard.common.adapters; | ||
|
||
import java.math.BigInteger; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.ColumnType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.ColumnsType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.ForeignKeyType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.ForeignKeysType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.FunctionalDescriptionType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.PrimaryKeyType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.ReferenceType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.SiardDiark; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.TableType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.TablesType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.ViewType; | ||
import com.databasepreservation.modules.siard.bindings.siard_dk_128.ViewsType; | ||
import com.databasepreservation.modules.siard.constants.SIARDDKConstants; | ||
|
||
/** | ||
* @author Gabriel Barros <gbarros@keep.pt> | ||
*/ | ||
public class SIARDDK128Adapter implements SIARDDKAdapter { | ||
private final SiardDiark siardDiark; | ||
private final TablesType tablesType; | ||
private final ViewsType viewsType; | ||
|
||
public SIARDDK128Adapter() { | ||
siardDiark = new SiardDiark(); | ||
tablesType = new TablesType(); | ||
viewsType = new ViewsType(); | ||
|
||
siardDiark.setTables(tablesType); | ||
siardDiark.setViews(viewsType); | ||
} | ||
|
||
@Override | ||
public void setVersion(String value) { | ||
siardDiark.setVersion(value); | ||
} | ||
|
||
@Override | ||
public void setDbName(String dbOriginalName) { | ||
siardDiark.setDbName(dbOriginalName); | ||
} | ||
|
||
@Override | ||
public void setDatabaseProduct(String productName) { | ||
siardDiark.setDatabaseProduct(productName); | ||
} | ||
|
||
@Override | ||
public void addTable(String tableName, String tableFolder, String tableDescription) { | ||
TableType tableType = new TableType(); | ||
tableType.setName(tableName); | ||
tableType.setFolder(tableFolder); | ||
tableType.setDescription(tableDescription); | ||
tableType.setColumns(new ColumnsType()); | ||
tablesType.getTable().add(tableType); | ||
} | ||
|
||
@Override | ||
public void addColumnForTable(String tableName, String columnName, String columnID, String columType, | ||
String columnOriginalType, String columnDefaultValue, Boolean columnStructureNillable, String columnDescription, | ||
String lobType) { | ||
ColumnType columnType = new ColumnType(); | ||
columnType.setName(columnName); | ||
columnType.setColumnID(columnID); | ||
columnType.setType(columType); | ||
columnType.setTypeOriginal(columnOriginalType); | ||
columnType.setDefaultValue(columnDefaultValue); | ||
columnType.setNullable(columnStructureNillable); | ||
columnType.setDescription(columnDescription); | ||
|
||
if (lobType != null) { | ||
if (lobType.equals(SIARDDKConstants.BINARY_LARGE_OBJECT)) { | ||
FunctionalDescriptionType functionalDescriptionType = FunctionalDescriptionType.DOKUMENTIDENTIFIKATION; | ||
columnType.getFunctionalDescription().add(functionalDescriptionType); | ||
} | ||
} | ||
tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get().getColumns() | ||
.getColumn().add(columnType); | ||
} | ||
|
||
@Override | ||
public Object getSIARDDK() { | ||
return siardDiark; | ||
} | ||
|
||
@Override | ||
public void addPrimaryKeyForTable(String tableName, String primaryKeyName, List<String> escapedColumnNames) { | ||
PrimaryKeyType primaryKeyType = new PrimaryKeyType(); | ||
primaryKeyType.setName(primaryKeyName); | ||
primaryKeyType.getColumn().addAll(escapedColumnNames); | ||
tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get() | ||
.setPrimaryKey(primaryKeyType); | ||
} | ||
|
||
@Override | ||
public void addForeignKeyForTable(String tableName, String foreignKeyName, String foreignKeyReferencedTable, | ||
Map<String, String> escapedReferencedColumns) { | ||
TableType tableType = tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst() | ||
.get(); | ||
if (tableType.getForeignKeys() == null) { | ||
tableType.setForeignKeys(new ForeignKeysType()); | ||
} | ||
ForeignKeyType foreignKeyType = new ForeignKeyType(); | ||
foreignKeyType.setName(foreignKeyName); | ||
foreignKeyType.setReferencedTable(foreignKeyReferencedTable); | ||
escapedReferencedColumns.forEach((column, ref) -> { | ||
ReferenceType referenceType = new ReferenceType(); | ||
referenceType.setColumn(column); | ||
referenceType.setReferenced(ref); | ||
foreignKeyType.getReference().add(referenceType); | ||
}); | ||
tableType.getForeignKeys().getForeignKey().add(foreignKeyType); | ||
} | ||
|
||
@Override | ||
public void setRowsForTable(String tableName, BigInteger bigInteger) { | ||
tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get() | ||
.setRows(bigInteger); | ||
} | ||
|
||
@Override | ||
public void addView(String viewName, String viewQueryOriginal, String viewDescription) { | ||
ViewType viewType = new ViewType(); | ||
viewType.setName(viewName); | ||
viewType.setQueryOriginal(viewQueryOriginal); | ||
viewType.setDescription(viewDescription); | ||
viewsType.getView().add(viewType); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDKAdapter.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,33 @@ | ||
package com.databasepreservation.modules.siard.common.adapters; | ||
|
||
import java.math.BigInteger; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Gabriel Barros <gbarros@keep.pt> | ||
*/ | ||
public interface SIARDDKAdapter { | ||
void setVersion(String value); | ||
|
||
void setDbName(String dbOriginalName); | ||
|
||
void setDatabaseProduct(String productName); | ||
|
||
void addTable(String tableName, String tableFolder, String tableDescription); | ||
|
||
void addColumnForTable(String tableName, String columnName, String columnID, String columType, | ||
String columnOriginalType, String columnDefaultValue, Boolean columnStructureNillable, String columnDescription, | ||
String lobType); | ||
|
||
Object getSIARDDK(); | ||
|
||
void addPrimaryKeyForTable(String tableName, String primaryKeyName, List<String> escapedColumnNames); | ||
|
||
void addForeignKeyForTable(String tableName, String foreignKeyName, String foreignKeyReferencedTable, | ||
Map<String, String> escapedReferencedColumns); | ||
|
||
void setRowsForTable(String tableName, BigInteger bigInteger); | ||
|
||
void addView(String viewName, String viewQueryOriginal, String viewDescription); | ||
} |
Oops, something went wrong.