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

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Jul 13 14:34:08 EDT 2009


Author: shawkins
Date: 2009-07-13 14:34:07 -0400 (Mon, 13 Jul 2009)
New Revision: 1122

Modified:
   trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDatabaseMetaData.java
   trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/DEFReaderWriter.java
   trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/ModelInfo.java
   trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java
   trunk/common-internal/src/main/java/com/metamatrix/metadata/runtime/api/MetadataSource.java
   trunk/common-internal/src/main/java/com/metamatrix/vdb/runtime/BasicModelInfo.java
   trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/AbstractMetadataRecord.java
   trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/MetadataFactory.java
   trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/TableRecordImpl.java
   trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
   trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnector.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/VDBConfigurationReader.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/VDBConfigurationWriter.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java
   trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java
   trunk/engine/src/main/java/com/metamatrix/dqp/service/DataService.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java
   trunk/engine/src/test/java/com/metamatrix/dqp/service/AutoGenDataService.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
   trunk/metadata/src/main/java/org/teiid/metadata/ConnectorMetadataStore.java
   trunk/metadata/src/main/java/org/teiid/metadata/QueryMetadataCache.java
   trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformDataService.java
   trunk/server/src/test/java/com/metamatrix/server/admin/apiimpl/FakeModelInfo.java
   trunk/test-integration/src/test/resources/vdbless/ConfigurationInfo.def
Log:
TEIID-684 added the ability to cache the connector metadata and to specify import properties in the model definition.

Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDatabaseMetaData.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDatabaseMetaData.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMDatabaseMetaData.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -24,7 +24,6 @@
 
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
-import java.sql.Driver;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;

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-07-13 16:25:41 UTC (rev 1121)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/DEFReaderWriter.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -162,8 +162,11 @@
     	
     	BasicModelInfo model = new BasicModelInfo(props.getProperty(Model.NAME));
     	String visibility = props.getProperty(Model.VISIBILITY, ModelInfo.PUBLIC_VISIBILITY);
+    	props.remove(Model.VISIBILITY);
     	model.setVisibility(visibility.equalsIgnoreCase(ModelInfo.PRIVATE_VISIBILITY)?ModelInfo.PRIVATE:ModelInfo.PUBLIC);
     	model.enableMutliSourceBindings(Boolean.parseBoolean(props.getProperty(Model.MULTI_SOURCE_ENABLED)));
+    	props.remove(Model.MULTI_SOURCE_ENABLED);
+    	model.setProperties(props);
     	
     	Element cbElement = modelElement.getChild(Model.CONNECTOR_BINDINGS_ELEMENT);
     	if (cbElement != null) {
@@ -308,17 +311,21 @@
         	   addPropertyElement(vdbInfoElement, VDBInfo.ACTIVE, TRUE); 
            }
            Properties p = info.getInfoProperties();
-           if (p != null) {
-	           for(String key : (List<String>) Collections.list(p.propertyNames())) {
-	        	   addPropertyElement(vdbInfoElement, key, p.getProperty(key));
-	           }
-           }
+           addPropertyElements(vdbInfoElement, p);
        }
        else {
     	   throw new IOException("Invalid DEF, No name supplied"); //$NON-NLS-1$
        }
        return vdbInfoElement;
-   }   
+   }
+
+	private void addPropertyElements(Element vdbInfoElement, Properties p) {
+		if (p != null) {
+			for (String key : (List<String>) Collections.list(p.propertyNames())) {
+				addPropertyElement(vdbInfoElement, key, p.getProperty(key));
+			}
+		}
+	}
    
    private Element createModel(ModelInfo model) throws IOException {
        Element modelElement = new Element(Model.ELEMENT);
@@ -326,7 +333,7 @@
        if (valid) {
     	   addPropertyElement(modelElement, Model.VISIBILITY, model.getVisibility()==ModelInfo.PRIVATE?ModelInfo.PRIVATE_VISIBILITY:ModelInfo.PUBLIC_VISIBILITY);
     	   addPropertyElement(modelElement, Model.MULTI_SOURCE_ENABLED, Boolean.toString(model.isMultiSourceBindingEnabled()));
-    	   
+    	   addPropertyElements(modelElement, model.getProperties());
     	   List<String> bindings = model.getConnectorBindingNames();
     	   if (bindings != null && !bindings.isEmpty()) {
     		   Element cbsElement = new Element(Model.CONNECTOR_BINDINGS_ELEMENT);

Modified: trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/ModelInfo.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/ModelInfo.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/ModelInfo.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -28,6 +28,7 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 /**
  * This interface provides the model information.
@@ -209,4 +210,6 @@
     
     String getPath();
     
+    Properties getProperties();
+    
 }

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-07-13 16:25:41 UTC (rev 1121)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -64,6 +64,7 @@
 public class VDBArchive implements MetadataSource {
 	
 	public static String USE_CONNECTOR_METADATA = "UseConnectorMetadata"; //$NON-NLS-1$
+	public static String CACHED = "CACHED"; //$NON-NLS-1$
 	
 	// configuration def contents
 	private BasicVDBDefn def;
@@ -121,7 +122,7 @@
         } 
 
         if (def == null) {
-    		throw new IllegalArgumentException("No ConfigurationInfo.def file associated with vdb " + vdbURL);
+    		throw new IllegalArgumentException("No ConfigurationInfo.def file associated with vdb " + vdbURL); //$NON-NLS-1$
         }
         
     	deployDirectory = new File(deployDirectory, def.getName().toLowerCase() + "/" + def.getVersion().toLowerCase()); //$NON-NLS-1$
@@ -255,12 +256,25 @@
 	
 	@Override
 	public Set<String> getConnectorMetadataModelNames() {
-		if (this.def.getInfoProperties() != null && PropertiesUtils.getBooleanProperty(this.def.getInfoProperties(), USE_CONNECTOR_METADATA, false)) {
+		if (this.def.getInfoProperties() != null && 
+				(cacheConnectorMetadata() || PropertiesUtils.getBooleanProperty(this.def.getInfoProperties(), USE_CONNECTOR_METADATA, false))) {
 			return new HashSet<String>(this.def.getModelNames());
 		}
 		return Collections.emptySet();
 	}
 	
+	public boolean cacheConnectorMetadata() {
+		if (this.def.getInfoProperties() == null) {
+			return false;
+		}
+		return CACHED.equalsIgnoreCase(this.def.getInfoProperties().getProperty(USE_CONNECTOR_METADATA));
+	}
+	
+	@Override
+	public void saveFile(InputStream is, String path) throws IOException {
+		FileUtils.write(is, new File(this.deployDirectory, path));
+	}
+	
 	private InputStream getStream(String path) throws IOException {
 		File f = new File(this.deployDirectory, path);
 		if (!f.exists()) {
@@ -542,5 +556,13 @@
 		}
 		return null;
 	}
+	
+	@Override
+	public ModelInfo getModelInfo(String name) {
+		if (this.def == null) {
+			return null;
+		}
+		return this.def.getModel(name);
+	}
 
 }

Modified: trunk/common-internal/src/main/java/com/metamatrix/metadata/runtime/api/MetadataSource.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/metadata/runtime/api/MetadataSource.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/common-internal/src/main/java/com/metamatrix/metadata/runtime/api/MetadataSource.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -1,8 +1,12 @@
 package com.metamatrix.metadata.runtime.api;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Set;
 
+import com.metamatrix.common.vdb.api.ModelInfo;
+
 public interface MetadataSource {
 	
 	String getName();
@@ -26,4 +30,23 @@
 	 */
 	Set<String> getConnectorMetadataModelNames();
 	
+	/**
+	 * Whether to cache connector metadata
+	 * @return
+	 */
+	boolean cacheConnectorMetadata();
+	
+	/**
+	 * Save the stream to given path.
+	 * @param path
+	 */
+	void saveFile(InputStream stream, String path) throws IOException;
+	
+	/**
+	 * Get the model with the given name.
+	 * @param name
+	 * @return
+	 */
+	ModelInfo getModelInfo(String name);
+	
 }

Modified: trunk/common-internal/src/main/java/com/metamatrix/vdb/runtime/BasicModelInfo.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/vdb/runtime/BasicModelInfo.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/common-internal/src/main/java/com/metamatrix/vdb/runtime/BasicModelInfo.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -33,6 +33,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import com.metamatrix.common.util.ByteArrayHelper;
@@ -67,6 +68,8 @@
     private boolean isVisible;
 
     private Map ddlFileNamesToFiles = Collections.EMPTY_MAP;
+    
+    private Properties properties;
 
     protected BasicModelInfo() {
         
@@ -418,6 +421,15 @@
     	this.pathInVdb = path;
     }
     
+    @Override
+    public Properties getProperties() {
+    	return this.properties;
+    }
+    
+    public void setProperties(Properties properties) {
+		this.properties = properties;
+	}
+    
     public String toString() {
         StringBuffer sw = new StringBuffer();
         

Modified: trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/AbstractMetadataRecord.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/AbstractMetadataRecord.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/AbstractMetadataRecord.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -22,6 +22,7 @@
 
 package org.teiid.connector.metadata.runtime;
 
+import java.io.Serializable;
 import java.util.Collection;
 import java.util.Properties;
 
@@ -32,7 +33,7 @@
 /**
  * AbstractMetadataRecord
  */
-public abstract class AbstractMetadataRecord {
+public abstract class AbstractMetadataRecord implements Serializable {
 	    
     /**
 	 * Constants for names of accessor methods that map to fields stored on the MetadataRecords.
@@ -63,7 +64,7 @@
 	private String name;
 	
 	private Collection<PropertyRecordImpl> extensionProperties;
-	private Properties properties;
+	private transient Properties properties;
 	private AnnotationRecordImpl annotation;
 	
 	public String getUUID() {

Modified: trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/MetadataFactory.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/MetadataFactory.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/MetadataFactory.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -28,6 +28,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import org.teiid.connector.DataPlugin;
@@ -43,6 +44,7 @@
 	
 	private transient UUIDFactory factory = new UUIDFactory();
 	private transient Map<String, DatatypeRecordImpl> dataTypes;
+	private transient Properties importProperties;
 	
 	private ModelRecordImpl model;
 	private Collection<TableRecordImpl> tables = new ArrayList<TableRecordImpl>();
@@ -52,8 +54,9 @@
 	
 	private Set<String> uniqueNames = new HashSet<String>();
 	
-	public MetadataFactory(String modelName, Map<String, DatatypeRecordImpl> dataTypes) {
+	public MetadataFactory(String modelName, Map<String, DatatypeRecordImpl> dataTypes, Properties importProperties) {
 		this.dataTypes = dataTypes;
+		this.importProperties = importProperties;
 		model = new ModelRecordImpl();
 		model.setFullName(modelName);
 		model.setModelType(ModelType.PHYSICAL);
@@ -62,6 +65,10 @@
 		setUUID(model);	
 	}
 	
+	public Properties getImportProperties() {
+		return importProperties;
+	}
+	
 	@Override
 	public ModelRecordImpl getModel() {
 		return model;

Modified: trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/TableRecordImpl.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/TableRecordImpl.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/TableRecordImpl.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -29,7 +29,7 @@
  */
 public class TableRecordImpl extends ColumnSetRecordImpl {
 
-    private int cardinality = -1;
+    private int cardinality;
     private int tableType;
     private String primaryKeyID;
     private String materializedTableID;

Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -351,6 +351,7 @@
 				conn = xaConn.getConnection();
 			}
 			JDBCMetdataProcessor metadataProcessor = new JDBCMetdataProcessor();
+			PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getImportProperties(), "importer"); //$NON-NLS-1$
 			PropertiesUtils.setBeanProperties(metadataProcessor, this.environment.getProperties(), "importer"); //$NON-NLS-1$
 			metadataProcessor.getConnectorMetadata(conn, metadataFactory);
 		} catch (SQLException e) {

Modified: trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnector.java
===================================================================
--- trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnector.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnector.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -69,7 +69,7 @@
         datatypes.put(DataTypeManager.DefaultDataTypes.BIG_INTEGER, new DatatypeRecordImpl());
         datatypes.put(DataTypeManager.DefaultDataTypes.INTEGER, new DatatypeRecordImpl());
         datatypes.put(DataTypeManager.DefaultDataTypes.TIMESTAMP, new DatatypeRecordImpl());
-        MetadataFactory metadata = new MetadataFactory("SummitData", datatypes); //$NON-NLS-1$
+        MetadataFactory metadata = new MetadataFactory("SummitData", datatypes, new Properties()); //$NON-NLS-1$
         connector.getConnectorMetadata(metadata); 
         assertFalse(metadata.getProcedures().iterator().hasNext());
         Iterator<TableRecordImpl> tableIter = metadata.getTables().iterator();

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/VDBConfigurationReader.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/VDBConfigurationReader.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/VDBConfigurationReader.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -36,6 +36,7 @@
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.protocol.URLHelper;
 import com.metamatrix.common.vdb.api.VDBArchive;
+import com.metamatrix.core.util.ArgCheck;
 import com.metamatrix.core.util.ObjectConverterUtil;
 import com.metamatrix.core.vdb.VdbConstants;
 import com.metamatrix.dqp.embedded.DQPEmbeddedPlugin;
@@ -97,9 +98,7 @@
     public static VDBArchive loadVDB(String name, byte[] vdbContents) 
         throws MetaMatrixComponentException{
     	
-    	if (vdbContents == null) {
-    		throw new IllegalArgumentException("VDB Content provided can not be null");
-    	}
+    	ArgCheck.isNotNull(vdbContents);
     	
         try {
         	VDBArchive archive = new VDBArchive(new ByteArrayInputStream(vdbContents));

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/VDBConfigurationWriter.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/VDBConfigurationWriter.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/VDBConfigurationWriter.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -35,6 +35,7 @@
 import com.metamatrix.common.protocol.URLHelper;
 import com.metamatrix.common.vdb.api.VDBArchive;
 import com.metamatrix.common.vdb.api.VDBDefn;
+import com.metamatrix.core.util.FileUtils;
 import com.metamatrix.dqp.embedded.DQPEmbeddedPlugin;
 
 
@@ -116,10 +117,11 @@
             }
         }         
         
+        VDBDefn def = vdb.getConfigurationDef();
+    	
         // If previous one is a DEF file, we also need to delete the VDB file        
-        if (url.getPath().endsWith(DEF)) {
+        if (url.getPath().endsWith(DEF) && def.getFileName() != null) {
             try {
-            	VDBDefn def = vdb.getConfigurationDef();
                 url = URLHelper.buildURL(url, def.getFileName());
                 urlPath = url.toString()+"?action=delete"; //$NON-NLS-1$
                 
@@ -136,6 +138,11 @@
                     try {in.close();}catch(IOException e) {}
                 }
             }
-        }        
+        }  
+        
+        if (vdb.getDeployDirectory().exists()) {
+        	FileUtils.removeDirectoryAndChildren(vdb.getDeployDirectory());
+        }
+        
     }
 }

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -26,7 +26,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
-import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -61,6 +60,7 @@
 import com.metamatrix.common.vdb.api.VDBArchive;
 import com.metamatrix.common.vdb.api.VDBDefn;
 import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.util.Assertion;
 import com.metamatrix.core.vdb.VDBStatus;
 import com.metamatrix.dqp.embedded.DQPEmbeddedPlugin;
 import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
@@ -283,15 +283,7 @@
      * @return URL - never null;
      * @since 4.3
      */
-    URL getVDBLocation(VDBArchive vdb) throws MetaMatrixComponentException {
-        // Check if this already existing VDB then overwrite the files.
-        if (this.availableVDBFiles != null && this.availableVDBFiles.size() > 0) {            
-            URL vdbFile = availableVDBFiles.get(vdbId(vdb));
-            if (vdbFile != null) {
-                return vdbFile;
-            }
-        }
-        
+    URL getNewVDBLocation(VDBArchive vdb) {
         // This is a new VDB, so where other vdbs are stored. Also since we storing this as
         // single VDB/DEF combination, update the archive file info.
         String vdbName = vdb.getName()+"_"+vdb.getVersion()+VDB; //$NON-NLS-1$
@@ -299,7 +291,6 @@
         
 		BasicVDBDefn def = vdb.getConfigurationDef();
 		def.setFileName(vdbName);     
-		updateDef(def,vdb);
         
         return fileToSave;
     }
@@ -315,14 +306,6 @@
         return urls[0];
     }    
     
-    private void updateDef(BasicVDBDefn def, VDBArchive vdb) throws MetaMatrixComponentException{
-        try {
-			vdb.updateConfigurationDef(def);
-		} catch (IOException e) {
-			throw new MetaMatrixComponentException(e);
-		}    	
-    }
-    
     /** 
      * @see com.metamatrix.dqp.service.ConfigurationService#saveVDB(com.metamatrix.metadata.runtime.admin.vdb.VDBDefn)
      * @since 4.3
@@ -348,26 +331,29 @@
                 archiveFileName = archiveFileName.substring(0, index)+"_"+nextVersion+".vdb"; //$NON-NLS-1$ //$NON-NLS-2$
             }
             def.setFileName(archiveFileName);
-            
-            // update the changes in the archive
-            updateDef(def,srcVdb);
         }
         
+        try {
+			srcVdb.updateConfigurationDef(srcVdb.getConfigurationDef());
+		} catch (IOException e) {
+			throw new MetaMatrixComponentException(e);
+		}
+        
         // make sure we match up the connector binding based on user preferences
-        URL vdbFile = getVDBLocation(srcVdb);
-        VDBConfigurationWriter.write(srcVdb, vdbFile);
-                        
+        URL vdbFile = availableVDBFiles.get(vdbId(srcVdb));
+        if (vdbFile == null) {
+        	vdbFile = getNewVDBLocation(srcVdb);
+        	VDBConfigurationWriter.write(srcVdb, vdbFile);
+        	srcVdb = VDBConfigurationReader.loadVDB(vdbFile, getDeployDir());
+        	try {
+				loadVDB(vdbFile, srcVdb);
+			} catch (ApplicationInitializationException e) {
+				throw new MetaMatrixComponentException(e);
+			}
+        	notifyVDBLoad(def.getName(), def.getVersion());
+        } 
+        
         DQPEmbeddedPlugin.logInfo("EmbeddedConfigurationService.vdb_saved", new Object[] {def.getName(), def.getVersion(), vdbFile}); //$NON-NLS-1$
-                
-        // Only notify on the first time loads, as the all other saves due to
-        // binding changes only
-        if (loadedVDBs.get(vdbId(srcVdb)) == null) {
-            notifyVDBLoad(def.getName(), def.getVersion());
-        }
-                
-        // Refresh the local holdings.
-        loadedVDBs.put(vdbId(srcVdb), srcVdb);
-        availableVDBFiles.put(vdbId(srcVdb), vdbFile);        
     }
 
     /**  
@@ -395,11 +381,6 @@
             // now try to add the connector bindings in the VDB to the configuration service
             addConnectorBindingsInVDB(vdb, replaceBindings);
             
-            // Now save the VDB for future use using the Configuration.
-            // configuration may alter the connector bindings on VDB based
-            // upon preferences set.
-            saveVDB(vdb, exists ? ConfigurationService.NEXT_VDB_VERSION : vdb.getVersion());
-            
             // make sure we have all the bindings, otherwise this is incomplete VDB
             if (!isFullyConfiguredVDB(vdb)) {
                 // mark as in-active
@@ -409,6 +390,11 @@
                 vdb.setStatus(VDBStatus.ACTIVE);
                 DQPEmbeddedPlugin.logInfo("VDBService.vdb_active", new Object[] {vdb.getName(), vdb.getVersion()}); //$NON-NLS-1$                                
             }
+            
+            // Now save the VDB for future use using the Configuration.
+            // configuration may alter the connector bindings on VDB based
+            // upon preferences set.
+            saveVDB(vdb, exists ? ConfigurationService.NEXT_VDB_VERSION : vdb.getVersion());
                         
             DQPEmbeddedPlugin.logInfo("VDBService.vdb_deployed", new Object[] {vdb.getName(), vdb.getVersion()}); //$NON-NLS-1$
             
@@ -451,7 +437,7 @@
                 // holds true when DQP restarted. Also, this will be only the case
                 // when shared binding is used.                    
                 def.addConnectorBinding(existing);
-                updateDef(def,vdb);
+                saveVDB(vdb, vdb.getVersion());
             }            
         }        
     }    
@@ -498,8 +484,12 @@
         throws MetaMatrixComponentException {
                 
     	try {
+    		
+    		URL vdbFile = availableVDBFiles.remove(vdbId(vdb));
+    		
+    		Assertion.isNotNull(vdbFile);
+    		
 	        // delete the def/vdb files
-	        URL vdbFile = getVDBLocation(vdb);
 	        VDBConfigurationWriter.deleteVDB(vdb, vdbFile);
 	
 	        // Notify any listeners that vdb is deleted
@@ -507,7 +497,6 @@
 	        
 	        // remove from local references.
 	        loadedVDBs.remove(vdbId(vdb));
-	        availableVDBFiles.remove(vdbId(vdb));
 	        
 	        VDBDefn def = vdb.getConfigurationDef();
 	                
@@ -585,7 +574,6 @@
                 }
                 
                 // Save the new vdb/model defination into the persistent store.
-                updateDef(def,vdb);
                 saveVDB(vdb, vdb.getVersion());
                 
                 deleteOrphanedConnectorBindings(orphanBindings);
@@ -724,7 +712,6 @@
                     // all the deployed VDBs that are using this connector binding.
                 	BasicVDBDefn def = vdb.getConfigurationDef();
                 	def.addConnectorBinding(binding);
-                	updateDef(def,vdb);
                 	
                     // we may need to save the VDB's here..
                     saveVDB(vdb, vdb.getVersion());                    
@@ -978,7 +965,7 @@
                         
             // Find all the VDB File in the configuration
             // Load them the available VDBs
-            this.availableVDBFiles  = loadVDBs();
+            loadVDBs();
             
             // load the connector bindings
             loadConnectorBindings(connectorBindings, connectorTypes);
@@ -1118,7 +1105,7 @@
      * @throws ApplicationInitializationException
      * @since 4.3
      */
-    HashMap<VDBKey, URL> loadVDBs() throws ApplicationInitializationException{
+    void loadVDBs() throws ApplicationInitializationException{
         // Get the files to load
         HashMap<URL, VDBArchive> vdbFiles;
 		try {
@@ -1126,7 +1113,6 @@
 		} catch (MetaMatrixComponentException e) {
 			throw new ApplicationInitializationException(e);
 		}
-        HashMap<VDBKey, URL> loadedVDBFiles = new HashMap<VDBKey, URL>();
 
         for (URL vdbURL:vdbFiles.keySet()){                               
             
@@ -1134,21 +1120,25 @@
             
             if (vdb != null) {
             
-                // Check to make sure there are two identical VDBs with same version 
-                // being loaded into DQP
-                if (loadedVDBs.get(vdbId(vdb)) != null) {
-                    throw new ApplicationInitializationException(DQPEmbeddedPlugin.Util.getString("EmbeddedConfigurationService.duplicate_vdb_found", new Object[] {vdbURL})); //$NON-NLS-1$
-                }
-                
-                // add vdb to loaded VDBS
-                loadedVDBs.put(vdbId(vdb), vdb);
-                loadedVDBFiles.put(vdbId(vdb), vdbURL);
-                DQPEmbeddedPlugin.logInfo("EmbeddedConfigurationService.loaded_vdb", new Object[] {vdbURL}); //$NON-NLS-1$
+                loadVDB(vdbURL, vdb);
             }
         }
-        return loadedVDBFiles;
     }
 
+	private void loadVDB(URL vdbURL, VDBArchive vdb)
+			throws ApplicationInitializationException {
+		// Check to make sure there are two identical VDBs with same version 
+		// being loaded into DQP
+		if (loadedVDBs.get(vdbId(vdb)) != null) {
+		    throw new ApplicationInitializationException(DQPEmbeddedPlugin.Util.getString("EmbeddedConfigurationService.duplicate_vdb_found", new Object[] {vdbURL})); //$NON-NLS-1$
+		}
+		
+		// add vdb to loaded VDBS
+		loadedVDBs.put(vdbId(vdb), vdb);
+		availableVDBFiles.put(vdbId(vdb), vdbURL);
+		DQPEmbeddedPlugin.logInfo("EmbeddedConfigurationService.loaded_vdb", new Object[] {vdbURL}); //$NON-NLS-1$
+	}
+
 	protected File getDeployDir() {
 		File f = new File(getFullyQualifiedPath("deploy").getPath()); //$NON-NLS-1$
 		if (f.exists()) {

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -125,7 +125,7 @@
     
     @Override
     public ConnectorMetadata getConnectorMetadata(String vdbName,
-    		String vdbVersion, String modelName) throws MetaMatrixComponentException {
+    		String vdbVersion, String modelName, Properties importProperties) throws MetaMatrixComponentException {
     	VDBService vdbService = (VDBService)this.lookupService(DQPServiceNames.VDB_SERVICE);
     	List<String> bindingNames = vdbService.getConnectorBindingNames(vdbName, vdbVersion, modelName);
     	if (bindingNames.isEmpty()) {
@@ -139,7 +139,7 @@
     	}
     	
     	try {
-			return mgr.getMetadata(modelName);
+			return mgr.getMetadata(modelName, importProperties);
 		} catch (ConnectorException e) {
 			throw new MetaMatrixComponentException(e);
 		}

Modified: trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java
===================================================================
--- trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -152,7 +152,7 @@
         VDBArchive vdb = service.getVDB("QT_Ora9DS", "1"); //$NON-NLS-1$ //$NON-NLS-2$
         vdb.getConfigurationDef().setName("Foo"); //$NON-NLS-1$
         vdb.getConfigurationDef().setVersion("2"); //$NON-NLS-1$
-        assertTrue(service.getVDBLocation(vdb).toString().endsWith("dqp/config/Foo_2.vdb")); //$NON-NLS-1$
+        assertTrue(service.getNewVDBLocation(vdb).toString().endsWith("dqp/config/Foo_2.vdb")); //$NON-NLS-1$
     }
     
     public void testGetFileToSaveNewFile() throws Exception{
@@ -164,21 +164,10 @@
         VDBArchive vdb = service.getVDB("QT_Ora9DS", "1"); //$NON-NLS-1$ //$NON-NLS-2$
         vdb.getConfigurationDef().setName("Foo"); //$NON-NLS-1$
         vdb.getConfigurationDef().setVersion("2"); //$NON-NLS-1$
-        URL f = service.getVDBLocation(vdb);
+        URL f = service.getNewVDBLocation(vdb);
         assertTrue(f.toString().endsWith("dqp/config/Foo_2.vdb")); //$NON-NLS-1$
     }
     
-    public void testGetFileAlreadyExisting() throws Exception{
-        Properties p = EmbeddedTestUtil.getProperties(); 
-        service.setUserPreferences(p);
-        service.initializeService(p);
-        
-        VDBArchive vdb = service.getVDB("QT_Ora9DS", "1"); //$NON-NLS-1$ //$NON-NLS-2$
-        
-        URL f = service.getVDBLocation(vdb);        
-        assertTrue(f.getPath().endsWith("dqp/config/QT_Ora9DS.vdb")); //$NON-NLS-1$
-    }
-    
     public void testGetFullyQualifiedPath() throws Exception{
         Properties p = EmbeddedTestUtil.getProperties(); 
         service.setUserPreferences(p);       

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/DataService.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/DataService.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/DataService.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -24,6 +24,7 @@
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Properties;
 
 import org.teiid.connector.metadata.runtime.ConnectorMetadata;
 import org.teiid.dqp.internal.process.DQPWorkContext;
@@ -84,10 +85,11 @@
      * @param vdbName
      * @param vdbVersion
      * @param modelName
+     * @param importProperties
      * @return
      * @throws MetaMatrixComponentException 
      */
-    ConnectorMetadata getConnectorMetadata(String vdbName, String vdbVersion, String modelName) throws MetaMatrixComponentException;
+    ConnectorMetadata getConnectorMetadata(String vdbName, String vdbVersion, String modelName, Properties importProperties) throws MetaMatrixComponentException;
                
     /**
      * Start the Connector Binding by the name given, if it is already added and not srarted. 

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -146,10 +146,10 @@
 		return classloader;
 	}
     
-    public ConnectorMetadata getMetadata(String modelName) throws ConnectorException {
+    public ConnectorMetadata getMetadata(String modelName, Properties importProperties) throws ConnectorException {
     	MetadataFactory factory;
 		try {
-			factory = new MetadataFactory(modelName, this.metadataService.getBuiltinDatatypes());
+			factory = new MetadataFactory(modelName, this.metadataService.getBuiltinDatatypes(), importProperties);
 		} catch (MetaMatrixComponentException e) {
 			throw new ConnectorException(e);
 		}

Modified: trunk/engine/src/test/java/com/metamatrix/dqp/service/AutoGenDataService.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/service/AutoGenDataService.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/service/AutoGenDataService.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -28,6 +28,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
 import org.teiid.connector.metadata.runtime.ConnectorMetadata;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorWorkItem;
@@ -249,7 +250,7 @@
 	
     @Override
     public ConnectorMetadata getConnectorMetadata(String vdbName,
-    		String vdbVersion, String modelName) {
+    		String vdbVersion, String modelName, Properties importProperties) {
     	throw new UnsupportedOperationException();
     }
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -394,7 +394,7 @@
 		}
 	    @Override
 	    public ConnectorMetadata getConnectorMetadata(String vdbName,
-	    		String vdbVersion, String modelName) {
+	    		String vdbVersion, String modelName, Properties importProperties) {
 	    	throw new UnsupportedOperationException();
 	    }
     }

Modified: trunk/metadata/src/main/java/org/teiid/metadata/ConnectorMetadataStore.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/ConnectorMetadataStore.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/metadata/src/main/java/org/teiid/metadata/ConnectorMetadataStore.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -44,18 +44,16 @@
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
 import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.dqp.service.DataService;
 import com.metamatrix.query.metadata.MetadataStore;
-import com.metamatrix.vdb.runtime.VDBKey;
 
 public class ConnectorMetadataStore implements MetadataStore {
 	
 	private ConnectorMetadata metadata;
 	private String modelName;
 	
-	public ConnectorMetadataStore(VDBKey key, String modelName, DataService dataService) throws MetaMatrixComponentException {
+	public ConnectorMetadataStore(String modelName, ConnectorMetadata metadata) {
 		this.modelName = modelName;
-		this.metadata = dataService.getConnectorMetadata(key.getName(), key.getVersion(), modelName);
+		this.metadata = metadata;
 	}
 	
 	@Override

Modified: trunk/metadata/src/main/java/org/teiid/metadata/QueryMetadataCache.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/QueryMetadataCache.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/metadata/src/main/java/org/teiid/metadata/QueryMetadataCache.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -23,7 +23,12 @@
 package org.teiid.metadata;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -37,6 +42,7 @@
 import org.teiid.connector.metadata.MetadataConnectorConstants;
 import org.teiid.connector.metadata.MultiObjectSource;
 import org.teiid.connector.metadata.PropertyFileObjectSource;
+import org.teiid.connector.metadata.runtime.ConnectorMetadata;
 import org.teiid.connector.metadata.runtime.DatatypeRecordImpl;
 import org.teiid.metadata.index.IndexMetadataStore;
 
@@ -167,7 +173,35 @@
 	        Set<String> modelNames = runtimeSelector.getConnectorMetadataModelNames();
 	        if (!modelNames.isEmpty()) {
 		        for (String modelName : modelNames) {
-		        	metadataStores.add(new ConnectorMetadataStore(vdbID, modelName, dataService));
+		        	ConnectorMetadata connectorMetadata = null;
+		        	String savedMetadata = "/META-INF/" + modelName.toLowerCase() + ".ser"; //$NON-NLS-1$ //$NON-NLS-2$
+	        		if (runtimeSelector.cacheConnectorMetadata()) {
+		        		File f = runtimeSelector.getFile(savedMetadata);
+		        		if (f != null) {
+		        			ObjectInputStream ois = null;
+		        			try {
+			        			ois = new ObjectInputStream(new FileInputStream(f));
+			        			connectorMetadata = (ConnectorMetadata)ois.readObject();
+		        			} catch (Exception e) {
+		        				
+		        			} finally {
+		        				if (ois != null) {
+				        			ois.close();
+		        				}
+		        			}
+		        		}
+		        	}
+		        	if (connectorMetadata == null) {
+		        		connectorMetadata = dataService.getConnectorMetadata(vdbID.getName(), vdbID.getVersion(), modelName, runtimeSelector.getModelInfo(modelName).getProperties());
+		        	}
+		        	if (runtimeSelector.cacheConnectorMetadata()) {
+		        		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		        		ObjectOutputStream oos = new ObjectOutputStream(baos);
+		        		oos.writeObject(connectorMetadata);
+		        		oos.close();
+		        		runtimeSelector.saveFile(new ByteArrayInputStream(baos.toByteArray()), savedMetadata);
+		        	}
+		        	metadataStores.add(new ConnectorMetadataStore(modelName, connectorMetadata));
 				}
 	        }
 			metadataStores.add(indexMetadataStore);

Modified: trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformDataService.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformDataService.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformDataService.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -234,7 +234,7 @@
     
     @Override
     public ConnectorMetadata getConnectorMetadata(String vdbName,
-    		String vdbVersion, String modelName) {
+    		String vdbVersion, String modelName, Properties importProperties) {
     	throw new UnsupportedOperationException();
     }
 

Modified: trunk/server/src/test/java/com/metamatrix/server/admin/apiimpl/FakeModelInfo.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/server/admin/apiimpl/FakeModelInfo.java	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/server/src/test/java/com/metamatrix/server/admin/apiimpl/FakeModelInfo.java	2009-07-13 18:34:07 UTC (rev 1122)
@@ -27,6 +27,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import com.metamatrix.common.util.ByteArrayHelper;
@@ -266,4 +267,9 @@
 	public String getPath() {
 		return null;
 	}
+	
+	@Override
+	public Properties getProperties() {
+		return new Properties();
+	}
 }

Modified: trunk/test-integration/src/test/resources/vdbless/ConfigurationInfo.def
===================================================================
--- trunk/test-integration/src/test/resources/vdbless/ConfigurationInfo.def	2009-07-13 16:25:41 UTC (rev 1121)
+++ trunk/test-integration/src/test/resources/vdbless/ConfigurationInfo.def	2009-07-13 18:34:07 UTC (rev 1122)
@@ -2,8 +2,8 @@
 <VDB>
     <VDBInfo>
         <Property Name="Name" Value="VDBLess" />
-        <Property Name="Version" Value="3" />
-        <Property Name="UseConnectorMetadata" Value="true" />
+        <Property Name="Version" Value="2" />
+        <Property Name="UseConnectorMetadata" Value="cached" />
     </VDBInfo>
     <Model>
         <Property Name="Name" Value="SummitData" />
@@ -13,9 +13,13 @@
     </Model>
     <Model>
         <Property Name="Name" Value="Derby" />
+        
         <ConnectorBindings>
             <Connector Name="Derby Connector" />
         </ConnectorBindings>
+        
+        <!-- import settings -->
+        <Property Name="importer.useFullSchemaName" Value="false"/>
     </Model>
     <ConnectorBindings>
         <Connector Name="Text Connector" ComponentType="Text File Connector">
@@ -28,9 +32,6 @@
             <Properties>
                 <Property Name="Immutable">true</Property>
                 <Property Name="URL">jdbc:derby:jar:(src/test/resources/derby/sample.zip)bqt</Property>
-                
-                <!-- import settings -->
-                <Property Name="importer.useFullSchemaName">false</Property>
             </Properties>
         </Connector>
     </ConnectorBindings>




More information about the teiid-commits mailing list