1 package org.apache.ojb.ejb.pb; 2 3 17 18 import javax.ejb.EJBException ; 19 import javax.ejb.SessionBean ; 20 import java.util.Collection ; 21 22 import org.apache.ojb.broker.PersistenceBroker; 23 import org.apache.ojb.broker.query.Criteria; 24 import org.apache.ojb.broker.query.Query; 25 import org.apache.ojb.broker.query.QueryByCriteria; 26 import org.apache.ojb.ejb.ArticleVO; 27 import org.apache.ojb.ejb.CategoryVO; 28 29 58 public class ArticleManagerPBBean extends PBBaseBeanImpl implements SessionBean 59 { 60 public ArticleManagerPBBean() 61 { 62 } 63 64 67 public ArticleVO storeArticle(ArticleVO article) 68 { 69 return (ArticleVO) this.storeObject(article); 70 } 71 72 75 public Collection storeArticles(Collection articles) 76 { 77 return this.storeObjects(articles); 78 } 79 80 83 public void deleteArticle(ArticleVO article) 84 { 85 this.deleteObject(article); 86 } 87 88 91 public void deleteArticles(Collection articles) 92 { 93 this.deleteObjects(articles); 94 } 95 96 99 public int countArticles() 100 { 101 return this.getCount(ArticleVO.class); 102 } 103 104 107 public Collection getAllArticles() 108 { 109 return this.getAllObjects(ArticleVO.class); 110 } 111 112 117 public ArticleVO failureStore(ArticleVO article) 118 { 119 storeArticle(article); 120 throw new EJBException ("# failureStore method test #"); 122 } 123 124 127 public Collection getArticles(String articleName) 128 { 129 PersistenceBroker broker = getBroker(); 130 Collection result; 131 try 132 { 133 Criteria criteria = new Criteria(); 134 if (articleName != null) criteria.addEqualTo("name", articleName); 135 Query q = new QueryByCriteria(ArticleVO.class, criteria); 136 result = broker.getCollectionByQuery(q); 137 } 138 finally 139 { 140 if (broker != null) broker.close(); 141 } 142 return result; 143 } 144 145 148 public CategoryVO storeCategory(CategoryVO category) 149 { 150 return (CategoryVO) this.storeObject(category); 151 } 152 153 156 public void deleteCategory(CategoryVO category) 157 { 158 this.deleteObject(category); 159 } 160 161 164 public Collection getCategoryByName(String categoryName) 165 { 166 PersistenceBroker broker = getBroker(); 167 Collection result; 168 try 169 { 170 Criteria criteria = new Criteria(); 171 if (categoryName != null) criteria.addEqualTo("categoryName", categoryName); 172 Query q = new QueryByCriteria(CategoryVO.class, criteria); 173 result = broker.getCollectionByQuery(q); 174 } 175 finally 176 { 177 if (broker != null) broker.close(); 178 } 179 return result; 180 } 181 } 182 | Popular Tags |