/** * Create valid transaction support value based on input values. * * @param transactionSupport Configured transaction support. * @param connectionType Valid connection type. * @return Valid transaction support. */ private TransactionSupport createTransactionSupport(TransactionSupport transactionSupport, String connectionType) { if (TransactionSupport.XA_TRANSACTION.equals(transactionSupport) || ConfigurationEntryType.XA_DATASOURCE.equals(connectionType)) { return TransactionSupport.XA_TRANSACTION; } else if (TransactionSupport.LOCAL_TRANSACTION.equals(transactionSupport)) { return TransactionSupport.LOCAL_TRANSACTION; } else { return TransactionSupport.NO_TRANSACTION; } }
/** * Create the datasource object. * @return Cargo datasource object. */ public DataSource createDataSource() { TransactionSupport tSupport = TransactionSupport.valueOf(transactionSupport); DataSource dataSource = new DataSource(jndiName, connectionType, tSupport, driverClass, url, username, password, id, connectionProperties); return dataSource; } }
@Override protected void addConfigurationScriptProperties(Map<String, String> propertiesMap) { Map<String, String> datasourceProperties = new HashMap<String, String>(); datasourceProperties.put("name", ds.getId()); datasourceProperties.put("jndi-name", getDataSourceJndi(ds)); datasourceProperties.put("driver-name", ds.getDriverClass()); datasourceProperties.put("connection-url", ds.getUrl()); datasourceProperties.put("user-name", ds.getUsername()); datasourceProperties.put("password", ds.getPassword()); if (TransactionSupport.NO_TRANSACTION.equals(ds.getTransactionSupport())) { datasourceProperties.put("jta", "false"); } else { datasourceProperties.put("jta", "true"); } String dsProps = mapResourceProperties(datasourceProperties); propertiesMap.put("cargo.datasource.properties", dsProps); } }
/** * Convert string representation of transaction support to appropriate value. * * @param transactionSupport String representation of transaction support. * @return Appropriate TransactionSupport instance. */ public static TransactionSupport valueOf(String transactionSupport) { if (TransactionSupport.XA_TRANSACTION.toString().equals(transactionSupport)) { return TransactionSupport.XA_TRANSACTION; } else if (TransactionSupport.LOCAL_TRANSACTION.toString().equals(transactionSupport)) { return TransactionSupport.LOCAL_TRANSACTION; } else { return TransactionSupport.NO_TRANSACTION; } }
/** * Create the datasource object. * @return Cargo datasource object. */ public DataSource createDataSource() { TransactionSupport tSupport = TransactionSupport.valueOf(transactionSupport); DataSource dataSource = new DataSource(jndiName, connectionType, tSupport, driverClass, url, username, password, id, connectionProperties); return dataSource; } }
@Override protected void addConfigurationScriptProperties(Map<String, String> propertiesMap) { Map<String, String> datasourceProperties = new HashMap<String, String>(); datasourceProperties.put("name", ds.getId()); datasourceProperties.put("jndi-name", getDataSourceJndi(ds)); datasourceProperties.put("driver-name", ds.getDriverClass()); datasourceProperties.put("connection-url", ds.getUrl()); datasourceProperties.put("user-name", ds.getUsername()); datasourceProperties.put("password", ds.getPassword()); if (TransactionSupport.NO_TRANSACTION.equals(ds.getTransactionSupport())) { datasourceProperties.put("jta", "false"); } else { datasourceProperties.put("jta", "true"); } String dsProps = mapResourceProperties(datasourceProperties); propertiesMap.put("cargo.datasource.properties", dsProps); } }
@Override protected void addConfigurationScriptProperties(Map<String, String> propertiesMap) { propertiesMap.put("cargo.datasource.id", ds.getId()); propertiesMap.put("cargo.datasource.driver", ds.getDriverClass()); propertiesMap.put("cargo.datasource.url", ds.getUrl()); propertiesMap.put("cargo.datasource.username", ds.getUsername()); propertiesMap.put("cargo.datasource.password", ds.getPassword()); propertiesMap.put("cargo.datasource.jndi", ds.getJndiLocation()); propertiesMap.put("cargo.datasource.type", ds.getConnectionType()); propertiesMap.put("cargo.datasource.transactionsupport", ds.getTransactionSupport(). toString()); } }
/** * Create the datasource object. * @return Cargo resource object. */ public org.codehaus.cargo.container.configuration.entry.DataSource createDataSource() { TransactionSupport tSupport = TransactionSupport.valueOf(transactionSupport); org.codehaus.cargo.container.configuration.entry.DataSource dataSource = new org.codehaus.cargo.container.configuration.entry.DataSource( jndiName, connectionType, tSupport, driverClass, url, username, password, id, connectionProperties); return dataSource; } }
/** * @param ds DataSource to be configured. * @param driverModule Module containing DataSource driver. * @return Configure DataSource Driver CLI script. */ public ScriptCommand dataSourceDriverScript(DataSource ds, String driverModule) { if (TransactionSupport.XA_TRANSACTION.equals(ds.getTransactionSupport())) { return new XaDriverScriptCommand(configuration, RESOURCE_PATH, ds, driverModule); } else { return new DriverScriptCommand(configuration, RESOURCE_PATH, ds, driverModule); } }
@Override protected void addConfigurationScriptProperties(Map<String, String> propertiesMap) { propertiesMap.put("cargo.datasource.id", ds.getId()); propertiesMap.put("cargo.datasource.driver", ds.getDriverClass()); propertiesMap.put("cargo.datasource.url", ds.getUrl()); propertiesMap.put("cargo.datasource.username", ds.getUsername()); propertiesMap.put("cargo.datasource.password", ds.getPassword()); propertiesMap.put("cargo.datasource.jndi", ds.getJndiLocation()); propertiesMap.put("cargo.datasource.type", ds.getConnectionType()); propertiesMap.put("cargo.datasource.transactionsupport", ds.getTransactionSupport(). toString()); } }
/** * Construct a DataSource from a list of properties. * * @param properties A list of properties representing this datasource * @return DataSource representing the properties * @see PropertyUtils#splitPropertiesOnPipe(String) */ public DataSource fromProperties(Properties properties) { String jndiLocation = properties.getProperty(DatasourcePropertySet.JNDI_LOCATION); String connectionType = properties.getProperty(DatasourcePropertySet.CONNECTION_TYPE); TransactionSupport transactionSupport = TransactionSupport.valueOf( properties.getProperty(DatasourcePropertySet.TRANSACTION_SUPPORT)); String driverClass = properties.getProperty(DatasourcePropertySet.DRIVER_CLASS); String url = properties.getProperty(DatasourcePropertySet.URL); String username = properties.getProperty(DatasourcePropertySet.USERNAME); String password = properties.getProperty(DatasourcePropertySet.PASSWORD); String id = properties.getProperty(DatasourcePropertySet.ID); String driverPropertiesAsASemicolonDelimitedString = properties.getProperty(DatasourcePropertySet.CONNECTION_PROPERTIES); Properties connectionProperties = getDriverPropertiesFromString( driverPropertiesAsASemicolonDelimitedString); DataSource data = new DataSource(jndiLocation, connectionType, transactionSupport, driverClass, url, username, password, id, connectionProperties); return data; }
/** * @param ds DataSource to be configured. * @param driverModule Module containing DataSource driver. * @return Configure DataSource Driver CLI script. */ public ScriptCommand dataSourceDriverScript(DataSource ds, String driverModule) { if (TransactionSupport.XA_TRANSACTION.equals(ds.getTransactionSupport())) { return new XaDriverScriptCommand(configuration, RESOURCE_PATH, ds, driverModule); } else { return new DriverScriptCommand(configuration, RESOURCE_PATH, ds, driverModule); } }
/** * Test that the {@link TransactionSupport#NO_TRANSACTION} mode is * {@link TransactionSupport#NO_TRANSACTION}. */ public void testNoTransactionIsNoTransaction() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.TRANSACTION_SUPPORT, TransactionSupport.NO_TRANSACTION.toString()); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(TransactionSupport.NO_TRANSACTION, ds.getTransactionSupport()); }
/** * Test that the {@link TransactionSupport#LOCAL_TRANSACTION} mode is * {@link TransactionSupport#LOCAL_TRANSACTION}. */ public void testLocalTransactionIsLocalTransaction() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.TRANSACTION_SUPPORT, TransactionSupport.LOCAL_TRANSACTION.toString()); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(TransactionSupport.LOCAL_TRANSACTION, ds.getTransactionSupport()); }
else if (ds.getTransactionSupport().equals(TransactionSupport.XA_TRANSACTION))
/** * Test that the {@link TransactionSupport#XA_TRANSACTION} mode is * {@link TransactionSupport#XA_TRANSACTION}. */ public void testXATransactionIsXATransaction() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.TRANSACTION_SUPPORT, TransactionSupport.XA_TRANSACTION.toString()); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(TransactionSupport.XA_TRANSACTION, ds.getTransactionSupport()); }
else if (ds.getTransactionSupport().equals(TransactionSupport.XA_TRANSACTION))
/** * Test the {@link Properties} constructor. */ public void testPropertiesConstructor() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.ID, "rudolf"); props.setProperty(DatasourcePropertySet.TRANSACTION_SUPPORT, TransactionSupport.NO_TRANSACTION.toString()); props.setProperty(DatasourcePropertySet.JNDI_LOCATION, "jdbc/JiraDS"); props .setProperty(DatasourcePropertySet.CONNECTION_TYPE, ConfigurationEntryType.JDBC_DRIVER); props.setProperty(DatasourcePropertySet.DRIVER_CLASS, "org.hsqldb.jdbcDriver"); props.setProperty(DatasourcePropertySet.URL, "postresql:localhost:jirads"); props.setProperty(DatasourcePropertySet.USERNAME, "sa"); props.setProperty(DatasourcePropertySet.PASSWORD, ""); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(0, ds.getConnectionProperties().size()); assertEquals("", ds.getPassword()); assertEquals(props, dataSourceConverter.toProperties(ds)); }