コード例 #1
0
 public void deleted(String pid) {
   DataSourceEntry dsEntry = dataSources.get(pid);
   if (dsEntry != null) {
     dsEntry.getServiceRegistration().unregister();
   }
   dataSources.remove(pid);
 }
コード例 #2
0
  @SuppressWarnings("rawtypes")
  public void updated(String pid, Dictionary properties) throws ConfigurationException {
    DataSourceEntry dsEntry = dataSources.get(pid);
    if (dsEntry != null) {
      dsEntry.getServiceRegistration().unregister();
      dataSources.remove(pid);
    }

    try {

      Properties dsProperties = filterDataSourceProperties(properties);
      DataSource ds = datasourceFactory.createDataSource(dsProperties);

      Dictionary<String, String> registrationProperties = new Hashtable<String, String>();
      String databaseName = (String) properties.get(DataSourceFactory.JDBC_DATABASE_NAME);
      String datasourceName = (String) properties.get(DataSourceFactory.JDBC_DATASOURCE_NAME);
      if (datasourceName != null)
        registrationProperties.put(DataSourceFactory.JDBC_DATASOURCE_NAME, datasourceName);
      registrationProperties.put(DataSourceFactory.JDBC_SERVER_NAME, databaseName);
      ServiceRegistration serviceRegistration =
          bundleContext.registerService(DataSource.class.getName(), ds, registrationProperties);
      dsEntry = new DataSourceEntry(ds, serviceRegistration);
      dataSources.put(pid, dsEntry);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }