use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method buildSelfReferenceExtractingTrySqlList.
// ===================================================================================
// Extraction SQL
// ==============
// -----------------------------------------------------
// Self Reference
// --------------
protected OptionalThing<List<String>> buildSelfReferenceExtractingTrySqlList(Table table) {
final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
if (selfReferenceFK == null || !selfReferenceFK.isSimpleKeyFK()) {
return OptionalThing.empty();
}
final String tableSqlName = table.getTableSqlNameDirectUse();
final Column firstLocalColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
final String firstLocalName = firstLocalColumn.getColumnSqlNameDirectUse();
final Column firstForeignColumn = table.getColumn(selfReferenceFK.getFirstForeignColumnName());
final String firstForeignName = firstForeignColumn.getColumnSqlNameDirectUse();
final List<String> sqlList = DfCollectionUtil.newArrayList();
sqlList.add(doBuildSelfReferenceRecursiveSql(table, tableSqlName, firstLocalName, firstForeignName));
sqlList.add(doBuildSelfReferenceJoinJoinSql(table, tableSqlName, firstLocalName, firstForeignName));
return OptionalThing.of(sqlList);
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method buildOrderByClause.
protected String buildOrderByClause(Table table) {
final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
final String orderBy;
if (selfReferenceFK != null && selfReferenceFK.isSimpleKeyFK()) {
final Column firstColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
final String firstName = firstColumn.getColumnSqlNameDirectUse();
orderBy = buildOrderByNullsFirst(firstName);
} else {
orderBy = "";
}
return orderBy;
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfLReverseOutputHandler method outputDelimiterData.
// ===================================================================================
// Delimiter Data
// ==============
protected void outputDelimiterData(final Table table, DfLReverseDataResult templateDataResult, final int limit, DfLReverseOutputResource resource, int sheetNumber, List<String> sectionInfoList) {
if (_delimiterDataDir == null) {
return;
}
final File delimiterDir = new File(_delimiterDataDir);
// fixed
final String ext = "tsv";
if (!delimiterDir.exists()) {
delimiterDir.mkdirs();
}
final FileToken fileToken = new FileToken();
// file name uses DB name (no display name) just in case
final String delimiterFilePath = buildDelimiterFilePath(table, resource, sheetNumber, delimiterDir, ext);
final List<String> columnNameList = new ArrayList<String>();
for (Column column : table.getColumnList()) {
if (!_containsCommonColumn && column.isCommonColumn()) {
continue;
}
columnNameList.add(column.getName());
}
final DfJFadCursorCallback cursorCallback = templateDataResult.getCursorCallback();
cursorCallback.select(new DfJFadCursorHandler() {
int count = 0;
public void handle(final DfJFadResultSetWrapper wrapper) {
try {
fileToken.make(delimiterFilePath, new FileMakingCallback() {
public void write(FileMakingRowWriter writer) throws IOException, SQLException {
while (wrapper.next()) {
if (limit >= 0 && limit < count) {
break;
}
final List<String> valueList = new ArrayList<String>();
for (String columnName : columnNameList) {
valueList.add(wrapper.getString(columnName));
}
writer.writeRow(valueList);
++count;
}
}
}, op -> op.encodeAsUTF8().separateByLf().delimitateByTab().headerInfo(columnNameList));
} catch (IOException e) {
handleDelimiterDataFailureException(table, delimiterFilePath, e);
}
final String delimiterInfo = " " + delimiterFilePath + " (" + count + ")";
_log.info(delimiterInfo);
sectionInfoList.add(delimiterInfo);
}
});
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfColumnListToStringBuilder method getColumnArgsSetupPropertyString.
public static String getColumnArgsSetupPropertyString(String beanName, List<Column> columnList) {
validateColumnList(columnList);
final boolean hasPrefix = beanName != null;
final String beanPrefix = (hasPrefix ? beanName + "." : "");
final DfLanguageDependency lang = getBasicProperties().getLanguageDependency();
final DfLanguageImplStyle implStyle = lang.getLanguageImplStyle();
String result = "";
for (Iterator<Column> ite = columnList.iterator(); ite.hasNext(); ) {
final Column column = (Column) ite.next();
final String javaName = column.getJavaName();
final String variable = column.getUncapitalisedJavaName();
final String cls = column.getClassificationName();
final String basic;
if (column.isForceClassificationSetting()) {
basic = "set" + javaName + "As" + cls + "(" + variable + ")";
} else {
basic = "set" + javaName + "(" + variable + ")";
}
final String adjusted = implStyle.adjustEntitySetPropertyCall(basic, !hasPrefix);
final String setter = beanPrefix + adjusted + ";";
if ("".equals(result)) {
result = setter;
} else {
result = result + setter;
}
}
return result;
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfColumnListToStringBuilder method getColumnUncapitalisedJavaNameCommaString.
public static String getColumnUncapitalisedJavaNameCommaString(List<Column> columnList) {
validateColumnList(columnList);
String result = "";
for (Column column : columnList) {
final String name = column.getUncapitalisedJavaName();
if ("".equals(result)) {
result = name;
} else {
result = result + ", " + name;
}
}
return result;
}
Aggregations