当前位置: 首页>>代码示例>>Java>>正文


Java XADataSource类代码示例

本文整理汇总了Java中javax.sql.XADataSource的典型用法代码示例。如果您正苦于以下问题:Java XADataSource类的具体用法?Java XADataSource怎么用?Java XADataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XADataSource类属于javax.sql包,在下文中一共展示了XADataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMatchOutcome

import javax.sql.XADataSource; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage
			.forCondition("DataSourceAvailable");
	if (hasBean(context, DataSource.class)
			|| hasBean(context, XADataSource.class)) {
		return ConditionOutcome
				.match(message.foundExactly("existing data source bean"));
	}
	if (anyMatches(context, metadata, this.pooledCondition,
			this.embeddedCondition)) {
		return ConditionOutcome.match(message
				.foundExactly("existing auto-configured data source bean"));
	}
	return ConditionOutcome
			.noMatch(message.didNotFind("any existing data source bean").atAll());
}
 
开发者ID:muxiangqiu,项目名称:spring-boot-multidatasource,代码行数:19,代码来源:DataSourceAutoConfiguration.java

示例2: GemFireTransactionDataSource

import javax.sql.XADataSource; //导入依赖的package包/类
/**
 * Creates a new instance of GemFireTransactionDataSource
 * 
 * @param xaDS The XADataSource object for the database driver.
 * @param configs - The ConfiguredDataSourceProperties containing the datasource properties.
 * @throws SQLException
 */
public GemFireTransactionDataSource(XADataSource xaDS, ConfiguredDataSourceProperties configs)
    throws SQLException {
  super(configs);
  if ((xaDS == null) || (configs == null)) {
    throw new SQLException(
        LocalizedStrings.GemFireTransactionDataSource_GEMFIRETRANSACTIONDATASOURCEXADATASOURCE_CLASS_OBJECT_IS_NULL_OR_CONFIGUREDDATASOURCEPROPERTIES_OBJECT_IS_NULL
            .toLocalizedString());
  }
  try {
    provider = new GemFireConnectionPoolManager(xaDS, configs, this);
    transManager = JNDIInvoker.getTransactionManager();
  } catch (Exception ex) {
    String exception = "GemFireTransactionDataSource::Exception = " + ex;
    if (logger.isDebugEnabled()) {
      logger.debug(exception, ex);
    }
    throw new SQLException(exception);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:27,代码来源:GemFireTransactionDataSource.java

示例3: getDataSource

import javax.sql.XADataSource; //导入依赖的package包/类
@Bean(name = "mybatisDataSource")
public DataSource getDataSource(@Autowired XADataSource xaDataSource, @Autowired TransactionManager transactionManager) {
	BasicManagedDataSource bds = new BasicManagedDataSource();
	bds.setXaDataSourceInstance(xaDataSource);
	bds.setTransactionManager(transactionManager);

	bds.setMaxTotal(50);
	bds.setInitialSize(20);
	bds.setMaxWaitMillis(60000);
	bds.setMinIdle(6);
	bds.setLogAbandoned(true);
	bds.setRemoveAbandonedOnBorrow(true);
	bds.setRemoveAbandonedOnMaintenance(true);
	bds.setRemoveAbandonedTimeout(1800);
	bds.setTestWhileIdle(true);
	bds.setTestOnBorrow(false);
	bds.setTestOnReturn(false);
	bds.setValidationQuery("select 'x' ");
	bds.setValidationQueryTimeout(1);
	bds.setTimeBetweenEvictionRunsMillis(30000);
	bds.setNumTestsPerEvictionRun(20);
	return bds;
}
 
开发者ID:liuyangming,项目名称:ByteJTA-sample,代码行数:24,代码来源:ConsumerConfig.java

示例4: getDataSource

import javax.sql.XADataSource; //导入依赖的package包/类
@Bean(name = "dataSource")
public DataSource getDataSource(@Autowired XADataSource xaDataSource, @Autowired TransactionManager transactionManager) {
	BasicManagedDataSource bds = new BasicManagedDataSource();
	bds.setXaDataSourceInstance(xaDataSource);
	bds.setTransactionManager(transactionManager);

	bds.setMaxTotal(50);
	bds.setInitialSize(20);
	bds.setMaxWaitMillis(60000);
	bds.setMinIdle(6);
	bds.setLogAbandoned(true);
	bds.setRemoveAbandonedOnBorrow(true);
	bds.setRemoveAbandonedOnMaintenance(true);
	bds.setRemoveAbandonedTimeout(1800);
	bds.setTestWhileIdle(true);
	bds.setTestOnBorrow(false);
	bds.setTestOnReturn(false);
	bds.setValidationQuery("select 'x' ");
	bds.setValidationQueryTimeout(1);
	bds.setTimeBetweenEvictionRunsMillis(30000);
	bds.setNumTestsPerEvictionRun(20);
	return bds;
}
 
开发者ID:liuyangming,项目名称:ByteJTA-sample,代码行数:24,代码来源:ProviderConfig.java

示例5: getXADataSource

import javax.sql.XADataSource; //导入依赖的package包/类
/**
 * Returns a MySQL XA data source. Note that this method may fail at
 * run-time if {@code MysqlXADataSource} is not available on the classpath.
 *
 * @throws IllegalStateException If the data source cannot be created.
 *
 * @see org.alfasoftware.morf.jdbc.DatabaseType#getXADataSource(java.lang.String,
 *      java.lang.String, java.lang.String)
 */
@Override
public XADataSource getXADataSource(String jdbcUrl, String username, String password) {
  try {
    log.info("Initialising MySQL XA data source...");
    XADataSource dataSource = (XADataSource) Class.forName("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource").newInstance();
    dataSource.getClass().getMethod("setURL", String.class).invoke(dataSource, jdbcUrl);
    dataSource.getClass().getMethod("setUser", String.class).invoke(dataSource, username);
    dataSource.getClass().getMethod("setPassword", String.class).invoke(dataSource, password);
    //see http://www.atomikos.com/Documentation/KnownProblems#MySQL_XA_bug
    //did not have to set com.atomikos.icatch.serial_jta_transactions=false
    dataSource.getClass().getMethod("setPinGlobalTxToPhysicalConnection", boolean.class).invoke(dataSource, true);
    return dataSource;
  } catch (Exception e) {
    throw new IllegalStateException("Failed to create Oracle XA data source", e);
  }
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:26,代码来源:MySql.java

示例6: createXADataSource

import javax.sql.XADataSource; //导入依赖的package包/类
/**
 * Creates a pooled XA data source.
 *
 * @param properties the properties for the data source.
 * @throws SQLException if unsupported properties are supplied, or if data
 *             source can not be created.
 * @return a new data source.
 */
@Override
public XADataSource createXADataSource(Properties properties)
        throws SQLException {
    // Make copy of properties
    Properties propertiesCopy = new Properties();
    if (properties != null) {
        propertiesCopy.putAll(properties);
    }

    // Verify that no unsupported standard options are used
    rejectUnsupportedOptions(propertiesCopy);

    // The integrated connection pool is H2 is not configurable
    rejectPoolingOptions(propertiesCopy);

    JdbcDataSource dataSource = new JdbcDataSource();

    setupH2DataSource(dataSource, propertiesCopy);

    return dataSource;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:30,代码来源:OsgiDataSourceFactory.java

示例7: shouldGetConnectionAndCommit

import javax.sql.XADataSource; //导入依赖的package包/类
@Test
public void shouldGetConnectionAndCommit() throws SQLException {
	Connection mockConnection = mock(Connection.class);
	XAConnection mockXaConnection = mock(XAConnection.class);
	given(mockXaConnection.getConnection()).willReturn(mockConnection);
	given(this.dataSource.getXAConnection()).willReturn(mockXaConnection);

	Properties properties = new Properties();
	properties.put(TransactionalDriver.XADataSource, this.dataSource);

	Connection connection = this.dataSourceBean.getConnection();
	assertThat(connection).isInstanceOf(ConnectionImple.class);

	connection.commit();

	verify(this.dataSource, times(1)).getXAConnection();
	verify(mockXaConnection, times(1)).getConnection();
	verify(mockConnection, times(1)).commit();
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:20,代码来源:NarayanaDataSourceBeanTests.java

示例8: openConnection

import javax.sql.XADataSource; //导入依赖的package包/类
public Connection openConnection(String databaseName) throws SQLException {
    JDBCDataSource.setBeanProperty(ds, "databaseName", databaseName);
    try {
        return ds.getXAConnection().getConnection();
    } catch (SQLException e) {
        // Expected state for database not found.
        // For the client the generic 08004 is returned,
        // will just retry on that.
        String expectedState = 
            config.getJDBCClient().isEmbedded() ? "XJ004" : "08004";

        // If there is a database not found exception
        // then retry the connection request with
        // a new DataSource with the createDtabase property set.
        if (!expectedState.equals(e.getSQLState()))
            throw e;
        XADataSource tmpDs = singleUseDS("createDatabase", "create");
        JDBCDataSource.setBeanProperty(tmpDs, "databaseName", databaseName);
        return tmpDs.getXAConnection().getConnection();
   }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:22,代码来源:XADataSourceConnector.java

示例9: assertConSetOK

import javax.sql.XADataSource; //导入依赖的package包/类
protected void assertConSetOK(Object ds, String expectedSQLState, 
    String dbName, String connAttrValue, String setter, String setValue) 
throws SQLException {
    JDBCDataSource.setBeanProperty(ds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(ds, setter, setValue);
    JDBCDataSource.setBeanProperty(
        ds, "ConnectionAttributes", connAttrValue);
    // check that the db exists; execute an unnecessary, but harmless, stmt
    try {
        if (ds instanceof javax.sql.ConnectionPoolDataSource)
            ((ConnectionPoolDataSource)ds).getPooledConnection();
        else
            ((XADataSource)ds).getXAConnection();
        fail("expected an sqlexception " + expectedSQLState);
    } catch (SQLException se) {
        assertSQLState(expectedSQLState, se);
    }
    JDBCDataSource.clearStringBeanProperty(ds, setter);
    JDBCDataSource.clearStringBeanProperty(ds, "ConnectionAttributes");
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:21,代码来源:PoolXADSCreateShutdownDBTest.java

示例10: assertConnectionWOUPFail

import javax.sql.XADataSource; //导入依赖的package包/类
protected void assertConnectionWOUPFail(
    String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
    XADataSource xads = J2EEDataSource.getXADataSource();
    JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(xads, "user", user);
    JDBCDataSource.setBeanProperty(xads, "password", password);
    try {
        xads.getXAConnection();
        fail("Connection should've been refused/failed");
    }
    catch (SQLException e) {
        assertSQLState(expectedSqlState, e);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:17,代码来源:XADSAuthenticationTest.java

示例11: assertShutdownWOUPOK

import javax.sql.XADataSource; //导入依赖的package包/类
protected void assertShutdownWOUPOK(
    String dbName, String user, String password)
throws SQLException {
    XADataSource xads = J2EEDataSource.getXADataSource();
    JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(
            xads, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(xads, "user", user);
    JDBCDataSource.setBeanProperty(xads, "password", password);
    try {
        xads.getXAConnection();
        fail ("expected a failed shutdown connection");
    } catch (SQLException e) {
        // expect 08006 on successful shutdown
        assertSQLState("08006", e);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:18,代码来源:XADSAuthenticationTest.java

示例12: assertShutdownWOUPFail

import javax.sql.XADataSource; //导入依赖的package包/类
protected void assertShutdownWOUPFail(
    String expectedSqlState, String dbName, String user, String password) 
throws SQLException
{
    XADataSource xads = J2EEDataSource.getXADataSource();
    JDBCDataSource.setBeanProperty(xads, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(xads, "user", user);
    JDBCDataSource.setBeanProperty(xads, "password", password);
    try {
        xads.getXAConnection();
        fail("expected failed shutdown");
    } catch (SQLException e) {
        assertSQLState(expectedSqlState, e);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:17,代码来源:XADSAuthenticationTest.java

示例13: assertSystemShutdownOK

import javax.sql.XADataSource; //导入依赖的package包/类
protected void assertSystemShutdownOK(
    String dbName, String user, String password)
throws SQLException {
    XADataSource xads = J2EEDataSource.getXADataSource();
    JDBCDataSource.setBeanProperty(
            xads, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(xads, "user", user);
    JDBCDataSource.setBeanProperty(xads, "password", password);
    try {
        xads.getXAConnection();
        fail("expected system shutdown resulting in XJ015 error");
    } catch (SQLException e) {
        // expect XJ015, system shutdown, on successful shutdown
        assertSQLState("XJ015", e);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:18,代码来源:XADSAuthenticationTest.java

示例14: assertSystemShutdownFail

import javax.sql.XADataSource; //导入依赖的package包/类
protected void assertSystemShutdownFail(
    String expectedError, String dbName, String user, String password)
throws SQLException {
    XADataSource xads = J2EEDataSource.getXADataSource();
    JDBCDataSource.setBeanProperty(
            xads, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(xads, "user", user);
    JDBCDataSource.setBeanProperty(xads, "password", password);
    try {
        xads.getXAConnection();
        fail("expected shutdown to fail");
    } catch (SQLException e) {
        assertSQLState(expectedError, e);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:17,代码来源:XADSAuthenticationTest.java

示例15: assertConnectionFail

import javax.sql.XADataSource; //导入依赖的package包/类
public void assertConnectionFail(String dbName) throws SQLException {
    XADataSource xads = J2EEDataSource.getXADataSource();
    // Reset to no user/password though client requires
    // a valid name, so reset to the default
    if (usingDerbyNetClient())
        JDBCDataSource.setBeanProperty(xads, "user", "APP");
    else
        JDBCDataSource.clearStringBeanProperty(xads, "user");
    JDBCDataSource.clearStringBeanProperty(xads, "password");
    JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
    try {
        xads.getXAConnection();
        fail("expected connection to fail");
    } catch (SQLException e) {
        assertSQLState("08004", e);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:18,代码来源:XADSAuthenticationTest.java


注:本文中的javax.sql.XADataSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。