HashMap layoutStructure = new HashMap();
StringBuffer structChanIds = new StringBuffer();
try {
int lastStructId = 0;
LayoutStructure ls = null;
String sepChar = "";
if (foundLayout) {
int structId = rs.getInt(1);
// Result Set returns 0 by default if structId was null
// Except if you are using poolman 2.0.4 in which case you get -1 back
if (rs.wasNull()) {
structId = 0;
}
readLayout: while (true) {
if (DEBUG > 1) System.err.println("Found layout structureID " + structId);
int nextId = rs.getInt(2);
if (rs.wasNull()) {
nextId = 0;
}
int childId = rs.getInt(3);
if (rs.wasNull()) {
childId = 0;
}
int chanId = rs.getInt(4);
if (rs.wasNull()) {
chanId = 0;
}
String temp5=rs.getString(5); // Some JDBC drivers require columns accessed in order
String temp6=rs.getString(6); // Access 5 and 6 now, save till needed.
// uPortal i18n
int name_index, value_index;
if (localeAware) {
ls = new LayoutStructure(
structId, nextId, childId, chanId,
rs.getString(7),rs.getString(8),rs.getString(9),
localeManager.getLocales()
[0].toString());
name_index=10;
value_index=11;
} else {
ls = new LayoutStructure(structId, nextId, childId, chanId, rs.getString(7),rs.getString(8),rs.getString(9));
name_index=10;
value_index=11;
}
layoutStructure.put(new Integer(structId), ls);
lastStructId = structId;
if (!ls.isChannel()) {
ls.addFolderData(temp5, temp6); // Plug in saved column values
}
if (this.databaseMetadata.supportsOuterJoins()) {
do {
String name = rs.getString(name_index);
String value = rs.getString(value_index); // Oracle JDBC requires us to do this for longs
if (name != null) { // may not be there because of the join
ls.addParameter(name, value);
}
if (!rs.next()) {
break readLayout;
}
structId = rs.getInt(1);
if (rs.wasNull()) {
structId = 0;
}
} while (structId == lastStructId);
} else { // Do second SELECT later on for structure parameters
if (ls.isChannel()) {
structChanIds.append(sepChar + ls.getChanId());
sepChar = ",";
}
if (rs.next()) {
structId = rs.getInt(1);
if (rs.wasNull()) {
structId = 0;
}
} else {
break readLayout;
}
}
} // while
}
} finally {
rs.close();
}
if (!this.databaseMetadata.supportsOuterJoins()) { // Pick up structure parameters
// first, get the struct ids for the channels
String sql = "SELECT STRUCT_ID FROM UP_LAYOUT_STRUCT WHERE USER_ID=" + userId +
" AND LAYOUT_ID=" + layoutId +
" AND CHAN_ID IN (" + structChanIds.toString() + ") ORDER BY STRUCT_ID";
if (log.isDebugEnabled())
log.debug("RDBMUserLayoutStore::getUserLayout(): " + sql);
StringBuffer structIdsSB = new StringBuffer( "" );
String sep = "";
rs = stmt.executeQuery(sql);
try {
// use the results to build a correct list of struct ids to look for
while( rs.next()) {
structIdsSB.append(sep + rs.getString(1));
sep = ",";
}// while
} finally {
rs.close();
} // be a good doobie
sql = "SELECT STRUCT_ID, STRUCT_PARM_NM,STRUCT_PARM_VAL FROM UP_LAYOUT_PARAM WHERE USER_ID=" + userId + " AND LAYOUT_ID=" + layoutId +
" AND STRUCT_ID IN (" + structIdsSB.toString() + ") ORDER BY STRUCT_ID";
if (log.isDebugEnabled())
log.debug("RDBMUserLayoutStore::getUserLayout(): " + sql);
rs = stmt.executeQuery(sql);
try {
if (rs.next()) {
int structId = rs.getInt(1);
readParm: while(true) {
LayoutStructure ls = (LayoutStructure)layoutStructure.get(new Integer(structId));
int lastStructId = structId;
do {
ls.addParameter(rs.getString(2), rs.getString(3));
if (!rs.next()) {
break readParm;
}
} while ((structId = rs.getInt(1)) == lastStructId);
}