use of lucee.runtime.type.SVArray in project Lucee by lucee.
the class DBInfo method toMap.
private Map<String, Map<String, SVArray>> toMap(ResultSet result, boolean closeResult, String columnName, String[] additional) throws SQLException {
Map<String, Map<String, SVArray>> map = new HashMap<String, Map<String, SVArray>>();
Map<String, SVArray> inner;
String col;
SVArray item;
if (result == null)
return map;
try {
while (result.next()) {
col = result.getString(columnName);
inner = map.get(col);
if (inner != null) {
for (int i = 0; i < additional.length; i++) {
item = inner.get(additional[i]);
item.add(result.getString(additional[i]));
item.setPosition(item.size());
}
} else {
inner = new HashMap<String, SVArray>();
map.put(col, inner);
for (int i = 0; i < additional.length; i++) {
item = new SVArray();
item.add(result.getString(additional[i]));
inner.put(additional[i], item);
}
}
}
} finally {
if (closeResult)
IOUtil.closeEL(result);
}
return map;
}
use of lucee.runtime.type.SVArray in project Lucee by lucee.
the class PageContextImpl method getTemplatePath.
@Override
public Array getTemplatePath() throws PageException {
int len = includePathList.size();
SVArray sva = new SVArray();
PageSource ps;
for (int i = 0; i < len; i++) {
ps = includePathList.get(i);
if (i == 0) {
if (!ps.equals(getBasePageSource()))
sva.append(getBasePageSource().getResourceTranslated(this).getAbsolutePath());
}
sva.append(ps.getResourceTranslated(this).getAbsolutePath());
}
// sva.setPosition(sva.size());
return sva;
}
use of lucee.runtime.type.SVArray in project Lucee by lucee.
the class DBInfo method typeColumns.
private void typeColumns(DatabaseMetaData metaData) throws PageException, SQLException {
required("table", table);
Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
stopwatch.start();
table = setCase(metaData, table);
pattern = setCase(metaData, pattern);
if (StringUtil.isEmpty(pattern, true))
pattern = null;
String schema = null;
int index = table.indexOf('.');
if (index > 0) {
schema = table.substring(0, index);
table = table.substring(index + 1);
}
checkTable(metaData);
Query qry = new QueryImpl(metaData.getColumns(dbname, schema, table, pattern), "query", pageContext.getTimeZone());
int len = qry.getRecordcount();
if (qry.getColumn(COLUMN_DEF, null) != null)
qry.rename(COLUMN_DEF, COLUMN_DEFAULT_VALUE);
else if (qry.getColumn(COLUMN_DEFAULT, null) != null)
qry.rename(COLUMN_DEFAULT, COLUMN_DEFAULT_VALUE);
// make sure decimal digits exists
QueryColumn col = qry.getColumn(DECIMAL_DIGITS, null);
if (col == null) {
Array arr = new ArrayImpl();
for (int i = 1; i <= len; i++) {
arr.append(lucee.runtime.op.Constants.DOUBLE_ZERO);
}
qry.addColumn(DECIMAL_DIGITS, arr);
}
// add is primary
Map primaries = new HashMap();
String tblName;
Array isPrimary = new ArrayImpl();
Set set;
Object o;
for (int i = 1; i <= len; i++) {
// decimal digits
o = qry.getAt(DECIMAL_DIGITS, i, null);
if (o == null)
qry.setAtEL(DECIMAL_DIGITS, i, lucee.runtime.op.Constants.DOUBLE_ZERO);
set = (Set) primaries.get(tblName = (String) qry.getAt(TABLE_NAME, i));
if (set == null) {
set = toSet(metaData.getPrimaryKeys(dbname, null, tblName), true, "COLUMN_NAME");
primaries.put(tblName, set);
}
isPrimary.append(set.contains(qry.getAt(COLUMN_NAME, i)) ? "YES" : "NO");
}
qry.addColumn(IS_PRIMARYKEY, isPrimary);
// add is foreignkey
Map foreigns = new HashMap();
Array isForeign = new ArrayImpl();
Array refPrim = new ArrayImpl();
Array refPrimTbl = new ArrayImpl();
// Map map,inner;
Map<String, Map<String, SVArray>> map;
Map<String, SVArray> inner;
for (int i = 1; i <= len; i++) {
map = (Map) foreigns.get(tblName = (String) qry.getAt(TABLE_NAME, i));
if (map == null) {
map = toMap(metaData.getImportedKeys(dbname, schema, table), true, "FKCOLUMN_NAME", new String[] { "PKCOLUMN_NAME", "PKTABLE_NAME" });
foreigns.put(tblName, map);
}
inner = map.get(qry.getAt(COLUMN_NAME, i));
if (inner != null) {
isForeign.append("YES");
refPrim.append(inner.get("PKCOLUMN_NAME"));
refPrimTbl.append(inner.get("PKTABLE_NAME"));
} else {
isForeign.append("NO");
refPrim.append("N/A");
refPrimTbl.append("N/A");
}
}
qry.addColumn(IS_FOREIGNKEY, isForeign);
qry.addColumn(REFERENCED_PRIMARYKEY, refPrim);
qry.addColumn(REFERENCED_PRIMARYKEY_TABLE, refPrimTbl);
qry.setExecutionTime(stopwatch.time());
pageContext.setVariable(name, qry);
}
Aggregations