[teiid-commits] teiid SVN: r2153 - in trunk: build/kits/jboss-container/deploy/teiid and 5 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue May 25 12:27:12 EDT 2010


Author: rareddy
Date: 2010-05-25 12:27:10 -0400 (Tue, 25 May 2010)
New Revision: 2153

Added:
   trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplate.java
   trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplateInfo.java
Modified:
   trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
   trunk/build/kits/jboss-container/deploy/teiid/teiid-connector-templates-jboss-beans.xml
   trunk/client/src/main/java/org/teiid/adminapi/Admin.java
   trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
   trunk/jboss-integration/src/main/java/org/teiid/templates/connector/XaJdbcConnectorTemplate.java
   trunk/jboss-integration/src/main/java/org/teiid/templates/connector/XaJdbcConnectorTemplateInfo.java
   trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
   trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
Log:
TEIID-1080: adding "createDataSource, deleteDataSource, getDataSourceNames, getDataSourceTemplateNames" methods to the Admin API, to support the data source creation from the Designer. Added required templates for the jdbc to make the configuration simpler than what is provided by the container.

Modified: trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
===================================================================
--- trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java	2010-05-25 14:46:43 UTC (rev 2152)
+++ trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java	2010-05-25 16:27:10 UTC (rev 2153)
@@ -74,7 +74,7 @@
 		currentName = connectionName;
 		Admin old = connections.put(connectionName, internalAdmin);
 		if (old != null) {
-			System.out.println("Closing previous admin associated with " + connectionName);
+			System.out.println("Closing previous admin associated with " + connectionName); //$NON-NLS-1$
 			old.close();
 		}
 	}
@@ -97,7 +97,7 @@
 		    fis = new FileInputStream("connection.properties"); //$NON-NLS-1$
 	    	props.load(fis);
 	    } catch (IOException e) {
-	    	log.log(Level.WARNING, "Could not load default connection properties.", e);
+	    	log.log(Level.WARNING, "Could not load default connection properties.", e); //$NON-NLS-1$
 	    } finally {
 	    	if (fis != null) {
 	    		try {
@@ -109,12 +109,12 @@
 	    p = props;
 	}
 	
-	@Doc(text = "Add a Translator")
-	public static Translator addTranslator(
+	@Doc(text = "Create a Translator")
+	public static Translator createTranslator(
 			@Doc(text = "deployed name") String deployedName,
 			@Doc(text = "type name") String typeName, 
 			Properties properties) throws AdminException {
-		return getAdmin().addTranslator(deployedName, typeName, properties);
+		return getAdmin().createTranslator(deployedName, typeName, properties);
 	}
 
 	@Doc(text = "Adds a role to the specified policy")
@@ -189,10 +189,10 @@
 		return getAdmin().getTranslatorTemplateNames();
 	}
 
-	@Doc(text = "Get all PropertyDefinitions for the given translator template")
+	@Doc(text = "Get all PropertyDefinitions for the given template")
 	public static Collection<PropertyDefinition> getTranslatorTemplatePropertyDefinitions(
 			@Doc(text = "template name") String templateName) throws AdminException {
-		return getAdmin().getTranslatorTemplatePropertyDefinitions(templateName);
+		return getAdmin().getTemplatePropertyDefinitions(templateName);
 	}
 
 	@Doc(text = "Get the ProcessObject instances for the given identifier")
@@ -331,7 +331,7 @@
 	private static void writeFile(String deployedName, String fileName,
 			InputStream contents) throws IOException, AdminProcessingException {
 		if (contents == null) {
-	    	throw new AdminProcessingException(deployedName + " not found for exporting");
+	    	throw new AdminProcessingException(deployedName + " not found for exporting");//$NON-NLS-1$
 	    }
 		ObjectConverterUtil.write(contents, fileName);	
 	}
@@ -359,11 +359,30 @@
 			}
 		}
 	}
+	@Doc(text = "Create a data source from supplied properties")
+	public static void createDataSource(@Doc(text = "deployed name")String deploymentName, @Doc(text = "template name")String templateName, @Doc(text = "properties")Properties properties) throws AdminException {
+		getAdmin().createDataSource(deploymentName, templateName, properties);
+	}
+	
+	@Doc(text = "Delete data source")
+	public static void deleteDataSource(@Doc(text = "deployed name")String deployedName) throws AdminException{
+		getAdmin().deleteDataSource(deployedName);
+	}
+	
+	@Doc(text = "Available data sources")
+	public static Collection<String> getDataSourceNames() throws AdminException{
+		return getAdmin().getDataSourceNames();
+	}
 
+	@Doc(text = "Available data source template names")
+	public static Set<String> getDataSourceTemplateNames() throws AdminException{
+		return getAdmin().getDataSourceTemplateNames();
+	}
+	
 	@Doc(text = "Get the current Admin connection")
 	public static Admin getAdmin() {
 		if (internalAdmin == null) {
-	        throw new NullPointerException("Not connected.  You must call a \"connectAsAdmin\" method or choose an active connection via \"useConnection\".");
+	        throw new NullPointerException("Not connected.  You must call a \"connectAsAdmin\" method or choose an active connection via \"useConnection\"."); //$NON-NLS-1$
 	    }
 		return internalAdmin;
 	}
@@ -393,7 +412,7 @@
 			@Doc(text = "connection name") String name) {
 		Admin admin = connections.get(name);
 		if (admin == null) {
-			System.out.println("Warning: connection is not active for " + name);
+			System.out.println("Warning: connection is not active for " + name); //$NON-NLS-1$
 			return;
 		}
 		internalAdmin = admin;

Modified: trunk/build/kits/jboss-container/deploy/teiid/teiid-connector-templates-jboss-beans.xml
===================================================================
--- trunk/build/kits/jboss-container/deploy/teiid/teiid-connector-templates-jboss-beans.xml	2010-05-25 14:46:43 UTC (rev 2152)
+++ trunk/build/kits/jboss-container/deploy/teiid/teiid-connector-templates-jboss-beans.xml	2010-05-25 16:27:10 UTC (rev 2153)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <deployment xmlns="urn:jboss:bean-deployer:2.0">
-    <!-- 
+
    <bean name="connector-jdbc-xa-${project.version}" class="org.teiid.templates.connector.XaJdbcConnectorTemplate">
       <property name="info"><inject bean="connector-jdbc-xa-templateinfo"/></property>
    </bean>   
@@ -10,13 +10,25 @@
          <factory bean="DSDeploymentTemplateInfoFactory"/>
          <parameter class="java.lang.Class">org.teiid.templates.connector.XaJdbcConnectorTemplateInfo</parameter>
          <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.XADataSourceDeploymentMetaData</parameter>
-         <parameter class="java.lang.String">connector-jdbc-xa-${project.version}</parameter>
+         <parameter class="java.lang.String">connector-jdbc-xa</parameter>
          <parameter class="java.lang.String">Teiid JDBC XA Connector</parameter>         
       </constructor>
-      <property name="rarName">connector-jdbc-${project.version}.rar</property>
    </bean> 
-    -->
     
+   <bean name="connector-jdbc-${project.version}" class="org.teiid.templates.connector.LocalJdbcConnectorTemplate">
+      <property name="info"><inject bean="connector-jdbc-templateinfo"/></property>
+   </bean>   
+   
+   <bean name="connector-jdbc-templateinfo" class="org.teiid.templates.connector.LocalJdbcConnectorTemplateInfo">
+      <constructor factoryMethod="createTemplateInfo">
+         <factory bean="DSDeploymentTemplateInfoFactory"/>
+         <parameter class="java.lang.Class">org.teiid.templates.connector.LocalJdbcConnectorTemplateInfo</parameter>
+         <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData</parameter>
+         <parameter class="java.lang.String">connector-jdbc</parameter>
+         <parameter class="java.lang.String">Teiid JDBC Connector</parameter>         
+      </constructor>
+   </bean>    
+    
    <bean name="connector-ldap-${project.version}" class="org.teiid.templates.connector.ConnectorDeploymentTemplate">
       <property name="info"><inject bean="connector-ldap-templateinfo"/></property>
       <property name="targetTemplate"><inject bean="NoTxConnectionFactoryTemplate"/></property>
@@ -27,7 +39,7 @@
          <parameter class="java.lang.Class">org.teiid.templates.connector.ConnectorTemplateInfo</parameter>
          <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>
          <parameter class="java.lang.String">connector-ldap-${project.version}</parameter>
-         <parameter class="java.lang.String">Teiid LDAP Connector</parameter>
+         <parameter class="java.lang.String">LDAP Connection</parameter>
       </constructor>
       <property name="rarName">connector-ldap-${project.version}.rar</property>
    </bean>    
@@ -42,7 +54,7 @@
          <parameter class="java.lang.Class">org.teiid.templates.connector.ConnectorTemplateInfo</parameter>
          <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>
          <parameter class="java.lang.String">connector-salesforce-${project.version}</parameter>
-         <parameter class="java.lang.String">Teiid Salesforce Connector</parameter>
+         <parameter class="java.lang.String">Salesforce Connection</parameter>
       </constructor>
       <property name="rarName">connector-salesforce-${project.version}.rar</property>
    </bean>    
@@ -57,7 +69,7 @@
          <parameter class="java.lang.Class">org.teiid.templates.connector.ConnectorTemplateInfo</parameter>
          <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>
          <parameter class="java.lang.String">connector-file-${project.version}</parameter>
-         <parameter class="java.lang.String">Teiid File Connector</parameter>
+         <parameter class="java.lang.String">File Connection</parameter>
       </constructor>
       <property name="rarName">connector-file-${project.version}.rar</property>
    </bean>    
@@ -72,56 +84,9 @@
          <parameter class="java.lang.Class">org.teiid.templates.connector.ConnectorTemplateInfo</parameter>
          <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>
          <parameter class="java.lang.String">connector-ws-${project.version}</parameter>
-         <parameter class="java.lang.String">Teiid WS Connector</parameter>
+         <parameter class="java.lang.String">WS Connection</parameter>
       </constructor>
       <property name="rarName">connector-ws-${project.version}.rar</property>
    </bean>  
    
-   <!-- 
-   <bean name="connector-xmlsource-file-${project.version}" class="org.teiid.templates.connector.ConnectorDeploymentTemplate">
-      <property name="info"><inject bean="connector-xmlsource-file-templateinfo"/></property>
-      <property name="targetTemplate"><inject bean="NoTxConnectionFactoryTemplate"/></property>
-   </bean>
-   <bean name="connector-xmlsource-file-templateinfo" class="org.teiid.templates.connector.ConnectorTemplateInfo">
-      <constructor factoryMethod="createTemplateInfo">
-         <factory bean="DSDeploymentTemplateInfoFactory"/>
-         <parameter class="java.lang.Class">org.teiid.templates.connector.ConnectorTemplateInfo</parameter>
-         <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>
-         <parameter class="java.lang.String">connector-xmlsource-file-${project.version}</parameter>
-         <parameter class="java.lang.String">Teiid XML File Connector</parameter>
-      </constructor>
-      <property name="rarName">connector-xmlsource-file-${project.version}.rar</property>
-   </bean>    
-   
-   <bean name="connector-xmlsource-soap-${project.version}" class="org.teiid.templates.connector.ConnectorDeploymentTemplate">
-      <property name="info"><inject bean="connector-xmlsource-soap-templateinfo"/></property>
-      <property name="targetTemplate"><inject bean="NoTxConnectionFactoryTemplate"/></property>
-   </bean>
-   <bean name="connector-xmlsource-soap-templateinfo" class="org.teiid.templates.connector.ConnectorTemplateInfo">
-      <constructor factoryMethod="createTemplateInfo">
-         <factory bean="DSDeploymentTemplateInfoFactory"/>
-         <parameter class="java.lang.Class">org.teiid.templates.connector.ConnectorTemplateInfo</parameter>
-         <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>
-         <parameter class="java.lang.String">connector-xmlsource-soap-${project.version}</parameter>
-         <parameter class="java.lang.String">Teiid XML SOAP Connector</parameter>
-      </constructor>
-      <property name="rarName">connector-xmlsource-soap-${project.version}.rar</property>
-   </bean> 
-   
-   <bean name="connector-xml-http-${project.version}" class="org.teiid.templates.connector.ConnectorDeploymentTemplate">
-      <property name="info"><inject bean="connector-xml-http-templateinfo"/></property>
-      <property name="targetTemplate"><inject bean="NoTxConnectionFactoryTemplate"/></property>
-   </bean>
-   <bean name="connector-xml-http-templateinfo" class="org.teiid.templates.connector.ConnectorTemplateInfo">
-      <constructor factoryMethod="createTemplateInfo">
-         <factory bean="DSDeploymentTemplateInfoFactory"/>
-         <parameter class="java.lang.Class">org.teiid.templates.connector.ConnectorTemplateInfo</parameter>
-         <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>
-         <parameter class="java.lang.String">connector-xml-http-${project.version}</parameter>
-         <parameter class="java.lang.String">Teiid XML HTTP Connector</parameter>
-      </constructor>
-      <property name="rarName">connector-xml-http-${project.version}.rar</property>
-   </bean>   
-    -->
-   
 </deployment>

Modified: trunk/client/src/main/java/org/teiid/adminapi/Admin.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/Admin.java	2010-05-25 14:46:43 UTC (rev 2152)
+++ trunk/client/src/main/java/org/teiid/adminapi/Admin.java	2010-05-25 16:27:10 UTC (rev 2153)
@@ -54,7 +54,7 @@
     void setTranslatorProperty(String deployedName, String propertyName, String propertyValue) throws AdminException;
     
     /**
-     * Deploy a {@link Translator} to Configuration
+     * Create a {@link Translator}
      *
      * @param deployedName  Translator name that will be added to Configuration
      * @param templateName template name 
@@ -62,7 +62,7 @@
 
      * @throws AdminException 
      */
-    Translator addTranslator(String deployedName, String templateName, Properties properties) throws AdminException;
+    Translator createTranslator(String deployedName, String templateName, Properties properties) throws AdminException;
 
     /**
      * Delete the {@link Translator} from the Configuration
@@ -194,7 +194,7 @@
      * @return
      * @throws AdminException
      */
-    Collection<PropertyDefinition> getTranslatorTemplatePropertyDefinitions(String templateName) throws AdminException;
+    Collection<PropertyDefinition> getTemplatePropertyDefinitions(String templateName) throws AdminException;
     
     
     /**
@@ -286,4 +286,33 @@
      */
     void mergeVDBs(String sourceVDBName, int sourceVDBVersion, String targetVDBName, int targetVDBVersion) throws AdminException;
 
+    
+    /**
+     * Creates a JCA data source
+     * @param deploymentName - name of the source
+     * @param templateName - template of data source
+     * @param properties - properties
+     * @throws AdminException
+     */
+    void createDataSource(String deploymentName, String templateName, Properties properties) throws AdminException;
+    
+    /**
+     * Delete data source. 
+     * @param deployedName
+     * @throws AdminException
+     */
+    void deleteDataSource(String deployedName) throws AdminException;
+    
+    /**
+     * Returns the all names of all the data sources available in the configuration.
+     */
+    Collection<String> getDataSourceNames() throws AdminException;
+    
+    /**
+     * Get the Datasource templates  available in the configuration.
+     *
+     * @return Set of template names.
+     * @throws AdminException 
+     */
+    Set<String> getDataSourceTemplateNames() throws AdminException;
 }

Modified: trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java	2010-05-25 14:46:43 UTC (rev 2152)
+++ trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java	2010-05-25 16:27:10 UTC (rev 2153)
@@ -49,6 +49,7 @@
 import org.jboss.metatype.api.values.CollectionValueSupport;
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.api.values.SimpleValue;
 import org.jboss.metatype.api.values.SimpleValueSupport;
 import org.jboss.profileservice.spi.NoSuchDeploymentException;
 import org.jboss.profileservice.spi.ProfileKey;
@@ -77,6 +78,7 @@
 
 public class Admin extends TeiidAdmin {
 	private static final String TRANSLATOR_PREFIX = "translator-"; //$NON-NLS-1$
+	private static final String CONNECTOR_PREFIX = "connector-"; //$NON-NLS-1$
 	private static final ProfileKey DEFAULT_PROFILE_KEY = new ProfileKey(ProfileKey.DEFAULT);
 	private static final long serialVersionUID = 7081309086056911304L;
 	private static ComponentType VDBTYPE = new ComponentType("teiid", "vdb");//$NON-NLS-1$ //$NON-NLS-2$
@@ -85,6 +87,10 @@
 	private static ComponentType TRANSLATOR_TYPE = new ComponentType("teiid", "translator");//$NON-NLS-1$ //$NON-NLS-2$
 	private static AdminObjectBuilder AOB = new AdminObjectBuilder();
 	
+	private static final String[] DS_TYPES = {"XA", "NoTx", "LocalTx"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	private static final String[] CF_TYPES = {"NoTx", "Tx"}; //$NON-NLS-1$ //$NON-NLS-2$
+	
+	
 	private ManagementView view;
 	private DeploymentManager deploymentMgr;
 	
@@ -181,7 +187,7 @@
 	}	
 	
 	@Override
-	public Translator addTranslator(String deploymentName, String typeName, Properties properties) throws AdminException {
+	public Translator createTranslator(String deploymentName, String typeName, Properties properties) throws AdminException {
 		try {
 			ManagedComponent mc = getView().getComponent(deploymentName, TRANSLATOR_TYPE);
 			if (mc != null) {
@@ -472,7 +478,7 @@
 	
 	
 	@Override
-	public Collection<PropertyDefinition> getTranslatorTemplatePropertyDefinitions(String templateName) throws AdminException {
+	public Collection<PropertyDefinition> getTemplatePropertyDefinitions(String templateName) throws AdminException {
 		try {
 			DeploymentTemplateInfo info = getView().getTemplate(templateName);
 			if(info == null) {
@@ -671,4 +677,107 @@
 			throw new AdminComponentException(e.getMessage(), e);
 		}   		
 	}
+
+	private ManagedComponent getDatasource(String deployedName) throws Exception {
+		ManagedComponent mc = null;
+		for (String type:DS_TYPES) {
+			ComponentType ct = new ComponentType("DataSource", type); //$NON-NLS-1$
+			mc = getView().getComponent(deployedName, ct);
+			if (mc != null) {
+				return mc;
+			}				
+		}		
+		for (String type:CF_TYPES) {
+			ComponentType ct = new ComponentType("ConnectionFactory", type); //$NON-NLS-1$
+			mc = getView().getComponent(deployedName, ct);
+			if (mc != null) {
+				return mc;
+			}				
+		}
+		return mc;
+	}
+	
+	
+	@Override
+	public void createDataSource(String deploymentName, String templateName, Properties properties) throws AdminException {
+		try {
+			ManagedComponent mc = getDatasource(deploymentName);
+			if (mc != null) {
+				throw new AdminProcessingException(IntegrationPlugin.Util.getString("datasource_exists",deploymentName)); //$NON-NLS-1$;	
+			}
+			
+			DeploymentTemplateInfo info = getView().getTemplate(templateName);
+			if(info == null) {
+				throw new AdminProcessingException(IntegrationPlugin.Util.getString("datasource_template_not_found", templateName)); //$NON-NLS-1$
+			}
+			
+			// template properties specific to the template
+			Map<String, ManagedProperty> propertyMap = info.getProperties();
+			
+			// walk through the supplied properties and assign properly to template
+			for (String key:properties.stringPropertyNames()) {
+				ManagedProperty mp = propertyMap.get(key);
+				if (mp != null) {
+					String value = properties.getProperty(key);
+					if (!ManagedUtil.sameValue(mp.getDefaultValue(), value)){
+						mp.setValue(SimpleValueSupport.wrap(value));
+					}
+				}
+			}
+			info.getProperties().get("jndi-name").setValue(SimpleValueSupport.wrap(deploymentName)); //$NON-NLS-1$
+			getView().applyTemplate(deploymentName, info);
+		} catch (NoSuchDeploymentException e) {
+			throw new AdminComponentException(e.getMessage(), e);
+		} catch(Exception e) {
+			throw new AdminComponentException(e.getMessage(), e);
+		} 
+	}
+
+	@Override
+	public void deleteDataSource(String deployedName) throws AdminException {
+		try {
+			ManagedComponent mc = getDatasource(deployedName);
+			if (mc != null) {
+				ManagedUtil.removeArchive(getDeploymentManager(),mc.getDeployment().getName());
+			}
+		} catch (Exception e) {
+			throw new AdminComponentException(e);
+		}
+	}
+
+	@Override
+	public Collection<String> getDataSourceNames() throws AdminException {
+		ArrayList<String> names = new ArrayList<String>();
+		try {
+			for (String type:DS_TYPES) {
+				ComponentType ct = new ComponentType("DataSource", type); //$NON-NLS-1$
+				Set<ManagedComponent> mcs = getView().getComponentsForType(ct);
+				for (ManagedComponent mc:mcs) {
+					names.add(((SimpleValue)mc.getProperty("jndi-name").getValue()).getValue().toString()); //$NON-NLS-1$
+				}
+			}		
+			for (String type:CF_TYPES) {
+				ComponentType ct = new ComponentType("ConnectionFactory", type); //$NON-NLS-1$
+				Set<ManagedComponent> mcs = getView().getComponentsForType(ct);
+				for (ManagedComponent mc:mcs) {
+					names.add(((SimpleValue)mc.getProperty("jndi-name").getValue()).getValue().toString()); //$NON-NLS-1$
+				}			
+			}
+		} catch (Exception e) {
+			throw new AdminComponentException(e);
+		}
+		return names;
+	}
+	
+	@Override
+	public Set<String> getDataSourceTemplateNames() throws AdminException{
+		Set<String> names = getView().getTemplateNames();
+		HashSet<String> matched = new HashSet<String>();
+		for(String name:names) {
+			if (name.startsWith(CONNECTOR_PREFIX)) {
+				matched.add(name);
+			}
+		}
+		return matched;		
+	}
 }

Added: trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplate.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplate.java	                        (rev 0)
+++ trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplate.java	2010-05-25 16:27:10 UTC (rev 2153)
@@ -0,0 +1,59 @@
+/*
+ * 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 org.teiid.templates.connector;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.virtual.VirtualFile;
+import org.teiid.adminapi.jboss.ManagedUtil;
+
+
+
+public class LocalJdbcConnectorTemplate extends org.jboss.resource.deployers.management.DsDataSourceTemplate {
+
+	@Override
+	public VirtualFile applyTemplate(DeploymentTemplateInfo values) throws Exception {
+
+		values.getProperties().get("connection-definition").setValue(ManagedUtil.wrap(SimpleMetaType.STRING, "javax.sql.DataSource"));//$NON-NLS-1$ //$NON-NLS-2$	
+		values.getProperties().get("dsType").setValue(ManagedUtil.wrap(SimpleMetaType.STRING, "local-tx-datasource"));//$NON-NLS-1$ //$NON-NLS-2$	
+		
+		Map<String, String> configProperties = new HashMap<String, String>();
+		configProperties.put(ConnectorTemplateInfo.TEMPLATE_NAME, getInfo().getName());
+		values.getProperties().get("config-property").setValue(ManagedUtil.compositeValueMap(configProperties));//$NON-NLS-1$	
+		
+		Map<String, String> connectionProperties = new HashMap<String, String>(); 
+		
+		ManagedProperty mp = values.getProperties().remove(LocalJdbcConnectorTemplateInfo.ADDITIONAL_CONNECTION_PROPS);
+		if (mp != null && mp.getValue() != null) {
+			XaJdbcConnectorTemplateInfo.parseProperties(ManagedUtil.stringValue(mp.getValue()), connectionProperties);
+		}
+		
+		values.getProperties().get("connection-properties").setValue(ManagedUtil.compositeValueMap(connectionProperties));//$NON-NLS-1$
+		
+		return super.applyTemplate(values);
+	}
+
+}


Property changes on: trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplate.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplateInfo.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplateInfo.java	                        (rev 0)
+++ trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplateInfo.java	2010-05-25 16:27:10 UTC (rev 2153)
@@ -0,0 +1,125 @@
+/*
+ * 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 org.teiid.templates.connector;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.resource.deployers.management.DsDataSourceTemplateInfo;
+import org.teiid.adminapi.jboss.ExtendedPropertyInfo;
+import org.teiid.adminapi.jboss.ManagedUtil;
+import org.teiid.deployers.ManagedPropertyUtil;
+
+/**
+ * This template is to create a simplified local JDBC datasource  
+ */
+public class LocalJdbcConnectorTemplateInfo extends DsDataSourceTemplateInfo implements ExtendedPropertyInfo {
+	private static final long serialVersionUID = 7618814758011974868L;
+	static final String ADDITIONAL_CONNECTION_PROPS = "addtional-connection-properties";//$NON-NLS-1$
+	
+	public LocalJdbcConnectorTemplateInfo(String name, String description, Map<String, ManagedProperty> properties) {
+		super(name, description, properties);
+	}
+
+	public void start() {
+		populate();
+	}
+
+	@Override
+	public LocalJdbcConnectorTemplateInfo copy() {
+		LocalJdbcConnectorTemplateInfo copy = new LocalJdbcConnectorTemplateInfo(getName(), getDescription(), getProperties());
+		super.copy(copy);
+		copy.populate();
+		return copy;
+	}
+	
+	private void populate() {
+		super.start();
+
+		ManagedProperty mp = this.getProperties().get("connection-definition");//$NON-NLS-1$	
+		mp.setValue(ManagedUtil.wrap(SimpleMetaType.STRING, "javax.sql.DataSource"));//$NON-NLS-1$	
+
+		mp = this.getProperties().get("dsType");//$NON-NLS-1$	
+		mp.setValue(ManagedUtil.wrap(SimpleMetaType.STRING, "local-tx-datasource"));//$NON-NLS-1$	
+		
+		ManagedPropertyImpl dsTypeMP = buildConfigProperty();
+		addProperty(dsTypeMP);
+		
+		addProperty(ConnectorTemplateInfo.buildTemplateProperty(getName()));
+		
+		ManagedPropertyUtil.markAsTeiidProperty(this.getProperties().get("user-name")); //$NON-NLS-1$
+		ManagedPropertyUtil.markAsTeiidProperty(this.getProperties().get("password"));//$NON-NLS-1$
+		ManagedPropertyUtil.markAsTeiidProperty(this.getProperties().get("driver-class")); //$NON-NLS-1$
+		ManagedPropertyUtil.markAsTeiidProperty(this.getProperties().get("connection-url"));//$NON-NLS-1$
+		
+		addProperty(ManagedPropertyUtil.createProperty(ADDITIONAL_CONNECTION_PROPS, SimpleMetaType.STRING,"Addtional Connection Properties", "Addtional Connection properties. (comma separated name value pairs)", false, false, null));//$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	static ManagedPropertyImpl buildConfigProperty() {
+		DefaultFieldsImpl fields = new DefaultFieldsImpl("config-property");//$NON-NLS-1$	
+		fields.setDescription("The config-property type"); //$NON-NLS-1$	
+		fields.setMetaType(new MapCompositeMetaType (SimpleMetaType.STRING));
+		ManagedPropertyImpl dsTypeMP = new ManagedPropertyImpl(fields);
+		return dsTypeMP;
+	}
+	
+	
+	@Override
+	/**
+	 * This is for updating a single property.
+	 */
+	public void updateProperty(String name, String value, ManagedComponent main) {
+		if (name.equals(ADDITIONAL_CONNECTION_PROPS)) {
+			Map<String, String> map = new HashMap<String, String>();
+			parseProperties(value, map);
+			
+			// update the container managed object.
+			MapCompositeValueSupport previousValues = (MapCompositeValueSupport)main.getProperty("connection-properties").getValue(); //$NON-NLS-1$
+			if (previousValues != null) {
+				for (String key:map.keySet()) {
+					previousValues.put(key, SimpleValueSupport.wrap(map.get(key)));
+				}
+			}
+		}
+	}
+	
+	static void parseProperties(String str, Map<String, String> props) {
+		str = str.trim();
+		StringTokenizer st = new StringTokenizer(str, ",");  //$NON-NLS-1$
+		while (st.hasMoreTokens()) {
+			String property = st.nextToken();
+			int index = property.indexOf('=');
+			if (index != -1 && property.length() > (index+1)) {
+				props.put(property.substring(0, index).trim(), property.substring(index+1).trim());
+			}
+		}
+	}	
+}


Property changes on: trunk/jboss-integration/src/main/java/org/teiid/templates/connector/LocalJdbcConnectorTemplateInfo.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/jboss-integration/src/main/java/org/teiid/templates/connector/XaJdbcConnectorTemplate.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/templates/connector/XaJdbcConnectorTemplate.java	2010-05-25 14:46:43 UTC (rev 2152)
+++ trunk/jboss-integration/src/main/java/org/teiid/templates/connector/XaJdbcConnectorTemplate.java	2010-05-25 16:27:10 UTC (rev 2153)
@@ -21,11 +21,12 @@
  */
 package org.teiid.templates.connector;
 
-import java.util.List;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.jboss.managed.api.DeploymentTemplateInfo;
 import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.SimpleMetaType;
 import org.jboss.virtual.VirtualFile;
 import org.teiid.adminapi.jboss.ManagedUtil;
 
@@ -39,25 +40,25 @@
 	public VirtualFile applyTemplate(DeploymentTemplateInfo values) throws Exception {
 		
 		XaJdbcConnectorTemplateInfo info = (XaJdbcConnectorTemplateInfo)getInfo();
+
+		values.getProperties().get("connection-definition").setValue(ManagedUtil.wrap(SimpleMetaType.STRING, "javax.sql.DataSource"));//$NON-NLS-1$ //$NON-NLS-2$	
+		values.getProperties().get("dsType").setValue(ManagedUtil.wrap(SimpleMetaType.STRING, "xa-datasource"));//$NON-NLS-1$ //$NON-NLS-2$	
 		
-		// combine connection factory specific properties.
-		List<String> connectorPropNames = RaXmlPropertyConverter.getPropertyNames(info.getRarName());
-		Map<String, String> props = ConnectorDeploymentTemplate.propertiesAsMap(values, connectorPropNames.toArray(new String[connectorPropNames.size()]), info.getName());
-		props.put(ConnectorTemplateInfo.TEMPLATE_NAME, getInfo().getName());
-		values.getProperties().get("config-property").setValue(ManagedUtil.compositeValueMap(props));//$NON-NLS-1$	
+		Map<String, String> configProperties = new HashMap<String, String>();
+		configProperties.put(ConnectorTemplateInfo.TEMPLATE_NAME, getInfo().getName());
+		values.getProperties().get("config-property").setValue(ManagedUtil.compositeValueMap(configProperties));//$NON-NLS-1$	
 		
-		// combine data source specific properties
-		props = ConnectorDeploymentTemplate.propertiesAsMap(values, XaJdbcConnectorTemplateInfo.EXTENDED_DS_PROPERTIES, info.getName());
+		// Data source specific properties
+		Map<String, String> dsProps = ConnectorDeploymentTemplate.propertiesAsMap(values, XaJdbcConnectorTemplateInfo.EXTENDED_DS_PROPERTIES, info.getName());
 		
 		ManagedProperty mp = values.getProperties().remove(XaJdbcConnectorTemplateInfo.ADDITIONAL_DS_PROPS);
 		if (mp != null && mp.getValue() != null) {
-			XaJdbcConnectorTemplateInfo.parseProperties(ManagedUtil.stringValue(mp.getValue()), props);
+			XaJdbcConnectorTemplateInfo.parseProperties(ManagedUtil.stringValue(mp.getValue()), dsProps);
 		}
 		
-		values.getProperties().get("xa-datasource-properties").setValue(ManagedUtil.compositeValueMap(props));//$NON-NLS-1$
+		values.getProperties().get("xa-datasource-properties").setValue(ManagedUtil.compositeValueMap(dsProps));//$NON-NLS-1$
 	      
 		return super.applyTemplate(values);
 	}
-	
 
 }

Modified: trunk/jboss-integration/src/main/java/org/teiid/templates/connector/XaJdbcConnectorTemplateInfo.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/templates/connector/XaJdbcConnectorTemplateInfo.java	2010-05-25 14:46:43 UTC (rev 2152)
+++ trunk/jboss-integration/src/main/java/org/teiid/templates/connector/XaJdbcConnectorTemplateInfo.java	2010-05-25 16:27:10 UTC (rev 2153)
@@ -22,7 +22,6 @@
 package org.teiid.templates.connector;
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
 
@@ -40,7 +39,7 @@
 import org.teiid.deployers.ManagedPropertyUtil;
 
 /**
- * This template is specific to XA data source combined with Teiid's JDBC connector.
+ * This template is to create a simplified XA JDBC datasource  
  */
 public class XaJdbcConnectorTemplateInfo extends DsDataSourceTemplateInfo implements ExtendedPropertyInfo {
 	
@@ -52,8 +51,6 @@
 	
 	static final String[] EXTENDED_DS_PROPERTIES = {SERVER_NAME, PORT_NUMBER,DATABASE_NAME};
 	
-	private String rarName;
-	
 	public XaJdbcConnectorTemplateInfo(String name, String description, Map<String, ManagedProperty> properties) {
 		super(name, description, properties);
 	}
@@ -65,7 +62,6 @@
 	@Override
 	public XaJdbcConnectorTemplateInfo copy() {
 		XaJdbcConnectorTemplateInfo copy = new XaJdbcConnectorTemplateInfo(getName(), getDescription(), getProperties());
-		copy.setRarName(getRarName());
 		super.copy(copy);
 		copy.populate();
 		return copy;
@@ -73,10 +69,6 @@
 	
 	private void populate() {
 		super.start();
-		List<ManagedProperty> props = RaXmlPropertyConverter.getAsManagedProperties(getRarName());
-		for (ManagedProperty p:props) {
-			addProperty(p);
-		}
 
 		ManagedProperty mp = this.getProperties().get("connection-definition");//$NON-NLS-1$	
 		mp.setValue(ManagedUtil.wrap(SimpleMetaType.STRING, "javax.sql.DataSource"));//$NON-NLS-1$	
@@ -84,7 +76,6 @@
 		mp = this.getProperties().get("dsType");//$NON-NLS-1$	
 		mp.setValue(ManagedUtil.wrap(SimpleMetaType.STRING, "xa-datasource"));//$NON-NLS-1$	
 		
-		
 		ManagedPropertyImpl dsTypeMP = buildConfigProperty();
 		addProperty(dsTypeMP);
 		
@@ -107,22 +98,12 @@
 	}
 	
 	
-	public String getRarName() {
-		return rarName;
-	}
-
-	public void setRarName(String rarName) {
-		this.rarName = rarName;
-	}
-
 	@Override
+	/**
+	 * This is for updating a single property.
+	 */
 	public void updateProperty(String name, String value, ManagedComponent main) {
-		List<String> connectorNames = RaXmlPropertyConverter.getPropertyNames(getRarName());
-		if (connectorNames.contains(name)) {
-			ConnectorTemplateInfo.updateManagedConnectionFactory(name, value, main);
-			//ConnectorTemplateInfo.updateConnectionFactory(name, value, cf);			
-		}
-		else if (name.equals(DATABASE_NAME)||name.equals(PORT_NUMBER)||name.equals(SERVER_NAME)||name.equals(ADDITIONAL_DS_PROPS)) {
+		if (name.equals(DATABASE_NAME)||name.equals(PORT_NUMBER)||name.equals(SERVER_NAME)||name.equals(ADDITIONAL_DS_PROPS)) {
 			Map<String, String> map = new HashMap<String, String>();
 			
 			if (name.equals(ADDITIONAL_DS_PROPS)) {

Modified: trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties	2010-05-25 14:46:43 UTC (rev 2152)
+++ trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties	2010-05-25 16:27:10 UTC (rev 2153)
@@ -43,4 +43,6 @@
 failed_to_convert=Failed to convert from String value to {0} type
 property_required_not_found="{0}" is required for the connector type "{1}", but was not supplied; There is no default value either.
 invalid_class={0} invalid type of class specified. Must be of type org.teiid.connector.api.ConnectorEnvironment
-class_not_found=Class {0} not found.
\ No newline at end of file
+class_not_found=Class {0} not found.
+datasource_exists=Data source with name {0} already exists!
+datasource_template_not_found=Template {0} for creating the data source is not found.
\ No newline at end of file

Modified: trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
===================================================================
--- trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java	2010-05-25 14:46:43 UTC (rev 2152)
+++ trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java	2010-05-25 16:27:10 UTC (rev 2153)
@@ -266,7 +266,7 @@
 	
 	@Test
 	public void testTranslatorTemplateProperties() throws Exception {
-		Collection<PropertyDefinition> defs = admin.getTranslatorTemplatePropertyDefinitions("translator-jdbc"+VERSION); //$NON-NLS-1$
+		Collection<PropertyDefinition> defs = admin.getTemplatePropertyDefinitions("translator-jdbc"+VERSION); //$NON-NLS-1$
 		for (PropertyDefinition pd:defs) {
 			System.out.println(pd.getName()+":"+pd.getPropertyTypeClassName()+":"+pd.getDefaultValue());
 			if (pd.getName().equals("ExtensionTranslationClassName")) { //$NON-NLS-1$
@@ -378,7 +378,7 @@
 		
 		// test blank add
 		try {
-			admin.addTranslator("foo", "translator-jdbc"+VERSION, props);
+			admin.createTranslator("foo", "translator-jdbc"+VERSION, props);
 			fail("must have failed because no exeuction factory set");
 		}catch(AdminException e) {
 			
@@ -386,7 +386,7 @@
 		
 		// test minimal correct add
 		props.setProperty("execution-factory-class", "org.teiid.translator.jdbc.JDBCExecutionFactory");
-		admin.addTranslator("foo", "translator-jdbc"+VERSION, props);
+		admin.createTranslator("foo", "translator-jdbc"+VERSION, props);
 		
 		// test set property
 		admin.setTranslatorProperty("foo", "TrimStrings", "true");
@@ -404,4 +404,32 @@
 		
 	}
 	
+	@Test
+	public void testCreateDataSource() throws Exception {
+		
+		Properties p = new Properties();
+		p.setProperty("DatabaseName", "txntest");
+		p.setProperty("PortNumber", "3306");
+		p.setProperty("ServerName", "localhost");
+		p.setProperty("addtional-ds-properties", "foo=bar, t= x");
+		p.setProperty("user-name", "rareddy");
+		p.setProperty("password", "mm");
+		p.setProperty("xa-datasource-class", "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
+		
+		admin.createDataSource("test-mysql","connector-jdbc-xa", p);	 //$NON-NLS-1$ //$NON-NLS-2$
+	}
+	
+	@Test
+	public void testCreateDriverSource() throws Exception {
+		
+		Properties p = new Properties();
+		p.setProperty("connection-url", "jdbc:mysql://localhost:3306/txntest");
+		p.setProperty("addtional-connection-properties", "foo=bar, t= x");
+		p.setProperty("user-name", "rareddy");
+		p.setProperty("password", "mm");
+		p.setProperty("driver-class", "com.mysql.jdbc.Driver");
+		
+		admin.createDataSource("test-mysql-driver","connector-jdbc", p);	 //$NON-NLS-1$ //$NON-NLS-2$
+	}
+	
 }



More information about the teiid-commits mailing list