use of org.openforis.collect.relational.model.Column in project collect by openforis.
the class SqlSchemaWriter method writeTable.
private void writeTable(Table<?> table) throws IOException {
writer.write("CREATE TABLE ");
if (!isSchemaless()) {
writer.write(doubleQuote(schema.getName()));
writer.write('.');
}
writer.write(doubleQuote(table.getName()));
writer.write(" (");
writer.write('\n');
List<Column<?>> columns = table.getColumns();
for (int i = 0; i < columns.size(); i++) {
if (i > 0) {
writer.write(',');
writer.write('\n');
}
Column<?> column = columns.get(i);
writeColumn(column);
}
if (includeForeignKeysInCreateTable && !table.getReferentialContraints().isEmpty()) {
writer.write(',');
writer.write('\n');
List<ReferentialConstraint> fks = table.getReferentialContraints();
for (int i = 0; i < fks.size(); i++) {
ReferentialConstraint fk = fks.get(i);
writer.write('\t');
writeForeignKeyConstraint(fk);
if (i < fks.size() - 1) {
writer.write(", \n");
}
}
}
writer.write('\n');
writer.write(");");
writer.write('\n');
}
use of org.openforis.collect.relational.model.Column in project collect by openforis.
the class CodeTableDataExtractor method extractRow.
public Row extractRow(CodeListItem source) {
Row row = new Row(table);
List<Column<?>> columns = table.getColumns();
for (int i = 0; i < columns.size(); i++) {
Column<?> col = columns.get(i);
Object val = extractValue(source, col);
row.setValue(i, val);
}
return row;
}
use of org.openforis.collect.relational.model.Column in project collect by openforis.
the class DDLCreator method write.
public void write(Writer output) {
Database db = new Database();
db.setName(schema.getName());
for (Table<?> table : schema.getTables()) {
org.apache.ddlutils.model.Table ddlTable = new org.apache.ddlutils.model.Table();
ddlTable.setName(table.getName());
ddlTable.setSchema(schema.getName());
for (Column<?> column : table.getColumns()) {
org.apache.ddlutils.model.Column ddlColumn = new org.apache.ddlutils.model.Column();
ddlColumn.setName(column.getName());
ddlColumn.setType(column.getType().getName());
ddlColumn.setTypeCode(column.getType().getCode());
ddlColumn.setSizeAndScale(column.getLength() == null ? 0 : column.getLength(), 0);
ddlTable.addColumn(ddlColumn);
}
db.addTable(ddlTable);
}
new DatabaseIO().write(db, output);
}
use of org.openforis.collect.relational.model.Column in project collect by openforis.
the class CodeTableDataExtractor method createDefaultCodeRow.
protected Row createDefaultCodeRow() {
Row row = new Row(table);
List<Column<?>> columns = table.getColumns();
for (int i = 0; i < columns.size(); i++) {
@SuppressWarnings("rawtypes") Column col = columns.get(i);
Object val;
if (col instanceof CodePrimaryKeyColumn) {
val = DEFAULT_CODE_ROW_ID;
} else if (col instanceof CodeListCodeColumn) {
val = table.getDefaultCode();
} else if (col instanceof CodeLabelColumn) {
val = table.getDefaultCodeLabel(((CodeLabelColumn) col).getLanguageCode());
} else {
val = null;
}
row.setValue(i, val);
}
return row;
}
use of org.openforis.collect.relational.model.Column in project collect by openforis.
the class DataTableDataExtractor method extractRow.
private Row extractRow(Node<?> source) {
List<Column<?>> columns = table.getColumns();
Row row = new Row(table);
for (int i = 0; i < columns.size(); i++) {
Column<?> col = columns.get(i);
Object val = extractColumnValue(source, col);
row.setValue(i, val);
}
return row;
}
Aggregations