001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.db;
007:
008: import com.sun.portal.search.rdm.*;
009: import com.sun.portal.search.soif.*;
010: import com.sun.portal.search.util.*;
011:
012: import java.sql.*;
013: import javax.naming.*;
014: import javax.sql.*;
015:
016: import java.util.*;
017:
018: /**
019: *
020: * JDBC search result set implementation using RDMResultSet
021: *
022: */
023: public class JDBCResultSet extends RDMResultSet {
024:
025: private String statement;
026: private List hits;
027:
028: int startHit;
029: int endHit;
030: long hitCount;
031: long docCount;
032: int resultCount;
033:
034: /**
035: * Creates a new instance of JNDIResultSet
036: */
037: JDBCResultSet(SToken st, RDMDb database, String query,
038: RDMTransaction t) {
039: super (st, database, query, t);
040: statement = query;
041: }
042:
043: /**
044: * Prepare JDBC Search Results
045: */
046: void setJDBCSearchResult(ResultSet rs, DatabaseMetaData dmd)
047: throws RDMException {
048: startHit = 0;
049: endHit = 0;
050: hitCount = 0;
051: resultCount = 0;
052: docCount = 0;
053:
054: hits = new ArrayList();
055:
056: ResultSetMetaData rsmd;
057:
058: try {
059:
060: if (rs != null) {
061:
062: rsmd = rs.getMetaData();
063: int numOfColumns = rsmd.getColumnCount();
064:
065: while (rs.next()) {
066: SOIF s = null;
067: s = new SOIF("DOCUMENT", dmd.getURL() + " "
068: + statement);
069:
070: for (int i = 1; i < numOfColumns + 1; i++) {
071: s.insert(rsmd.getColumnName(i), rs
072: .getString(rsmd.getColumnName(i)));
073: }
074:
075: hits.add(s);
076:
077: }
078: }
079: } catch (Exception e) {
080: throw new RDMException(e);
081: }
082:
083: int i = hits.size();
084: if (i > 0) {
085: startHit = 1;
086: endHit = i;
087: hitCount = i;
088: resultCount = i;
089: docCount = i;
090: }
091:
092: }
093:
094: /**
095: * Set default attributes
096: */
097: static Set defaultView = new HashSet();
098: static {
099: defaultView.add("hl-description");
100: defaultView.add("hl-title");
101: defaultView.add("url");
102: defaultView.add("content-length");
103: }
104:
105: /**
106: * Retrieve Search Results
107: * @param i Document index
108: * @param view Attributes
109: * @param hltags Highlight tags
110: * @return a SOIF hit, highlighted and filtered by view
111: */
112: public SOIF getResult(int i, Set view, String[] hltags) {
113:
114: SOIF s = (SOIF) hits.get(i);
115:
116: if (view != null && view.contains("score"))
117: s.insert("score", "100");
118:
119: return s;
120: }
121:
122: /**
123: * Get hit count
124: * @return total number of hits for this search
125: */
126: public long getHitCount() {
127: return hitCount;
128: }
129:
130: /**
131: * Get document count
132: * @return number of docs searched
133: */
134: public long getDocCount() {
135: return hits.size();
136: }
137:
138: /**
139: * Transform the result set to string
140: * @return number of docs in this result set
141: */
142: public java.lang.String toString() {
143: return super .toString();
144: }
145:
146: /**
147: * Get search result count
148: * @return current number of hits in this set
149: */
150: public int getResultCount() {
151: return resultCount;
152: }
153:
154: }
|