1 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 44 public class EntryListDatabaseTestUtils extends ListDatabaseTestUtils 45 { 46 48 51 protected BlogFactory m_blogFactory; 52 53 55 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 72 75 public Object insertParent( 76 int iDomainId, 77 String str1, 78 String str2 79 ) throws Exception 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 91 public void deleteParent( 92 Object parent, 93 int iDomainId 94 ) throws Exception 95 { 96 m_blogFactory.delete(((Blog)parent).getId(), iDomainId); 97 } 98 99 102 public DataObject constructData( 103 Object parent, 104 int iDomainId, 105 String str1, 106 String str2 107 ) throws Exception 108 { 109 return new Entry(DataObject.NEW_ID, iDomainId, ((Blog)parent).getId(), 110 str1, str2, str1 + str2, str2 + str1, null, null); 111 } 112 113 116 protected void deleteData( 117 Object parent, 118 final int iDomainId, 119 final String strPrefix1, 120 final String strPrefix2 121 ) throws Exception 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 135 public String getColumnOneValue( 136 DataObject data 137 ) 138 { 139 return ((Entry)data).getCaption(); 141 } 142 143 146 public String getColumnTwoValue( 147 DataObject data 148 ) 149 { 150 return ((Entry)data).getComments(); 152 } 153 154 156 159 public ListOptions getDefaultListOptions( 160 Object 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 |