001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on 24/05/2004 / 12:04:11
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.dao.oracle;
044:
045: import java.sql.PreparedStatement;
046: import java.sql.ResultSet;
047: import java.sql.SQLException;
048: import java.util.List;
049:
050: import net.jforum.JForumExecutionContext;
051: import net.jforum.dao.generic.GenericPostDAO;
052: import net.jforum.entities.Post;
053: import net.jforum.exceptions.DatabaseException;
054: import net.jforum.util.DbUtils;
055: import net.jforum.util.preferences.SystemGlobals;
056:
057: /**
058: * @author Dmitriy Kiriy
059: * @version $Id: OraclePostDAO.java,v 1.12 2007/08/31 22:56:40 rafaelsteil Exp $
060: */
061: public class OraclePostDAO extends GenericPostDAO {
062: /**
063: * @see net.jforum.dao.generic.GenericPostDAO#addNewPostText(net.jforum.entities.Post)
064: */
065: protected void addNewPostText(Post post) throws Exception {
066: PreparedStatement p = null;
067:
068: try {
069: p = JForumExecutionContext
070: .getConnection()
071: .prepareStatement(
072: SystemGlobals
073: .getSql("PostModel.addNewPostText"));
074: p.setInt(1, post.getId());
075: p.setString(2, post.getSubject());
076: p.executeUpdate();
077: p.close();
078:
079: OracleUtils.writeBlobUTF16BinaryStream(SystemGlobals
080: .getSql("PostModel.addNewPostTextField"), post
081: .getId(), post.getText());
082: } finally {
083: DbUtils.close(p);
084: }
085: }
086:
087: /**
088: * @see net.jforum.dao.generic.GenericPostDAO#updatePostsTextTable(net.jforum.entities.Post)
089: */
090: protected void updatePostsTextTable(Post post) {
091: PreparedStatement p = null;
092:
093: try {
094: p = JForumExecutionContext
095: .getConnection()
096: .prepareStatement(
097: SystemGlobals
098: .getSql("PostModel.updatePostText"));
099: p.setString(1, post.getSubject());
100: p.setInt(2, post.getId());
101:
102: p.executeUpdate();
103:
104: OracleUtils.writeBlobUTF16BinaryStream(SystemGlobals
105: .getSql("PostModel.addNewPostTextField"), post
106: .getId(), post.getText());
107: } catch (Exception e) {
108: throw new DatabaseException(e);
109: } finally {
110: DbUtils.close(p);
111: }
112: }
113:
114: /**
115: * @see net.jforum.dao.generic.GenericPostDAO#getPostTextFromResultSet(java.sql.ResultSet)
116: */
117: protected String getPostTextFromResultSet(ResultSet rs)
118: throws SQLException {
119: return OracleUtils.readBlobUTF16BinaryStream(rs, "post_text");
120: }
121:
122: /**
123: * @see net.jforum.dao.PostDAO#selectAllByTopicByLimit(int, int, int)
124: */
125: public List selectAllByTopicByLimit(int topicId, int startFrom,
126: int count) {
127: return super .selectAllByTopicByLimit(topicId, startFrom,
128: startFrom + count);
129: }
130:
131: /**
132: * @see net.jforum.dao.PostDAO#selectByUserByLimit(int, int, int)
133: */
134: public List selectByUserByLimit(int userId, int startFrom, int count) {
135: return super.selectByUserByLimit(userId, startFrom, startFrom
136: + count);
137: }
138: }
|