use of jodd.db.oom.sqlgen.DbSqlBuilderException in project jodd by oblac.
the class ReferenceChunk method process.
// ---------------------------------------------------------------- process
@Override
public void process(StringBuilder out) {
DbEntityDescriptor ded;
if (tableRef != null) {
ded = lookupTableRef(tableRef);
String tableName = resolveTable(tableRef, ded);
out.append(tableName);
} else {
ded = findColumnRef(columnRef);
}
if (onlyId) {
if (tableRef != null) {
out.append('.');
}
out.append(ded.getIdColumnName());
} else if (columnRef != null) {
DbEntityColumnDescriptor dec = ded.findByPropertyName(columnRef);
templateData.lastColumnDec = dec;
String column = dec == null ? null : dec.getColumnName();
//String column = ded.getColumnName(columnRef);
if (column == null) {
throw new DbSqlBuilderException("Invalid column reference: " + tableRef + '.' + columnRef);
}
if (tableRef != null) {
out.append('.');
}
out.append(column);
}
}
use of jodd.db.oom.sqlgen.DbSqlBuilderException in project jodd by oblac.
the class ColumnsSelectChunk method process.
@Override
public void process(StringBuilder out) {
// hints
if (templateData.hasHints()) {
templateData.registerHint(hint == null ? tableRef : hint);
}
// columns
separateByCommaOrSpace(out);
// special case, only column name, no table ref/name
if (tableRef.length() == 0) {
out.append(columnRef);
return;
}
boolean useTableReference = true;
DbEntityDescriptor ded = lookupTableRef(tableRef, false);
if (ded == null) {
useTableReference = false;
ded = lookupName(tableRef);
}
if (columnRef == null) {
DbEntityColumnDescriptor[] decList = ded.getColumnDescriptors();
int count = 0;
boolean withIds = (columnRefArr != null) && ArraysUtil.contains(columnRefArr, StringPool.PLUS);
for (DbEntityColumnDescriptor dec : decList) {
if ((includeColumns == COLS_ONLY_IDS) && (!dec.isId())) {
continue;
}
if ((includeColumns == COLS_ALL_BUT_ID) && (dec.isId())) {
continue;
}
if ((includeColumns == COLS_NA_MULTI) && (!withIds || (!dec.isId())) && (!ArraysUtil.contains(columnRefArr, dec.getPropertyName()))) {
continue;
}
if (count > 0) {
out.append(',').append(' ');
}
templateData.lastColumnDec = dec;
if (useTableReference) {
appendColumnName(out, ded, dec.getColumnName());
} else {
appendAlias(out, ded, dec.getColumnName());
}
count++;
}
} else {
DbEntityColumnDescriptor dec = ded.findByPropertyName(columnRef);
templateData.lastColumnDec = dec;
String columnName = dec == null ? null : dec.getColumnName();
//String columnName = ded.getColumnName(columnRef);
if (columnName == null) {
throw new DbSqlBuilderException("Invalid column reference: " + tableRef + '.' + columnRef);
}
if (useTableReference) {
appendColumnName(out, ded, columnName);
} else {
appendAlias(out, ded, columnName);
}
}
}
Aggregations