[teiid-commits] teiid SVN: r1622 - in trunk: common-internal/src/main/java/com/metamatrix/common/vdb/api and 7 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Dec 4 14:07:15 EST 2009


Author: shawkins
Date: 2009-12-04 14:07:14 -0500 (Fri, 04 Dec 2009)
New Revision: 1622

Removed:
   trunk/common-internal/src/main/java/com/metamatrix/api/core/
   trunk/test-integration/db/src/test/java/org/teiid/transaction/
Modified:
   trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/DEFReaderWriter.java
   trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java
   trunk/common-internal/src/test/java/com/metamatrix/common/vdb/api/TestDEFReaderWriter.java
   trunk/connector-sdk/src/main/java/com/metamatrix/cdk/api/TranslationUtility.java
   trunk/metadata/src/main/java/org/teiid/metadata/index/VDBMetadataFactory.java
   trunk/metadata/src/test/java/com/metamatrix/metadata/runtime/FakeMetadataService.java
   trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedMetadataService.java
   trunk/test-integration/common/src/test/java/com/metamatrix/systemmodel/TestSystemVirtualModel.java
Log:
TEIID-893 fix for bad error message when reading an invalid def file.  also ensuring that all vdb paths are based upon an abstract path name.

Modified: trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/DEFReaderWriter.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/DEFReaderWriter.java	2009-12-03 21:24:13 UTC (rev 1621)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/DEFReaderWriter.java	2009-12-04 19:07:14 UTC (rev 1622)
@@ -38,6 +38,7 @@
 import org.jdom.Element;
 import org.jdom.JDOMException;
 
+import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.CommonPlugin;
 import com.metamatrix.common.config.api.ComponentType;
 import com.metamatrix.common.config.api.ConnectorBinding;
@@ -55,7 +56,7 @@
     private static final String TRUE = "true"; //$NON-NLS-1$
 	private final static String UNKNOWN = "Unknown"; //$NON-NLS-1$
     
-    public BasicVDBDefn read(InputStream defStream) throws IOException {
+    public BasicVDBDefn read(InputStream defStream) throws IOException, MetaMatrixComponentException {
     	BasicVDBDefn vdbDefn = null;
         try {
         	XMLReaderWriter reader = new XMLReaderWriterImpl();
@@ -80,7 +81,7 @@
             loadConnectorBindings(vdbDefn, root);
             
         } catch (JDOMException e) {
-            throw new IOException(CommonPlugin.Util.getString("VDBDefnXMLHelper.Unable_to_read_defn_file"));//$NON-NLS-1$
+            throw new MetaMatrixComponentException(e, CommonPlugin.Util.getString("VDBDefnXMLHelper.Unable_to_read_defn_file"));//$NON-NLS-1$
         } 
         return vdbDefn;
     }

Modified: trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java	2009-12-03 21:24:13 UTC (rev 1621)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java	2009-12-04 19:07:14 UTC (rev 1622)
@@ -96,7 +96,7 @@
         return CoreConstants.SYSTEM_MODEL.equalsIgnoreCase(modelName);
     }
 		
-	public static VDBArchive loadVDB(URL vdbURL, File deployDirectory) throws IOException {
+	public static VDBArchive loadVDB(URL vdbURL, File deployDirectory) throws IOException, MetaMatrixComponentException {
 		boolean loadedFromDef = false;
     	BasicVDBDefn def = null;
     	String vdblocation = vdbURL.toString().toLowerCase();
@@ -177,7 +177,7 @@
 	 * @return
 	 * @throws IOException
 	 */
-	public VDBArchive(InputStream vdbStream) throws IOException {
+	public VDBArchive(InputStream vdbStream) throws IOException, MetaMatrixComponentException {
 		this.tempVDB = true;
 		loadFromFile(createTempVDB(vdbStream));
 	}
@@ -187,11 +187,11 @@
 	 * @param vdb
 	 * @throws IOException
 	 */
-	public VDBArchive(File vdb) throws IOException {
+	public VDBArchive(File vdb) throws IOException, MetaMatrixComponentException {
 		loadFromFile(vdb);
 	}
 
-	private void loadFromFile(File vdb) throws ZipException, IOException {
+	private void loadFromFile(File vdb) throws ZipException, IOException, MetaMatrixComponentException {
 		this.vdbFile = vdb;
 		this.archive = new ZipFile(this.vdbFile);
 		this.tempDir = TempDirectory.getTempDirectory(null);
@@ -210,7 +210,7 @@
 	 * @return BasicVDBDefn
 	 * @throws IOException
 	 */
-	private void load() throws IOException{
+	private void load() throws IOException, MetaMatrixComponentException{
 		this.pathsInArchive = Collections.unmodifiableSet(getListOfEntries());
 		
 		// check if manifest file is available then load it.
@@ -311,8 +311,9 @@
 		BasicVDBDefn manifestVdb = manifest.getVDB();
 		
 		// if models defined n the def file; add them the manifest
-		if (models == null || models.isEmpty()) {
+		if (models.isEmpty()) {
 			mydef.setModelInfos(manifestVdb.getModels());
+			models = mydef.getModels();
 		}
 
 		// if they are defined, but incomplete them add that info.
@@ -328,9 +329,9 @@
 	}
 	
 	private static InputStream getStream(String wantedFile, ZipFile archive) throws IOException {
-        Enumeration entries = archive.entries();
+        Enumeration<? extends ZipEntry> entries = archive.entries();
         while(entries.hasMoreElements()) {
-            ZipEntry entry = (ZipEntry)entries.nextElement();
+            ZipEntry entry = entries.nextElement();
             if (entry != null && entry.getName().equalsIgnoreCase(wantedFile)) {
                 return archive.getInputStream(entry);
             }
@@ -341,13 +342,17 @@
 	private HashSet<String> getListOfEntries() {
 		HashSet<String> files = new HashSet<String>();
 		File[] allFiles = FileUtils.findAllFilesInDirectoryRecursively(deployDirectory.getAbsolutePath());
-		int length = deployDirectory.getAbsolutePath().length();
+		int length = getAbstractPath(deployDirectory).length() - 1;
 		for (File file : allFiles) {
-			files.add(file.getAbsolutePath().substring(length));
+			files.add(getAbstractPath(file).substring(length));
 		}
 		return files;
 	}
 	
+    private static String getAbstractPath(File f) {
+    	return f.getAbsoluteFile().toURI().getPath();
+    }
+	
 	private void checkOpen() {
 		if(!open) {
 			throw new IllegalStateException("Archive already closed"); //$NON-NLS-1$
@@ -362,7 +367,7 @@
 	 * @return VDBDefn
 	 * @throws IOException 
 	 */
-	public static BasicVDBDefn readFromDef(InputStream defStream) throws IOException {
+	public static BasicVDBDefn readFromDef(InputStream defStream) throws IOException, MetaMatrixComponentException {
 		DEFReaderWriter reader = new DEFReaderWriter();
 		BasicVDBDefn vdbDefn = reader.read(defStream);
 		return vdbDefn;

Modified: trunk/common-internal/src/test/java/com/metamatrix/common/vdb/api/TestDEFReaderWriter.java
===================================================================
--- trunk/common-internal/src/test/java/com/metamatrix/common/vdb/api/TestDEFReaderWriter.java	2009-12-03 21:24:13 UTC (rev 1621)
+++ trunk/common-internal/src/test/java/com/metamatrix/common/vdb/api/TestDEFReaderWriter.java	2009-12-04 19:07:14 UTC (rev 1622)
@@ -92,7 +92,7 @@
 		assertNull(defn.getConnectorType("dummy"));
 	}
 	
-	public void testDEFWrite() throws IOException {
+	public void testDEFWrite() throws Exception {
 		File defFile = new File(UnitTestUtil.getTestDataPath()+"/example.def");
 		File exportedFile = new File(UnitTestUtil.getTestDataPath()+"/example.def.exported");
 		

Modified: trunk/connector-sdk/src/main/java/com/metamatrix/cdk/api/TranslationUtility.java
===================================================================
--- trunk/connector-sdk/src/main/java/com/metamatrix/cdk/api/TranslationUtility.java	2009-12-03 21:24:13 UTC (rev 1621)
+++ trunk/connector-sdk/src/main/java/com/metamatrix/cdk/api/TranslationUtility.java	2009-12-04 19:07:14 UTC (rev 1622)
@@ -22,7 +22,6 @@
 
 package com.metamatrix.cdk.api;
 
-import java.io.IOException;
 import java.net.URL;
 
 import org.teiid.connector.language.ICommand;
@@ -56,11 +55,7 @@
     }
     
     public TranslationUtility(URL url) {
-        try {
-			metadata = VDBMetadataFactory.getVDBMetadata(url);
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}     
+		metadata = VDBMetadataFactory.getVDBMetadata(url);
     }
     
     public TranslationUtility(QueryMetadataInterface metadata) {

Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/VDBMetadataFactory.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/VDBMetadataFactory.java	2009-12-03 21:24:13 UTC (rev 1621)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/VDBMetadataFactory.java	2009-12-04 19:07:14 UTC (rev 1622)
@@ -33,6 +33,7 @@
 import org.teiid.metadata.CompositeMetadataStore;
 import org.teiid.metadata.TransformationMetadata;
 
+import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.vdb.api.VDBArchive;
 import com.metamatrix.core.MetaMatrixRuntimeException;
 import com.metamatrix.core.util.LRUCache;
@@ -51,16 +52,22 @@
 		}
     }
 	
-	public static QueryMetadataInterface getVDBMetadata(URL vdbURL) throws IOException {
+	public static QueryMetadataInterface getVDBMetadata(URL vdbURL) {
 		QueryMetadataInterface vdb = VDB_CACHE.get(vdbURL);
 		if (vdb != null) {
 			return vdb;
 		}
-		MetadataSource source = new VDBArchive(vdbURL.openStream());
-		IndexMetadataFactory selector = new IndexMetadataFactory(source);
-        vdb = new TransformationMetadata(new CompositeMetadataStore(Arrays.asList(selector.getMetadataStore()), source));
-        VDB_CACHE.put(vdbURL, vdb);
-        return vdb;
+		try {
+			MetadataSource source = new VDBArchive(vdbURL.openStream());
+			IndexMetadataFactory selector = new IndexMetadataFactory(source);
+	        vdb = new TransformationMetadata(new CompositeMetadataStore(Arrays.asList(selector.getMetadataStore()), source));
+	        VDB_CACHE.put(vdbURL, vdb);
+	        return vdb;
+		} catch (IOException e) {
+			throw new MetaMatrixRuntimeException(e);
+		} catch (MetaMatrixComponentException e) {
+			throw new MetaMatrixRuntimeException(e);
+		}
     }	
 	
 	public static QueryMetadataInterface getVDBMetadata(String[] vdbFile) {
@@ -76,6 +83,8 @@
 				selectors.add(new IndexMetadataFactory(tempSource).getMetadataStore());
 			} catch (IOException e) {
 				throw new MetaMatrixRuntimeException(e);
+			} catch (MetaMatrixComponentException e) {
+				throw new MetaMatrixRuntimeException(e);
 			}        
         }
         

Modified: trunk/metadata/src/test/java/com/metamatrix/metadata/runtime/FakeMetadataService.java
===================================================================
--- trunk/metadata/src/test/java/com/metamatrix/metadata/runtime/FakeMetadataService.java	2009-12-03 21:24:13 UTC (rev 1621)
+++ trunk/metadata/src/test/java/com/metamatrix/metadata/runtime/FakeMetadataService.java	2009-12-04 19:07:14 UTC (rev 1622)
@@ -48,7 +48,7 @@
 public class FakeMetadataService implements ApplicationService, MetadataService {
     private CompositeMetadataStore compositeMetadataStore;
     
-    public FakeMetadataService(URL vdbFile) throws IOException {
+    public FakeMetadataService(URL vdbFile) throws IOException, MetaMatrixComponentException {
         TempDirectoryMonitor.turnOn();
     	MetadataSource source = new VDBArchive(vdbFile.openStream());
     	compositeMetadataStore = new CompositeMetadataStore(Arrays.asList(new IndexMetadataFactory(source).getMetadataStore()), source);

Modified: trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedMetadataService.java
===================================================================
--- trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedMetadataService.java	2009-12-03 21:24:13 UTC (rev 1621)
+++ trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedMetadataService.java	2009-12-04 19:07:14 UTC (rev 1622)
@@ -158,15 +158,6 @@
         return new TransformationMetadata(composite);
     }
     
-    public void updateCostMetadata(String vdbName, String vdbVersion, String modelName) throws MetaMatrixComponentException {
-    	CompositeMetadataStore store = getMetadataObjectSource(vdbName, vdbVersion);
-    	//...
-    }
-    
-    public void updateCostMetadata(String vdbName, String vdbVersion, String objectName, String propertyName, String value) {
-    	
-    }
-    
 	private void saveMetadataStore(final MetadataSource runtimeSelector,
 			MetadataStore connectorMetadata, String savedMetadata)
 			throws IOException {
@@ -194,8 +185,8 @@
 			try {
 				ois = new ObjectInputStream(new FileInputStream(f));
 				return (MetadataStore)ois.readObject();
-			} catch (Exception e) {
-				
+			} catch (Throwable e) {
+				LogManager.logDetail(LogConstants.CTX_DQP, e, "invalid metadata in file", savedMetadata);  //$NON-NLS-1$
 			} finally {
 				if (ois != null) {
 					ois.close();
@@ -246,6 +237,8 @@
             configSvc.register(listener);
         } catch (IOException e) {
             throw new ApplicationLifecycleException(e, DQPPlugin.Util.getString("QueryMetadataCache.Failed_creating_Runtime_Index_Selector._4", CoreConstants.SYSTEM_VDB));  //$NON-NLS-1$
+        } catch (MetaMatrixComponentException e) {
+        	throw new ApplicationLifecycleException(e, DQPPlugin.Util.getString("QueryMetadataCache.Failed_creating_Runtime_Index_Selector._4", CoreConstants.SYSTEM_VDB));  //$NON-NLS-1$
         }
     }
 

Modified: trunk/test-integration/common/src/test/java/com/metamatrix/systemmodel/TestSystemVirtualModel.java
===================================================================
--- trunk/test-integration/common/src/test/java/com/metamatrix/systemmodel/TestSystemVirtualModel.java	2009-12-03 21:24:13 UTC (rev 1621)
+++ trunk/test-integration/common/src/test/java/com/metamatrix/systemmodel/TestSystemVirtualModel.java	2009-12-04 19:07:14 UTC (rev 1622)
@@ -22,8 +22,6 @@
 
 package com.metamatrix.systemmodel;
 
-import java.io.File;
-
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -111,8 +109,9 @@
 	}
 
 	@Test public void testVDBResourcePathsProcedure() {
+
 		String[] expected = { "ResourcePath[string]	isBinary[boolean]	", //$NON-NLS-1$
-				File.separator + "parts" + File.separator + "partsmd" + File.separator + "PartsSupplier.xmi	false"
+				"/parts/partsmd/PartsSupplier.xmi	false", //$NON-NLS-1$
 		};
 		execute("exec getVDBResourcePaths()",new Object[] {}); //$NON-NLS-1$
 		assertResults(expected);



More information about the teiid-commits mailing list