diff options
Diffstat (limited to 'plugins')
61 files changed, 3436 insertions, 199 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchData.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchData.java new file mode 100644 index 00000000000..9ec77a051e2 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchData.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds; + +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.orcs.data.HasLocalId; + +/** + * @author Roberto E. Escobar + */ +public interface BranchData extends HasLocalId { + + void setLocalId(int id); + + String getGuid(); + + void setGuid(String guid); + + String getName(); + + void setName(String name); + + int getAssociatedArtifactId(); + + void setAssociatedArtifactId(int artId); + + int getBaseTransaction(); + + void setBaseTransaction(int baseTx); + + int getSourceTransaction(); + + void setSourceTransaction(int sourceTx); + + int getParentBranch(); + + void setParentBranch(int parent); + + boolean hasParentBranch(); + + BranchArchivedState getArchiveState(); + + void setArchiveState(BranchArchivedState state); + + BranchState getBranchState(); + + void setBranchState(BranchState state); + + BranchType getBranchType(); + + void setBranchType(BranchType type); + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandler.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandler.java index 036f118457f..fa450f1f0a6 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandler.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandler.java @@ -21,6 +21,8 @@ public interface LoadDataHandler extends AttributeDataMatchHandler { void onLoadDescription(LoadDescription data) throws OseeCoreException; + void onData(BranchData data) throws OseeCoreException; + void onData(ArtifactData data) throws OseeCoreException; void onData(AttributeData data) throws OseeCoreException; diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandlerAdapter.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandlerAdapter.java index c696bdc922a..183fbf8b6a2 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandlerAdapter.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandlerAdapter.java @@ -32,6 +32,12 @@ public class LoadDataHandlerAdapter implements LoadDataHandler { @Override @SuppressWarnings("unused") + public void onData(BranchData data) throws OseeCoreException { + // + } + + @Override + @SuppressWarnings("unused") public void onData(ArtifactData data) throws OseeCoreException { // } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandlerDecorator.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandlerDecorator.java index b5fe2bbb539..ad9af34b0ab 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandlerDecorator.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/LoadDataHandlerDecorator.java @@ -54,6 +54,13 @@ public class LoadDataHandlerDecorator extends LoadDataHandlerAdapter { } @Override + public void onData(BranchData data) throws OseeCoreException { + if (handler != null) { + handler.onData(data); + } + } + + @Override public void onData(ArtifactData data) throws OseeCoreException { if (handler != null) { handler.onData(data); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/OptionsUtil.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/OptionsUtil.java index 5ee9dbc3cb6..c8e4d464e58 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/OptionsUtil.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/OptionsUtil.java @@ -26,6 +26,14 @@ public final class OptionsUtil { private static final String INCLUDE_CACHE = "include.cache"; private static final String LOAD_LEVEL = "load.level"; + public static Options createBranchOptions() { + Options options = new Options(); + setIncludeCache(options, false); + setIncludeDeleted(options, false); + setLoadLevel(options, LoadLevel.SHALLOW); + return options; + } + public static Options createOptions() { Options options = new Options(); setIncludeCache(options, false); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java index 5ae0c9c3738..133f21ee7c4 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java @@ -22,4 +22,8 @@ public interface QueryEngine { CancellableCallable<Integer> createArtifactQuery(OrcsSession session, QueryData queryData, LoadDataHandler handler); + CancellableCallable<Integer> createBranchCount(OrcsSession session, QueryData queryData); + + CancellableCallable<Integer> createBranchQuery(OrcsSession session, QueryData queryData, LoadDataHandler handler); + } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAllBranches.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAllBranches.java new file mode 100644 index 00000000000..b617fbe07ab --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAllBranches.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaAllBranches extends Criteria { + + public CriteriaAllBranches() { + super(); + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + } + + @Override + public String toString() { + return "CriteriaAllBranches"; + } +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchArchived.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchArchived.java new file mode 100644 index 00000000000..652e8697375 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchArchived.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import java.util.Collection; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaBranchArchived extends Criteria { + + private final Collection<BranchArchivedState> state; + + public CriteriaBranchArchived(Collection<BranchArchivedState> state) { + super(); + this.state = state; + } + + public Collection<BranchArchivedState> getStates() { + return state; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + Conditions.checkNotNullOrEmpty(getStates(), "branch archived state"); + } + + @Override + public String toString() { + return "CriteriaBranchArchived [archivedState=" + state + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchChildOf.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchChildOf.java new file mode 100644 index 00000000000..39d4e9cc8d0 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchChildOf.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaBranchChildOf extends Criteria { + + private final IOseeBranch parent; + + public CriteriaBranchChildOf(IOseeBranch parent) { + super(); + this.parent = parent; + } + + public IOseeBranch getParent() { + return parent; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + Conditions.checkNotNull(getParent(), "Parent branch"); + } + + @Override + public String toString() { + return "CriteriaBranchChildOf [parent=" + parent + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchIds.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchIds.java new file mode 100644 index 00000000000..61bdb48562b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchIds.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import java.util.Collection; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaBranchIds extends Criteria { + + private final Collection<Integer> ids; + + public CriteriaBranchIds(Collection<Integer> ids) { + super(); + this.ids = ids; + } + + public Collection<Integer> getIds() { + return ids; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + Conditions.checkExpressionFailOnTrue(getIds().isEmpty(), "Branch Ids cannot be empty"); + } + + @Override + public String toString() { + return "CriteriaBranchIds [ids=" + ids + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchName.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchName.java new file mode 100644 index 00000000000..be3e1286fdc --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchName.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaBranchName extends Criteria { + + private final boolean isPattern; + private final String value; + + public CriteriaBranchName(String value, boolean isPattern) { + super(); + this.value = value; + this.isPattern = isPattern; + } + + public boolean isPattern() { + return isPattern; + } + + public String getValue() { + return value; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + Conditions.checkNotNullOrEmpty(getValue(), "branch name value"); + } + + @Override + public String toString() { + return "CriteriaBranchName [isPattern=" + isPattern + ", value=" + value + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchState.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchState.java new file mode 100644 index 00000000000..33ecc88ccfb --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchState.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import java.util.Collection; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaBranchState extends Criteria { + + private final Collection<BranchState> states; + + public CriteriaBranchState(Collection<BranchState> states) { + super(); + this.states = states; + } + + public Collection<BranchState> getStates() { + return states; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + Conditions.checkExpressionFailOnTrue(getStates().isEmpty(), "Branch States cannot be empty"); + } + + @Override + public String toString() { + return "CriteriaBranchState [states=" + states + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchToSearch.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchToSearch.java new file mode 100644 index 00000000000..6e4d97e51a4 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchToSearch.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; +import org.eclipse.osee.orcs.data.HasBranch; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaBranchToSearch extends Criteria implements HasBranch { + + private final IOseeBranch branch; + + public CriteriaBranchToSearch(IOseeBranch branch) { + super(); + this.branch = branch; + } + + @Override + public IOseeBranch getBranch() { + return branch; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + } + + @Override + public String toString() { + return "CriteriaBranchToSearch [branch=" + branch + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchType.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchType.java new file mode 100644 index 00000000000..af67576f6fb --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchType.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import java.util.Collection; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaBranchType extends Criteria { + + private final Collection<BranchType> types; + + public CriteriaBranchType(Collection<BranchType> types) { + super(); + this.types = types; + } + + public Collection<BranchType> getTypes() { + return types; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + Conditions.checkExpressionFailOnTrue(getTypes().isEmpty(), "Branch Types cannot be empty"); + } + + @Override + public String toString() { + return "CriteriaBranchType [types=" + types + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchUuids.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchUuids.java new file mode 100644 index 00000000000..7edecaf5f21 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaBranchUuids.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.ds.criteria; + +import java.util.Collection; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.Options; + +/** + * @author Roberto E. Escobar + */ +public class CriteriaBranchUuids extends Criteria { + + private final Collection<String> ids; + + public CriteriaBranchUuids(Collection<String> ids) { + super(); + this.ids = ids; + } + + public Collection<String> getIds() { + return ids; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + Conditions.checkExpressionFailOnTrue(getIds().isEmpty(), "Branch Ids cannot be empty"); + } + + @Override + public String toString() { + return "CriteriaBranchUuids [ids=" + ids + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchCallableQueryFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchCallableQueryFactory.java new file mode 100644 index 00000000000..ad5952f1196 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchCallableQueryFactory.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.internal.search; + +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.eclipse.osee.executor.admin.CancellableCallable; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.ResultSet; +import org.eclipse.osee.framework.core.data.ResultSetList; +import org.eclipse.osee.framework.core.data.TokenFactory; +import org.eclipse.osee.framework.core.enums.LoadLevel; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsSession; +import org.eclipse.osee.orcs.core.ds.BranchData; +import org.eclipse.osee.orcs.core.ds.LoadDataHandlerAdapter; +import org.eclipse.osee.orcs.core.ds.OptionsUtil; +import org.eclipse.osee.orcs.core.ds.QueryCollector; +import org.eclipse.osee.orcs.core.ds.QueryData; +import org.eclipse.osee.orcs.core.ds.QueryEngine; +import org.eclipse.osee.orcs.data.BranchReadable; + +/** + * @author Roberto E. Escobar + */ +public class BranchCallableQueryFactory { + + private final Log logger; + private final QueryEngine queryEngine; + private final QueryCollector collector; + + public BranchCallableQueryFactory(Log logger, QueryEngine queryEngine, QueryCollector collector) { + super(); + this.logger = logger; + this.queryEngine = queryEngine; + this.collector = collector; + } + + public CancellableCallable<Integer> createBranchCount(OrcsSession session, QueryData queryData) { + return new AbstractSearchCallable<Integer>(session, queryData) { + @Override + protected Integer innerCall() throws Exception { + Integer results = queryEngine.createBranchCount(getSession(), getQueryData()).call(); + setItemsFound(results); + return results; + } + }; + } + + public CancellableCallable<ResultSet<BranchReadable>> createBranchSearch(OrcsSession session, QueryData queryData) { + return new AbstractSearchCallable<ResultSet<BranchReadable>>(session, queryData) { + + @Override + protected ResultSet<BranchReadable> innerCall() throws Exception { + BranchBuilder<BranchReadable> handler = new BranchBuilder<BranchReadable>() { + @Override + public BranchReadable createBranch(BranchData data) { + // For now we assume the row is also readable + // This will change once write branch API is added. + return (BranchReadable) data; + } + }; + OptionsUtil.setLoadLevel(getQueryData().getOptions(), LoadLevel.FULL); + queryEngine.createBranchQuery(getSession(), getQueryData(), handler).call(); + List<BranchReadable> results = handler.getBranches(); + setItemsFound(results.size()); + return new ResultSetList<BranchReadable>(results); + } + }; + } + + public CancellableCallable<ResultSet<IOseeBranch>> createBranchAsIdSearch(OrcsSession session, QueryData queryData) { + return new AbstractSearchCallable<ResultSet<IOseeBranch>>(session, queryData) { + + @Override + protected ResultSet<IOseeBranch> innerCall() throws Exception { + BranchBuilder<IOseeBranch> handler = new BranchBuilder<IOseeBranch>() { + + @Override + public IOseeBranch createBranch(BranchData data) { + return TokenFactory.createBranch(data.getGuid(), data.getName()); + } + + }; + OptionsUtil.setLoadLevel(getQueryData().getOptions(), LoadLevel.FULL); + queryEngine.createBranchQuery(getSession(), getQueryData(), handler).call(); + List<IOseeBranch> results = handler.getBranches(); + setItemsFound(results.size()); + return new ResultSetList<IOseeBranch>(results); + } + }; + } + + private abstract class BranchBuilder<T extends IOseeBranch> extends LoadDataHandlerAdapter { + + private Map<String, T> branchMap; + private List<T> results; + + @Override + public void onLoadStart() throws OseeCoreException { + super.onLoadStart(); + branchMap = new LinkedHashMap<String, T>(); + } + + @Override + public void onLoadEnd() throws OseeCoreException { + super.onLoadEnd(); + results = new LinkedList<T>(branchMap.values()); + branchMap.clear(); + } + + @Override + public void onData(BranchData data) throws OseeCoreException { + String key = data.getGuid(); + T branch = branchMap.get(key); + if (branch == null) { + branch = createBranch(data); + branchMap.put(key, branch); + } + } + + public List<T> getBranches() { + return results; + } + + public abstract T createBranch(BranchData data) throws OseeCoreException; + + } + + private abstract class AbstractSearchCallable<T> extends CancellableCallable<T> { + + private final OrcsSession session; + private final QueryData queryData; + private int itemsFound = 0; + + public AbstractSearchCallable(OrcsSession session, QueryData queryData) { + super(); + this.session = session; + this.queryData = queryData; + } + + protected OrcsSession getSession() { + return session; + } + + protected QueryData getQueryData() { + return queryData; + } + + protected void setItemsFound(int itemsFound) { + this.itemsFound = itemsFound; + } + + @Override + public final T call() throws Exception { + long startTime = System.currentTimeMillis(); + long endTime = startTime; + T result = null; + try { + if (logger.isTraceEnabled()) { + logger.trace("%s [start] - [%s]", getClass().getSimpleName(), queryData); + } + result = innerCall(); + } finally { + endTime = System.currentTimeMillis() - startTime; + } + if (result != null) { + notifyStats(endTime); + } + if (logger.isTraceEnabled()) { + logger.trace("%s [%s] - completed [%s]", getClass().getSimpleName(), Lib.asTimeString(endTime), queryData); + } + return result; + } + + private void notifyStats(long processingTime) { + if (collector != null) { + try { + collector.collect(session, itemsFound, processingTime, queryData); + } catch (Exception ex) { + logger.error(ex, "Error reporting search to search collector\n%s", queryData); + } + } + } + + protected abstract T innerCall() throws Exception; + + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchCriteriaFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchCriteriaFactory.java new file mode 100644 index 00000000000..03101e46d51 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchCriteriaFactory.java @@ -0,0 +1,54 @@ +package org.eclipse.osee.orcs.core.internal.search; + +import java.util.Collection; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAllBranches; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchArchived; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchChildOf; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchIds; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchName; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchState; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchType; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchUuids; + +/** + * @author Roberto E. Escobar + */ +public class BranchCriteriaFactory { + + public Criteria createAllBranchesCriteria() { + return new CriteriaAllBranches(); + } + + public Criteria createBranchIdsCriteria(Collection<Integer> ids) { + return new CriteriaBranchIds(ids); + } + + public Criteria createBranchUuidsCriteria(Collection<String> ids) { + return new CriteriaBranchUuids(ids); + } + + public Criteria createBranchTypeCriteria(Collection<BranchType> types) { + return new CriteriaBranchType(types); + } + + public Criteria createBranchStateCriteria(Collection<BranchState> states) { + return new CriteriaBranchState(states); + } + + public Criteria createBranchNameCriteria(String value, boolean isPattern) { + return new CriteriaBranchName(value, isPattern); + } + + public Criteria createBranchChildOfCriteria(IOseeBranch parent) { + return new CriteriaBranchChildOf(parent); + } + + public Criteria createBranchArchivedCriteria(Collection<BranchArchivedState> states) { + return new CriteriaBranchArchived(states); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchQueryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchQueryImpl.java new file mode 100644 index 00000000000..1b593e24662 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchQueryImpl.java @@ -0,0 +1,259 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.core.internal.search; + +import static org.eclipse.osee.framework.core.enums.BranchArchivedState.UNARCHIVED; +import static org.eclipse.osee.framework.core.enums.BranchState.DELETED; +import static org.eclipse.osee.framework.core.enums.BranchState.DELETE_IN_PROGRESS; +import static org.eclipse.osee.framework.core.enums.BranchState.PURGED; +import static org.eclipse.osee.framework.core.enums.BranchState.PURGE_IN_PROGRESS; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import org.eclipse.osee.executor.admin.CancellableCallable; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.ResultSet; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.orcs.OrcsSession; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.CriteriaSet; +import org.eclipse.osee.orcs.core.ds.Options; +import org.eclipse.osee.orcs.core.ds.OptionsUtil; +import org.eclipse.osee.orcs.core.ds.QueryData; +import org.eclipse.osee.orcs.data.BranchReadable; +import org.eclipse.osee.orcs.search.BranchQuery; + +/** + * @author Roberto E. Escobar + */ +public class BranchQueryImpl implements BranchQuery { + + private final BranchCallableQueryFactory queryFactory; + private final BranchCriteriaFactory criteriaFactory; + private final OrcsSession session; + private final QueryData queryData; + private boolean includeArchived; + + public BranchQueryImpl(BranchCallableQueryFactory queryFactory, BranchCriteriaFactory criteriaFactory, OrcsSession session, QueryData queryData) { + this.queryFactory = queryFactory; + this.criteriaFactory = criteriaFactory; + this.session = session; + this.queryData = queryData; + } + + private QueryData getQueryData() { + return queryData; + } + + private Options getOptions() { + return queryData.getOptions(); + } + + @Override + public BranchQuery includeDeleted() { + includeDeleted(true); + return this; + } + + @Override + public BranchQuery excludeDeleted() { + includeDeleted(false); + return this; + } + + @Override + public BranchQuery includeDeleted(boolean enabled) { + OptionsUtil.setIncludeDeleted(getOptions(), enabled); + return this; + } + + @Override + public boolean areDeletedIncluded() { + return OptionsUtil.areDeletedIncluded(getOptions()); + } + + @Override + public BranchQuery includeArchived() { + includeArchived(true); + return this; + } + + @Override + public BranchQuery includeArchived(boolean enabled) { + includeArchived = enabled; + return this; + } + + @Override + public BranchQuery excludeArchived() { + includeArchived(false); + return this; + } + + @Override + public boolean areArchivedIncluded() { + return includeArchived; + } + + @Override + public BranchQuery andLocalId(int... ids) throws OseeCoreException { + Set<Integer> allIds = new HashSet<Integer>(); + for (Integer id : ids) { + allIds.add(id); + } + return andLocalIds(allIds); + } + + @Override + public BranchQuery andLocalIds(Collection<Integer> ids) throws OseeCoreException { + Criteria criteria = criteriaFactory.createBranchIdsCriteria(ids); + return addAndCheck(getQueryData(), criteria); + } + + @Override + public BranchQuery andUuids(String... ids) throws OseeCoreException { + return andUuids(Arrays.asList(ids)); + } + + @Override + public BranchQuery andUuids(Collection<String> ids) throws OseeCoreException { + Criteria criteria = criteriaFactory.createBranchUuidsCriteria(ids); + return addAndCheck(getQueryData(), criteria); + } + + @Override + public BranchQuery andIds(IOseeBranch... ids) throws OseeCoreException { + return andIds(Arrays.asList(ids)); + } + + @Override + public BranchQuery andIds(Collection<? extends IOseeBranch> ids) throws OseeCoreException { + Set<String> allIds = new HashSet<String>(); + for (IOseeBranch token : ids) { + allIds.add(token.getGuid()); + } + Criteria criteria = criteriaFactory.createBranchUuidsCriteria(allIds); + return addAndCheck(getQueryData(), criteria); + } + + @Override + public BranchQuery andIsOfType(BranchType... branchType) throws OseeCoreException { + Criteria criteria = criteriaFactory.createBranchTypeCriteria(Arrays.asList(branchType)); + return addAndCheck(getQueryData(), criteria); + } + + @Override + public BranchQuery andStateIs(BranchState... branchState) throws OseeCoreException { + Criteria criteria = criteriaFactory.createBranchStateCriteria(Arrays.asList(branchState)); + return addAndCheck(getQueryData(), criteria); + } + + @Override + public BranchQuery andNameEquals(String value) throws OseeCoreException { + Criteria criteria = criteriaFactory.createBranchNameCriteria(value, false); + return addAndCheck(getQueryData(), criteria); + } + + @Override + public BranchQuery andNamePattern(String pattern) throws OseeCoreException { + Criteria criteria = criteriaFactory.createBranchNameCriteria(pattern, true); + return addAndCheck(getQueryData(), criteria); + } + + @Override + public BranchQuery andIsChildOf(IOseeBranch parent) throws OseeCoreException { + Criteria criteria = criteriaFactory.createBranchChildOfCriteria(parent); + return addAndCheck(getQueryData(), criteria); + } + + @Override + public ResultSet<BranchReadable> getResults() throws OseeCoreException { + ResultSet<BranchReadable> result = null; + try { + result = createSearch().call(); + } catch (Exception ex) { + OseeExceptions.wrapAndThrow(ex); + } + return result; + } + + @Override + public ResultSet<IOseeBranch> getResultsAsId() throws OseeCoreException { + ResultSet<IOseeBranch> result = null; + try { + result = createSearchResultsAsIds().call(); + } catch (Exception ex) { + OseeExceptions.wrapAndThrow(ex); + } + return result; + } + + @Override + public int getCount() throws OseeCoreException { + Integer result = -1; + try { + result = createCount().call(); + } catch (Exception ex) { + OseeExceptions.wrapAndThrow(ex); + } + return result; + } + + @Override + public CancellableCallable<Integer> createCount() throws OseeCoreException { + return queryFactory.createBranchCount(session, checkAndCloneQueryData()); + } + + @Override + public CancellableCallable<ResultSet<BranchReadable>> createSearch() throws OseeCoreException { + return queryFactory.createBranchSearch(session, checkAndCloneQueryData()); + } + + @Override + public CancellableCallable<ResultSet<IOseeBranch>> createSearchResultsAsIds() throws OseeCoreException { + return queryFactory.createBranchAsIdSearch(session, checkAndCloneQueryData()); + } + + private QueryData checkAndCloneQueryData() throws OseeCoreException { + QueryData queryData = getQueryData().clone(); + CriteriaSet criteriaSet = queryData.getCriteriaSet(); + if (criteriaSet.getCriterias().isEmpty()) { + addAndCheck(queryData, criteriaFactory.createAllBranchesCriteria()); + } + if (!areArchivedIncluded()) { + Collection<BranchArchivedState> states = Arrays.asList(UNARCHIVED); + addAndCheck(queryData, criteriaFactory.createBranchArchivedCriteria(states)); + } + if (!areDeletedIncluded()) { + Collection<BranchState> states = new ArrayList<BranchState>(); + for (BranchState state : BranchState.values()) { + if (state != DELETE_IN_PROGRESS && state != DELETED && state != PURGE_IN_PROGRESS && state != PURGED) { + states.add(state); + } + } + addAndCheck(queryData, criteriaFactory.createBranchStateCriteria(states)); + } + return queryData; + } + + private BranchQuery addAndCheck(QueryData queryData, Criteria criteria) throws OseeCoreException { + criteria.checkValid(getOptions()); + queryData.addCriteria(criteria); + return this; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java index af08a895507..bb255be9735 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java @@ -24,6 +24,7 @@ import org.eclipse.osee.orcs.core.ds.OptionsUtil; import org.eclipse.osee.orcs.core.ds.QueryData; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranch; import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.search.BranchQuery; import org.eclipse.osee.orcs.search.QueryBuilder; import org.eclipse.osee.orcs.search.QueryFactory; @@ -35,12 +36,16 @@ public class QueryFactoryImpl implements QueryFactory { private final OrcsSession context; private final CriteriaFactory criteriaFctry; private final CallableQueryFactory queryFctry; + private final BranchCriteriaFactory branchCriteriaFactory; + private final BranchCallableQueryFactory branchQueryFactory; - public QueryFactoryImpl(OrcsSession context, CriteriaFactory criteriaFctry, CallableQueryFactory queryFctry) { + public QueryFactoryImpl(OrcsSession context, CriteriaFactory criteriaFctry, CallableQueryFactory queryFctry, BranchCriteriaFactory branchCriteriaFactory, BranchCallableQueryFactory branchQueryFactory) { super(); this.context = context; this.criteriaFctry = criteriaFctry; this.queryFctry = queryFctry; + this.branchCriteriaFactory = branchCriteriaFactory; + this.branchQueryFactory = branchQueryFactory; } private QueryBuilder createBuilder(IOseeBranch branch) { @@ -55,6 +60,15 @@ public class QueryFactoryImpl implements QueryFactory { } @Override + public BranchQuery branchQuery() { + Options options = OptionsUtil.createOptions(); + CriteriaSet criteriaSet = new CriteriaSet(); + QueryData queryData = new QueryData(criteriaSet, options); + BranchQueryImpl query = new BranchQueryImpl(branchQueryFactory, branchCriteriaFactory, context, queryData); + return query; + } + + @Override public QueryBuilder fromBranch(IOseeBranch branch) throws OseeCoreException { Conditions.checkNotNull(branch, "branch"); return createBuilder(branch); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryModule.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryModule.java index b798a82ea81..26e28cbe205 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryModule.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryModule.java @@ -30,17 +30,23 @@ public class QueryModule implements HasStatistics<QueryStatistics> { private final QueryStatisticsImpl statistics = new QueryStatisticsImpl(); private final CriteriaFactory criteriaFctry; - private final CallableQueryFactory callableQueryFactory; + private final CallableQueryFactory artQueryFactory; + + private final BranchCallableQueryFactory branchQueryFactory; + private final BranchCriteriaFactory branchCriteriaFactory; public QueryModule(Log logger, QueryEngine queryEngine, GraphBuilderFactory builderFactory, GraphProvider provider, ArtifactTypes artifactTypeCache, AttributeTypes attributeTypeCache, ExternalArtifactManager proxyManager) { QueryStatsCollectorImpl queryStatsCollector = new QueryStatsCollectorImpl(statistics); - this.criteriaFctry = new CriteriaFactory(artifactTypeCache, attributeTypeCache); - this.callableQueryFactory = + criteriaFctry = new CriteriaFactory(artifactTypeCache, attributeTypeCache); + artQueryFactory = new CallableQueryFactory(logger, queryEngine, queryStatsCollector, builderFactory, provider, proxyManager); + + branchCriteriaFactory = new BranchCriteriaFactory(); + branchQueryFactory = new BranchCallableQueryFactory(logger, queryEngine, queryStatsCollector); } public QueryFactory createQueryFactory(OrcsSession session) { - return new QueryFactoryImpl(session, criteriaFctry, callableQueryFactory); + return new QueryFactoryImpl(session, criteriaFctry, artQueryFactory, branchCriteriaFactory, branchQueryFactory); } @Override diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/BranchQuerySqlContextFactoryImplTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/BranchQuerySqlContextFactoryImplTest.java new file mode 100644 index 00000000000..a0692531a62 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/BranchQuerySqlContextFactoryImplTest.java @@ -0,0 +1,430 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.engines; + +import static org.eclipse.osee.framework.core.enums.BranchArchivedState.ARCHIVED; +import static org.eclipse.osee.framework.core.enums.BranchState.COMMITTED; +import static org.eclipse.osee.framework.core.enums.BranchState.CREATED; +import static org.eclipse.osee.framework.core.enums.BranchState.CREATION_IN_PROGRESS; +import static org.eclipse.osee.framework.core.enums.BranchType.SYSTEM_ROOT; +import static org.eclipse.osee.framework.core.enums.BranchType.WORKING; +import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.services.IdentityService; +import org.eclipse.osee.framework.database.IOseeDatabaseService; +import org.eclipse.osee.framework.database.core.AbstractJoinQuery; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsSession; +import org.eclipse.osee.orcs.core.ds.Criteria; +import org.eclipse.osee.orcs.core.ds.CriteriaSet; +import org.eclipse.osee.orcs.core.ds.Options; +import org.eclipse.osee.orcs.core.ds.OptionsUtil; +import org.eclipse.osee.orcs.core.ds.QueryData; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAllBranches; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchArchived; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchChildOf; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchIds; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchName; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchState; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchType; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchUuids; +import org.eclipse.osee.orcs.db.internal.SqlProvider; +import org.eclipse.osee.orcs.db.internal.search.Engines; +import org.eclipse.osee.orcs.db.internal.search.QuerySqlContext; +import org.eclipse.osee.orcs.db.internal.search.QuerySqlContextFactory; +import org.eclipse.osee.orcs.db.internal.sql.OseeSql; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test Case for {@link QuerySqlContextFactoryImpl} + * + * @author Roberto E. Escobar + */ +public class BranchQuerySqlContextFactoryImplTest { + + private static final Criteria GUIDS = uuid(GUID.create(), GUID.create()); + private static final Criteria IDS = id(1, 2, 3, 4, 5); + private static final Criteria TYPES = type(WORKING, SYSTEM_ROOT); + + private static final Criteria IS_ARCHIVED = archive(ARCHIVED); + private static final Criteria NAME_PATTERN = namePattern("Hello.*"); + private static final Criteria STATE = state(CREATED, COMMITTED); + + private static final Criteria ALL_BRANCHES = new CriteriaAllBranches(); + + // @formatter:off + @Mock private Log logger; + @Mock private IOseeDatabaseService dbService; + @Mock private SqlProvider sqlProvider; + @Mock private IdentityService identityService; + + @Mock private OrcsSession session; + // @formatter:on + + private QuerySqlContextFactory queryEngine; + private QueryData queryData; + + @Before + public void setUp() throws OseeCoreException { + MockitoAnnotations.initMocks(this); + + String sessionId = GUID.create(); + when(session.getGuid()).thenReturn(sessionId); + + queryEngine = Engines.newBranchSqlContextFactory(logger, dbService, identityService, sqlProvider); + + CriteriaSet criteriaSet = new CriteriaSet(); + Options options = OptionsUtil.createBranchOptions(); + queryData = new QueryData(criteriaSet, options); + + when(sqlProvider.getSql(OseeSql.QUERY_BUILDER)).thenReturn("/*+ ordered */"); + } + + @Test + public void testCount() throws Exception { + String expected = "SELECT/*+ ordered */ count(br1.branch_id)\n" + // + " FROM \n" + // + "osee_join_id jid1, osee_branch br1, osee_join_char_id jch1, osee_join_id jid2\n" + // + " WHERE \n" + // + "br1.branch_id = jid1.id AND jid1.query_id = ?\n" + // + " AND \n" + // + "br1.branch_guid = jch1.id AND jch1.query_id = ?\n" + // + " AND \n" + // + "br1.branch_type = jid2.id AND jid2.query_id = ?"; + + queryData.addCriteria(GUIDS, IDS, TYPES); + + QuerySqlContext context = queryEngine.createCountContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(3, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(3, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals(iterator.next(), joins.get(0).getQueryId()); + assertEquals(5, joins.get(0).size()); + assertEquals(iterator.next(), joins.get(1).getQueryId()); + assertEquals(2, joins.get(1).size()); + assertEquals(iterator.next(), joins.get(2).getQueryId()); + assertEquals(2, joins.get(2).size()); + } + + @Test + public void testQueryUuidIdsTypes() throws Exception { + String expected = "SELECT/*+ ordered */ br1.*\n" + // + " FROM \n" + // + "osee_join_id jid1, osee_branch br1, osee_join_char_id jch1, osee_join_id jid2\n" + // + " WHERE \n" + // + "br1.branch_id = jid1.id AND jid1.query_id = ?\n" + // + " AND \n" + // + "br1.branch_guid = jch1.id AND jch1.query_id = ?\n" + // + " AND \n" + // + "br1.branch_type = jid2.id AND jid2.query_id = ?\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(GUIDS, IDS, TYPES); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(3, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(3, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals(iterator.next(), joins.get(0).getQueryId()); + assertEquals(5, joins.get(0).size()); + assertEquals(iterator.next(), joins.get(1).getQueryId()); + assertEquals(2, joins.get(1).size()); + assertEquals(iterator.next(), joins.get(2).getQueryId()); + assertEquals(2, joins.get(2).size()); + } + + @Test + public void testQueryAllBranches() throws Exception { + String expected = "SELECT/*+ ordered */ br1.*\n" + // + " FROM \n" + // + "osee_branch br1\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(ALL_BRANCHES); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(0, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(0, joins.size()); + } + + @Test + public void testQueryUuidIdsTypesSingles() throws Exception { + String expected = "SELECT/*+ ordered */ br1.*\n" + // + " FROM \n" + // + "osee_branch br1\n" + // + " WHERE \n" + // + "br1.branch_id = ?\n" + // + " AND \n" + // + "br1.branch_guid = ?\n" + // + " AND \n" + // + "br1.branch_type = ?\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(uuid("12313123"), id(2), type(SYSTEM_ROOT)); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(3, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(0, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals(2, iterator.next()); + assertEquals("12313123", iterator.next()); + assertEquals(SYSTEM_ROOT.getValue(), iterator.next()); + } + + @Test + public void testQueryName() throws Exception { + String expected = "SELECT/*+ ordered */ br1.*\n" + // + " FROM \n" + // + "osee_branch br1\n" + // + " WHERE \n" + // + "br1.branch_name = ?\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(name("Hello")); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(1, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(0, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals("Hello", iterator.next()); + } + + @Test + public void testQueryNamePattern() throws Exception { + String expected = "SELECT/*+ ordered */ br1.*\n" + // + " FROM \n" + // + "osee_branch br1\n" + // + " WHERE \n" + // + "REGEXP_MATCHES (br1.branch_name, ?)\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(NAME_PATTERN); + + when(sqlProvider.getSql(SqlProvider.SQL_REG_EXP_PATTERN_KEY)).thenReturn("REGEXP_MATCHES (%s, %s)"); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(1, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(0, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals("Hello.*", iterator.next()); + } + + @Test + public void testQueryStateArchive() throws Exception { + String expected = "SELECT/*+ ordered */ br1.*\n" + // + " FROM \n" + // + "osee_join_id jid1, osee_branch br1\n" + // + " WHERE \n" + // + "br1.branch_state = jid1.id AND jid1.query_id = ?\n" + // + " AND \n" + // + "br1.archived = ?\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(STATE, IS_ARCHIVED); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(2, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(1, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals(iterator.next(), joins.get(0).getQueryId()); + assertEquals(2, joins.get(0).size()); + assertEquals(ARCHIVED.getValue(), iterator.next()); + } + + @Test + public void testQuerySingleStateArchive() throws Exception { + String expected = "SELECT/*+ ordered */ br1.*\n" + // + " FROM \n" + // + "osee_branch br1\n" + // + " WHERE \n" + // + "br1.branch_state = ?\n" + // + " AND \n" + // + "br1.archived = ?\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(state(CREATION_IN_PROGRESS), IS_ARCHIVED); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(2, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(0, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals(CREATION_IN_PROGRESS.getValue(), iterator.next()); + assertEquals(ARCHIVED.getValue(), iterator.next()); + } + + @Test + public void testQueryChildOf() throws OseeCoreException { + String expected = + "WITH chof1 (child_id, branch_level) AS ( SELECT anch_br1.branch_id, 0 as branch_level FROM osee_branch anch_br1, osee_branch anch_br2\n" + // + " WHERE anch_br1.parent_branch_id = anch_br2.branch_id AND anch_br2.branch_guid = ?\n" + // + " UNION ALL \n" + // + " SELECT branch_id, branch_level + 1 FROM chof1 recurse, osee_branch br WHERE recurse.child_id = br.parent_branch_id\n" + // + ")\n" + // + "SELECT br1.*\n" + // + " FROM \n" + // + "osee_branch br1, chof1\n" + // + " WHERE \n" + // + "br1.branch_id = chof1.child_id\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(childOf(COMMON)); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(1, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(0, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals(COMMON.getGuid(), iterator.next()); + } + + @Test + public void testMultiples() throws OseeCoreException { + String expected = + "WITH chof1 (child_id, branch_level) AS ( SELECT anch_br1.branch_id, 0 as branch_level FROM osee_branch anch_br1, osee_branch anch_br2\n" + // + " WHERE anch_br1.parent_branch_id = anch_br2.branch_id AND anch_br2.branch_guid = ?\n" + // + " UNION ALL \n" + // + " SELECT branch_id, branch_level + 1 FROM chof1 recurse, osee_branch br WHERE recurse.child_id = br.parent_branch_id\n" + // + ")\n" + // + "SELECT br1.*\n" + // + " FROM \n" + // + "osee_branch br1, osee_join_id jid1, chof1\n" + // + " WHERE \n" + // + "br1.branch_id = chof1.child_id\n" + // + " AND \n" + // + "br1.branch_type = ?\n" + // + " AND \n" + // + "br1.branch_state = jid1.id AND jid1.query_id = ?\n" + // + " AND \n" + // + "br1.archived = ?\n" + // + " AND \n" + // + "REGEXP_MATCHES (br1.branch_name, ?)\n" + // + " ORDER BY br1.branch_id"; + + queryData.addCriteria(STATE, IS_ARCHIVED, type(WORKING), childOf(COMMON), NAME_PATTERN); + + when(sqlProvider.getSql(SqlProvider.SQL_REG_EXP_PATTERN_KEY)).thenReturn("REGEXP_MATCHES (%s, %s)"); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(5, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(1, joins.size()); + assertEquals(2, joins.get(0).size()); + + Iterator<Object> iterator = parameters.iterator(); + + assertEquals(COMMON.getGuid(), iterator.next()); + assertEquals(WORKING.getValue(), iterator.next()); + assertEquals(joins.get(0).getQueryId(), iterator.next()); + assertEquals(ARCHIVED.getValue(), iterator.next()); + assertEquals("Hello.*", iterator.next()); + } + + private static Criteria childOf(IOseeBranch parent) { + return new CriteriaBranchChildOf(parent); + } + + private static Criteria uuid(String... values) { + return new CriteriaBranchUuids(Arrays.asList(values)); + } + + private static Criteria id(Integer... values) { + return new CriteriaBranchIds(Arrays.asList(values)); + } + + private static Criteria type(BranchType... values) { + return new CriteriaBranchType(Arrays.asList(values)); + } + + private static Criteria state(BranchState... values) { + return new CriteriaBranchState(Arrays.asList(values)); + } + + private static Criteria namePattern(String value) { + return new CriteriaBranchName(value, true); + } + + private static Criteria name(String value) { + return new CriteriaBranchName(value, false); + } + + private static Criteria archive(BranchArchivedState... states) { + return new CriteriaBranchArchived(Arrays.asList(states)); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/EnginesTestSuite.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/EnginesTestSuite.java index 7bc4e658363..982eb15a494 100644 --- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/EnginesTestSuite.java +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/EnginesTestSuite.java @@ -17,7 +17,7 @@ import org.junit.runners.Suite; * @author Roberto E. Escobar */ @RunWith(Suite.class) -@Suite.SuiteClasses({ArtifactQuerySqlContextFactoryImplTest.class}) +@Suite.SuiteClasses({ArtifactQuerySqlContextFactoryImplTest.class, BranchQuerySqlContextFactoryImplTest.class}) public class EnginesTestSuite { // Test Suite } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/OrcsObjectFactory.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/OrcsObjectFactory.java index abd1b95aa7f..92e105243a8 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/OrcsObjectFactory.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/OrcsObjectFactory.java @@ -12,11 +12,12 @@ package org.eclipse.osee.orcs.db.internal; import org.eclipse.osee.orcs.db.internal.loader.data.ArtifactObjectFactory; import org.eclipse.osee.orcs.db.internal.loader.data.AttributeObjectFactory; +import org.eclipse.osee.orcs.db.internal.loader.data.BranchObjectFactory; import org.eclipse.osee.orcs.db.internal.loader.data.RelationObjectFactory; /** * @author Roberto E. Escobar */ -public interface OrcsObjectFactory extends ArtifactObjectFactory, AttributeObjectFactory, RelationObjectFactory { +public interface OrcsObjectFactory extends BranchObjectFactory, ArtifactObjectFactory, AttributeObjectFactory, RelationObjectFactory { // } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderFactoryImpl.java index fb6d247b118..8ec50ec5082 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderFactoryImpl.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderFactoryImpl.java @@ -29,6 +29,7 @@ import org.eclipse.osee.orcs.core.ds.Options; import org.eclipse.osee.orcs.core.ds.OptionsUtil; import org.eclipse.osee.orcs.core.ds.QueryContext; import org.eclipse.osee.orcs.db.internal.loader.executors.AbstractLoadExecutor; +import org.eclipse.osee.orcs.db.internal.loader.executors.ArtifactQueryContextLoadExecutor; import org.eclipse.osee.orcs.db.internal.loader.executors.LoadExecutor; import org.eclipse.osee.orcs.db.internal.loader.executors.QueryContextLoadExecutor; import org.eclipse.osee.orcs.db.internal.loader.executors.UuidsLoadExecutor; @@ -91,8 +92,14 @@ public class DataLoaderFactoryImpl implements DataLoaderFactory { @Override public DataLoader fromQueryContext(QueryContext queryContext) throws OseeCoreException { - ArtifactQuerySqlContext sqlQueryContext = adapt(ArtifactQuerySqlContext.class, queryContext); - AbstractLoadExecutor executor = new QueryContextLoadExecutor(loader, dbService, sqlQueryContext); + AbstractLoadExecutor executor; + if (queryContext instanceof ArtifactQuerySqlContext) { + ArtifactQuerySqlContext sqlQueryContext = adapt(ArtifactQuerySqlContext.class, queryContext); + executor = new ArtifactQueryContextLoadExecutor(loader, dbService, sqlQueryContext); + } else { + QuerySqlContext sqlQueryContext = adapt(QuerySqlContext.class, queryContext); + executor = new QueryContextLoadExecutor(loader, dbService, sqlQueryContext); + } Options options = OptionsUtil.createOptions(); return new DataLoaderImpl(logger, executor, options); } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java index 73abe927274..702d471ad9a 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java @@ -24,6 +24,7 @@ import org.eclipse.osee.logger.Log; import org.eclipse.osee.orcs.OrcsSession; import org.eclipse.osee.orcs.core.ds.ArtifactData; import org.eclipse.osee.orcs.core.ds.AttributeData; +import org.eclipse.osee.orcs.core.ds.BranchData; import org.eclipse.osee.orcs.core.ds.Criteria; import org.eclipse.osee.orcs.core.ds.LoadDataHandler; import org.eclipse.osee.orcs.core.ds.LoadDescription; @@ -38,11 +39,14 @@ import org.eclipse.osee.orcs.db.internal.loader.criteria.CriteriaOrcsLoad; import org.eclipse.osee.orcs.db.internal.loader.data.OrcsDataFactory; import org.eclipse.osee.orcs.db.internal.loader.processor.ArtifactLoadProcessor; import org.eclipse.osee.orcs.db.internal.loader.processor.AttributeLoadProcessor; +import org.eclipse.osee.orcs.db.internal.loader.processor.BranchLoadProcessor; import org.eclipse.osee.orcs.db.internal.loader.processor.LoadProcessor; import org.eclipse.osee.orcs.db.internal.loader.processor.RelationLoadProcessor; +import org.eclipse.osee.orcs.db.internal.search.QuerySqlContext; import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; import org.eclipse.osee.orcs.db.internal.sql.OseeSql; import org.eclipse.osee.orcs.db.internal.sql.RelationalConstants; +import org.eclipse.osee.orcs.db.internal.sql.SqlContext; import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; import org.eclipse.osee.orcs.db.internal.sql.SqlHandlerFactory; @@ -51,6 +55,7 @@ import org.eclipse.osee.orcs.db.internal.sql.SqlHandlerFactory; */ public class SqlObjectLoader { + private final BranchLoadProcessor branchProcessor; private final ArtifactLoadProcessor artifactProcessor; private final AttributeLoadProcessor attributeProcessor; private final RelationLoadProcessor relationProcessor; @@ -70,6 +75,7 @@ public class SqlObjectLoader { artifactProcessor = new ArtifactLoadProcessor(objectFactory); attributeProcessor = new AttributeLoadProcessor(objectFactory); relationProcessor = new RelationLoadProcessor(objectFactory); + branchProcessor = new BranchLoadProcessor(objectFactory); } private IOseeDatabaseService getDatabaseService() { @@ -97,14 +103,14 @@ public class SqlObjectLoader { writer.build(handler); } - public void loadArtifacts(HasCancellation cancellation, LoadDataHandler builder, ArtifactJoinQuery join, CriteriaOrcsLoad criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { + public void loadArtifacts(HasCancellation cancellation, LoadDataHandler handler, ArtifactJoinQuery join, CriteriaOrcsLoad criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { logger.trace("Sql Artifact Load - artifactJoinQuery[%s] loadSqlContext[%s]", join, loadContext); if (!join.isEmpty()) { try { join.store(); criteria.setQueryId(join.getQueryId()); - loadArtifacts(cancellation, builder, criteria, loadContext, fetchSize); + loadArtifacts(cancellation, handler, criteria, loadContext, fetchSize); } finally { join.delete(); } @@ -114,18 +120,29 @@ public class SqlObjectLoader { } } - private void loadArtifacts(HasCancellation cancellation, LoadDataHandler builder, CriteriaOrcsLoad criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { + public void loadBranches(HasCancellation cancellation, LoadDataHandler handler, QuerySqlContext context, int fetchSize) throws OseeCoreException { + logger.trace("Sql Branch Load - loadContext[%s] fetchSize[%s]", context, fetchSize); checkCancelled(cancellation); - loadDescription(builder, loadContext); + LoadDescription description = createDescription(context.getSession(), context.getOptions()); + handler.onLoadDescription(description); + + OrcsDataHandler<BranchData> branchHandler = asBranchHandler(handler); + load(branchProcessor, branchHandler, context, fetchSize); + } + + private void loadArtifacts(HasCancellation cancellation, LoadDataHandler handler, CriteriaOrcsLoad criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { checkCancelled(cancellation); - loadArtifacts(builder, criteria.getArtifactCriteria(), loadContext, fetchSize); + loadDescription(handler, loadContext); checkCancelled(cancellation); - loadAttributes(builder, criteria.getAttributeCriteria(), loadContext, fetchSize); + loadArtifacts(handler, criteria.getArtifactCriteria(), loadContext, fetchSize); checkCancelled(cancellation); - loadRelations(builder, criteria.getRelationCriteria(), loadContext, fetchSize); + loadAttributes(handler, criteria.getAttributeCriteria(), loadContext, fetchSize); + + checkCancelled(cancellation); + loadRelations(handler, criteria.getRelationCriteria(), loadContext, fetchSize); } protected void loadDescription(LoadDataHandler builder, final LoadSqlContext loadContext) throws OseeCoreException { @@ -144,25 +161,25 @@ public class SqlObjectLoader { builder.onLoadDescription(description); } - protected void loadArtifacts(LoadDataHandler builder, Criteria criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { - OrcsDataHandler<ArtifactData> artHandler = asArtifactHandler(builder); + protected void loadArtifacts(LoadDataHandler handler, Criteria criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { + OrcsDataHandler<ArtifactData> artHandler = asArtifactHandler(handler); writeSql(criteria, loadContext); load(artifactProcessor, artHandler, loadContext, fetchSize); } - protected void loadAttributes(LoadDataHandler builder, Criteria criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { + protected void loadAttributes(LoadDataHandler handler, Criteria criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { LoadLevel loadLevel = OptionsUtil.getLoadLevel(loadContext.getOptions()); if (isAttributeLoadingAllowed(loadLevel)) { - OrcsDataHandler<AttributeData> attrHandler = asAttributeHandler(builder); + OrcsDataHandler<AttributeData> attrHandler = asAttributeHandler(handler); writeSql(criteria, loadContext); load(attributeProcessor, attrHandler, loadContext, fetchSize); } } - protected void loadRelations(LoadDataHandler builder, Criteria criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { + protected void loadRelations(LoadDataHandler handler, Criteria criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { LoadLevel loadLevel = OptionsUtil.getLoadLevel(loadContext.getOptions()); if (isRelationLoadingAllowed(loadLevel)) { - OrcsDataHandler<RelationData> relHandler = asRelationHandler(builder); + OrcsDataHandler<RelationData> relHandler = asRelationHandler(handler); writeSql(criteria, loadContext); load(relationProcessor, relHandler, loadContext, fetchSize); } @@ -174,7 +191,7 @@ public class SqlObjectLoader { branch.getGuid()); } - protected <D extends HasLocalId, F extends OrcsDataFactory> void load(LoadProcessor<D, F> processor, OrcsDataHandler<D> handler, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { + protected <D extends HasLocalId, F extends OrcsDataFactory> void load(LoadProcessor<D, F> processor, OrcsDataHandler<D> handler, SqlContext loadContext, int fetchSize) throws OseeCoreException { try { for (AbstractJoinQuery join : loadContext.getJoins()) { join.store(); @@ -212,6 +229,10 @@ public class SqlObjectLoader { } } + private static LoadDescription createDescription(final OrcsSession session, final Options options) { + return createDescription(session, options, null, -1); + } + private static LoadDescription createDescription(final OrcsSession session, final Options options, final IOseeBranch branch, final int transactionLoaded) { return new LoadDescription() { @@ -271,4 +292,14 @@ public class SqlObjectLoader { } }; } + + private static OrcsDataHandler<BranchData> asBranchHandler(final LoadDataHandler handler) { + return new OrcsDataHandler<BranchData>() { + + @Override + public void onData(BranchData data) throws OseeCoreException { + handler.onData(data); + } + }; + } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/BranchDataImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/BranchDataImpl.java new file mode 100644 index 00000000000..a74bd5dc1e6 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/BranchDataImpl.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright (c) 2012 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.loader.data; + +import org.eclipse.osee.framework.core.data.Identity; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.orcs.core.ds.BranchData; +import org.eclipse.osee.orcs.data.BranchReadable; +import org.eclipse.osee.orcs.db.internal.sql.RelationalConstants; + +/** + * @author Roberto E. Escobar + */ +public class BranchDataImpl extends OrcsObjectImpl implements BranchData, BranchReadable { + + private String guid = RelationalConstants.DEFAULT_GUID; + private String name = ""; + private int associatedArtifactId = RelationalConstants.ART_ID_SENTINEL; + private int baseTransaction = RelationalConstants.TRANSACTION_SENTINEL; + private int sourceTransaction = RelationalConstants.TRANSACTION_SENTINEL; + private int parentBranch = RelationalConstants.BRANCH_SENTINEL; + private BranchArchivedState archiveState = BranchArchivedState.UNARCHIVED; + private BranchState branchState = BranchState.CREATED; + private BranchType branchType = BranchType.WORKING; + + public BranchDataImpl() { + super(); + } + + @Override + public String getGuid() { + return guid; + } + + @Override + public void setGuid(String guid) { + this.guid = guid; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public int getAssociatedArtifactId() { + return associatedArtifactId; + } + + @Override + public void setAssociatedArtifactId(int artId) { + associatedArtifactId = artId; + } + + @Override + public int getBaseTransaction() { + return baseTransaction; + } + + @Override + public void setBaseTransaction(int baseTx) { + baseTransaction = baseTx; + } + + @Override + public int getSourceTransaction() { + return sourceTransaction; + } + + @Override + public void setSourceTransaction(int sourceTx) { + sourceTransaction = sourceTx; + } + + @Override + public int getParentBranch() { + return parentBranch; + } + + @Override + public void setParentBranch(int parent) { + parentBranch = parent; + } + + @Override + public boolean hasParentBranch() { + return getParentBranch() != RelationalConstants.BRANCH_SENTINEL; + } + + @Override + public BranchArchivedState getArchiveState() { + return archiveState; + } + + @Override + public void setArchiveState(BranchArchivedState state) { + this.archiveState = state; + } + + @Override + public BranchState getBranchState() { + return branchState; + } + + @Override + public void setBranchState(BranchState state) { + this.branchState = state; + } + + @Override + public BranchType getBranchType() { + return branchType; + } + + @Override + public void setBranchType(BranchType type) { + branchType = type; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((guid == null) ? 0 : guid.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Identity) { + return getGuid().equals(((Identity<?>) obj).getGuid()); + } + return false; + } + + @Override + public String toString() { + return "BranchData [guid=" + guid + super.toString() + "]"; + } + + @Override + public boolean matches(Identity<?>... identities) { + for (Identity<?> identity : identities) { + if (equals(identity)) { + return true; + } + } + return false; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/BranchObjectFactory.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/BranchObjectFactory.java new file mode 100644 index 00000000000..ad33ad9a8f2 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/BranchObjectFactory.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2012 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.loader.data; + +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.ds.BranchData; + +/** + * @author Roberto E. Escobar + */ +public interface BranchObjectFactory extends OrcsDataFactory { + + BranchData createBranchData(int localId, String guid, BranchType branchType, String name, int parentBranch, int baseTransaction, int sourceTransaction, BranchArchivedState archiveState, BranchState branchState, int associatedArtifactId) throws OseeCoreException; + + BranchData createCopy(BranchData source) throws OseeCoreException; +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/OrcsObjectFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/OrcsObjectFactoryImpl.java index 9734ecd68f6..4ea31fed1af 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/OrcsObjectFactoryImpl.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/OrcsObjectFactoryImpl.java @@ -13,11 +13,15 @@ package org.eclipse.osee.orcs.db.internal.loader.data; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.ModificationType; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.services.IdentityService; import org.eclipse.osee.orcs.core.ds.ArtifactData; import org.eclipse.osee.orcs.core.ds.AttributeData; +import org.eclipse.osee.orcs.core.ds.BranchData; import org.eclipse.osee.orcs.core.ds.DataProxy; import org.eclipse.osee.orcs.core.ds.RelationData; import org.eclipse.osee.orcs.core.ds.VersionData; @@ -182,4 +186,27 @@ public class OrcsObjectFactoryImpl implements OrcsObjectFactory { source.getRationale()); } + @Override + public BranchData createBranchData(int localId, String guid, BranchType branchType, String name, int parentBranch, int baseTransaction, int sourceTransaction, BranchArchivedState archiveState, BranchState branchState, int associatedArtifactId) { + BranchData data = new BranchDataImpl(); + data.setArchiveState(archiveState); + data.setAssociatedArtifactId(associatedArtifactId); + data.setBaseTransaction(baseTransaction); + data.setBranchState(branchState); + data.setBranchType(branchType); + data.setGuid(guid); + data.setLocalId(localId); + data.setName(name); + data.setParentBranch(parentBranch); + data.setSourceTransaction(sourceTransaction); + return data; + } + + @Override + public BranchData createCopy(BranchData source) { + return createBranchData(source.getLocalId(), source.getGuid(), source.getBranchType(), source.getName(), + source.getParentBranch(), source.getBaseTransaction(), source.getSourceTransaction(), + source.getArchiveState(), source.getBranchState(), source.getAssociatedArtifactId()); + } + } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/AbstractLoadExecutor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/AbstractLoadExecutor.java index d969c4afd94..b7c73c8fcb2 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/AbstractLoadExecutor.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/AbstractLoadExecutor.java @@ -14,10 +14,8 @@ import java.util.concurrent.CancellationException; import org.eclipse.osee.executor.admin.HasCancellation; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.database.IOseeDatabaseService; -import org.eclipse.osee.framework.database.core.ArtifactJoinQuery; import org.eclipse.osee.orcs.core.ds.LoadDataHandler; import org.eclipse.osee.orcs.core.ds.Options; -import org.eclipse.osee.orcs.db.internal.loader.LoadSqlContext; import org.eclipse.osee.orcs.db.internal.loader.SqlObjectLoader; import org.eclipse.osee.orcs.db.internal.loader.criteria.CriteriaOrcsLoad; @@ -41,8 +39,8 @@ public abstract class AbstractLoadExecutor { return dbService; } - protected void loadFromJoin(ArtifactJoinQuery join, HasCancellation cancellation, LoadDataHandler handler, CriteriaOrcsLoad criteria, LoadSqlContext loadContext, int fetchSize) throws OseeCoreException { - loader.loadArtifacts(cancellation, handler, join, criteria, loadContext, fetchSize); + protected SqlObjectLoader getLoader() { + return loader; } protected void checkCancelled(HasCancellation cancellation) throws CancellationException { diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/ArtifactQueryContextLoadExecutor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/ArtifactQueryContextLoadExecutor.java new file mode 100644 index 00000000000..2abec895c3e --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/ArtifactQueryContextLoadExecutor.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2012 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.loader.executors; + +import java.util.List; +import org.eclipse.osee.executor.admin.HasCancellation; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.IOseeDatabaseService; +import org.eclipse.osee.framework.database.core.AbstractJoinQuery; +import org.eclipse.osee.framework.database.core.ArtifactJoinQuery; +import org.eclipse.osee.framework.database.core.IOseeStatement; +import org.eclipse.osee.framework.database.core.JoinUtility; +import org.eclipse.osee.orcs.core.ds.LoadDataHandler; +import org.eclipse.osee.orcs.core.ds.Options; +import org.eclipse.osee.orcs.core.ds.OptionsUtil; +import org.eclipse.osee.orcs.db.internal.loader.LoadSqlContext; +import org.eclipse.osee.orcs.db.internal.loader.LoadUtil; +import org.eclipse.osee.orcs.db.internal.loader.SqlObjectLoader; +import org.eclipse.osee.orcs.db.internal.loader.criteria.CriteriaOrcsLoad; +import org.eclipse.osee.orcs.db.internal.search.engines.ArtifactQuerySqlContext; +import org.eclipse.osee.orcs.db.internal.sql.RelationalConstants; +import org.eclipse.osee.orcs.db.internal.sql.SqlContext; + +/** + * @author Andrew M. Finkbeiner + */ +public class ArtifactQueryContextLoadExecutor extends AbstractLoadExecutor { + + private final ArtifactQuerySqlContext queryContext; + + public ArtifactQueryContextLoadExecutor(SqlObjectLoader loader, IOseeDatabaseService dbService, ArtifactQuerySqlContext queryContext) { + super(loader, dbService); + this.queryContext = queryContext; + } + + @Override + public void load(HasCancellation cancellation, LoadDataHandler handler, CriteriaOrcsLoad criteria, Options options) throws OseeCoreException { + int fetchSize = computeFetchSize(queryContext); + + ArtifactJoinQuery join = createArtifactIdJoin(getDatabaseService(), cancellation, fetchSize); + + LoadSqlContext loadContext = new LoadSqlContext(queryContext.getSession(), options, queryContext.getBranch()); + getLoader().loadArtifacts(cancellation, handler, join, criteria, loadContext, fetchSize); + } + + private int computeFetchSize(SqlContext sqlContext) { + int fetchSize = RelationalConstants.MIN_FETCH_SIZE; + for (AbstractJoinQuery join : sqlContext.getJoins()) { + fetchSize = Math.max(fetchSize, join.size()); + } + return LoadUtil.computeFetchSize(fetchSize); + } + + private ArtifactJoinQuery createArtifactIdJoin(IOseeDatabaseService dbService, HasCancellation cancellation, int fetchSize) throws OseeCoreException { + ArtifactJoinQuery artifactJoin = JoinUtility.createArtifactJoinQuery(dbService); + try { + for (AbstractJoinQuery join : queryContext.getJoins()) { + join.store(); + checkCancelled(cancellation); + } + Integer transactionId = -1; + IOseeStatement chStmt = dbService.getStatement(); + try { + checkCancelled(cancellation); + String query = queryContext.getSql(); + List<Object> params = queryContext.getParameters(); + chStmt.runPreparedQuery(fetchSize, query, params.toArray()); + while (chStmt.next()) { + checkCancelled(cancellation); + Integer artId = chStmt.getInt("art_id"); + Integer branchId = chStmt.getInt("branch_id"); + if (OptionsUtil.isHistorical(queryContext.getOptions())) { + transactionId = chStmt.getInt("transaction_id"); + } + artifactJoin.add(artId, branchId, transactionId); + checkCancelled(cancellation); + } + } finally { + chStmt.close(); + } + } finally { + for (AbstractJoinQuery join : queryContext.getJoins()) { + try { + join.delete(); + } catch (OseeCoreException ex) { + // Ensure we try to delete all + } + } + } + return artifactJoin; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/LoadExecutor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/LoadExecutor.java index 3dc4e4fe2d4..daee9486d1f 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/LoadExecutor.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/LoadExecutor.java @@ -59,6 +59,6 @@ public class LoadExecutor extends AbstractLoadExecutor { LoadSqlContext loadContext = new LoadSqlContext(session, options, branch); int fetchSize = LoadUtil.computeFetchSize(artifactIds.size()); - loadFromJoin(join, cancellation, handler, criteria, loadContext, fetchSize); + getLoader().loadArtifacts(cancellation, handler, join, criteria, loadContext, fetchSize); } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/QueryContextLoadExecutor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/QueryContextLoadExecutor.java index 9852cf3d13d..e431d1ded7b 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/QueryContextLoadExecutor.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/QueryContextLoadExecutor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Boeing. + * Copyright (c) 2013 Boeing. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,92 +10,33 @@ *******************************************************************************/ package org.eclipse.osee.orcs.db.internal.loader.executors; -import java.util.List; +import static org.eclipse.osee.orcs.db.internal.sql.RelationalConstants.MIN_FETCH_SIZE; import org.eclipse.osee.executor.admin.HasCancellation; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.database.IOseeDatabaseService; -import org.eclipse.osee.framework.database.core.AbstractJoinQuery; -import org.eclipse.osee.framework.database.core.ArtifactJoinQuery; -import org.eclipse.osee.framework.database.core.IOseeStatement; -import org.eclipse.osee.framework.database.core.JoinUtility; import org.eclipse.osee.orcs.core.ds.LoadDataHandler; import org.eclipse.osee.orcs.core.ds.Options; -import org.eclipse.osee.orcs.core.ds.OptionsUtil; -import org.eclipse.osee.orcs.db.internal.loader.LoadSqlContext; import org.eclipse.osee.orcs.db.internal.loader.LoadUtil; import org.eclipse.osee.orcs.db.internal.loader.SqlObjectLoader; import org.eclipse.osee.orcs.db.internal.loader.criteria.CriteriaOrcsLoad; -import org.eclipse.osee.orcs.db.internal.search.engines.ArtifactQuerySqlContext; -import org.eclipse.osee.orcs.db.internal.sql.RelationalConstants; -import org.eclipse.osee.orcs.db.internal.sql.SqlContext; +import org.eclipse.osee.orcs.db.internal.search.QuerySqlContext; /** * @author Andrew M. Finkbeiner */ public class QueryContextLoadExecutor extends AbstractLoadExecutor { - private final ArtifactQuerySqlContext queryContext; + private final QuerySqlContext queryContext; - public QueryContextLoadExecutor(SqlObjectLoader loader, IOseeDatabaseService dbService, ArtifactQuerySqlContext queryContext) { + public QueryContextLoadExecutor(SqlObjectLoader loader, IOseeDatabaseService dbService, QuerySqlContext queryContext) { super(loader, dbService); this.queryContext = queryContext; } @Override public void load(HasCancellation cancellation, LoadDataHandler handler, CriteriaOrcsLoad criteria, Options options) throws OseeCoreException { - int fetchSize = computeFetchSize(queryContext); - - ArtifactJoinQuery join = createArtifactIdJoin(getDatabaseService(), cancellation, fetchSize); - - LoadSqlContext loadContext = new LoadSqlContext(queryContext.getSession(), options, queryContext.getBranch()); - loadFromJoin(join, cancellation, handler, criteria, loadContext, fetchSize); - } - - private int computeFetchSize(SqlContext sqlContext) { - int fetchSize = RelationalConstants.MIN_FETCH_SIZE; - for (AbstractJoinQuery join : sqlContext.getJoins()) { - fetchSize = Math.max(fetchSize, join.size()); - } - return LoadUtil.computeFetchSize(fetchSize); - } - - private ArtifactJoinQuery createArtifactIdJoin(IOseeDatabaseService dbService, HasCancellation cancellation, int fetchSize) throws OseeCoreException { - ArtifactJoinQuery artifactJoin = JoinUtility.createArtifactJoinQuery(dbService); - try { - for (AbstractJoinQuery join : queryContext.getJoins()) { - join.store(); - checkCancelled(cancellation); - } - Integer transactionId = -1; - IOseeStatement chStmt = dbService.getStatement(); - try { - checkCancelled(cancellation); - String query = queryContext.getSql(); - List<Object> params = queryContext.getParameters(); - chStmt.runPreparedQuery(fetchSize, query, params.toArray()); - while (chStmt.next()) { - checkCancelled(cancellation); - Integer artId = chStmt.getInt("art_id"); - Integer branchId = chStmt.getInt("branch_id"); - if (OptionsUtil.isHistorical(queryContext.getOptions())) { - transactionId = chStmt.getInt("transaction_id"); - } - artifactJoin.add(artId, branchId, transactionId); - checkCancelled(cancellation); - } - } finally { - chStmt.close(); - } - } finally { - for (AbstractJoinQuery join : queryContext.getJoins()) { - try { - join.delete(); - } catch (OseeCoreException ex) { - // Ensure we try to delete all - } - } - } - return artifactJoin; + int fetchSize = LoadUtil.computeFetchSize(MIN_FETCH_SIZE); + getLoader().loadBranches(cancellation, handler, queryContext, fetchSize); } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java index 4e4d3a52f16..c0b1d0140fe 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java @@ -56,7 +56,7 @@ public class UuidsLoadExecutor extends AbstractLoadExecutor { ArtifactJoinQuery join = createIdJoin(options); LoadSqlContext loadContext = new LoadSqlContext(session, options, branch); int fetchSize = LoadUtil.computeFetchSize(artifactIds.size()); - loadFromJoin(join, cancellation, handler, criteria, loadContext, fetchSize); + getLoader().loadArtifacts(cancellation, handler, join, criteria, loadContext, fetchSize); } private ArtifactJoinQuery createIdJoin(Options options) throws OseeCoreException { diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/processor/BranchLoadProcessor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/processor/BranchLoadProcessor.java new file mode 100644 index 00000000000..9509ebee163 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/processor/BranchLoadProcessor.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.loader.processor; + +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.core.IOseeStatement; +import org.eclipse.osee.orcs.core.ds.BranchData; +import org.eclipse.osee.orcs.core.ds.Options; +import org.eclipse.osee.orcs.db.internal.loader.data.BranchObjectFactory; + +/** + * @author Roberto E. Escobar + */ +public class BranchLoadProcessor extends LoadProcessor<BranchData, BranchObjectFactory> { + + public BranchLoadProcessor(BranchObjectFactory factory) { + super(factory); + } + + @Override + protected BranchData createData(Object conditions, BranchObjectFactory factory, IOseeStatement chStmt, Options options) throws OseeCoreException { + int branchId = chStmt.getInt("branch_id"); + + String branchName = chStmt.getString("branch_name"); + BranchState branchState = BranchState.getBranchState(chStmt.getInt("branch_state")); + BranchType branchType = BranchType.valueOf(chStmt.getInt("branch_type")); + BranchArchivedState archiveState = BranchArchivedState.valueOf(chStmt.getInt("archived")); + String branchGuid = chStmt.getString("branch_guid"); + + int parentBranchId = chStmt.getInt("parent_branch_id"); + int sourceTx = chStmt.getInt("parent_transaction_id"); + int baseTx = chStmt.getInt("baseline_transaction_id"); + int assocArtId = chStmt.getInt("associated_art_id"); + + return factory.createBranchData(branchId, branchGuid, branchType, branchName, parentBranchId, baseTx, sourceTx, + archiveState, branchState, assocArtId); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/Engines.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/Engines.java new file mode 100644 index 00000000000..8f1f8614be5 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/Engines.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import org.eclipse.osee.executor.admin.ExecutorAdmin; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.cache.BranchCache; +import org.eclipse.osee.framework.core.services.IdentityService; +import org.eclipse.osee.framework.database.IOseeDatabaseService; +import org.eclipse.osee.framework.resource.management.IResourceManager; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.core.ds.BranchData; +import org.eclipse.osee.orcs.core.ds.DataLoaderFactory; +import org.eclipse.osee.orcs.core.ds.LoadDataHandler; +import org.eclipse.osee.orcs.core.ds.LoadDataHandlerDecorator; +import org.eclipse.osee.orcs.core.ds.QueryEngineIndexer; +import org.eclipse.osee.orcs.data.AttributeTypes; +import org.eclipse.osee.orcs.db.internal.SqlProvider; +import org.eclipse.osee.orcs.db.internal.search.engines.AbstractSimpleQueryCallableFactory; +import org.eclipse.osee.orcs.db.internal.search.engines.ArtifactQueryCallableFactory; +import org.eclipse.osee.orcs.db.internal.search.engines.ArtifactQuerySqlContextFactoryImpl; +import org.eclipse.osee.orcs.db.internal.search.engines.QueryFilterFactoryImpl; +import org.eclipse.osee.orcs.db.internal.search.engines.QuerySqlContextFactoryImpl; +import org.eclipse.osee.orcs.db.internal.search.handlers.SqlHandlerFactoryUtil; +import org.eclipse.osee.orcs.db.internal.search.indexer.IndexedResourceLoader; +import org.eclipse.osee.orcs.db.internal.search.indexer.IndexerCallableFactory; +import org.eclipse.osee.orcs.db.internal.search.indexer.IndexerCallableFactoryImpl; +import org.eclipse.osee.orcs.db.internal.search.indexer.IndexingTaskConsumer; +import org.eclipse.osee.orcs.db.internal.search.indexer.IndexingTaskConsumerImpl; +import org.eclipse.osee.orcs.db.internal.search.indexer.QueryEngineIndexerImpl; +import org.eclipse.osee.orcs.db.internal.search.indexer.data.GammaQueueIndexerDataSourceLoader; +import org.eclipse.osee.orcs.db.internal.search.language.EnglishLanguage; +import org.eclipse.osee.orcs.db.internal.search.tagger.StreamMatcher; +import org.eclipse.osee.orcs.db.internal.search.tagger.TagEncoder; +import org.eclipse.osee.orcs.db.internal.search.tagger.TagProcessor; +import org.eclipse.osee.orcs.db.internal.search.tagger.Tagger; +import org.eclipse.osee.orcs.db.internal.search.tagger.TaggingEngine; +import org.eclipse.osee.orcs.db.internal.search.tagger.TextStreamTagger; +import org.eclipse.osee.orcs.db.internal.search.tagger.XmlTagger; +import org.eclipse.osee.orcs.db.internal.search.util.AttributeDataMatcher; +import org.eclipse.osee.orcs.db.internal.search.util.MatcherFactory; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandlerFactory; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public final class Engines { + + private Engines() { + // + } + + public static ArtifactQueryCallableFactory newArtifactQueryEngine(Log logger, IOseeDatabaseService dbService, IdentityService idService, SqlProvider sqlProvider, TaggingEngine taggingEngine, ExecutorAdmin executorAdmin, DataLoaderFactory objectLoader, BranchCache branchCache, AttributeTypes attrTypes) { + SqlHandlerFactory handlerFactory = + SqlHandlerFactoryUtil.createArtifactSqlHandlerFactory(logger, idService, taggingEngine.getTagProcessor()); + QuerySqlContextFactory sqlContextFactory = + new ArtifactQuerySqlContextFactoryImpl(logger, dbService, sqlProvider, branchCache, handlerFactory); + AttributeDataMatcher matcher = new AttributeDataMatcher(logger, taggingEngine, attrTypes); + QueryFilterFactoryImpl filterFactory = new QueryFilterFactoryImpl(logger, executorAdmin, matcher); + return new ArtifactQueryCallableFactory(logger, objectLoader, sqlContextFactory, filterFactory); + } + + public static QueryCallableFactory newBranchQueryEngine(Log logger, IOseeDatabaseService dbService, IdentityService idService, SqlProvider sqlProvider, DataLoaderFactory objectLoader) { + QuerySqlContextFactory sqlContextFactory = newBranchSqlContextFactory(logger, dbService, idService, sqlProvider); + return new AbstractSimpleQueryCallableFactory(logger, objectLoader, sqlContextFactory) { + @Override + protected LoadDataHandler createCountingHandler(final AtomicInteger counter, LoadDataHandler handler) { + return new LoadDataHandlerDecorator(handler) { + @Override + public void onData(BranchData data) throws OseeCoreException { + counter.getAndIncrement(); + super.onData(data); + } + }; + } + }; + } + + public static TaggingEngine newTaggingEngine(Log logger) { + TagProcessor tagProcessor = new TagProcessor(new EnglishLanguage(logger), new TagEncoder()); + Map<String, Tagger> taggers = new HashMap<String, Tagger>(); + + StreamMatcher matcher = MatcherFactory.createMatcher(); + taggers.put("DefaultAttributeTaggerProvider", new TextStreamTagger(tagProcessor, matcher)); + taggers.put("XmlAttributeTaggerProvider", new XmlTagger(tagProcessor, matcher)); + + return new TaggingEngine(taggers, tagProcessor); + } + + public static QuerySqlContextFactory newSqlContextFactory(Log logger, IOseeDatabaseService dbService, SqlProvider sqlProvider, TableEnum table, String idColumn, SqlHandlerFactory handlerFactory) { + return new QuerySqlContextFactoryImpl(logger, dbService, sqlProvider, handlerFactory, table, idColumn); + } + + public static QuerySqlContextFactory newBranchSqlContextFactory(Log logger, IOseeDatabaseService dbService, IdentityService idService, SqlProvider sqlProvider) { + SqlHandlerFactory handlerFactory = SqlHandlerFactoryUtil.createBranchSqlHandlerFactory(logger, idService); + return newSqlContextFactory(logger, dbService, sqlProvider, TableEnum.BRANCH_TABLE, "branch_id", handlerFactory); + } + + public static QueryEngineIndexer newIndexingEngine(Log logger, IOseeDatabaseService dbService, IdentityService idService, TaggingEngine taggingEngine, ExecutorAdmin executorAdmin, IResourceManager resourceManager) { + IndexedResourceLoader resourceLoader = + new GammaQueueIndexerDataSourceLoader(logger, dbService, idService, resourceManager); + IndexerCallableFactory callableFactory = + new IndexerCallableFactoryImpl(logger, dbService, taggingEngine, resourceLoader); + IndexingTaskConsumer indexConsumer = new IndexingTaskConsumerImpl(executorAdmin, callableFactory); + return new QueryEngineIndexerImpl(logger, dbService, idService, indexConsumer); + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryModule.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryModule.java index 228ce23e0e8..2534c245d23 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryModule.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryModule.java @@ -10,8 +10,10 @@ *******************************************************************************/ package org.eclipse.osee.orcs.db.internal.search; -import java.util.HashMap; -import java.util.Map; +import static org.eclipse.osee.orcs.db.internal.search.Engines.newArtifactQueryEngine; +import static org.eclipse.osee.orcs.db.internal.search.Engines.newBranchQueryEngine; +import static org.eclipse.osee.orcs.db.internal.search.Engines.newIndexingEngine; +import static org.eclipse.osee.orcs.db.internal.search.Engines.newTaggingEngine; import org.eclipse.osee.executor.admin.ExecutorAdmin; import org.eclipse.osee.framework.core.model.cache.BranchCache; import org.eclipse.osee.framework.core.services.IdentityService; @@ -23,30 +25,9 @@ import org.eclipse.osee.orcs.core.ds.QueryEngine; import org.eclipse.osee.orcs.core.ds.QueryEngineIndexer; import org.eclipse.osee.orcs.data.AttributeTypes; import org.eclipse.osee.orcs.db.internal.SqlProvider; -import org.eclipse.osee.orcs.db.internal.search.engines.ArtifactQueryCallableFactory; -import org.eclipse.osee.orcs.db.internal.search.engines.ArtifactQuerySqlContextFactoryImpl; import org.eclipse.osee.orcs.db.internal.search.engines.QueryEngineImpl; -import org.eclipse.osee.orcs.db.internal.search.engines.QueryFilterFactoryImpl; -import org.eclipse.osee.orcs.db.internal.search.handlers.SqlHandlerFactoryUtil; -import org.eclipse.osee.orcs.db.internal.search.indexer.IndexedResourceLoader; -import org.eclipse.osee.orcs.db.internal.search.indexer.IndexerCallableFactory; -import org.eclipse.osee.orcs.db.internal.search.indexer.IndexerCallableFactoryImpl; import org.eclipse.osee.orcs.db.internal.search.indexer.IndexerConstants; -import org.eclipse.osee.orcs.db.internal.search.indexer.IndexingTaskConsumer; -import org.eclipse.osee.orcs.db.internal.search.indexer.IndexingTaskConsumerImpl; -import org.eclipse.osee.orcs.db.internal.search.indexer.QueryEngineIndexerImpl; -import org.eclipse.osee.orcs.db.internal.search.indexer.data.GammaQueueIndexerDataSourceLoader; -import org.eclipse.osee.orcs.db.internal.search.language.EnglishLanguage; -import org.eclipse.osee.orcs.db.internal.search.tagger.StreamMatcher; -import org.eclipse.osee.orcs.db.internal.search.tagger.TagEncoder; -import org.eclipse.osee.orcs.db.internal.search.tagger.TagProcessor; -import org.eclipse.osee.orcs.db.internal.search.tagger.Tagger; import org.eclipse.osee.orcs.db.internal.search.tagger.TaggingEngine; -import org.eclipse.osee.orcs.db.internal.search.tagger.TextStreamTagger; -import org.eclipse.osee.orcs.db.internal.search.tagger.XmlTagger; -import org.eclipse.osee.orcs.db.internal.search.util.AttributeDataMatcher; -import org.eclipse.osee.orcs.db.internal.search.util.MatcherFactory; -import org.eclipse.osee.orcs.db.internal.sql.SqlHandlerFactory; /** * @author Roberto E. Escobar @@ -72,9 +53,10 @@ public class QueryModule { } public void startIndexer(IResourceManager resourceManager) throws Exception { - taggingEngine = createTaggingEngine(); + taggingEngine = newTaggingEngine(logger); + queryIndexer = newIndexingEngine(logger, dbService, idService, taggingEngine, executorAdmin, resourceManager); + executorAdmin.createFixedPoolExecutor(IndexerConstants.INDEXING_CONSUMER_EXECUTOR_ID, 4); - queryIndexer = createQueryEngineIndexer(taggingEngine, resourceManager); } public void stopIndexer() throws Exception { @@ -88,38 +70,11 @@ public class QueryModule { } public QueryEngine createQueryEngine(DataLoaderFactory objectLoader, BranchCache branchCache, AttributeTypes attrTypes) { - ArtifactQueryCallableFactory factory1 = createArtifactQueryEngine(objectLoader, branchCache, attrTypes); - return new QueryEngineImpl(factory1); - } - - protected ArtifactQueryCallableFactory createArtifactQueryEngine(DataLoaderFactory objectLoader, BranchCache branchCache, AttributeTypes attrTypes) { - SqlHandlerFactory handlerFactory = - SqlHandlerFactoryUtil.createArtifactSqlHandlerFactory(logger, idService, taggingEngine.getTagProcessor()); - QuerySqlContextFactory sqlContextFactory = - new ArtifactQuerySqlContextFactoryImpl(logger, dbService, sqlProvider, branchCache, handlerFactory); - AttributeDataMatcher matcher = new AttributeDataMatcher(logger, taggingEngine, attrTypes); - QueryFilterFactoryImpl filterFactory = new QueryFilterFactoryImpl(logger, executorAdmin, matcher); - return new ArtifactQueryCallableFactory(logger, objectLoader, sqlContextFactory, filterFactory); - } - - protected TaggingEngine createTaggingEngine() { - TagProcessor tagProcessor = new TagProcessor(new EnglishLanguage(logger), new TagEncoder()); - Map<String, Tagger> taggers = new HashMap<String, Tagger>(); - - StreamMatcher matcher = MatcherFactory.createMatcher(); - taggers.put("DefaultAttributeTaggerProvider", new TextStreamTagger(tagProcessor, matcher)); - taggers.put("XmlAttributeTaggerProvider", new XmlTagger(tagProcessor, matcher)); - - return new TaggingEngine(taggers, tagProcessor); - } - - protected QueryEngineIndexer createQueryEngineIndexer(TaggingEngine taggingEngine, IResourceManager resourceManager) { - IndexedResourceLoader resourceLoader = - new GammaQueueIndexerDataSourceLoader(logger, dbService, idService, resourceManager); - IndexerCallableFactory callableFactory = - new IndexerCallableFactoryImpl(logger, dbService, taggingEngine, resourceLoader); - IndexingTaskConsumer indexConsumer = new IndexingTaskConsumerImpl(executorAdmin, callableFactory); - return new QueryEngineIndexerImpl(logger, dbService, idService, indexConsumer); + QueryCallableFactory factory1 = + newArtifactQueryEngine(logger, dbService, idService, sqlProvider, taggingEngine, executorAdmin, objectLoader, + branchCache, attrTypes); + QueryCallableFactory factory2 = newBranchQueryEngine(logger, dbService, idService, sqlProvider, objectLoader); + return new QueryEngineImpl(factory1, factory2); } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/AbstractSearchCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/AbstractSearchCallable.java new file mode 100644 index 00000000000..855ae9ba8e1 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/AbstractSearchCallable.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.engines; + +import org.eclipse.osee.executor.admin.CancellableCallable; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsSession; +import org.eclipse.osee.orcs.core.ds.QueryData; + +/** + * @author Roberto E. Escobar + */ +public abstract class AbstractSearchCallable extends CancellableCallable<Integer> { + + private final Log logger; + private final OrcsSession session; + private final QueryData queryData; + + public AbstractSearchCallable(Log logger, OrcsSession session, QueryData queryData) { + super(); + this.logger = logger; + this.session = session; + this.queryData = queryData; + } + + protected OrcsSession getSession() { + return session; + } + + protected QueryData getQueryData() { + return queryData; + } + + @Override + public final Integer call() throws Exception { + long startTime = System.currentTimeMillis(); + long endTime = startTime; + Integer result = null; + try { + if (logger.isTraceEnabled()) { + logger.trace("%s [start] - [%s]", getClass().getSimpleName(), queryData); + } + result = innerCall(); + } finally { + endTime = System.currentTimeMillis() - startTime; + } + if (logger.isTraceEnabled()) { + logger.trace("%s [%s] - completed [%s]", getClass().getSimpleName(), Lib.asTimeString(endTime), queryData); + } + return result; + } + + protected abstract Integer innerCall() throws Exception; + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/AbstractSimpleQueryCallableFactory.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/AbstractSimpleQueryCallableFactory.java new file mode 100644 index 00000000000..b57ab6a4daf --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/AbstractSimpleQueryCallableFactory.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.engines; + +import java.util.concurrent.atomic.AtomicInteger; +import org.eclipse.osee.executor.admin.CancellableCallable; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsSession; +import org.eclipse.osee.orcs.core.ds.DataLoader; +import org.eclipse.osee.orcs.core.ds.DataLoaderFactory; +import org.eclipse.osee.orcs.core.ds.LoadDataHandler; +import org.eclipse.osee.orcs.core.ds.QueryData; +import org.eclipse.osee.orcs.db.internal.search.QueryCallableFactory; +import org.eclipse.osee.orcs.db.internal.search.QuerySqlContext; +import org.eclipse.osee.orcs.db.internal.search.QuerySqlContextFactory; + +/** + * @author Roberto E. Escobar + */ +public abstract class AbstractSimpleQueryCallableFactory implements QueryCallableFactory { + + private final Log logger; + private final DataLoaderFactory objectLoader; + private final QuerySqlContextFactory queryContextFactory; + + public AbstractSimpleQueryCallableFactory(Log logger, DataLoaderFactory objectLoader, QuerySqlContextFactory queryEngine) { + super(); + this.logger = logger; + this.objectLoader = objectLoader; + this.queryContextFactory = queryEngine; + } + + @Override + public CancellableCallable<Integer> createCount(OrcsSession session, QueryData queryData) { + return new AbstractSearchCallable(logger, session, queryData) { + + @Override + protected Integer innerCall() throws Exception { + QuerySqlContext queryContext = queryContextFactory.createCountContext(getSession(), getQueryData()); + checkForCancelled(); + return objectLoader.getCount(this, queryContext); + } + + }; + } + + @Override + public CancellableCallable<Integer> createQuery(OrcsSession session, final QueryData queryData, final LoadDataHandler handler) { + return new AbstractSearchCallable(logger, session, queryData) { + + @Override + protected Integer innerCall() throws Exception { + QuerySqlContext queryContext = queryContextFactory.createQueryContext(getSession(), getQueryData()); + checkForCancelled(); + + DataLoader loader = objectLoader.fromQueryContext(queryContext); + loader.setOptions(getQueryData().getOptions()); + + final AtomicInteger counter = new AtomicInteger(); + LoadDataHandler countingHandler = createCountingHandler(counter, handler); + loader.load(this, countingHandler); + return counter.get(); + } + }; + } + + protected abstract LoadDataHandler createCountingHandler(AtomicInteger counter, LoadDataHandler handler); + +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQueryCallableFactory.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQueryCallableFactory.java index 71d5f073b3d..b826afbe4b5 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQueryCallableFactory.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQueryCallableFactory.java @@ -13,7 +13,6 @@ package org.eclipse.osee.orcs.db.internal.search.engines; import org.eclipse.osee.executor.admin.CancellableCallable; import org.eclipse.osee.framework.core.enums.LoadLevel; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.logger.Log; import org.eclipse.osee.orcs.OrcsSession; import org.eclipse.osee.orcs.core.ds.DataLoader; @@ -46,7 +45,7 @@ public class ArtifactQueryCallableFactory implements QueryCallableFactory { @Override public CancellableCallable<Integer> createCount(OrcsSession session, QueryData queryData) { - return new AbstractSearchCallable(session, queryData) { + return new AbstractArtifactSearchCallable(logger, session, queryData) { @Override protected Integer innerCall() throws Exception { @@ -71,7 +70,7 @@ public class ArtifactQueryCallableFactory implements QueryCallableFactory { @Override public CancellableCallable<Integer> createQuery(OrcsSession session, final QueryData queryData, final LoadDataHandler handler) { - return new AbstractSearchCallable(session, queryData) { + return new AbstractArtifactSearchCallable(logger, session, queryData) { @Override protected Integer innerCall() throws Exception { @@ -81,52 +80,18 @@ public class ArtifactQueryCallableFactory implements QueryCallableFactory { }; } - private abstract class AbstractSearchCallable extends CancellableCallable<Integer> { + private abstract class AbstractArtifactSearchCallable extends AbstractSearchCallable { - private final OrcsSession session; - private final QueryData queryData; - - public AbstractSearchCallable(OrcsSession session, QueryData queryData) { - super(); - this.session = session; - this.queryData = queryData; - } - - protected OrcsSession getSession() { - return session; + public AbstractArtifactSearchCallable(Log logger, OrcsSession session, QueryData queryData) { + super(logger, session, queryData); } - protected QueryData getQueryData() { - return queryData; - } - - @Override - public final Integer call() throws Exception { - long startTime = System.currentTimeMillis(); - long endTime = startTime; - Integer result = null; - try { - if (logger.isTraceEnabled()) { - logger.trace("%s [start] - [%s]", getClass().getSimpleName(), queryData); - } - result = innerCall(); - } finally { - endTime = System.currentTimeMillis() - startTime; - } - if (logger.isTraceEnabled()) { - logger.trace("%s [%s] - completed [%s]", getClass().getSimpleName(), Lib.asTimeString(endTime), queryData); - } - return result; - } - - protected abstract Integer innerCall() throws Exception; - private boolean isLoadLevelTooLow(LoadLevel level) { return LoadLevel.SHALLOW == level; } protected boolean isPostProcessRequired() { - return factory.isFilterRequired(queryData); + return factory.isFilterRequired(getQueryData()); } protected int loadAndGetArtifactCount(LoadDataHandler handler, boolean enableFilter) throws Exception { @@ -143,7 +108,7 @@ public class ArtifactQueryCallableFactory implements QueryCallableFactory { loader.setLoadLevel(LoadLevel.ATTRIBUTE); } } - ArtifactDataCountHandler countingHandler = factory.createHandler(this, queryData, queryContext, handler); + ArtifactDataCountHandler countingHandler = factory.createHandler(this, getQueryData(), queryContext, handler); loader.load(this, countingHandler); return countingHandler.getArtifactCount(); } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryEngineImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryEngineImpl.java index 5f3bfa5401f..58b28174e45 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryEngineImpl.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryEngineImpl.java @@ -15,17 +15,20 @@ import org.eclipse.osee.orcs.OrcsSession; import org.eclipse.osee.orcs.core.ds.LoadDataHandler; import org.eclipse.osee.orcs.core.ds.QueryData; import org.eclipse.osee.orcs.core.ds.QueryEngine; +import org.eclipse.osee.orcs.db.internal.search.QueryCallableFactory; /** * @author Roberto E. Escobar */ public class QueryEngineImpl implements QueryEngine { - private final ArtifactQueryCallableFactory factory1; + private final QueryCallableFactory factory1; + private final QueryCallableFactory factory2; - public QueryEngineImpl(ArtifactQueryCallableFactory factory1) { + public QueryEngineImpl(QueryCallableFactory factory1, QueryCallableFactory factory2) { super(); this.factory1 = factory1; + this.factory2 = factory2; } @Override @@ -38,4 +41,14 @@ public class QueryEngineImpl implements QueryEngine { return factory1.createQuery(session, queryData, handler); } + @Override + public CancellableCallable<Integer> createBranchCount(OrcsSession session, QueryData queryData) { + return factory2.createCount(session, queryData); + } + + @Override + public CancellableCallable<Integer> createBranchQuery(OrcsSession session, QueryData queryData, LoadDataHandler handler) { + return factory2.createQuery(session, queryData, handler); + } + } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlContextFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlContextFactoryImpl.java new file mode 100644 index 00000000000..ae59338d9c7 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlContextFactoryImpl.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2012 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.engines; + +import java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.IOseeDatabaseService; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsSession; +import org.eclipse.osee.orcs.core.ds.CriteriaSet; +import org.eclipse.osee.orcs.core.ds.QueryData; +import org.eclipse.osee.orcs.db.internal.SqlProvider; +import org.eclipse.osee.orcs.db.internal.search.QuerySqlContext; +import org.eclipse.osee.orcs.db.internal.search.QuerySqlContextFactory; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.QueryType; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandlerFactory; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class QuerySqlContextFactoryImpl implements QuerySqlContextFactory { + + private final Log logger; + private final SqlHandlerFactory handlerFactory; + private final SqlProvider sqlProvider; + private final IOseeDatabaseService dbService; + private final TableEnum table; + private final String idColumn; + + public QuerySqlContextFactoryImpl(Log logger, IOseeDatabaseService dbService, SqlProvider sqlProvider, SqlHandlerFactory handlerFactory, TableEnum table, String idColumn) { + this.logger = logger; + this.dbService = dbService; + this.sqlProvider = sqlProvider; + this.handlerFactory = handlerFactory; + this.table = table; + this.idColumn = idColumn; + } + + @Override + public QuerySqlContext createCountContext(OrcsSession session, QueryData queryData) throws OseeCoreException { + return createQueryContext(session, queryData, QueryType.COUNT); + } + + @Override + public QuerySqlContext createQueryContext(OrcsSession session, QueryData queryData) throws OseeCoreException { + return createQueryContext(session, queryData, QueryType.SELECT); + } + + private QuerySqlContext createQueryContext(OrcsSession session, QueryData queryData, QueryType queryType) throws OseeCoreException { + QuerySqlContext context = new QuerySqlContext(session, queryData.getOptions()); + CriteriaSet criteriaSet = queryData.getCriteriaSet(); + AbstractSqlWriter writer = + new QuerySqlWriter(logger, dbService, sqlProvider, context, queryType, table, idColumn); + List<SqlHandler<?>> handlers = handlerFactory.createHandlers(criteriaSet); + writer.build(handlers); + return context; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlWriter.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlWriter.java new file mode 100644 index 00000000000..dd8858304c1 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlWriter.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.engines; + +import java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.IOseeDatabaseService; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.db.internal.SqlProvider; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.QueryType; +import org.eclipse.osee.orcs.db.internal.sql.SqlContext; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class QuerySqlWriter extends AbstractSqlWriter { + + private final TableEnum table; + private final String idColumn; + private final QueryType queryType; + + public QuerySqlWriter(Log logger, IOseeDatabaseService dbService, SqlProvider sqlProvider, SqlContext context, QueryType queryType, TableEnum table, String idColumn) { + super(logger, dbService, sqlProvider, context); + this.queryType = queryType; + this.table = table; + this.idColumn = idColumn; + } + + @Override + public void writeSelect(List<SqlHandler<?>> handlers) throws OseeCoreException { + String tableAlias = getAliasManager().getFirstAlias(table); + if (queryType == QueryType.COUNT) { + write("SELECT%s count(%s.%s)", getSqlHint(), tableAlias, idColumn); + } else { + write("SELECT%s %s.*", getSqlHint(), tableAlias); + } + } + + @Override + protected void write(List<SqlHandler<?>> handlers) throws OseeCoreException { + computeTables(handlers); + computeWithClause(handlers); + + writeWithClause(); + writeSelect(handlers); + write("\n FROM \n"); + writeTables(); + write("\n WHERE \n"); + writePredicates(handlers); + + if (toString().endsWith("\n WHERE \n")) { + removeDanglingSeparator("\n WHERE \n"); + } + writeGroupAndOrder(); + } + + @Override + public void writeGroupAndOrder() throws OseeCoreException { + if (queryType != QueryType.COUNT) { + String tableAlias = getAliasManager().getFirstAlias(table); + write("\n ORDER BY %s.%s", tableAlias, idColumn); + } + } + + @Override + public String getTxBranchFilter(String txsAlias) { + return Strings.emptyString(); + } + +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AllBranchesSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AllBranchesSqlHandler.java new file mode 100644 index 00000000000..749e05ceb82 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AllBranchesSqlHandler.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +import java.util.List; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAllBranches; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class AllBranchesSqlHandler extends SqlHandler<CriteriaAllBranches> { + + private String brAlias; + + @Override + public void setData(CriteriaAllBranches criteria) { + // Criteria not used + } + + @Override + public void addTables(AbstractSqlWriter writer) { + List<String> branchAliases = writer.getAliases(TableEnum.BRANCH_TABLE); + if (branchAliases.isEmpty()) { + brAlias = writer.addTable(TableEnum.BRANCH_TABLE); + } else { + brAlias = branchAliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) { + boolean modified = false; + if (brAlias != null) { + modified = true; + } + return modified; + } + + @Override + public int getPriority() { + return BranchSqlHandlerPriority.ALL_BRANCHES.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchArchivedSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchArchivedSqlHandler.java new file mode 100644 index 00000000000..3aa55c40680 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchArchivedSqlHandler.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.core.AbstractJoinQuery; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchArchived; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class BranchArchivedSqlHandler extends SqlHandler<CriteriaBranchArchived> { + + private CriteriaBranchArchived criteria; + + private String brAlias; + private String jIdAlias; + + @Override + public void setData(CriteriaBranchArchived criteria) { + this.criteria = criteria; + } + + @Override + public void addTables(AbstractSqlWriter writer) { + if (criteria.getStates().size() > 1) { + jIdAlias = writer.addTable(TableEnum.ID_JOIN_TABLE); + } + List<String> branchAliases = writer.getAliases(TableEnum.BRANCH_TABLE); + if (branchAliases.isEmpty()) { + brAlias = writer.addTable(TableEnum.BRANCH_TABLE); + } else { + brAlias = branchAliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException { + Collection<BranchArchivedState> states = criteria.getStates(); + if (states.size() > 1) { + Set<Integer> ids = new HashSet<Integer>(); + for (BranchArchivedState state : states) { + ids.add(state.getValue()); + } + AbstractJoinQuery joinQuery = writer.writeIdJoin(ids); + writer.write(brAlias); + writer.write(".archived = "); + writer.write(jIdAlias); + writer.write(".id AND "); + writer.write(jIdAlias); + writer.write(".query_id = ?"); + writer.addParameter(joinQuery.getQueryId()); + } else { + writer.write(brAlias); + writer.write(".archived = ?"); + writer.addParameter(states.iterator().next().getValue()); + } + return true; + } + + @Override + public int getPriority() { + return BranchSqlHandlerPriority.BRANCH_ARCHIVED.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchChildOfSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchChildOfSqlHandler.java new file mode 100644 index 00000000000..610a145647c --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchChildOfSqlHandler.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +import static org.eclipse.osee.orcs.db.internal.sql.SqlUtil.newRecursiveWithClause; +import java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchChildOf; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.AliasEntry; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.SqlUtil; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + * @author Ryan D. Brooks + */ +public class BranchChildOfSqlHandler extends SqlHandler<CriteriaBranchChildOf> { + + private static final AliasEntry CHILDREN_OF_ENTRY = SqlUtil.newAlias("children_of", "chof"); + + private CriteriaBranchChildOf criteria; + private String withAlias; + private String brAlias; + + @Override + public void setData(CriteriaBranchChildOf criteria) { + this.criteria = criteria; + } + + @Override + public void addWithTables(final AbstractSqlWriter writer) { + withAlias = writer.getNextAlias(CHILDREN_OF_ENTRY); + final StringBuilder body = new StringBuilder(); + body.append(" SELECT anch_br1.branch_id, 0 as branch_level FROM osee_branch anch_br1, osee_branch anch_br2\n"); + body.append(" WHERE anch_br1.parent_branch_id = anch_br2.branch_id AND anch_br2.branch_guid = ?"); + body.append("\n UNION ALL \n"); + body.append(" SELECT branch_id, branch_level + 1 FROM ").append(withAlias).append(" recurse, osee_branch br"); + body.append(" WHERE recurse.child_id = br.parent_branch_id\n"); + writer.addParameter(criteria.getParent().getGuid()); + writer.addWithClause(newRecursiveWithClause(withAlias, "(child_id, branch_level)", body.toString())); + writer.addTable(withAlias); + } + + @Override + public void addTables(AbstractSqlWriter writer) { + List<String> branchAliases = writer.getAliases(TableEnum.BRANCH_TABLE); + if (branchAliases.isEmpty()) { + brAlias = writer.addTable(TableEnum.BRANCH_TABLE); + } else { + brAlias = branchAliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException { + writer.write("%s.branch_id = %s.child_id", brAlias, withAlias); + return true; + } + + @Override + public int getPriority() { + return BranchSqlHandlerPriority.BRANCH_CHILD_OF.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchGuidSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchGuidSqlHandler.java new file mode 100644 index 00000000000..5b3162af6e6 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchGuidSqlHandler.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +import java.util.Collection; +import java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.core.AbstractJoinQuery; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchUuids; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class BranchGuidSqlHandler extends SqlHandler<CriteriaBranchUuids> { + + private CriteriaBranchUuids criteria; + + private String brAlias; + private String jguidAlias; + private AbstractJoinQuery joinQuery; + + @Override + public void setData(CriteriaBranchUuids criteria) { + this.criteria = criteria; + } + + @Override + public void addTables(AbstractSqlWriter writer) { + if (criteria.getIds().size() > 1) { + jguidAlias = writer.addTable(TableEnum.CHAR_JOIN_TABLE); + } + + List<String> branchAliases = writer.getAliases(TableEnum.BRANCH_TABLE); + if (branchAliases.isEmpty()) { + brAlias = writer.addTable(TableEnum.BRANCH_TABLE); + } else { + brAlias = branchAliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException { + Collection<String> ids = criteria.getIds(); + if (ids.size() > 1) { + joinQuery = writer.writeCharJoin(ids); + writer.write(brAlias); + writer.write(".branch_guid = "); + writer.write(jguidAlias); + writer.write(".id AND "); + writer.write(jguidAlias); + writer.write(".query_id = ?"); + writer.addParameter(joinQuery.getQueryId()); + } else { + writer.write(brAlias); + writer.write(".branch_guid = ?"); + writer.addParameter(ids.iterator().next()); + } + return true; + } + + @Override + public int getPriority() { + return BranchSqlHandlerPriority.BRANCH_GUID.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchIdsSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchIdsSqlHandler.java new file mode 100644 index 00000000000..9753e28b6a4 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchIdsSqlHandler.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +import java.util.Collection; +import java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.core.AbstractJoinQuery; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchIds; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class BranchIdsSqlHandler extends SqlHandler<CriteriaBranchIds> { + + private CriteriaBranchIds criteria; + + private String brAlias; + private String jIdAlias; + + @Override + public void setData(CriteriaBranchIds criteria) { + this.criteria = criteria; + } + + @Override + public void addTables(AbstractSqlWriter writer) { + if (criteria.getIds().size() > 1) { + jIdAlias = writer.addTable(TableEnum.ID_JOIN_TABLE); + } + List<String> branchAliases = writer.getAliases(TableEnum.BRANCH_TABLE); + if (branchAliases.isEmpty()) { + brAlias = writer.addTable(TableEnum.BRANCH_TABLE); + } else { + brAlias = branchAliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException { + Collection<Integer> ids = criteria.getIds(); + if (ids.size() > 1) { + AbstractJoinQuery joinQuery = writer.writeIdJoin(ids); + writer.write(brAlias); + writer.write(".branch_id = "); + writer.write(jIdAlias); + writer.write(".id AND "); + writer.write(jIdAlias); + writer.write(".query_id = ?"); + writer.addParameter(joinQuery.getQueryId()); + } else { + writer.write(brAlias); + writer.write(".branch_id = ?"); + writer.addParameter(ids.iterator().next()); + } + return true; + } + + @Override + public int getPriority() { + return BranchSqlHandlerPriority.BRANCH_ID.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchNameSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchNameSqlHandler.java new file mode 100644 index 00000000000..593a39965a5 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchNameSqlHandler.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +import java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchName; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class BranchNameSqlHandler extends SqlHandler<CriteriaBranchName> { + + private CriteriaBranchName criteria; + + private String brAlias; + + @Override + public void setData(CriteriaBranchName criteria) { + this.criteria = criteria; + } + + @Override + public void addTables(AbstractSqlWriter writer) { + List<String> branchAliases = writer.getAliases(TableEnum.BRANCH_TABLE); + if (branchAliases.isEmpty()) { + brAlias = writer.addTable(TableEnum.BRANCH_TABLE); + } else { + brAlias = branchAliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException { + String value = criteria.getValue(); + if (criteria.isPattern()) { + writer.writePatternMatch(brAlias + ".branch_name", "?"); + } else { + writer.write(brAlias); + writer.write(".branch_name = ?"); + } + writer.addParameter(value); + return true; + } + + @Override + public int getPriority() { + return BranchSqlHandlerPriority.BRANCH_NAME.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchSqlHandlerPriority.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchSqlHandlerPriority.java new file mode 100644 index 00000000000..5ad2f45d3a7 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchSqlHandlerPriority.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +/** + * @author Roberto E. Escobar + */ +public enum BranchSqlHandlerPriority { + BRANCH_CHILD_OF, + BRANCH_ID, + BRANCH_GUID, + BRANCH_TYPE, + BRANCH_STATE, + BRANCH_ARCHIVED, + BRANCH_NAME, + ALL_BRANCHES; +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchStateSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchStateSqlHandler.java new file mode 100644 index 00000000000..a306a75588a --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchStateSqlHandler.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.core.AbstractJoinQuery; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchState; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class BranchStateSqlHandler extends SqlHandler<CriteriaBranchState> { + + private CriteriaBranchState criteria; + + private String brAlias; + private String jIdAlias; + + @Override + public void setData(CriteriaBranchState criteria) { + this.criteria = criteria; + } + + @Override + public void addTables(AbstractSqlWriter writer) { + if (criteria.getStates().size() > 1) { + jIdAlias = writer.addTable(TableEnum.ID_JOIN_TABLE); + } + List<String> branchAliases = writer.getAliases(TableEnum.BRANCH_TABLE); + if (branchAliases.isEmpty()) { + brAlias = writer.addTable(TableEnum.BRANCH_TABLE); + } else { + brAlias = branchAliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException { + Collection<BranchState> types = criteria.getStates(); + if (types.size() > 1) { + Set<Integer> ids = new HashSet<Integer>(); + for (BranchState type : types) { + ids.add(type.getValue()); + } + AbstractJoinQuery joinQuery = writer.writeIdJoin(ids); + writer.write(brAlias); + writer.write(".branch_state = "); + writer.write(jIdAlias); + writer.write(".id AND "); + writer.write(jIdAlias); + writer.write(".query_id = ?"); + writer.addParameter(joinQuery.getQueryId()); + } else { + writer.write(brAlias); + writer.write(".branch_state = ?"); + writer.addParameter(types.iterator().next().getValue()); + } + return true; + } + + @Override + public int getPriority() { + return BranchSqlHandlerPriority.BRANCH_STATE.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchTypesSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchTypesSqlHandler.java new file mode 100644 index 00000000000..bd5fb9c4a9e --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/BranchTypesSqlHandler.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.handlers; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.database.core.AbstractJoinQuery; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchType; +import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter; +import org.eclipse.osee.orcs.db.internal.sql.SqlHandler; +import org.eclipse.osee.orcs.db.internal.sql.TableEnum; + +/** + * @author Roberto E. Escobar + */ +public class BranchTypesSqlHandler extends SqlHandler<CriteriaBranchType> { + + private CriteriaBranchType criteria; + + private String brAlias; + private String jIdAlias; + + @Override + public void setData(CriteriaBranchType criteria) { + this.criteria = criteria; + } + + @Override + public void addTables(AbstractSqlWriter writer) { + if (criteria.getTypes().size() > 1) { + jIdAlias = writer.addTable(TableEnum.ID_JOIN_TABLE); + } + List<String> branchAliases = writer.getAliases(TableEnum.BRANCH_TABLE); + if (branchAliases.isEmpty()) { + brAlias = writer.addTable(TableEnum.BRANCH_TABLE); + } else { + brAlias = branchAliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException { + Collection<BranchType> types = criteria.getTypes(); + if (types.size() > 1) { + Set<Integer> ids = new HashSet<Integer>(); + for (BranchType type : types) { + ids.add(type.getValue()); + } + AbstractJoinQuery joinQuery = writer.writeIdJoin(ids); + writer.write(brAlias); + writer.write(".branch_type = "); + writer.write(jIdAlias); + writer.write(".id AND "); + writer.write(jIdAlias); + writer.write(".query_id = ?"); + writer.addParameter(joinQuery.getQueryId()); + } else { + writer.write(brAlias); + writer.write(".branch_type = ?"); + writer.addParameter(types.iterator().next().getValue()); + } + return true; + } + + @Override + public int getPriority() { + return BranchSqlHandlerPriority.BRANCH_TYPE.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java index 71be1e9cf96..8c3364bed55 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java @@ -16,6 +16,7 @@ import org.eclipse.osee.framework.core.services.IdentityService; import org.eclipse.osee.logger.Log; import org.eclipse.osee.orcs.core.ds.Criteria; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAllArtifacts; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAllBranches; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactGuids; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactHrids; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactIds; @@ -23,6 +24,13 @@ import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactType; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeKeywords; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeOther; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeTypeExists; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchArchived; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchChildOf; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchIds; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchName; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchState; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchType; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchUuids; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelatedTo; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists; import org.eclipse.osee.orcs.db.internal.search.tagger.TagProcessor; @@ -56,4 +64,21 @@ public final class SqlHandlerFactoryUtil { return new SqlHandlerFactoryImpl(logger, identityService, tagProcessor, handleMap); } + + public static SqlHandlerFactory createBranchSqlHandlerFactory(Log logger, IdentityService identityService) { + Map<Class<? extends Criteria>, Class<? extends SqlHandler<?>>> handleMap = + new HashMap<Class<? extends Criteria>, Class<? extends SqlHandler<?>>>(); + + // Query + handleMap.put(CriteriaBranchArchived.class, BranchArchivedSqlHandler.class); + handleMap.put(CriteriaBranchUuids.class, BranchGuidSqlHandler.class); + handleMap.put(CriteriaBranchIds.class, BranchIdsSqlHandler.class); + handleMap.put(CriteriaBranchName.class, BranchNameSqlHandler.class); + handleMap.put(CriteriaBranchState.class, BranchStateSqlHandler.class); + handleMap.put(CriteriaBranchType.class, BranchTypesSqlHandler.class); + handleMap.put(CriteriaBranchChildOf.class, BranchChildOfSqlHandler.class); + handleMap.put(CriteriaAllBranches.class, AllBranchesSqlHandler.class); + + return new SqlHandlerFactoryImpl(logger, identityService, handleMap); + } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/RelationalConstants.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/RelationalConstants.java index 78ea7913bde..08f3926f902 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/RelationalConstants.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/RelationalConstants.java @@ -28,6 +28,7 @@ public final class RelationalConstants { public static final boolean IS_HISTORICAL_DEFAULT = false; public static final int ART_ID_SENTINEL = -1; public static final String DEFAULT_RATIONALE = ""; + public static final String DEFAULT_NAME = ""; public static final int DEFAULT_ITEM_ID = -1; public static final long DEFAULT_TYPE_UUID = -1L; diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java index b4f40bd600b..06a6b1124fd 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java @@ -10,11 +10,11 @@ *******************************************************************************/ package org.eclipse.osee.orcs.db.internal.sql; - /** * @author Roberto E. Escobar */ public enum TableEnum implements AliasEntry { + BRANCH_TABLE("osee_branch", "br"), TXS_TABLE("osee_txs", "txs"), ARTIFACT_TABLE("osee_artifact", "art"), ATTRIBUTE_TABLE("osee_attribute", "att"), diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationTestSuite.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationTestSuite.java index 7d48188a8a8..cfec7eba84e 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationTestSuite.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationTestSuite.java @@ -12,6 +12,7 @@ package org.eclipse.osee.orcs; import org.eclipse.osee.orcs.api.OrcsAttributeLoadingTest; import org.eclipse.osee.orcs.api.OrcsAttributeSearchTest; +import org.eclipse.osee.orcs.api.OrcsBranchQueryTest; import org.eclipse.osee.orcs.api.OrcsBranchTest; import org.eclipse.osee.orcs.api.OrcsPortingTest; import org.eclipse.osee.orcs.api.OrcsQueryTest; @@ -27,6 +28,7 @@ import org.junit.runners.Suite; @Suite.SuiteClasses({ OrcsAttributeLoadingTest.class, OrcsAttributeSearchTest.class, + OrcsBranchQueryTest.class, OrcsBranchTest.class, OrcsPortingTest.class, OrcsQueryTest.class, diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsBranchQueryTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsBranchQueryTest.java new file mode 100644 index 00000000000..fe36ea107a6 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsBranchQueryTest.java @@ -0,0 +1,319 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.api; + +import static org.eclipse.osee.framework.core.enums.BranchState.CREATED; +import static org.eclipse.osee.framework.core.enums.BranchState.MODIFIED; +import static org.eclipse.osee.framework.core.enums.BranchType.BASELINE; +import static org.eclipse.osee.framework.core.enums.BranchType.SYSTEM_ROOT; +import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON; +import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule; +import static org.eclipse.osee.orcs.api.TestBranches.CIS_Bld_1; +import static org.eclipse.osee.orcs.api.TestBranches.SAW_Bld_1; +import static org.eclipse.osee.orcs.api.TestBranches.SAW_Bld_2; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import java.util.Iterator; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.ResultSet; +import org.eclipse.osee.framework.core.data.TokenFactory; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.core.enums.SystemUser; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.orcs.ApplicationContext; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.OrcsBranch; +import org.eclipse.osee.orcs.data.ArchiveOperation; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.BranchReadable; +import org.eclipse.osee.orcs.db.mock.OsgiService; +import org.eclipse.osee.orcs.search.BranchQuery; +import org.eclipse.osee.orcs.search.QueryFactory; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; +import org.junit.rules.TestRule; + +/** + * @author Roberto E. Escobar + */ +public class OrcsBranchQueryTest { + + @Rule + public TestRule osgi = integrationRule(this, "osee.demo.hsql"); + + @Rule + public TestName testName = new TestName(); + + @OsgiService + private OrcsApi orcsApi; + + private QueryFactory factory; + + private static IOseeBranch SYS_ROOT = CoreBranches.SYSTEM_ROOT; + + @Before + public void setup() { + ApplicationContext context = null; // TODO use real application context + factory = orcsApi.getQueryFactory(context); + } + + // 'System Root Branch',4,1,'AyH_fDnM2RFEhyybolQA', -1,0,1,1,-1, 1) + // 'Common', 2,4,'AyH_fDpMERA+zDfML4gA', -1,0,2,1, 1, 3) + // 'SAW_Bld_1', 2,15,'AyH_f2sSKy3l07fIvAAA',-1,0,3,1, 1, 3) + // 'CIS_Bld_1', 2,17,'AyH_f2sSKy3l07fIvDDD',-1,0,4,1, 1, 3) + // 'SAW_Bld_2', 2,23,'AyH_f2sSKy3l07fIvBBB', 9,0,5,0, 3,22) + + @Test + public void testGetAll() throws OseeCoreException { + BranchQuery query = factory.branchQuery(); + + ResultSet<BranchReadable> results = query.getResults(); + assertEquals(5, results.size()); + assertEquals(5, query.getCount()); + + Iterator<BranchReadable> iterator = results.iterator(); + BranchReadable branch1 = iterator.next(); + BranchReadable branch2 = iterator.next(); + BranchReadable branch3 = iterator.next(); + BranchReadable branch4 = iterator.next(); + BranchReadable branch5 = iterator.next(); + + // actual, IOseeBranch, localId, type, state, isArchived, parentId, baseTx, sourceTx, assocArtId + assertBranch(branch1, SYS_ROOT, 1, SYSTEM_ROOT, MODIFIED, false, -1, 1, 1, -1); + assertBranch(branch2, COMMON, 2, BASELINE, MODIFIED, false, 1, 4, 3, -1); + assertBranch(branch3, SAW_Bld_1, 3, BASELINE, MODIFIED, false, 1, 15, 3, -1); + assertBranch(branch4, CIS_Bld_1, 4, BASELINE, MODIFIED, false, 1, 17, 3, -1); + assertBranch(branch5, SAW_Bld_2, 5, BASELINE, CREATED, false, 3, 23, 22, 9); + } + + @Test + public void testGetByType() throws OseeCoreException { + BranchQuery query = factory.branchQuery(); + query.andIsOfType(SYSTEM_ROOT); + + assertEquals(1, query.getCount()); + assertEquals(CoreBranches.SYSTEM_ROOT, query.getResults().getExactlyOne()); + + query = factory.branchQuery(); + query.andIsOfType(BASELINE); + + ResultSet<BranchReadable> results = query.getResults(); + assertEquals(4, results.size()); + assertEquals(4, query.getCount()); + + Iterator<BranchReadable> iterator = results.iterator(); + BranchReadable branch1 = iterator.next(); + BranchReadable branch2 = iterator.next(); + BranchReadable branch3 = iterator.next(); + BranchReadable branch4 = iterator.next(); + + assertEquals(COMMON, branch1); + assertEquals(SAW_Bld_1, branch2); + assertEquals(CIS_Bld_1, branch3); + assertEquals(SAW_Bld_2, branch4); + } + + @Test + public void testGetByUuid() throws OseeCoreException { + BranchQuery query = factory.branchQuery(); + query.andUuids(COMMON.getGuid(), SAW_Bld_2.getGuid()); + + ResultSet<BranchReadable> results = query.getResults(); + assertEquals(2, results.size()); + assertEquals(2, query.getCount()); + + Iterator<BranchReadable> iterator = results.iterator(); + BranchReadable branch1 = iterator.next(); + BranchReadable branch2 = iterator.next(); + + assertEquals(COMMON, branch1); + assertEquals(SAW_Bld_2, branch2); + } + + @Test + public void testGetByLocalId() throws OseeCoreException { + BranchQuery query = factory.branchQuery(); + query.andLocalId(5, 3); + + ResultSet<BranchReadable> results = query.getResults(); + assertEquals(2, results.size()); + assertEquals(2, query.getCount()); + + Iterator<BranchReadable> iterator = results.iterator(); + BranchReadable branch1 = iterator.next(); + BranchReadable branch2 = iterator.next(); + + assertEquals(SAW_Bld_1, branch1); + assertEquals(SAW_Bld_2, branch2); + } + + @Test + public void testGetByNameEquals() throws OseeCoreException { + BranchQuery query = factory.branchQuery(); + query.andNameEquals("CIS_Bld_1"); + + assertEquals(CIS_Bld_1, query.getResults().getExactlyOne()); + assertEquals(1, query.getCount()); + } + + @Test + public void testGetByNamePatternEquals() throws OseeCoreException { + BranchQuery query = factory.branchQuery(); + query.andNamePattern("SAW.*?_Bld.*"); + + ResultSet<BranchReadable> results = query.getResults(); + assertEquals(2, results.size()); + assertEquals(2, query.getCount()); + + Iterator<BranchReadable> iterator = results.iterator(); + BranchReadable branch1 = iterator.next(); + BranchReadable branch2 = iterator.next(); + + assertEquals(SAW_Bld_1, branch1); + assertEquals(SAW_Bld_2, branch2); + } + + @Test + public void testGetByState() throws OseeCoreException { + BranchQuery query = factory.branchQuery(); + query.andStateIs(CREATED); + + assertEquals(SAW_Bld_2, query.getResults().getExactlyOne()); + assertEquals(1, query.getCount()); + } + + @Test + public void testGetByChildOf() throws OseeCoreException { + BranchQuery query = factory.branchQuery(); + query.andIsChildOf(SAW_Bld_1); + + assertEquals(SAW_Bld_2, query.getResults().getExactlyOne()); + assertEquals(1, query.getCount()); + + query = factory.branchQuery(); + query.andIsChildOf(SYS_ROOT); + + ResultSet<BranchReadable> results = query.getResults(); + assertEquals(4, results.size()); + assertEquals(4, query.getCount()); + + Iterator<BranchReadable> iterator = results.iterator(); + BranchReadable branch1 = iterator.next(); + BranchReadable branch2 = iterator.next(); + BranchReadable branch3 = iterator.next(); + BranchReadable branch4 = iterator.next(); + + assertEquals(COMMON, branch1); + assertEquals(SAW_Bld_1, branch2); + assertEquals(CIS_Bld_1, branch3); + assertEquals(SAW_Bld_2, branch4); + } + + @Test + public void testGetIncludeArchived() throws Exception { + IOseeBranch child = TokenFactory.createBranch(GUID.create(), testName.getMethodName()); + + BranchQuery query = factory.branchQuery(); + query.andIds(CIS_Bld_1); + BranchReadable cisBranch = query.getResults().getExactlyOne(); + + IOseeBranch actual = createBranch(cisBranch, child); + assertEquals(child, actual); + + getBranchOps().archiveUnarchiveBranch(actual, ArchiveOperation.ARCHIVE).call(); + + query = factory.branchQuery(); + query.andIds(child); + query.excludeArchived(); + assertNull(query.getResults().getOneOrNull()); + + query.includeArchived(); + assertEquals(child, query.getResults().getExactlyOne()); + } + + @Test + public void testGetIncludeDeleted() throws Exception { + IOseeBranch child = TokenFactory.createBranch(GUID.create(), testName.getMethodName()); + + BranchQuery query = factory.branchQuery(); + query.andIds(CIS_Bld_1); + BranchReadable cisBranch = query.getResults().getExactlyOne(); + + IOseeBranch actual = createBranch(cisBranch, child); + assertEquals(child, actual); + + query = factory.branchQuery(); + query.andIds(child); + assertEquals(child, query.getResults().getOneOrNull()); + + getBranchOps().changeBranchState(actual, BranchState.DELETED).call(); + + query = factory.branchQuery(); + query.andIds(child); + query.excludeDeleted(); + assertNull(query.getResults().getOneOrNull()); + + query.includeDeleted(); + assertEquals(child, query.getResults().getExactlyOne()); + } + + @Test + public void testGetWithMultipleConditions1() throws Exception { + IOseeBranch child = TokenFactory.createBranch(GUID.create(), testName.getMethodName()); + + IOseeBranch actual = createBranch(SAW_Bld_2, child); + + BranchQuery query = factory.branchQuery(); + query.andIsOfType(BranchType.WORKING).andIsChildOf(SAW_Bld_1).andStateIs(BranchState.CREATED); + + ResultSet<BranchReadable> results = query.getResults(); + assertEquals(actual, results.getExactlyOne()); + assertEquals(1, query.getCount()); + } + + private IOseeBranch createBranch(IOseeBranch parent, IOseeBranch id) throws Exception { + ArtifactReadable author = getSystemUser(); + return getBranchOps().createWorkingBranch(id, author, parent, null).call(); + } + + private ArtifactReadable getSystemUser() throws OseeCoreException { + return factory.fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne(); + } + + private OrcsBranch getBranchOps() { + return orcsApi.getBranchOps(null); + } + + private static void assertBranch(BranchReadable actual, IOseeBranch token, int localId, BranchType type, BranchState state, boolean isArchived, int parent, int baseTx, int sourceTx, int assocArtId) { + assertEquals(token, actual); + assertBranch(actual, token.getName(), token.getGuid(), localId, type, state, isArchived, parent, baseTx, + sourceTx, assocArtId); + } + + private static void assertBranch(BranchReadable actual, String name, String guid, int localId, BranchType type, BranchState state, boolean isArchived, int parent, int baseTx, int sourceTx, int assocArtId) { + assertEquals(guid, actual.getGuid()); + assertEquals(name, actual.getName()); + assertEquals(localId, actual.getLocalId()); + + assertEquals(type, actual.getBranchType()); + assertEquals(state, actual.getBranchState()); + assertEquals(isArchived, actual.getArchiveState().isArchived()); + assertEquals(parent, actual.getParentBranch()); + assertEquals(baseTx, actual.getBaseTransaction()); + assertEquals(sourceTx, actual.getSourceTransaction()); + assertEquals(assocArtId, actual.getAssociatedArtifactId()); + } +} diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java index 7bd1ec44e72..a09ae8f1dfc 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java @@ -403,7 +403,7 @@ public class OrcsTransactionTest { tx1.addChildren(art1, art2, art3); ArtifactId art4 = tx1.createArtifact(GeneralDocument, "Document"); tx1.relate(art1, Dependency__Dependency, art4); - int txId = tx1.commit().getId(); + tx1.commit(); ArtifactReadable artifact4 = query.fromBranch(CoreBranches.COMMON).andIds(art4).getResults().getExactlyOne(); assertEquals(art4, artifact4); @@ -418,7 +418,7 @@ public class OrcsTransactionTest { // Un-relate a child TransactionBuilder tx2 = createTx(); tx2.unrelate(art1, Default_Hierarchical__Child, art2); - int txId2 = tx2.commit().getId(); + tx2.commit(); artifact4 = query.fromBranch(CoreBranches.COMMON).andIds(art4).getResults().getExactlyOne(); assertEquals(art4, artifact4); diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/TestBranches.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/TestBranches.java index 7e1f63e1ef5..f9ee089a60b 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/TestBranches.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/TestBranches.java @@ -24,4 +24,6 @@ public final class TestBranches { public static final IOseeBranch SAW_Bld_1 = TokenFactory.createBranch("AyH_f2sSKy3l07fIvAAA", "SAW_Bld_1"); public static final IOseeBranch SAW_Bld_2 = TokenFactory.createBranch("AyH_f2sSKy3l07fIvBBB", "SAW_Bld_2"); + + public static final IOseeBranch CIS_Bld_1 = TokenFactory.createBranch("AyH_f2sSKy3l07fIvDDD", "CIS_Bld_1"); } diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/BranchReadable.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/BranchReadable.java new file mode 100644 index 00000000000..19cd2c8ef4c --- /dev/null +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/BranchReadable.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2012 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.data; + +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.Identifiable; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; + +/** + * @author Roberto E. Escobar + */ +public interface BranchReadable extends Identifiable, HasLocalId, IOseeBranch { + + BranchArchivedState getArchiveState(); + + BranchState getBranchState(); + + BranchType getBranchType(); + + boolean hasParentBranch(); + + // These get Id method might change + int getAssociatedArtifactId(); + + int getBaseTransaction(); + + int getSourceTransaction(); + + int getParentBranch(); + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/BranchQuery.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/BranchQuery.java new file mode 100644 index 00000000000..279aadd92c6 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/BranchQuery.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.search; + +import java.util.Collection; +import org.eclipse.osee.executor.admin.CancellableCallable; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.ResultSet; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.data.BranchReadable; + +/** + * @author Ryan D. Brooks + * @author Roberto E. Escobar + */ +public interface BranchQuery { + + BranchQuery includeDeleted(); + + BranchQuery excludeDeleted(); + + BranchQuery includeDeleted(boolean enabled); + + boolean areDeletedIncluded(); + + BranchQuery includeArchived(); + + BranchQuery includeArchived(boolean enabled); + + BranchQuery excludeArchived(); + + boolean areArchivedIncluded(); + + BranchQuery andLocalId(int... id) throws OseeCoreException; + + BranchQuery andLocalIds(Collection<Integer> ids) throws OseeCoreException; + + BranchQuery andUuids(String... ids) throws OseeCoreException; + + BranchQuery andUuids(Collection<String> ids) throws OseeCoreException; + + BranchQuery andIds(Collection<? extends IOseeBranch> ids) throws OseeCoreException; + + BranchQuery andIds(IOseeBranch... ids) throws OseeCoreException; + + BranchQuery andIsOfType(BranchType... branchType) throws OseeCoreException; + + BranchQuery andStateIs(BranchState... branchState) throws OseeCoreException; + + BranchQuery andNameEquals(String value) throws OseeCoreException; + + BranchQuery andNamePattern(String pattern) throws OseeCoreException; + + BranchQuery andIsChildOf(IOseeBranch branch) throws OseeCoreException; + + ResultSet<BranchReadable> getResults() throws OseeCoreException; + + ResultSet<IOseeBranch> getResultsAsId() throws OseeCoreException; + + int getCount() throws OseeCoreException; + + CancellableCallable<Integer> createCount() throws OseeCoreException; + + CancellableCallable<ResultSet<BranchReadable>> createSearch() throws OseeCoreException; + + CancellableCallable<ResultSet<IOseeBranch>> createSearchResultsAsIds() throws OseeCoreException; + +} diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java index b8168b6882b..0c97d0c28f3 100644 --- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java @@ -28,4 +28,6 @@ public interface QueryFactory { QueryBuilder fromArtifacts(Collection<? extends ArtifactReadable> artifacts) throws OseeCoreException; + BranchQuery branchQuery(); + } |