Search in sources :

Example 1 with DataSourceProvider

use of org.exoplatform.services.jdbc.DataSourceProvider in project kernel by exoplatform.

the class TestDataSourceProviderImpl method testIsManaged.

public void testIsManaged() throws Exception {
    DataSourceProvider dsp = new DataSourceProviderImpl(null);
    assertFalse(dsp.isManaged(DS_NAME));
    InitParams params = new InitParams();
    dsp = new DataSourceProviderImpl(params);
    assertFalse(dsp.isManaged(DS_NAME));
    ValueParam paramConf = new ValueParam();
    paramConf.setName(DataSourceProviderImpl.PARAM_ALWAYS_MANAGED);
    paramConf.setValue("true");
    params.addParameter(paramConf);
    dsp = new DataSourceProviderImpl(params);
    assertTrue(dsp.isManaged(DS_NAME));
    paramConf.setValue("false");
    dsp = new DataSourceProviderImpl(params);
    assertFalse(dsp.isManaged(DS_NAME));
    ValuesParam paramsConf = new ValuesParam();
    paramsConf.setName(DataSourceProviderImpl.PARAM_MANAGED_DS);
    ArrayList<String> values = new ArrayList<String>();
    values.add(DS_NAME);
    values.add(" ds-foo1, ds-foo2 ");
    values.add("ds-foo3");
    paramsConf.setValues(values);
    params.addParameter(paramsConf);
    dsp = new DataSourceProviderImpl(params);
    assertTrue(dsp.isManaged(DS_NAME));
    assertTrue(dsp.isManaged("ds-foo1"));
    assertTrue(dsp.isManaged("ds-foo2"));
    assertTrue(dsp.isManaged("ds-foo3"));
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ValuesParam(org.exoplatform.container.xml.ValuesParam) DataSourceProvider(org.exoplatform.services.jdbc.DataSourceProvider) ArrayList(java.util.ArrayList) ValueParam(org.exoplatform.container.xml.ValueParam)

Example 2 with DataSourceProvider

use of org.exoplatform.services.jdbc.DataSourceProvider in project kernel by exoplatform.

the class TestDataSourceProviderImpl method testGetDataSource.

public void testGetDataSource() throws Exception {
    DataSourceProvider dsp = new DataSourceProviderImpl(null);
    DataSource ds = dsp.getDataSource(DS_NAME);
    assertNotNull(ds);
    Connection con = ds.getConnection();
    con.commit();
    assertTrue(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertTrue(mds.con.committed);
    MyTransactionService mts = new MyTransactionService();
    mts.tm.setStatus(Status.STATUS_ACTIVE);
    dsp = new DataSourceProviderImpl(null, mts);
    ds = dsp.getDataSource(DS_NAME);
    assertNotNull(ds);
    con = ds.getConnection();
    con.commit();
    assertTrue(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertTrue(mds.con.committed);
    mts.tm.setStatus(Status.STATUS_NO_TRANSACTION);
    con = ds.getConnection();
    con.commit();
    assertTrue(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertTrue(mds.con.committed);
    InitParams params = new InitParams();
    ValueParam paramConf = new ValueParam();
    paramConf.setName(DataSourceProviderImpl.PARAM_ALWAYS_MANAGED);
    paramConf.setValue("true");
    params.addParameter(paramConf);
    dsp = new DataSourceProviderImpl(params, mts);
    ds = dsp.getDataSource(DS_NAME);
    assertNotNull(ds);
    mts.tm.setStatus(Status.STATUS_ACTIVE);
    con = ds.getConnection();
    con.commit();
    assertFalse(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertFalse(mds.con.committed);
    mts.tm.setStatus(Status.STATUS_NO_TRANSACTION);
    con = ds.getConnection();
    con.commit();
    assertTrue(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertTrue(mds.con.committed);
    paramConf = new ValueParam();
    paramConf.setName(DataSourceProviderImpl.PARAM_CHECK_TX);
    paramConf.setValue("false");
    params.addParameter(paramConf);
    dsp = new DataSourceProviderImpl(params, mts);
    ds = dsp.getDataSource(DS_NAME);
    assertNotNull(ds);
    mts.tm.setStatus(Status.STATUS_ACTIVE);
    con = ds.getConnection();
    con.commit();
    assertFalse(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertFalse(mds.con.committed);
    mts.tm.setStatus(Status.STATUS_NO_TRANSACTION);
    con = ds.getConnection();
    con.commit();
    assertFalse(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertFalse(mds.con.committed);
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) DataSourceProvider(org.exoplatform.services.jdbc.DataSourceProvider) Connection(java.sql.Connection) ValueParam(org.exoplatform.container.xml.ValueParam) DataSource(javax.sql.DataSource)

Aggregations

InitParams (org.exoplatform.container.xml.InitParams)2 ValueParam (org.exoplatform.container.xml.ValueParam)2 DataSourceProvider (org.exoplatform.services.jdbc.DataSourceProvider)2 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1 ValuesParam (org.exoplatform.container.xml.ValuesParam)1