Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kew.doctype.dao.impl;
 
 import java.util.List;
 
 
 
 public class DocumentTypeDAOOjbImpl extends PersistenceBrokerDaoSupport implements DocumentTypeDAO {
 
 	public static final Logger LOG = Logger.getLogger(DocumentTypeDAOOjbImpl.class);
 
 	public void delete(DocumentType documentType) {
 		this.getPersistenceBrokerTemplate().delete(documentType);
 	}
 
 	public DocumentType findById(String docTypeId) {
 		Criteria crit = new Criteria();
 		crit.addEqualTo("documentTypeId"docTypeId);
 	}
 
 	public DocumentType findByName(String name) {
 		return findByName(nametrue);
 	}
 
     public DocumentType findByName(String nameboolean caseSensitive) {
         Criteria crit = new Criteria();
         if (!caseSensitive) {
             if (name.contains("*") || name.contains("%")) {
                 name.replace("*""%");
                 crit.addLike("UPPER(name)"name.trim().toUpperCase());
             } else {
                 crit.addEqualTo("UPPER(name)"name.trim().toUpperCase());
             }
         } else {
             if (name.contains("*")) {
                 name.replace("*""%");
                 crit.addLike("name"name.trim().toUpperCase());
             } else {
                 crit.addEqualTo("name"name);
             }
 
         }
         crit.addEqualTo("currentInd".);
                 DocumentType.classcrit));
         return docType;
     }
 
     public Integer getMaxVersionNumber(String docTypeName) {
 		return getMostRecentDocType(docTypeName).getVersion();
 	}
 
 	public List<StringgetChildDocumentTypeIds(String parentDocumentTypeId) {
 		List<StringchildrenIds = new ArrayList<String>();
 		Connection conn = null;
 		PreparedStatement st = null;
 		ResultSet rs = null;
 		try {
 			st = conn.prepareStatement("select DOC_TYP_ID from KREW_DOC_TYP_T where CUR_IND = 1 and PARNT_ID = ?");
 			st.setString(1, parentDocumentTypeId);
 			rs = st.executeQuery();
 			while (rs.next()) {
				childrenIds.add(rs.getString("DOC_TYP_ID"));
			}
catch (Exception e) {
			.error("Error occured fetching children document type ids for document type " + parentDocumentTypeIde);
			throw new RuntimeException(e);
finally {
			try {
				st.close();
catch (Exception e) {
				.warn("Failed to close Statement"e);
			}
			try {
				rs.close();
catch (Exception e) {
				.warn("Failed to close Resultset"e);
			}
        	if (broker != null) {
        		try {
        			OjbFactoryUtils.releasePersistenceBroker(brokerthis.getPersistenceBrokerTemplate().getPbKey());
        		} catch (Exception e) {
        			.error("Failed closing connection: " + e.getMessage(), e);
        		}
        	}
		}
		return childrenIds;
	}
	protected DocumentType getMostRecentDocType(String docTypeName) {
		Criteria crit = new Criteria();
		crit.addEqualTo("name"docTypeName);
		QueryByCriteria query = new QueryByCriteria(DocumentType.classcrit);
		query.addOrderByDescending("version");
		while (docTypes.hasNext()) {
			return (DocumentTypedocTypes.next();
		}
		return null;
	}
	public void save(DocumentType documentType) {
		this.getPersistenceBrokerTemplate().store(documentType);
	}
	public List findByDocumentId(String documentId) {
		Criteria crit = new Criteria();
		crit.addEqualTo("documentId"documentId);
	}
	public Collection<DocumentTypefind(DocumentType documentTypeDocumentType docTypeParentboolean climbHierarchy) {
		.debug("documentType: "documentType);
		.debug("docTypeParent: "docTypeParent);
		.debug("climbHierarchy: " + climbHierarchy);
		Criteria crit = new Criteria();
		if (documentType != null && !org.apache.commons.lang.StringUtils.isEmpty(documentType.getLabel())) {
			crit.addLike("UPPER(label)"documentType.getLabel().trim().toUpperCase());
		}
		if (documentType != null && !org.apache.commons.lang.StringUtils.isEmpty(documentType.getName())) {
			String docTypeName = documentType.getName();
			crit.addLike("UPPER(name)", ("%" + docTypeName.trim() + "%").toUpperCase());
		}
		if (documentType != null && documentType.getActive() != null) {
			crit.addEqualTo("active"documentType.getActive());
		}
		if (documentType != null && documentType.getDocumentTypeId() != null) {
			crit.addEqualTo("documentTypeId"documentType.getDocumentTypeId());
		}
		if (documentType != null && documentType.getActualApplicationId() != null){
			crit.addEqualTo("actualApplicationIde"documentType.getActualApplicationId());
		}
		if (docTypeParent != null) {
			if (!"".equals(docTypeParent.getName()) && docTypeParent.getName() != null) {
				Criteria parentCrit = new Criteria();
				//addParentNameOrCriteria(docTypeParent.getName(), parentCrit);
				addParentIdOrCriteria(docTypeParent.getDocumentTypeId(), parentCrit);
				if (climbHierarchy) {
					assembleChildrenCriteria(docTypeParent.getChildrenDocTypes(), parentCrit);
				}
				parentCrit.addEqualTo("currentInd".);
				crit.addAndCriteria(parentCrit);
			}
else {
			if (documentType != null && !org.apache.commons.lang.StringUtils.isEmpty(documentType.getName())) {
				DocumentType searchDocumentType = findByName(documentType.getName());
				if ((searchDocumentType != null) && climbHierarchy) {
					.debug("searchDocumentType: "searchDocumentType);
					Criteria criteria = new Criteria();
					//addParentNameOrCriteria(searchDocumentType.getName(), criteria);
                    addParentIdOrCriteria(searchDocumentType.getDocumentTypeId(), criteria);
                    assembleChildrenCriteria(searchDocumentType.getChildrenDocTypes(), criteria);
					criteria.addEqualTo("currentInd".);
					crit.addOrCriteria(criteria);
				}
			}
		}
		crit.addEqualTo("currentInd".);
	}
    private void addParentIdOrCriteria(String parentIdCriteria mainCriteria) {
        Criteria parentCriteria = new Criteria();
        parentCriteria.addEqualTo("docTypeParentId"parentId);
        mainCriteria.addOrCriteria(parentCriteria);
    }
	private void assembleChildrenCriteria(Collection childrenDocTypesCriteria crit) {
		if (childrenDocTypes != null) {
			Iterator childrenDocTypesIter = childrenDocTypes.iterator();
			while (childrenDocTypesIter.hasNext()) {
				DocumentType child = (DocumentTypechildrenDocTypesIter.next();
			}
		}
	}
		Criteria crit = new Criteria();
		crit.addIsNull("docTypeParentId");
		return findAllCurrent(crit);
	}
    public List<DocumentTypefindAllCurrent() {
	return findAllCurrent(new Criteria());
    }
    public List<DocumentTypefindAllCurrentByName(String name) {
	Criteria crit = new Criteria();
	crit.addEqualTo("name"name);
	return findAllCurrent(crit);
    }
    public List<DocumentTypefindPreviousInstances(String documentTypeName) {
        Criteria crit = new Criteria();
        crit.addEqualTo("name"documentTypeName);
        crit.addEqualTo("currentInd".);
        return findAll(crit);
    }
    private List<DocumentTypefindAllCurrent(Criteria crit) {
        crit.addEqualTo("currentInd".);
        return findAll(crit);
    }
    private List<DocumentTypefindAll(Criteria crit) {
    }
    public List findDocumentTypeAttributes(RuleAttribute ruleAttribute) {
    	Criteria crit = new Criteria();
    	crit.addEqualTo("ruleAttributeId"ruleAttribute.getId());
    }
    public String findDocumentTypeIdByDocumentId(String documentId) {
    	Criteria crit = new Criteria();
    	crit.addEqualTo("documentId"documentId);
    	ReportQueryByCriteria query = QueryFactory.newReportQuery(DocumentRouteHeaderValue.classcrit);
    	query.setAttributes(new String[] { "documentTypeId" });
        try {
            while (iter.hasNext()) {
                Object[] row = (Object[]) iter.next();
                return (String)row[0];
            }
    	} finally {
    	    iter.releaseDbResources();
    	}
    	return null;
    }
    
    public String findDocumentTypeIdByName(String documentTypeName) {
    	Criteria crit = new Criteria();
    	crit.addEqualTo("name"documentTypeName);
        crit.addEqualTo("currentInd".);
    	ReportQueryByCriteria query = QueryFactory.newReportQuery(DocumentType.classcrit);
    	query.setAttributes(new String[] { "documentTypeId" });
    	try {
    		while (iter.hasNext()) {
    			Object[] row = (Object[]) iter.next();
    			return (String)row[0];
    		}
    	} finally {
    		iter.releaseDbResources();
    	}
    	return null;
    }
    
    public String findDocumentTypeNameById(String documentTypeId) {
        Criteria crit = new Criteria();
        crit.addEqualTo("documentTypeId"documentTypeId);
        ReportQueryByCriteria query = QueryFactory.newReportQuery(DocumentType.classcrit);
        query.setAttributes(new String[] { "name" });
        try {
            while (iter.hasNext()) {
                Object[] row = (Object[]) iter.next();
                return (String)row[0];
            }
        } finally {
            iter.releaseDbResources();
        }
        return null;
    }
New to GrepCode? Check out our FAQ X