Author: shawkins
Date: 2009-09-30 14:18:30 -0400 (Wed, 30 Sep 2009)
New Revision: 1506
Removed:
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/index/FakeVDBService.java
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/validator/ModelVisibilityValidationVisitor.java
trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeVDBService.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/index/TestMetadataConnectorMetadata.java
Log:
TEIID-750 cleaning up some of the visibility logic and adding a test case for resolving
against only public models.
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/validator/ModelVisibilityValidationVisitor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/validator/ModelVisibilityValidationVisitor.java 2009-09-30
17:01:20 UTC (rev 1505)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/validator/ModelVisibilityValidationVisitor.java 2009-09-30
18:18:30 UTC (rev 1506)
@@ -34,7 +34,6 @@
import com.metamatrix.query.function.FunctionLibrary;
import com.metamatrix.query.metadata.TempMetadataID;
import com.metamatrix.query.resolver.util.ResolverUtil;
-import com.metamatrix.query.resolver.util.ResolverUtil.ResolvedLookup;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Delete;
import com.metamatrix.query.sql.lang.Insert;
Modified: trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeVDBService.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeVDBService.java 2009-09-30
17:01:20 UTC (rev 1505)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeVDBService.java 2009-09-30
18:18:30 UTC (rev 1506)
@@ -24,8 +24,10 @@
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -37,52 +39,16 @@
import com.metamatrix.common.application.exception.ApplicationLifecycleException;
import com.metamatrix.common.vdb.api.ModelInfo;
import com.metamatrix.common.vdb.api.VDBArchive;
+import com.metamatrix.vdb.runtime.VDBKey;
/**
*/
public class FakeVDBService extends FakeAbstractService implements VDBService {
private Map vdbsMap = new HashMap(); // VdbInfo -> Map<Model name (upper),
<ModelInfo>>
private Map bindingNames = new HashMap(); // binding UUID -> binding name
+ public Collection publicFiles = new HashSet();
+ private boolean defaultPrivate;
- private static class VdbInfo {
- private final String vdbName;
- private final String vdbVersion;
-
- private final String key;
-
- public VdbInfo(String name, String version) {
- this.vdbName = name;
- this.vdbVersion = version;
- this.key = name.toUpperCase() + ":" + version; //$NON-NLS-1$
- }
-
- public String getName() {
- return this.vdbName;
- }
-
- public String getVersion() {
- return this.vdbVersion;
- }
-
- public boolean equals(Object obj) {
- if(obj == null) {
- return false;
- } else if(obj == this) {
- return true;
- } else {
- return this.key.equals(((VdbInfo)obj).key);
- }
- }
-
- public int hashCode() {
- return this.key.hashCode();
- }
-
- public String toString() {
- return vdbName + ":" + vdbVersion; //$NON-NLS-1$
- }
- }
-
private static class FakeModel {
String modelName;
boolean multiSource = false;
@@ -91,6 +57,10 @@
List bindingUUIDs = new ArrayList(); // mapped to names
}
+ public void setDefaultPrivate(boolean defaultPrivate) {
+ this.defaultPrivate = defaultPrivate;
+ }
+
/**
* Method for testing - add a model with the specified properties. The vdb will be
created
* automatically under the hood.
@@ -107,7 +77,7 @@
model.multiSource = multiSource;
model.modelName = modelName;
- VdbInfo vdb = new VdbInfo(vdbName, version);
+ VDBKey vdb = new VDBKey(vdbName, version);
Map vdbModels = (Map)this.vdbsMap.get(vdb);
if(vdbModels == null) {
vdbModels = new HashMap();
@@ -131,7 +101,7 @@
FakeModel model = null;
// Find existing model
- VdbInfo vdb = new VdbInfo(vdbName, version);
+ VDBKey vdb = new VDBKey(vdbName, version);
Map vdbModels = (Map)this.vdbsMap.get(vdb);
if(vdbModels != null) {
model = (FakeModel) vdbModels.get(modelName.toUpperCase());
@@ -158,14 +128,14 @@
* @see com.metamatrix.dqp.service.VDBService#isActiveVDB(java.lang.String,
java.lang.String)
*/
public boolean isActiveVDB(String vdbName, String vdbVersion) {
- return vdbsMap.containsKey(new VdbInfo(vdbName, vdbVersion));
+ return vdbsMap.containsKey(new VDBKey(vdbName, vdbVersion));
}
/* (non-Javadoc)
* @see com.metamatrix.dqp.service.VDBService#getConnectorBinding(java.lang.String,
java.lang.String, java.lang.String)
*/
public List getConnectorBindingNames(String vdbName, String vdbVersion, String
modelName) {
- VdbInfo vdb = new VdbInfo(vdbName, vdbVersion);
+ VDBKey vdb = new VDBKey(vdbName, vdbVersion);
Map vdbModels = (Map)this.vdbsMap.get(vdb);
if(vdbModels != null) {
FakeModel model = (FakeModel) vdbModels.get(modelName.toUpperCase());
@@ -187,7 +157,7 @@
* @see com.metamatrix.dqp.service.VDBService#getModelVisibility(java.lang.String,
java.lang.String, java.lang.String)
*/
public int getModelVisibility(String vdbName, String vdbVersion, String modelName) {
- VdbInfo vdb = new VdbInfo(vdbName, vdbVersion);
+ VDBKey vdb = new VDBKey(vdbName, vdbVersion);
Map vdbModels = (Map)this.vdbsMap.get(vdb);
if(vdbModels != null) {
FakeModel model = (FakeModel) vdbModels.get(modelName.toUpperCase());
@@ -195,7 +165,9 @@
return model.visibility;
}
}
-
+ if (defaultPrivate) {
+ return ModelInfo.PRIVATE;
+ }
return ModelInfo.PUBLIC;
}
@@ -204,7 +176,10 @@
* @since 4.2
*/
public int getFileVisibility(String vdbName, String vdbVersion, String pathInVDB)
throws MetaMatrixComponentException {
- return ModelInfo.PUBLIC;
+ if(this.publicFiles.contains(pathInVDB)) {
+ return ModelInfo.PUBLIC;
+ }
+ return ModelInfo.PRIVATE;
}
/* (non-Javadoc)
@@ -240,7 +215,7 @@
public List getMultiSourceModels(String vdbName,
String vdbVersion) throws
MetaMatrixComponentException {
- VdbInfo vdb = new VdbInfo(vdbName, vdbVersion);
+ VDBKey vdb = new VDBKey(vdbName, vdbVersion);
Map vdbModels = (Map)this.vdbsMap.get(vdb);
if(vdbModels != null) {
List multiModels = new ArrayList();
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2009-09-30
17:01:20 UTC (rev 1505)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2009-09-30
18:18:30 UTC (rev 1506)
@@ -80,8 +80,8 @@
env.bindService(DQPServiceNames.DATA_SERVICE, new AutoGenDataService());
env.bindService(DQPServiceNames.TRANSACTION_SERVICE, new
FakeTransactionService());
FakeVDBService vdbService = new FakeVDBService();
+ vdbService.setDefaultPrivate(true);
vdbService.addBinding(vdbName, vdbVersion, "BQT1",
"mmuuid:blah", "BQT"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- vdbService.addBinding(vdbName, vdbVersion, "BQT2",
"mmuuid:blah", "BQT"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
vdbService.addBinding(vdbName, vdbVersion, "BQT3",
"mmuuid:blah", "BQT"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
vdbService.addModel(vdbName, vdbVersion, "BQT3", ModelInfo.PRIVATE,
false); //$NON-NLS-1$
env.bindService(DQPServiceNames.VDB_SERVICE, vdbService);
@@ -247,6 +247,10 @@
helpTestVisibilityFails(xquery);
}
+ @Test public void testResolvingVisibility() throws Exception {
+ String sql = "SELECT * FROM SmallA"; //$NON-NLS-1$
+ helpExecute(sql, "a"); //$NON-NLS-1$
+ }
///////////////////////////Helper method///////////////////////////////////
private ResultsMessage helpExecute(String sql, String userName) throws Exception {
Deleted:
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/index/FakeVDBService.java
===================================================================
---
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/index/FakeVDBService.java 2009-09-30
17:01:20 UTC (rev 1505)
+++
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/index/FakeVDBService.java 2009-09-30
18:18:30 UTC (rev 1506)
@@ -1,171 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.metadata.index;
-
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.application.ApplicationEnvironment;
-import com.metamatrix.common.application.exception.ApplicationInitializationException;
-import com.metamatrix.common.application.exception.ApplicationLifecycleException;
-import com.metamatrix.common.vdb.api.ModelInfo;
-import com.metamatrix.common.vdb.api.VDBArchive;
-import com.metamatrix.dqp.service.VDBService;
-
-
-/**
- * @since 4.3
- */
-public class FakeVDBService implements
- VDBService {
- public Collection publicModels = new HashSet();
-
- public Collection publicFiles = new HashSet();
-
- /**
- * @see
com.metamatrix.dqp.service.VDBService#getConnectorBindingNames(java.lang.String,
java.lang.String, java.lang.String)
- * @since 4.3
- */
- public List getConnectorBindingNames(String vdbName,
- String vdbVersion,
- String modelName) throws
MetaMatrixComponentException {
- return null;
- }
-
- /**
- * @see com.metamatrix.dqp.service.VDBService#getModelVisibility(java.lang.String,
java.lang.String, java.lang.String)
- * @since 4.3
- */
- public int getModelVisibility(String vdbName,
- String vdbVersion,
- String modelName) throws MetaMatrixComponentException
{
- if(this.publicModels.contains(modelName)) {
- return ModelInfo.PUBLIC;
- }
- return ModelInfo.PRIVATE;
- }
-
- /**
- * @see com.metamatrix.dqp.service.VDBService#getFileVisibility(java.lang.String,
java.lang.String, java.lang.String)
- * @since 4.3
- */
- public int getFileVisibility(String vdbName,
- String vdbVersion,
- String pathInVDB) throws MetaMatrixComponentException {
- if(this.publicFiles.contains(pathInVDB)) {
- return ModelInfo.PUBLIC;
- }
- return ModelInfo.PRIVATE;
- }
-
- /**
- * @see com.metamatrix.dqp.service.VDBService#getVDBResource(java.lang.String,
java.lang.String)
- * @since 4.3
- */
- public InputStream getVDBResource(String vdbName,
- String vdbVersion) throws
MetaMatrixComponentException {
- return null;
- }
-
- /**
- * @see com.metamatrix.dqp.service.VDBService#getMultiSourceModels(java.lang.String,
java.lang.String)
- * @since 4.3
- */
- public List getMultiSourceModels(String vdbName,
- String vdbVersion) throws
MetaMatrixComponentException {
- return null;
- }
-
-
- /**
- * @see com.metamatrix.dqp.service.VDBService#getAvailableVDBs()
- * @since 4.3
- */
- public List getAvailableVDBs() throws MetaMatrixComponentException {
- return null;
- }
-
- /**
- * @see com.metamatrix.dqp.service.VDBService#getVDBStatus(java.lang.String,
java.lang.String)
- * @since 4.3
- */
- public int getVDBStatus(String vdbName,
- String vdbVersion) throws MetaMatrixComponentException {
- return 0;
- }
-
- /**
- * @see com.metamatrix.dqp.service.VDBService#changeVDBStatus(java.lang.String,
java.lang.String, int)
- * @since 4.3
- */
- public void changeVDBStatus(String vdbName,
- String vdbVersion,
- int status) throws ApplicationLifecycleException,
- MetaMatrixComponentException {
- }
-
- /**
- * @see com.metamatrix.dqp.service.VDBService#getConnectorName(java.lang.String)
- * @since 4.3
- */
- public String getConnectorName(String connectorBindingID) {
- return null;
- }
-
- /**
- * @see
com.metamatrix.common.application.ApplicationService#initialize(java.util.Properties)
- * @since 4.3
- */
- public void initialize(Properties props) throws ApplicationInitializationException {
- }
-
- /**
- * @see
com.metamatrix.common.application.ApplicationService#start(com.metamatrix.common.application.ApplicationEnvironment)
- * @since 4.3
- */
- public void start(ApplicationEnvironment environment) throws
ApplicationLifecycleException {
- }
-
- /**
- * @see com.metamatrix.common.application.ApplicationService#stop()
- * @since 4.3
- */
- public void stop() throws ApplicationLifecycleException {
- }
-
- @Override
- public String getActiveVDBVersion(String vdbName, String vdbVersion) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public VDBArchive getVDB(String vdbName, String vdbVersion)
- throws MetaMatrixComponentException {
- throw new UnsupportedOperationException();
- }
-
-}
Modified:
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/index/TestMetadataConnectorMetadata.java
===================================================================
---
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/index/TestMetadataConnectorMetadata.java 2009-09-30
17:01:20 UTC (rev 1505)
+++
trunk/metadata/src/test/java/com/metamatrix/connector/metadata/index/TestMetadataConnectorMetadata.java 2009-09-30
18:18:30 UTC (rev 1506)
@@ -28,6 +28,8 @@
import java.util.HashMap;
import java.util.Map;
+import junit.framework.TestCase;
+
import org.teiid.connector.metadata.FileRecordImpl;
import org.teiid.connector.metadata.MetadataConnectorMetadata;
import org.teiid.connector.metadata.MetadataLiteralCriteria;
@@ -39,10 +41,10 @@
import org.teiid.metadata.index.IndexConstants;
import org.teiid.metadata.index.IndexMetadataStore;
-import junit.framework.TestCase;
-
+import com.metamatrix.common.vdb.api.ModelInfo;
import com.metamatrix.common.vdb.api.VDBArchive;
import com.metamatrix.core.util.UnitTestUtil;
+import com.metamatrix.dqp.service.FakeVDBService;
import com.metamatrix.dqp.service.VDBService;
import com.metamatrix.metadata.runtime.api.MetadataSource;
@@ -78,13 +80,15 @@
return new MetadataConnectorMetadata(context, new
CompositeMetadataStore(Arrays.asList(composite), source));
}
- public VDBService helpGetVdbService() {
- return new FakeVDBService();
+ public FakeVDBService helpGetVdbService() {
+ FakeVDBService vdbService = new FakeVDBService();
+ vdbService.setDefaultPrivate(true);
+ return vdbService;
}
public void testGetFileRecords() throws Exception {
String entityPath = "/parts/partsmd/PartsSupplier.xmi"; //$NON-NLS-1$
- FakeVDBService service = (FakeVDBService) helpGetVdbService();
+ FakeVDBService service = helpGetVdbService();
service.publicFiles.add(entityPath);
MetadataLiteralCriteria literalcriteria = new
MetadataLiteralCriteria(FileRecordImpl.MetadataMethodNames.PATH_IN_VDB_FIELD, entityPath);
Map criteria = new HashMap();
@@ -97,8 +101,8 @@
public void testGetPublicModelRecords() throws Exception {
String modelName = "PartsSupplier"; //$NON-NLS-1$
- FakeVDBService service = (FakeVDBService) helpGetVdbService();
- service.publicModels.add(modelName);
+ FakeVDBService service = helpGetVdbService();
+ service.addModel(TEST_VDB_NAME, TEST_VDB_VERSION, modelName, ModelInfo.PUBLIC,
false);
MetadataLiteralCriteria literalcriteria = new
MetadataLiteralCriteria(AbstractMetadataRecord.MetadataFieldNames.FULL_NAME_FIELD,
modelName);
Map criteria = new HashMap();
criteria.put(AbstractMetadataRecord.MetadataFieldNames.FULL_NAME_FIELD.toUpperCase(),
literalcriteria);
@@ -112,7 +116,7 @@
public void testGetPrivateModelRecords() throws Exception {
String modelName = "PartsSupplier"; //$NON-NLS-1$
- FakeVDBService service = (FakeVDBService) helpGetVdbService();
+ FakeVDBService service = helpGetVdbService();
//service.publicModels.add(modelName);
MetadataLiteralCriteria literalcriteria = new
MetadataLiteralCriteria(AbstractMetadataRecord.MetadataFieldNames.FULL_NAME_FIELD,
modelName);
Map criteria = new HashMap();
@@ -126,7 +130,7 @@
}
public void testGetWrappedVdbRecords() throws Exception {
- FakeVDBService service = (FakeVDBService) helpGetVdbService();
+ FakeVDBService service = helpGetVdbService();
Map criteria = new HashMap();
MetadataConnectorMetadata metadata = helpGetMetadata(TEST_FILE_NAME,
TEST_VDB_NAME, TEST_VDB_VERSION, service);
Collection records = metadata.getObjects(IndexConstants.INDEX_NAME.VDBS_INDEX,
criteria);
@@ -138,8 +142,8 @@
public void testGetRecordsWithFalseCriteria() throws Exception {
String modelName = "PartsSupplier"; //$NON-NLS-1$
- FakeVDBService service = (FakeVDBService) helpGetVdbService();
- service.publicModels.add(modelName);
+ FakeVDBService service = helpGetVdbService();
+ service.addModel(TEST_VDB_NAME, TEST_VDB_VERSION, modelName, ModelInfo.PUBLIC,
false);
MetadataLiteralCriteria literalcriteria = new
MetadataLiteralCriteria(AbstractMetadataRecord.MetadataFieldNames.FULL_NAME_FIELD,
modelName);
literalcriteria.setFieldFunction("UPPER"); //$NON-NLS-1$
Map criteria = new HashMap();