001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.rm.resources.workflow.properties.domains;
020:
021: import java.sql.*;
022: import java.util.*;
023:
024: import org.openharmonise.commons.dsi.*;
025: import org.openharmonise.commons.dsi.dml.*;
026: import org.openharmonise.commons.dsi.dml.functions.*;
027: import org.openharmonise.rm.DataAccessException;
028: import org.openharmonise.rm.resources.*;
029: import org.openharmonise.rm.resources.metadata.properties.Property;
030: import org.openharmonise.rm.resources.metadata.properties.domains.Domain;
031: import org.openharmonise.rm.resources.workflow.properties.WorkflowProperty;
032:
033: /**
034: * Represents a domain which applies specifically to a <code>WorkflowProperty</code>.
035: *
036: * @author Michael Bell
037: * @version $Revision: 1.2 $
038: *
039: */
040: public class WorkflowPropertyDomain extends Domain {
041:
042: public static boolean validate(WorkflowProperty prop, Domain domain)
043: throws DataAccessException {
044: boolean bIsValid = true;
045:
046: List domainDetails = domain.getDetails();
047:
048: if (domainDetails.size() > 0) {
049:
050: ResultSet rs = null;
051: try {
052: SelectStatement select = new SelectStatement();
053:
054: select.addSelectColumn(Domain.getColumnRef(
055: CLMN_DOMAIN_ID, false));
056: select.addWhereCondition(prop.getInstanceColumnRef(
057: Property.ATTRIB_TYPE, false), "=",
058: WorkflowProperty.class.getName());
059: select.addJoinCondition(prop.getInstanceColumnRef(
060: AbstractObject.ATTRIB_KEY, false), Domain
061: .getColumnRef(CLMN_PROPERTY_KEY, false));
062:
063: ColumnRef domainDetailsCol = Domain
064: .getDetailsColumnRef(CLMN_DOMAIN_DETAILS, false);
065: if (domainDetails.size() > 1) {
066: WhereConditionGroup wheres = new WhereConditionGroup();
067: for (Iterator iter = domainDetails.iterator(); iter
068: .hasNext();) {
069: String detail = (String) iter.next();
070: wheres.addCondition(domainDetailsCol,
071: "STARTS_WITH", detail);
072: Substring substr = new Substring(detail,
073: new Integer(1), new Length(
074: domainDetailsCol));
075: wheres.addCondition(domainDetailsCol, "=",
076: substr);
077: }
078: wheres.setStringingOperator("or");
079: select.addWhereCondition(wheres);
080: } else {
081: WhereConditionGroup wheres = new WhereConditionGroup();
082:
083: Substring substr = new Substring(
084: (String) domainDetails.get(0), new Integer(
085: 1), new Length(domainDetailsCol));
086:
087: wheres.addCondition(domainDetailsCol, "=", substr);
088: wheres.addCondition(domainDetailsCol,
089: "STARTS_WITH", domainDetails.get(0));
090:
091: wheres.setStringingOperator("or");
092: select.addWhereCondition(wheres);
093: }
094:
095: select.addJoinCondition(Domain.getColumnRef(
096: CLMN_DOMAIN_ID, false), Domain
097: .getDetailsColumnRef(CLMN_DETAILS_DOMAIN_ID,
098: false));
099: select.addWhereCondition(Domain.getColumnRef(
100: CLMN_DOMAIN_OBJECT, false), "=", domain
101: .getDomainClass());
102:
103: if (prop.getKey() != Property.NOTDBSAVED_KEY) {
104: Property liveVer = (Property) prop.getLiveVersion();
105: if (liveVer != null) {
106: select
107: .addWhereCondition(
108: prop
109: .getInstanceColumnRef(
110: AbstractObject.ATTRIB_ID,
111: false), "!=",
112: liveVer.getId());
113: select
114: .addWhereCondition(
115: prop
116: .getInstanceColumnRef(
117: AbstractEditableObject.TAG_LIVE_VERSION,
118: false), "!=",
119: liveVer.getId());
120:
121: } else {
122: select
123: .addWhereCondition(
124: prop
125: .getInstanceColumnRef(
126: AbstractObject.ATTRIB_ID,
127: false), "!=",
128: prop.getId());
129:
130: }
131: }
132: rs = prop.getDataStoreInterface().execute(select);
133:
134: if (rs.next()) {
135: bIsValid = false;
136: }
137: } catch (DataStoreException e) {
138: throw new DataAccessException(e);
139: } catch (SQLException e) {
140: throw new DataAccessException(e);
141: } finally {
142: if (rs != null) {
143: try {
144: rs.close();
145: } catch (SQLException e) {
146: throw new DataAccessException(e);
147: }
148: }
149: }
150: }
151:
152: return bIsValid;
153: }
154:
155: }
|