Hi,
I'm a bit confused on how data sources component's data source lookup is
working. In the data source UI, we have the "Name" and the "Data Source
Name" (the fields themselves are a bit confusing to start with) .. and in
the code, the backend admin service assigns them to the "alias" and the
"dataSourceName" fields to a "DataSourceInformation" instance, respectively.
In
"org.apache.synapse.commons.datasource.factory.DataSourceInformationFactory"
class's "createDataSourceInformation" method is like this,
public static DataSourceInformation createDataSourceInformation(String
dsName,
Properties properties) {
...
DataSourceInformation datasourceInformation = new
DataSourceInformation();
datasourceInformation.setAlias(dsName);
...
String dataSourceName = MiscellaneousUtil.getProperty(
properties, prefix + DataSourceConstants.PROP_DSNAME, dsName,
String.class);
datasourceInformation.setDatasourceName(dataSourceName);
So "dsName" parameter is what we get from our UI's "Name" field, and the
property bags' "PROP_DSNAME" is from the UI's "Data Source Name".
Starting from the data sources admin service, when a data source is added,
it calls
"DataSourceInformantionManager->addDataSourceInformation(DataSourceInformation)".
public void addDataSourceInformation(DataSourceInformation information) {
repository.addDataSourceInformation(information);
}
Here "repository" is
"org.apache.synapse.commons.datasource.DataSourceInformationRepository".
public void addDataSourceInformation(DataSourceInformation
dataSourceInformation) {
assertNull(dataSourceInformation, "DataSource information is null");
dataSourceInformationMap.put(dataSourceInformation.getAlias(),
dataSourceInformation);
...
So here, they store the data source info in a map using the alias as the
key. So many data sources with different aliases and possibly with the same
"Data Source Name" can coexist. This is compatible with the UI we have. But
looking at how the data sources are actually saved, not the info, but the
actual DataSource objects, in
org.apache.synapse.commons.datasource.DataSourceRepositoryManager,
public void addDataSourceInformation(DataSourceInformation
dataSourceInformation) {
if (dataSourceInformation == null) {
return;
}
String repositoryType = dataSourceInformation.getRepositoryType();
if (DataSourceConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) {
jndiBasedDataSourceRepository.register(dataSourceInformation);
} else {
inMemoryDataSourceRepository.register(dataSourceInformation);
}
}
A look at
"org.apache.synapse.commons.datasource.InMemoryDataSourceRepository",
public void register(DataSourceInformation dataSourceInformation) {
...
String name = dataSourceInformation.getDatasourceName();
...
dataSources.put(name, dataSource);
...
So here effectively at the end, the "dataSourceName" field is used in
storing the actual data sources, and not the alias. So in this place, if we
have registered several data source from our UI that have the same "Data
Source Name" field, those will be replaced and only the last data source
will survive.
Ultimately the point is, the class "DataSourceInformationRepository" works
with the "alias" and the class "DataSourceRepositoryManager" works with the
other property "dataSourceName", to store/retrieve data sources.
I was checking this because, in DSS i was using the following code to get a
registered data source,
private DataSource
createDataSource(DataSourceInformationRepositoryService cdService) {
DataSourceInformationRepository datasourceRepo = cdService.
getDataSourceInformationRepository();
DataSourceHelper dataSourceHelper = DataSourceHelper.getInstance();
dataSourceHelper.init(datasourceRepo, null);
return
dataSourceHelper.getDataSourceRepositoryManager().getDataSource(
this.getDataSourceName());
}
And there for the "getDataSource" method, you have to give the "Data Source
Name" that's there in the UI (2'nd field) not the alias, and you actually
can't use the alias as I explained earlier.
So can someone who's familiar with the data source component, please look
into this, maybe I'm missing something here.
Cheers,
Anjana.
--
Anjana Fernando
Software Engineer
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware
_______________________________________________
Carbon-dev mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev