Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2010-09-15 22:01:57 +0000
committerRyan D. Brooks2010-09-15 22:01:57 +0000
commit63518f90be8a8eae9b65af5a15ec69778b4ef255 (patch)
tree105be9d0e6847b46ff47c38d20cc5b5a2b9c7077
parent5bbe536bc0bb97fd2af4e851bbf51658c0e894a8 (diff)
downloadorg.eclipse.osee-63518f90be8a8eae9b65af5a15ec69778b4ef255.tar.gz
org.eclipse.osee-63518f90be8a8eae9b65af5a15ec69778b4ef255.tar.xz
org.eclipse.osee-63518f90be8a8eae9b65af5a15ec69778b4ef255.zip
refactor: Make searchTag query testable
-rw-r--r--plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/SearchTagQueryBuilderTest.java109
-rw-r--r--plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/UtilityTestSuite.java14
-rw-r--r--plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/attribute/AttributeDataStore.java74
-rw-r--r--plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/utility/SearchTagQueryBuilder.java79
4 files changed, 201 insertions, 75 deletions
diff --git a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/SearchTagQueryBuilderTest.java b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/SearchTagQueryBuilderTest.java
new file mode 100644
index 00000000000..b2768fe62b3
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/SearchTagQueryBuilderTest.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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.framework.search.engine.test.utility;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.search.engine.utility.SearchTagQueryBuilder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Test Case for {@link SearchTagQueryBuilder}
+ *
+ * @author Roberto E. Escobar
+ */
+@RunWith(Parameterized.class)
+public class SearchTagQueryBuilderTest {
+
+ private final int numberOfItems;
+ private final boolean useAttributeTypeJoin;
+ private final int branchId;
+ private final boolean includeDeleted;
+
+ public SearchTagQueryBuilderTest(int numberOfItems, boolean useAttributeTypeJoin, int branchId, boolean includeDeleted) {
+ super();
+ this.numberOfItems = numberOfItems;
+ this.useAttributeTypeJoin = useAttributeTypeJoin;
+ this.branchId = branchId;
+ this.includeDeleted = includeDeleted;
+ }
+
+ @Test
+ public void testCase() {
+ SearchTagQueryBuilder builder = new SearchTagQueryBuilder();
+ String actualQuery = builder.getQuery(numberOfItems, useAttributeTypeJoin, branchId, includeDeleted);
+ String expectedQuery = createExpected(numberOfItems, useAttributeTypeJoin, branchId, includeDeleted);
+ Assert.assertEquals(expectedQuery, actualQuery);
+ }
+
+ @Parameters
+ public static Collection<Object[]> data() {
+ List<Object[]> data = new ArrayList<Object[]>();
+
+ data.add(new Object[] {1, true, 2, false});
+ data.add(new Object[] {1, false, -1, false});
+ data.add(new Object[] {1, true, -1, false});
+ data.add(new Object[] {1, false, -1, true});
+
+ data.add(new Object[] {3, false, 2, false});
+ data.add(new Object[] {3, true, 2, false});
+ data.add(new Object[] {3, false, -1, false});
+ data.add(new Object[] {3, true, -1, false});
+ data.add(new Object[] {3, false, -1, true});
+
+ data.add(new Object[] {4, true, 2, false});
+ data.add(new Object[] {4, false, -1, false});
+ data.add(new Object[] {4, true, 6, false});
+ data.add(new Object[] {4, false, -1, true});
+ return data;
+ }
+
+ private static String createExpected(int count, boolean hasJoin, int branchId, boolean includeDeleted) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT /*+ ordered FIRST_ROWS */ attr1.art_id, attr1.gamma_id, attr1.value, attr1.uri, attr1.attr_type_id, txs1.branch_id FROM \n");
+
+ for (int index = 0; index < count; index++) {
+ builder.append(String.format("osee_search_tags ost%s, \n", index));
+ }
+ if (hasJoin) {
+ builder.append(" osee_join_id idj,");
+ }
+ builder.append(" osee_attribute attr1, osee_txs txs1 WHERE \n");
+
+ for (int index = 0; index < count; index++) {
+ builder.append(String.format("ost%s.coded_tag_id = ? AND\n", index));
+ }
+
+ for (int index = 0; index < count - 1; index++) {
+ builder.append(String.format("ost%s.gamma_id = ost%s.gamma_id AND \n", index, index + 1));
+ }
+ builder.append(String.format("ost%s.gamma_id = attr1.gamma_id AND\n", count - 1));
+ builder.append(" attr1.gamma_id = txs1.gamma_id\n");
+
+ if (hasJoin) {
+ builder.append(" AND attr1.attr_type_id = idj.id AND idj.query_id = ?\n");
+ }
+ if (branchId > -1) {
+ builder.append(" AND txs1.branch_id = ?");
+ }
+ if (includeDeleted) {
+ builder.append(" AND txs1.tx_current IN (1,3)");
+ } else {
+ builder.append(" AND txs1.tx_current = 1");
+ }
+ return builder.toString();
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/UtilityTestSuite.java b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/UtilityTestSuite.java
index bc84dfdb289..3601dccb66d 100644
--- a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/UtilityTestSuite.java
+++ b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/UtilityTestSuite.java
@@ -17,12 +17,14 @@ import org.junit.runners.Suite;
* @author Roberto E. Escobar
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({ //
-// SearchTagQueryBuilderTest.class, //
-TagEncoderTest.class, //
- TagProcessorTest.class, //
- WordOrderMatcherTest.class, //
- WordsUtilTest.class //
+@Suite.SuiteClasses({
+//@formatter:off
+ SearchTagQueryBuilderTest.class,
+ TagEncoderTest.class,
+ TagProcessorTest.class,
+ WordOrderMatcherTest.class,
+ WordsUtilTest.class
+//@formatter:on
})
public class UtilityTestSuite {
// Test Suite
diff --git a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/attribute/AttributeDataStore.java b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/attribute/AttributeDataStore.java
index f87d0815f6b..7bb1aea93fd 100644
--- a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/attribute/AttributeDataStore.java
+++ b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/attribute/AttributeDataStore.java
@@ -24,9 +24,7 @@ import org.eclipse.osee.framework.database.core.IOseeStatement;
import org.eclipse.osee.framework.database.core.JoinUtility;
import org.eclipse.osee.framework.database.core.JoinUtility.IdJoinQuery;
import org.eclipse.osee.framework.database.core.OseeConnection;
-import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
-import org.eclipse.osee.framework.search.engine.SearchOptions;
-import org.eclipse.osee.framework.search.engine.SearchOptions.SearchOptionsEnum;
+import org.eclipse.osee.framework.search.engine.utility.SearchTagQueryBuilder;
/**
* @author Roberto E. Escobar
@@ -46,8 +44,7 @@ public final class AttributeDataStore {
private static final String RESTRICT_BY_BRANCH = " AND txs1.branch_id = ?";
- private static final CompositeKeyHashMap<Integer, Boolean, String> queryCache =
- new CompositeKeyHashMap<Integer, Boolean, String>();
+ private static final SearchTagQueryBuilder searchTagQueryBuilder = new SearchTagQueryBuilder();
private AttributeDataStore() {
// Utility Class
@@ -70,76 +67,15 @@ public final class AttributeDataStore {
return attributeData;
}
- private static String getAttributeTagQuery(int numberOfTags, boolean useAttrTypeJoin) {
- String query = queryCache.get(numberOfTags, useAttrTypeJoin);
- if (query == null) {
- StringBuilder codedTag = new StringBuilder();
- codedTag.append("SELECT /*+ ordered FIRST_ROWS */ attr1.art_id, attr1.gamma_id, attr1.value, attr1.uri, attr1.attr_type_id, txs1.branch_id FROM \n");
- for (int index = 0; index < numberOfTags; index++) {
- codedTag.append(String.format("osee_search_tags ost%d, \n", index));
- }
- codedTag.append("osee_attribute attr1,");
- if (useAttrTypeJoin) {
- codedTag.append(" osee_join_id idj,");
- }
- codedTag.append(" osee_txs txs1 WHERE \n");
-
- for (int index = 0; index < numberOfTags; index++) {
- codedTag.append(String.format("ost%d.coded_tag_id = ? and\n", index));
- }
- for (int index = 1; index < numberOfTags; index++) {
- codedTag.append(String.format("ost%d.gamma_id = ost%d.gamma_id and \n", index - 1, index));
- }
- codedTag.append(String.format("ost%d.gamma_id = attr1.gamma_id and\n attr1.gamma_id = txs1.gamma_id \n",
- numberOfTags - 1));
-
- if (useAttrTypeJoin) {
- codedTag.append(" and attr1.attr_type_id = idj.id and idj.query_id = ? ");
- }
- query = codedTag.toString();
- queryCache.put(numberOfTags, useAttrTypeJoin, query);
- }
- return query;
- }
-
- private static String getQuery(final String baseQuery, final int branchId, final SearchOptions options) {
- StringBuilder toReturn = new StringBuilder(baseQuery);
- if (branchId > -1) {
- toReturn.append(RESTRICT_BY_BRANCH);
- }
- // txs1 is for attributes, txs2 is for artifact
- if (options.getBoolean(SearchOptionsEnum.include_deleted.asStringOption())) {
- toReturn.append(" AND txs1.tx_current IN (1,3)");
- } else {
- toReturn.append(" AND txs1.tx_current = 1");
- }
- return toReturn.toString();
- }
-
- public static void main(String[] args) {
- for (int index = 1; index < 13; index++) {
- System.out.println("\n------------------------------------------------------------");
- System.out.println(getQuery(getAttributeTagQuery(index, false), 2, new SearchOptions()));
- System.out.println("\n------------------------------------------------------------");
- System.out.println(getQuery(getAttributeTagQuery(index, true), 2, new SearchOptions()));
- }
-
- for (int index = 1; index < 13; index++) {
- System.out.println("\n------------------------------------------------------------");
- System.out.println(getQuery(getAttributeTagQuery(index, false), 2, new SearchOptions()));
- System.out.println("\n------------------------------------------------------------");
- System.out.println(getQuery(getAttributeTagQuery(index, true), 2, new SearchOptions()));
- }
- }
-
- public static Set<AttributeData> getAttributesByTags(final int branchId, final SearchOptions options, final Collection<Long> tagData, final AttributeType... attributeTypes) throws OseeCoreException {
+ public static Set<AttributeData> getAttributesByTags(int branchId, boolean includeDeleted, final Collection<Long> tagData, final AttributeType... attributeTypes) throws OseeCoreException {
final Set<AttributeData> toReturn = new HashSet<AttributeData>();
+
IdJoinQuery oseeIdJoin = null;
IOseeStatement chStmt = ConnectionHandler.getStatement();
boolean useAttrTypeJoin = attributeTypes.length > 1;
try {
- String sqlQuery = getQuery(getAttributeTagQuery(tagData.size(), useAttrTypeJoin), branchId, options);
+ String sqlQuery = searchTagQueryBuilder.getQuery(tagData.size(), useAttrTypeJoin, branchId, includeDeleted);
List<Object> params = new ArrayList<Object>();
params.addAll(tagData);
diff --git a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/utility/SearchTagQueryBuilder.java b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/utility/SearchTagQueryBuilder.java
new file mode 100644
index 00000000000..550dd24a48c
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/utility/SearchTagQueryBuilder.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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.framework.search.engine.utility;
+
+import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class SearchTagQueryBuilder {
+ private static final String RESTRICT_BY_BRANCH = " AND txs1.branch_id = ?";
+
+ private static final CompositeKeyHashMap<Integer, Boolean, String> queryCache =
+ new CompositeKeyHashMap<Integer, Boolean, String>();
+
+ public SearchTagQueryBuilder() {
+ super();
+ }
+
+ public String getQuery(int numberOfTags, boolean useAttrTypeJoin, final int branchId, final boolean includeDeleted) {
+ String baseQuery = getTagQuery(numberOfTags, useAttrTypeJoin);
+
+ StringBuilder toReturn = new StringBuilder();
+ toReturn.append(baseQuery);
+ if (branchId > -1) {
+ toReturn.append(RESTRICT_BY_BRANCH);
+ }
+ // txs1 is for attributes, txs2 is for artifact
+ if (includeDeleted) {
+ toReturn.append(" AND txs1.tx_current IN (1,3)");
+ } else {
+ toReturn.append(" AND txs1.tx_current = 1");
+ }
+ return toReturn.toString();
+ }
+
+ private static synchronized String getTagQuery(int numberOfTags, boolean useAttrTypeJoin) {
+ String query = queryCache.get(numberOfTags, useAttrTypeJoin);
+ if (query == null) {
+ query = createTagQuery(numberOfTags, useAttrTypeJoin);
+ queryCache.put(numberOfTags, useAttrTypeJoin, query);
+ }
+ return query;
+ }
+
+ private static String createTagQuery(int numberOfTags, boolean useAttrTypeJoin) {
+ StringBuilder codedTag = new StringBuilder();
+ codedTag.append("SELECT /*+ ordered FIRST_ROWS */ attr1.art_id, attr1.gamma_id, attr1.value, attr1.uri, attr1.attr_type_id, txs1.branch_id FROM \n");
+ for (int index = 0; index < numberOfTags; index++) {
+ codedTag.append(String.format("osee_search_tags ost%d, \n", index));
+ }
+ if (useAttrTypeJoin) {
+ codedTag.append(" osee_join_id idj,");
+ }
+ codedTag.append(" osee_attribute attr1, osee_txs txs1 WHERE \n");
+
+ for (int index = 0; index < numberOfTags; index++) {
+ codedTag.append(String.format("ost%d.coded_tag_id = ? AND\n", index));
+ }
+ for (int index = 1; index < numberOfTags; index++) {
+ codedTag.append(String.format("ost%d.gamma_id = ost%d.gamma_id AND \n", index - 1, index));
+ }
+ codedTag.append(String.format("ost%d.gamma_id = attr1.gamma_id AND\n attr1.gamma_id = txs1.gamma_id\n",
+ numberOfTags - 1));
+
+ if (useAttrTypeJoin) {
+ codedTag.append(" AND attr1.attr_type_id = idj.id AND idj.query_id = ?\n");
+ }
+ return codedTag.toString();
+ }
+}

Back to the top