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


Java DataSourceFactory类代码示例

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


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

示例1: foundDSF

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
public void foundDSF(DataSourceFactory dsf) {
	boolean build = false;
	Map<String,Object> props = null;
	synchronized (this) {
		if(activeConnectionProvider == null) {
			activeConnectionProvider = dsf;
			build = true;
			props = activeProps == null ? new HashMap<String, Object>() :
				new HashMap<String, Object>(activeProps);
		}
	}
	
	if(build) {
		Properties punitProps = persistenceUnit.getProperties();
		for(String key : punitProps.stringPropertyNames()) {
			if(!props.containsKey(key)) {
				props.put(key, punitProps.get(key));
			}
		}
		
		DataSource ds = DSFTracker.createDataSource(dsf, props, persistenceUnit.getName());
		dataSourceReady(ds, props);
	}
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:25,代码来源:AriesEntityManagerFactoryBuilder.java

示例2: lostDSF

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
public void lostDSF(DataSourceFactory dsf, DataSourceFactory replacement) {
	boolean destroy = false;
	synchronized (this) {
		if(activeConnectionProvider == dsf) {
			activeConnectionProvider = null;
			destroy = true;
		}
	}
	
	if(destroy) {
		closeEMF();
	}
	
	if(replacement != null) {
		foundDSF(replacement);
	}
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:18,代码来源:AriesEntityManagerFactoryBuilder.java

示例3: testEntityManagerFactoryBuilderWithIncompletePersistenceUnitAddPlugin

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
  public void testEntityManagerFactoryBuilderWithIncompletePersistenceUnitAddPlugin() throws Exception {
  	EntityManagerFactoryBuilder builder = getService(EntityManagerFactoryBuilder.class, "(osgi.unit.name=incompleteTestUnit2)", 1000);
  	
  	DataSourceFactory dsf = getService(DataSourceFactory.class, 
  			"(" + OSGI_JDBC_DRIVER_CLASS + "=org.apache.derby.jdbc.EmbeddedDriver)");
     
  	Properties jdbcProps = new Properties();
  	jdbcProps.setProperty("url", "jdbc:derby:memory:DSFTEST;create=true");
  	
  	Map<String, Object> props = new HashMap<String, Object>();
  	props.put("javax.persistence.nonJtaDataSource", dsf.createDataSource(jdbcProps));
  	props.put("javax.persistence.transactionType", RESOURCE_LOCAL.name());
  	
  	props.put("org.apache.aries.jpa.eclipselink.plugin.types", SessionCustomizerImpl.class);
  	props.put("eclipselink.session.customizer", SessionCustomizerImpl.class.getName());
  	
  	EntityManagerFactory emf = builder.createEntityManagerFactory(props);
  	emf.createEntityManager();
assertEquals("invoked", emf
  			.getProperties().get(CUSTOMIZER_CALLED));
  	
  }
 
开发者ID:apache,项目名称:aries-jpa,代码行数:24,代码来源:EclipseAdditionalTest.java

示例4: testCarEMFBuilderExternalDS

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testCarEMFBuilderExternalDS() throws Exception {
	DataSourceFactory dsf = getService(DataSourceFactory.class, 
			"(" + OSGI_JDBC_DRIVER_CLASS + "=org.apache.derby.jdbc.EmbeddedDriver)");
   
	EntityManagerFactoryBuilder emfBuilder = getService(EntityManagerFactoryBuilder.class,
			"(osgi.unit.name=" + EXTERNAL_TEST_UNIT + ")");
	
    assertEquals(getProviderClassName(), emfBuilder.getPersistenceProviderName());
	assertEquals(getProviderBundle(), emfBuilder.getPersistenceProviderBundle());
	
	Properties jdbcProps = new Properties();
	jdbcProps.setProperty("url", "jdbc:derby:memory:DSFTEST;create=true");
	
	Map<String, Object> props = new HashMap<String, Object>();
	props.put("javax.persistence.nonJtaDataSource", dsf.createDataSource(jdbcProps));
	props.put("javax.persistence.transactionType", RESOURCE_LOCAL.name());
	
	EntityManagerFactory emf = emfBuilder.createEntityManagerFactory(props);
	carLifecycleRL(emf.createEntityManager());
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:22,代码来源:JPAContainerTest.java

示例5: testTruckEMFBuilderExternalDS

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testTruckEMFBuilderExternalDS() throws Exception {
	DataSourceFactory dsf = getService(DataSourceFactory.class, 
			"(" + OSGI_JDBC_DRIVER_CLASS + "=org.apache.derby.jdbc.EmbeddedDriver)");
	
	EntityManagerFactoryBuilder emfBuilder = getService(EntityManagerFactoryBuilder.class,
			"(osgi.unit.name=" + EXTERNAL_TEST_UNIT + ")");
	 
    assertEquals(getProviderClassName(), emfBuilder.getPersistenceProviderName());
	assertEquals(getProviderBundle(), emfBuilder.getPersistenceProviderBundle());
    
	Properties jdbcProps = new Properties();
	jdbcProps.setProperty("url", "jdbc:derby:memory:DSFTEST;create=true");
	
	Map<String, Object> props = new HashMap<String, Object>();
	props.put("javax.persistence.nonJtaDataSource", dsf.createDataSource(jdbcProps));
	props.put("javax.persistence.transactionType", RESOURCE_LOCAL.name());
	
	EntityManagerFactory emf = emfBuilder.createEntityManagerFactory(props);
	truckLifecycleRL(emf.createEntityManager());
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:22,代码来源:JPAContainerTest.java

示例6: start

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
@Override
public void start ( final BundleContext context ) throws Exception
{
    this.scheduler = Executors.newSingleThreadScheduledExecutor ( new NamedThreadFactory ( context.getBundle ().getSymbolicName () ) );
    final String driver = DataSourceHelper.getDriver ( DS_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    if ( driver == null )
    {
        logger.error ( "JDBC driver is not set" );
        throw new IllegalStateException ( "JDBC driver name is not set" );
    }

    this.dataSourceFactoryTracker = new DataSourceFactoryTracker ( context, driver, new SingleServiceListener<DataSourceFactory> () {

        @Override
        public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service )
        {
            unregister ();
            if ( service != null )
            {
                register ( service, context );
            }
        }
    } );
    this.dataSourceFactoryTracker.open ( true );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:Activator.java

示例7: EventInjector

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
public EventInjector ( final DataSourceFactory factory, final Properties properties, final int delay, final Long loginTimeout ) throws SQLException
{
    logger.info ( "Starting event injector" ); //$NON-NLS-1$
    this.storage = new JdbcStorageDao ( factory, properties, false, loginTimeout, null );

    if ( !System.getProperty ( Activator.SPECIFIC_PREFIX + ".schema", "" ).trim ().isEmpty () )
    {
        this.storage.setSchema ( System.getProperty ( Activator.SPECIFIC_PREFIX + ".schema" ) + "." );
    }

    this.scheduler = new ScheduledExportedExecutorService ( "org.eclipse.scada.ae.slave.inject", 1 ); //$NON-NLS-1$

    this.scheduler.scheduleWithFixedDelay ( new Runnable () {

        @Override
        public void run ()
        {
            process ();
        }
    }, 0, delay, TimeUnit.MILLISECONDS );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:EventInjector.java

示例8: start

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
@Override
public void start ( final BundleContext bundleContext ) throws Exception
{
    Activator.context = bundleContext;

    final String driver = DataSourceHelper.getDriver ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    if ( driver == null )
    {
        logger.error ( "JDBC driver is not set" );
        throw new IllegalStateException ( "JDBC driver name is not set" );
    }

    this.tracker = new DataSourceFactoryTracker ( bundleContext, driver, new SingleServiceListener<DataSourceFactory> () {

        @Override
        public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service )
        {
            setService ( service );
        }
    } );
    this.tracker.open ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:24,代码来源:Activator.java

示例9: setService

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
protected void setService ( final DataSourceFactory service )
{
    if ( this.injector != null )
    {
        this.injector.dispose ();
        this.injector = null;
    }

    if ( service != null )
    {
        try
        {
            final Long loginTimeout = DataSourceHelper.getLoginTimeout ( System.getProperties (), SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );
            this.injector = new EventInjector ( service, DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX ), Integer.getInteger ( SPECIFIC_PREFIX + ".loopDelay", 10 * 1000 ), loginTimeout );
        }
        catch ( final SQLException e )
        {
            logger.warn ( "Failed to start event injector", e ); //$NON-NLS-1$
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:Activator.java

示例10: activate

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
private void activate ( final DataSourceFactory dataSourceFactory ) throws Exception
{
    logger.info ( "Activating: {}", dataSourceFactory );

    final Properties dbProperties = DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    final Long loginTimeout = DataSourceHelper.getLoginTimeout ( System.getProperties (), SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );
    this.jdbcStorage = createJdbcStorage ( dataSourceFactory, dbProperties, DataSourceHelper.isConnectionPool ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX, false ), loginTimeout );
    this.jdbcStorage.start ();

    final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 2 );
    properties.put ( Constants.SERVICE_DESCRIPTION, "JDBC implementation for org.eclipse.scada.ae.server.storage.Storage" );
    properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    properties.put ( "osgi.command.scope", "ae" );
    properties.put ( "osgi.command.function", new String[] { "cleanupArchive", "showQueueSize" } );
    this.jdbcStorageHandle = context.registerService ( new String[] { JdbcStorage.class.getName (), Storage.class.getName () }, this.jdbcStorage, properties );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:18,代码来源:Activator.java

示例11: EventInjector

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
public EventInjector ( final DataSourceFactory dataSourceFactory, final Properties dataSourceProperties, final Integer delay, final boolean usePool, final Long loginTimeout, final String schema, final String replicationSchema, final String instance ) throws SQLException
{
    logger.info ( "Starting event injector" ); //$NON-NLS-1$
    this.schema = schema;
    this.replicationSchema = replicationSchema;
    this.accessor = usePool ? new PoolConnectionAccessor ( dataSourceFactory, dataSourceProperties ) : new DataSourceConnectionAccessor ( dataSourceFactory, dataSourceProperties, loginTimeout );
    this.jdbcDao = new JdbcDao ( this.accessor, schema, instance, new NodeIdProvider () {
        @Override
        public String getNodeId ()
        {
            return EventInjector.this.getNodeId ();
        }
    } );
    this.scheduler = new ScheduledExportedExecutorService ( "org.eclipse.scada.ae.slave.inject.postgres", 1 ); //$NON-NLS-1$

    this.scheduler.scheduleWithFixedDelay ( new Runnable () {

        @Override
        public void run ()
        {
            process ();
        }
    }, 0, delay, TimeUnit.MILLISECONDS );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:EventInjector.java

示例12: setService

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
protected void setService ( final DataSourceFactory service )
{
    if ( this.injector != null )
    {
        this.injector.dispose ();
        this.injector = null;
    }

    if ( service != null )
    {
        try
        {
            final String schema = getSchema ();
            final String replicationSchema = getReplicationSchema ();
            final String instance = getInstance ();
            final Long loginTimeout = DataSourceHelper.getLoginTimeout ( System.getProperties (), SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );
            final boolean usePool = DataSourceHelper.isConnectionPool ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX, false );
            this.injector = new EventInjector ( service, DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX ), Integer.getInteger ( SPECIFIC_PREFIX + ".loopDelay", 10 * 1000 ), usePool, loginTimeout, schema, replicationSchema, instance );
        }
        catch ( final SQLException e )
        {
            logger.warn ( "Failed to start event injector", e ); //$NON-NLS-1$
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:26,代码来源:Activator.java

示例13: activate

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
private void activate ( final DataSourceFactory dataSourceFactory ) throws Exception
{
    logger.debug ( "Activate storage" );
    this.scheduler = ScheduledExportedExecutorService.newSingleThreadExportedScheduledExecutor ( "org.eclipse.scada.ae.server.storage.postgresql/ScheduledExecutor" );

    final Properties dbProperties = DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    final String schema = getSchema ();
    final String instance = getInstance ();
    this.jdbcStorage = new JdbcStorage ( dataSourceFactory, this.scheduler, dbProperties, DataSourceHelper.isConnectionPool ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX, false ), schema, instance );
    this.jdbcStorage.start ();

    final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 2 );
    properties.put ( Constants.SERVICE_DESCRIPTION, "PostgreSQL specific JDBC implementation for org.eclipse.scada.ae.server.storage.Storage" );
    properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    this.jdbcStorageHandle = context.registerService ( new String[] { JdbcStorage.class.getName (), Storage.class.getName () }, this.jdbcStorage, properties );
    logger.debug ( "Storage activated - {}", this.jdbcStorageHandle );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:Activator.java

示例14: registerService

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
/**
 * Register the H2 JDBC driver service.
 *
 * @param bundleContext the bundle context
 * @param driver the driver
 */
static void registerService(BundleContext bundleContext,
        org.h2.Driver driver) {
    Properties properties = new Properties();
    properties.put(
            DataSourceFactory.OSGI_JDBC_DRIVER_CLASS,
            org.h2.Driver.class.getName());
    properties.put(
            DataSourceFactory.OSGI_JDBC_DRIVER_NAME,
            "H2 JDBC Driver");
    properties.put(
            DataSourceFactory.OSGI_JDBC_DRIVER_VERSION,
            Constants.getFullVersion());
    bundleContext.registerService(
            DataSourceFactory.class.getName(),
            new OsgiDataSourceFactory(driver), properties);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:OsgiDataSourceFactory.java

示例15: testMySQL

import org.osgi.service.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testMySQL() throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException {
    String driverClassName = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/wisdom";

    DataSourceFactory factory = helper.getServiceObject(DataSourceFactory.class,
            "(" + DataSourceFactory.OSGI_JDBC_DRIVER_NAME + "=MySQL)");

    Driver driver = factory.createDriver(null);
    assertThat(driver).isNotNull();
    System.out.println("JDBC Driver " + driverClassName + " version " + driver.getMajorVersion() + "." + driver
            .getMinorVersion());
    assertThat(driver.acceptsURL(url)).isTrue();

    // Test with default attributes
    url = "jdbc:mysql://localhost/test?useUnicode=yes&characterEncoding=UTF-8&connectionCollation=utf8_general_ci";
    assertThat(driver.acceptsURL(url)).isTrue();
}
 
开发者ID:wisdom-framework,项目名称:wisdom-jdbc,代码行数:19,代码来源:DriverIT.java


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