001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.notes.dao.impl;
017
018 import java.util.List;
019
020 import org.apache.ojb.broker.query.Criteria;
021 import org.apache.ojb.broker.query.QueryByCriteria;
022 import org.kuali.rice.kew.notes.Attachment;
023 import org.kuali.rice.kew.notes.Note;
024 import org.kuali.rice.kew.notes.dao.NoteDAO;
025 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
026
027
028 public class NoteDAOOjbImpl extends PersistenceBrokerDaoSupport implements NoteDAO {
029
030 public Note getNoteByNoteId(String noteId) {
031 Criteria crit = new Criteria();
032 crit.addEqualTo("noteId", noteId);
033 return (Note) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(Note.class, crit));
034 }
035
036 public List getNotesByDocumentId(String documentId) {
037 Criteria crit = new Criteria();
038 crit.addEqualTo("documentId", documentId);
039 QueryByCriteria query = new QueryByCriteria(Note.class, crit);
040 query.addOrderByAscending("noteId");
041 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
042 }
043
044 public void saveNote(Note note) {
045 this.getPersistenceBrokerTemplate().store(note);
046 }
047
048 public void deleteNote(Note note) {
049 Criteria crit = new Criteria();
050 crit.addEqualTo("noteId", note.getNoteId());
051 this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(Note.class, crit));
052 }
053
054 public void deleteAttachment(Attachment attachment) {
055 Criteria crit = new Criteria();
056 crit.addEqualTo("attachmentId", attachment.getAttachmentId());
057 this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(Attachment.class, crit));
058 }
059
060
061 public Attachment findAttachment(String attachmentId) {
062 Criteria crit = new Criteria();
063 crit.addEqualTo("attachmentId", attachmentId);
064 return (Attachment)this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(Attachment.class, crit));
065 }
066
067 }