001: /*
002: * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
003: *
004: * Project: OpenSubsystems
005: *
006: * $Id: EntryListDatabaseTestUtils.java,v 1.1 2007/02/01 07:31:05 bastafidli Exp $
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License as published by
010: * the Free Software Foundation; either version 2 of the License, or
011: * (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: */
022:
023: package org.opensubsystems.blog.persist.db;
024:
025: import org.opensubsystems.blog.data.Blog;
026: import org.opensubsystems.blog.data.Entry;
027: import org.opensubsystems.blog.persist.BlogFactory;
028: import org.opensubsystems.blog.persist.EntryFactory;
029: import org.opensubsystems.core.data.DataConstant;
030: import org.opensubsystems.core.data.DataObject;
031: import org.opensubsystems.core.error.OSSException;
032: import org.opensubsystems.core.persist.DataFactoryManager;
033: import org.opensubsystems.patterns.listdata.data.ListOptions;
034: import org.opensubsystems.patterns.listdata.persist.db.ListDatabaseTestUtils;
035:
036: /**
037: * Utility class to enable test list pattern implementation for blog entries.
038: *
039: * @version $Id: EntryListDatabaseTestUtils.java,v 1.1 2007/02/01 07:31:05 bastafidli Exp $
040: * @author Miro Halas
041: * @code.reviewer Miro Halas
042: * @code.reviewed Initial revision
043: */
044: public class EntryListDatabaseTestUtils extends ListDatabaseTestUtils {
045: // Cached values ////////////////////////////////////////////////////////////
046:
047: /**
048: * Factory to use to execute persistence operations.
049: */
050: protected BlogFactory m_blogFactory;
051:
052: // Constructors /////////////////////////////////////////////////////////////
053:
054: /**
055: * Constructor
056: *
057: * @throws OSSException - an error has occured
058: */
059: public EntryListDatabaseTestUtils() throws OSSException {
060: super (EntryFactory.class, BlogDatabaseSchema.class,
061: Entry.ALL_COLUMNS, Entry.COL_BLOGENTRY_CAPTION,
062: Entry.COL_BLOGENTRY_COMMENTS);
063:
064: m_blogFactory = (BlogFactory) DataFactoryManager
065: .getInstance(BlogFactory.class);
066: }
067:
068: // Implemented abstract methods /////////////////////////////////////////////
069:
070: /**
071: * {@inheritDoc}
072: */
073: public Object insertParent(int iDomainId, String str1, String str2)
074: throws Exception {
075: Blog blog = new Blog(DataObject.NEW_ID, iDomainId, str1, str2,
076: str1 + str2, null, null);
077: blog = (Blog) m_blogFactory.create(blog);
078:
079: return blog;
080: }
081:
082: /**
083: * {@inheritDoc}
084: */
085: public void deleteParent(Object parent, int iDomainId)
086: throws Exception {
087: m_blogFactory.delete(((Blog) parent).getId(), iDomainId);
088: }
089:
090: /**
091: * {@inheritDoc}
092: */
093: public DataObject constructData(Object parent, int iDomainId,
094: String str1, String str2) throws Exception {
095: return new Entry(DataObject.NEW_ID, iDomainId, ((Blog) parent)
096: .getId(), str1, str2, str1 + str2, str2 + str1, null,
097: null);
098: }
099:
100: /**
101: * {@inheritDoc}
102: */
103: protected void deleteData(Object parent, final int iDomainId,
104: final String strPrefix1, final String strPrefix2)
105: throws Exception {
106: deleteData(parent, iDomainId, strPrefix1, strPrefix2,
107: "DELETE FROM "
108: + BlogDatabaseSchema.BLOGENTRY_TABLE_NAME
109: + " WHERE (CAPTION LIKE '" + strPrefix1
110: + "%' OR COMMENTS LIKE '" + strPrefix2
111: + "%') AND BLOG_ID = "
112: + ((Blog) parent).getId() + " AND DOMAIN_ID = "
113: + iDomainId, false);
114: }
115:
116: /**
117: * {@inheritDoc}
118: */
119: public String getColumnOneValue(DataObject data) {
120: // In constructor we have specified that the first column is folder
121: return ((Entry) data).getCaption();
122: }
123:
124: /**
125: * {@inheritDoc}
126: */
127: public String getColumnTwoValue(DataObject data) {
128: // In constructor we have specified that the second column is caption
129: return ((Entry) data).getComments();
130: }
131:
132: // Overrident methods ///////////////////////////////////////////////////////
133:
134: /**
135: * {@inheritDoc}
136: */
137: public ListOptions getDefaultListOptions(Object parent)
138: throws OSSException {
139: ListOptions options = super .getDefaultListOptions(parent);
140:
141: if (parent != null) {
142: options.setParentDataType(DataConstant.BLOG_DATA_TYPE);
143: options.setParentId(((Blog) parent).getId());
144: }
145:
146: return options;
147: }
148: }
|