1 package org.apache.ojb.ejb.odmg; 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.OJBRuntimeException; 23 import org.apache.ojb.broker.util.logging.Logger; 24 import org.apache.ojb.broker.util.logging.LoggerFactory; 25 import org.apache.ojb.ejb.ArticleVO; 26 import org.apache.ojb.ejb.CategoryVO; 27 import org.odmg.OQLQuery; 28 29 57 public class ArticleManagerODMGBean extends ODMGBaseBeanImpl implements SessionBean 58 { 59 private Logger log = LoggerFactory.getLogger(ArticleManagerODMGBean.class); 60 61 public ArticleManagerODMGBean() 62 { 63 } 64 65 68 public ArticleVO storeArticle(ArticleVO article) 69 { 70 return (ArticleVO) this.storeObject(article); 71 } 72 73 76 public Collection storeArticles(Collection articles) 77 { 78 return this.storeObjects(articles); 79 } 80 81 86 public ArticleVO failureStore(ArticleVO article) 87 { 88 storeArticle(article); 89 throw new EJBException ("# failureStore method test #"); 91 } 92 93 96 public void deleteArticle(ArticleVO article) 97 { 98 this.deleteObject(article); 99 } 100 101 104 public void deleteArticles(Collection articles) 105 { 106 this.deleteObjects(articles); 107 } 108 109 112 public int countArticles() 113 { 114 return this.getCount(ArticleVO.class); 115 } 116 117 120 public Collection getAllArticles() 121 { 122 return this.getAllObjects(ArticleVO.class); 123 } 124 125 128 public Collection getArticles(String articleName) 129 { 130 OQLQuery query = getImplementation().newOQLQuery(); 131 try 132 { 133 StringBuffer buf = new StringBuffer ("select allObjects from " + ArticleVO.class.getName()); 134 if (articleName != null) 136 buf.append(" where name = $1"); 137 else 138 buf.append(" where name is null"); 139 query.create(buf.toString()); 140 if (articleName != null) query.bind(articleName); 141 return (Collection ) query.execute(); 142 } 143 catch (Exception e) 144 { 145 log.error("OQLQuery failed", e); 146 throw new OJBRuntimeException("OQLQuery failed", e); 147 } 148 } 149 150 153 public CategoryVO storeCategory(CategoryVO category) 154 { 155 return (CategoryVO) this.storeObject(category); 156 } 157 158 161 public void deleteCategory(CategoryVO category) 162 { 163 this.deleteObject(category); 164 } 165 166 169 public Collection getCategoryByName(String categoryName) 170 { 171 OQLQuery query = getImplementation().newOQLQuery(); 172 try 173 { 174 StringBuffer buf = new StringBuffer ("select allObjects from " + CategoryVO.class.getName()); 175 if (categoryName != null) 176 buf.append(" where categoryName = $1"); 177 else 178 buf.append(" where categoryName is null"); 179 query.create(buf.toString()); 180 if (categoryName != null) query.bind(categoryName); 181 return (Collection ) query.execute(); 182 } 183 catch (Exception e) 184 { 185 log.error("OQLQuery failed", e); 186 throw new OJBRuntimeException("OQLQuery failed", e); 187 } 188 } 189 } 190 | Popular Tags |