KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > blog > persist > db > EntryListDatabaseTestUtils


1 /*
2  * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: EntryListDatabaseTestUtils.java,v 1.1 2007/02/01 07:31:05 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */

22
23 package org.opensubsystems.blog.persist.db;
24
25 import org.opensubsystems.blog.data.Blog;
26 import org.opensubsystems.blog.data.Entry;
27 import org.opensubsystems.blog.persist.BlogFactory;
28 import org.opensubsystems.blog.persist.EntryFactory;
29 import org.opensubsystems.core.data.DataConstant;
30 import org.opensubsystems.core.data.DataObject;
31 import org.opensubsystems.core.error.OSSException;
32 import org.opensubsystems.core.persist.DataFactoryManager;
33 import org.opensubsystems.patterns.listdata.data.ListOptions;
34 import org.opensubsystems.patterns.listdata.persist.db.ListDatabaseTestUtils;
35
36 /**
37  * Utility class to enable test list pattern implementation for blog entries.
38  *
39  * @version $Id: EntryListDatabaseTestUtils.java,v 1.1 2007/02/01 07:31:05 bastafidli Exp $
40  * @author Miro Halas
41  * @code.reviewer Miro Halas
42  * @code.reviewed Initial revision
43  */

44 public class EntryListDatabaseTestUtils extends ListDatabaseTestUtils
45 {
46    // Cached values ////////////////////////////////////////////////////////////
47

48    /**
49     * Factory to use to execute persistence operations.
50     */

51    protected BlogFactory m_blogFactory;
52
53    // Constructors /////////////////////////////////////////////////////////////
54

55    /**
56     * Constructor
57     *
58     * @throws OSSException - an error has occured
59     */

60    public EntryListDatabaseTestUtils(
61    ) throws OSSException
62    {
63       super(EntryFactory.class, BlogDatabaseSchema.class, Entry.ALL_COLUMNS,
64             Entry.COL_BLOGENTRY_CAPTION, Entry.COL_BLOGENTRY_COMMENTS);
65
66       m_blogFactory = (BlogFactory)DataFactoryManager.getInstance(
67                                                          BlogFactory.class);
68    }
69    
70    // Implemented abstract methods /////////////////////////////////////////////
71

72    /**
73     * {@inheritDoc}
74     */

75    public Object JavaDoc insertParent(
76       int iDomainId,
77       String JavaDoc str1,
78       String JavaDoc str2
79    ) throws Exception JavaDoc
80    {
81       Blog blog = new Blog(DataObject.NEW_ID, iDomainId, str1, str2,
82                            str1 + str2, null, null);
83       blog = (Blog)m_blogFactory.create(blog);
84       
85       return blog;
86    }
87
88    /**
89     * {@inheritDoc}
90     */

91    public void deleteParent(
92       Object JavaDoc parent,
93       int iDomainId
94    ) throws Exception JavaDoc
95    {
96       m_blogFactory.delete(((Blog)parent).getId(), iDomainId);
97    }
98    
99    /**
100     * {@inheritDoc}
101     */

102    public DataObject constructData(
103       Object JavaDoc parent,
104       int iDomainId,
105       String JavaDoc str1,
106       String JavaDoc str2
107    ) throws Exception JavaDoc
108    {
109       return new Entry(DataObject.NEW_ID, iDomainId, ((Blog)parent).getId(),
110                        str1, str2, str1 + str2, str2 + str1, null, null);
111    }
112
113    /**
114     * {@inheritDoc}
115     */

116    protected void deleteData(
117       Object JavaDoc parent,
118       final int iDomainId,
119       final String JavaDoc strPrefix1,
120       final String JavaDoc strPrefix2
121    ) throws Exception JavaDoc
122    {
123       deleteData(parent, iDomainId, strPrefix1, strPrefix2,
124                  "DELETE FROM " + BlogDatabaseSchema.BLOGENTRY_TABLE_NAME
125                  + " WHERE (CAPTION LIKE '" + strPrefix1
126                  + "%' OR COMMENTS LIKE '" + strPrefix2
127                  + "%') AND BLOG_ID = " + ((Blog)parent).getId()
128                  + " AND DOMAIN_ID = " + iDomainId,
129                  false);
130    }
131    
132    /**
133     * {@inheritDoc}
134     */

135    public String JavaDoc getColumnOneValue(
136       DataObject data
137    )
138    {
139       // In constructor we have specified that the first column is folder
140
return ((Entry)data).getCaption();
141    }
142
143    /**
144     * {@inheritDoc}
145     */

146    public String JavaDoc getColumnTwoValue(
147       DataObject data
148    )
149    {
150       // In constructor we have specified that the second column is caption
151
return ((Entry)data).getComments();
152    }
153
154    // Overrident methods ///////////////////////////////////////////////////////
155

156    /**
157     * {@inheritDoc}
158     */

159    public ListOptions getDefaultListOptions(
160       Object JavaDoc parent
161    ) throws OSSException
162    {
163       ListOptions options = super.getDefaultListOptions(parent);
164       
165       if (parent != null)
166       {
167          options.setParentDataType(DataConstant.BLOG_DATA_TYPE);
168          options.setParentId(((Blog)parent).getId());
169       }
170
171       return options;
172    }
173 }
174
Popular Tags