[teiid-commits] teiid SVN: r1722 - in branches/JCA: jboss-integration/src/main/java/org/teiid/adminapi/jboss and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Jan 8 14:50:03 EST 2010


Author: rareddy
Date: 2010-01-08 14:50:03 -0500 (Fri, 08 Jan 2010)
New Revision: 1722

Modified:
   branches/JCA/client/src/main/java/org/teiid/adminapi/Admin.java
   branches/JCA/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
   branches/JCA/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
Log:
TEIID-833, TEIID-910: Adding admin methods to manage XA data sources in container

Modified: branches/JCA/client/src/main/java/org/teiid/adminapi/Admin.java
===================================================================
--- branches/JCA/client/src/main/java/org/teiid/adminapi/Admin.java	2010-01-08 16:42:28 UTC (rev 1721)
+++ branches/JCA/client/src/main/java/org/teiid/adminapi/Admin.java	2010-01-08 19:50:03 UTC (rev 1722)
@@ -388,4 +388,26 @@
      */
     @RolesAllowed(value=AdminRoles.RoleName.ADMIN_PRODUCT)
     void restart() throws AdminException;      
+    
+    /**
+     * Adds JDBC XA Data Source in the container.
+     * @param dsName - name of the source
+     * @param properties - properties
+     * @throws AdminException
+     */
+    void addDataSource(String deploymentName, Properties properties) throws AdminException;
+    
+    /**
+     * Delete data source. 
+     * @param dsName
+     * @throws AdminException
+     */
+    void deleteDataSource(String deploymentName) throws AdminException;
+    
+    /**
+     * Get the property definitions for creating the JDBC data source.
+     * @return
+     * @throws AdminException
+     */
+    Collection<PropertyDefinition> getDataSourcePropertyDefinitions() throws AdminException;
 }

Modified: branches/JCA/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
===================================================================
--- branches/JCA/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java	2010-01-08 16:42:28 UTC (rev 1721)
+++ branches/JCA/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java	2010-01-08 19:50:03 UTC (rev 1722)
@@ -83,12 +83,14 @@
 public class Admin extends BaseAdmin implements TeiidAdminMBean{
 	protected Logger log = Logger.getLogger(getClass());
 	private static final String TEIID_RUNTIME_ENGINE = "teiid/runtime-engine";
+	private static final String XA_DATA_SOURCE_TEMPLATE = "XADataSourceTemplate";
 	private static final long serialVersionUID = 7081309086056911304L;
 	private static ComponentType VDBTYPE = new ComponentType("teiid", "vdb");
 	private static ComponentType MODELTYPE = new ComponentType("teiid", "model");
 	private static ComponentType NOTXTYPE = new ComponentType("ConnectionFactory", "NoTx");
 	private static ComponentType TXTYPE = new ComponentType("ConnectionFactory", "Tx");
 	private static ComponentType DQPTYPE = new ComponentType("teiid", "dqp");
+	private static ComponentType DSTYPE = new ComponentType("DataSource", "XA");
 	
 	private ManagementView getView() throws AdminComponentException {
 		try {
@@ -133,14 +135,15 @@
 			if (deployedName.startsWith("java:")) {
 				deployedName = deployedName.substring(5);
 			}
-			ManagedComponent mc = getView().getComponent(deployedName, NOTXTYPE);
+			ManagementView view = getView();
+			ManagedComponent mc = view.getComponent(deployedName, NOTXTYPE);
 			if (mc != null) {
 				if (isConnectorBinding(mc)) {
 					return mc;	
 				}
 			}
 	
-			mc = getView().getComponent(deployedName, TXTYPE);
+			mc = view.getComponent(deployedName, TXTYPE);
 			if (mc != null) {
 				if (isConnectorBinding(mc)) {
 					return mc;	
@@ -207,54 +210,12 @@
 	}
 	
 	@Override
-	public void addConnectorBinding(String deploymentName, String typeName, Properties properties) throws AdminException{
-		try {
-			if (getConnectorBinding(deploymentName) != null) {
-				throw new AdminProcessingException("Connector binding with name "+deploymentName+" already exists.");
-			}
-			
-			DeploymentTemplateInfo info = getView().getTemplate(typeName);
-			if(info == null) {
-				throw new AdminProcessingException("Connector Type template supplied not found in the configuration."+typeName);
-			}
-
-			// override these properties always. 
-			info.getProperties().get("connection-definition").setValue(SimpleValueSupport.wrap("org.teiid.connector.api.Connector"));
-
-			//config-properties list
-			Map<String, String> configProps = new HashMap<String, String>();
-			
-			// template properties specific to the template
-			Map<String, ManagedProperty> propertyMap = info.getProperties();
-			
-			// walk through the supplied properties and assign properly to either template
-			// of config-properties.
-			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));
-					}
-				}
-				else {
-					configProps.put(key, properties.getProperty(key));
-					configProps.put(key+".type", "java.lang.String");
-				}
-			}
-			
-			if (configProps.size() > 0) {
-				MetaValue metaValue = ManagedUtil.compositeValueMap(configProps);
-				info.getProperties().get("config-property").setValue(metaValue);				
-			}
-			
-			getView().applyTemplate(deploymentName, info);
-
-		} catch (NoSuchDeploymentException e) {
-			throw new AdminComponentException(e.getMessage(), e);
-		} catch(Exception e) {
-			throw new AdminComponentException(e.getMessage(), e);
+	public void addConnectorBinding(String deploymentName, String typeName, Properties properties) throws AdminException {
+		if (getConnectorBinding(deploymentName) != null) {
+			throw new AdminProcessingException("Connector binding with name "+deploymentName+" already exists.");
 		}
+		properties.setProperty("connection-definition", "org.teiid.connector.api.Connector");
+		addConnectionfactory(deploymentName, typeName, properties);
 	}
 	
 	@Override
@@ -687,4 +648,70 @@
 			throw new AdminComponentException(e.getMessage(), e);
 		}
 	}	
+	
+	@Override
+    public void addDataSource(String deploymentName, Properties properties) throws AdminException {
+		addConnectionfactory(deploymentName, XA_DATA_SOURCE_TEMPLATE, properties);
+	}
+	
+    private void addConnectionfactory(String deploymentName, String typeName, Properties properties) throws AdminException {	
+		try {
+			DeploymentTemplateInfo info = getView().getTemplate(typeName);
+			if(info == null) {
+				throw new AdminProcessingException("Connector Type template supplied not found in the configuration."+typeName);
+			}
+		
+			//config-properties list
+			Map<String, String> configProps = new HashMap<String, String>();
+			
+			// template properties specific to the template
+			Map<String, ManagedProperty> propertyMap = info.getProperties();
+			
+			// walk through the supplied properties and assign properly to either template
+			// of config-properties.
+			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));
+					}
+				}
+				else {
+					configProps.put(key, properties.getProperty(key));
+					configProps.put(key+".type", "java.lang.String");
+				}
+			}
+			
+			if (configProps.size() > 0) {
+				MetaValue metaValue = ManagedUtil.compositeValueMap(configProps);
+				info.getProperties().get("config-property").setValue(metaValue);				
+			}
+			
+			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 {
+			ManagementView view = getView();
+			ManagedComponent mc = view.getComponent(deployedName, DSTYPE);
+			if (mc != null) {
+				ManagedUtil.removeArchive(getDeploymentManager(),mc.getDeployment().getName());
+			}
+		} catch (Exception e) {
+			throw new AdminComponentException(e.getMessage(), e);
+		}
+    }
+    
+	@Override
+    public Collection<PropertyDefinition> getDataSourcePropertyDefinitions() throws AdminException {
+		return getConnectorTypePropertyDefinitions(XA_DATA_SOURCE_TEMPLATE);
+	}
 }

Modified: branches/JCA/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
===================================================================
--- branches/JCA/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java	2010-01-08 16:42:28 UTC (rev 1721)
+++ branches/JCA/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java	2010-01-08 19:50:03 UTC (rev 1722)
@@ -57,7 +57,7 @@
 		p.setProperty("CapabilitiesClass", "org.teiid.connector.jdbc.derby.DerbyCapabilities");
 		p.setProperty("XaCapable", "true");
 		p.setProperty("SourceJNDIName", "java:DerbyDS");
-		admin.addConnectorBinding("test-mysql-cb","connector-jdbc-template", p);	
+		admin.addConnectorBinding("test-mysql-cb","connector-jdbc-7.0.0-SNAPSHOT", p);	
 		
 		binding = admin.getConnectorBinding("test-mysql-cb");
 		
@@ -241,5 +241,11 @@
 	public void testConnectorTypes() throws Exception {
 		Set<String> defs = admin.getConnectorTypes();
 		System.out.println(defs);
-	}	
+	}
+	
+	@Test
+	public void testPropertyDefsForDS() throws Exception {
+		Collection<PropertyDefinition> defs = admin.getDataSourcePropertyDefinitions();		
+		System.out.println(defs);
+	}
 }



More information about the teiid-commits mailing list