001: /*
002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
003: C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.addrbook;
034:
035: import java.util.Date;
036: import java.sql.SQLException;
037: import java.sql.PreparedStatement;
038: import java.sql.CallableStatement;
039: import java.sql.ResultSet;
040: import java.sql.Timestamp;
041: import java.sql.Types;
042:
043: import com.knowgate.jdc.JDCConnection;
044: import com.knowgate.dataobjs.DB;
045: import com.knowgate.dataobjs.DBPersist;
046:
047: /**
048: * <p>Meeting Room or other type of Resource used at Meeting</p>
049: * @author Sergio Montoro Ten
050: * @version 1.0
051: */
052:
053: public class Room extends DBPersist {
054: public Room() {
055: super (DB.k_rooms, "Room");
056: }
057:
058: // ----------------------------------------------------------
059:
060: /**
061: * Load Room
062: * @param oConn JDCConnection
063: * @param sNmRoom String Room name
064: * @param sGuWorkArea String WorkArea Guid
065: * @return boolean
066: * @throws SQLException
067: */
068: public boolean load(JDCConnection oConn, Object sNmRoom,
069: Object sGuWorkArea) throws SQLException {
070: Object oCol;
071: clear();
072: PreparedStatement oStmt = oConn
073: .prepareStatement("SELECT " + DB.id_domain + ","
074: + DB.bo_available + "," + DB.tp_room + ","
075: + DB.nu_capacity + "," + DB.tx_company + ","
076: + DB.tx_location + "," + DB.tx_comments
077: + " FROM " + DB.k_rooms + " WHERE "
078: + DB.nm_room + "=? AND " + DB.gu_workarea
079: + "=?", ResultSet.TYPE_FORWARD_ONLY,
080: ResultSet.CONCUR_READ_ONLY);
081: oStmt.setObject(1, sNmRoom, Types.VARCHAR);
082: oStmt.setObject(2, sGuWorkArea, Types.CHAR);
083: ResultSet oRSet = oStmt.executeQuery();
084: boolean bRetVal = oRSet.next();
085: if (bRetVal) {
086: put(DB.nm_room, sNmRoom);
087: put(DB.gu_workarea, sGuWorkArea);
088: put(DB.id_domain, oRSet.getInt(1));
089: put(DB.bo_available, oRSet.getShort(2));
090: oCol = oRSet.getObject(3);
091: if (!oRSet.wasNull())
092: put(DB.tp_room, oCol);
093: oCol = oRSet.getObject(4);
094: if (!oRSet.wasNull())
095: put(DB.tp_room, oCol);
096: oCol = oRSet.getObject(5);
097: if (!oRSet.wasNull())
098: put(DB.tp_room, oCol);
099: oCol = oRSet.getObject(6);
100: if (!oRSet.wasNull())
101: put(DB.tp_room, oCol);
102: oCol = oRSet.getObject(7);
103: if (!oRSet.wasNull())
104: put(DB.tp_room, oCol);
105: }
106: oRSet.close();
107: oStmt.close();
108: return bRetVal;
109: } // load
110:
111: // ----------------------------------------------------------
112:
113: /**
114: * Load Room
115: * @param oConn JDCConnection
116: * @param NmRoomGuWrkA Object[] { Room Name, WorkArea Guid}
117: * @return boolean
118: * @throws SQLException
119: */
120: public boolean load(JDCConnection oConn, Object[] NmRoomGuWrkA)
121: throws SQLException {
122: return load(oConn, NmRoomGuWrkA[0], NmRoomGuWrkA[1]);
123: }
124:
125: // ----------------------------------------------------------
126:
127: public boolean delete(JDCConnection oConn) throws SQLException {
128:
129: return Room.delete(oConn, getString(DB.nm_room),
130: getString(DB.gu_workarea));
131: }
132:
133: // ----------------------------------------------------------
134:
135: /**
136: * Get meeting that takes place at this room on given dates
137: * @param oConn JDCConnection
138: * @param dtFrom Date From
139: * @param dtTo Date To
140: * @return String GUID of meeting taking place or <b>null</b> if room is available at that time.
141: * @throws SQLException
142: * @since 3.0
143: */
144: public String getMeetingForDate(JDCConnection oConn, Date dtFrom,
145: Date dtTo) throws SQLException {
146: String sGuMeeting;
147: Timestamp tsFrom = new Timestamp(dtFrom.getTime());
148: Timestamp tsTo = new Timestamp(dtTo.getTime());
149: PreparedStatement oStmt = oConn
150: .prepareStatement("SELECT x." + DB.gu_meeting
151: + " FROM " + DB.k_rooms + " r,"
152: + DB.k_x_meeting_room + " x WHERE r."
153: + DB.nm_room + "=x." + DB.nm_room + " AND r."
154: + DB.gu_workarea + "=? AND r." + DB.nm_room
155: + "=? AND (x." + DB.dt_start
156: + " BETWEEN ? AND ?" + "OR x." + DB.dt_end
157: + " BETWEEN ? AND ? OR (x." + DB.dt_start
158: + "<=? AND x." + DB.dt_end + ">=?))",
159: ResultSet.TYPE_FORWARD_ONLY,
160: ResultSet.CONCUR_READ_ONLY);
161: oStmt.setString(1, getString(DB.gu_workarea));
162: oStmt.setString(2, getString(DB.nm_room));
163: oStmt.setTimestamp(3, tsFrom);
164: oStmt.setTimestamp(4, tsTo);
165: oStmt.setTimestamp(5, tsFrom);
166: oStmt.setTimestamp(6, tsTo);
167: oStmt.setTimestamp(7, tsFrom);
168: oStmt.setTimestamp(8, tsTo);
169: ResultSet oRset = oStmt.executeQuery();
170: if (oRset.next())
171: sGuMeeting = oRset.getString(1);
172: else
173: sGuMeeting = null;
174: oRset.close();
175: oStmt.close();
176: return sGuMeeting;
177: } // available
178:
179: // ----------------------------------------------------------
180:
181: /**
182: * Check whether or not this room is available between two dates
183: * @param oConn JDCConnection
184: * @param dtFrom Date From
185: * @param dtTo Date To
186: * @return boolean <b>true</b> if room is available on given dates, <b>false</b> otherwise.
187: * @throws SQLException
188: * @since 3.0
189: */
190: public boolean isAvailable(JDCConnection oConn, Date dtFrom,
191: Date dtTo) throws SQLException {
192: return (getMeetingForDate(oConn, dtFrom, dtTo) == null);
193: }
194:
195: // **********************************************************
196: // Static Methods
197:
198: /**
199: * <p>Delete Room</p>
200: * Calls k_sp_del_room stored procedure
201: * @param oConn Database Connection
202: * @param sRoomNm Room Name
203: * @param sWrkAId Identifier of {@link WorkArea} to witch Room belongs
204: * @throws SQLException
205: */
206:
207: public static boolean delete(JDCConnection oConn, String sRoomNm,
208: String sWrkAId) throws SQLException {
209: boolean bRetVal;
210:
211: CallableStatement oCall = oConn
212: .prepareCall("{call k_sp_del_room ('" + sRoomNm + "','"
213: + sWrkAId + "')}");
214: bRetVal = oCall.execute();
215: oCall.close();
216:
217: return bRetVal;
218: } // delete
219:
220: // **********************************************************
221: // Variables Privadas
222:
223: public static final short ClassId = 21;
224:
225: } // Room
|