001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/TKDBTemplate.java,v 1.7 2001/11/09 12:53:55 markus Exp $
003: *
004: */
005: package com.teamkonzept.lib;
006:
007: import java.sql.*;
008:
009: /**
010: *
011: * @author
012: * @version
013: */
014: public class TKDBTemplate {
015:
016: /**
017: *
018: * @param resultSet
019: * @param templateName
020: */
021: public static boolean prepareTemplate(ResultSet resultSet,
022: TKTemplate template) {
023:
024: boolean boolResultSet = false;
025: TKHashtable result = getHashFromResult(resultSet);
026:
027: if (result != null) {
028: template.set(result);
029: boolResultSet = true;
030: } else {
031: boolResultSet = false;
032: }
033: return boolResultSet;
034: }
035:
036: public static boolean prepareTemplate(TKDBResultRow row,
037: TKTemplate template) {
038: TKHashtable result = getHashFromResult(row);
039: if (result != null) {
040: template.set(result);
041: return true;
042: }
043: return false;
044: }
045:
046: public static TKHashtable getHashFromResult(ResultSet resultSet) {
047: TKHashtable result = null;
048: try {
049: // Get the ResultSetMetaData. This will be used for
050: // the column headings
051: ResultSetMetaData rsmd = resultSet.getMetaData();
052:
053: // Get the number of columns in the result set
054: int numCols = rsmd.getColumnCount();
055:
056: if (resultSet.next()) {
057: result = new TKHashtable();
058: for (int x = 1; x <= numCols; x++) {
059: String str = resultSet.getString(x);
060: if (str == null)
061: str = "";
062: result.put(rsmd.getColumnLabel(x).toUpperCase(),
063: str);
064: }
065: }
066: } catch (SQLException ex) {
067: TKDBLogger.logSQLException(ex);
068: }
069: return result;
070: }
071:
072: public static TKHashtable getHashFromResult(TKDBResultRow row) {
073: if (!row.hasResult())
074: return null;
075:
076: int numCols = row.getColumnCount();
077: TKHashtable result = new TKHashtable();
078:
079: for (int i = 0; i < numCols; i++) {
080: result.put(row.getColumnLabel(i).toUpperCase(), row
081: .getColumn(i));
082: }
083: return result;
084: }
085:
086: /**
087: *
088: *
089: * @param resultSet
090: * @param template
091: * @param listName
092: */
093: public static void prepareListTemplate(ResultSet resultSet,
094: TKTemplate template, String listName) {
095: TKResultSetIterator iterator = new TKResultSetIterator(
096: resultSet, template.getListIterator(), listName);
097: template.setListIterator(iterator);
098: }
099:
100: /**
101: *
102: *
103: * @param resultSet
104: * @param template
105: * @param listName
106: */
107: public static void prepareListTemplate(TKDBResult result,
108: TKTemplate template, String listName) {
109: TKDBResultIterator iterator = new TKDBResultIterator(result,
110: template.getListIterator(), listName);
111: template.setListIterator(iterator);
112: }
113:
114: }//end class
|