I have a database declared in a module. I have a core business logic module I need to expose the database in. I have the database defined as a singleton, and as a service. however, I also need to access the database from the Core business logic module. The Service's work but I can't reference the tkn database from core.
I need to reference the TKN database defined in module fleet.mt1.dataserviceimpl in fleet.mt1.core module.
wondering how to accomplish this? if there is a way in camel blueprint / spring that can do this???
fleet.mt1.dataserviceimpl
<cm:property-placeholder persistent-id="com.ge.digital.fleet.dataservice.impl"/>
<!-- Ensure that only one instance of a class pdxDb is created -->
<!-- Provide a global point of access to the object -->
<bean class="com.ge.digital.fleet.dataservice.impl.db.PDXDatabase"
id="pdxDb" scope="singleton"/>
<bean class="com.ge.digital.fleet.dataservice.impl.db.TKNDatabase"
id="tknDb" scope="singleton"/>
<!-- PDX Data Service Implementation -->
<bean
class="com.ge.digital.fleet.dataservice.impl.PDXDataServiceImpl" id="pdxDataService">
<property name="pdxDatabase" ref="pdxDb"/>
</bean>
<bean
class="com.ge.digital.fleet.dataservice.impl.TKNDataServiceImpl" id="tknDataService">
<property name="tknDatabase" ref="tknDb"/>
</bean>
<!-- PDX Data Service Registration -->
<service depends-on="pdxDb"
interface="com.ge.digital.fleet.dataservice.PDXDataService" ref="pdxDataService"/>
<service depends-on="tknDb"
interface="com.ge.digital.fleet.dataservice.TKNDataService" ref="tknDataService"/>
<bean
class="com.ge.digital.fleet.dataservice.impl.processor.ReplicatedDataProcessor" id="replicatedDataProcessor">
<property name="pdxDatabase" ref="pdxDb"/>
</bean>
<bean
class="com.ge.digital.fleet.dataservice.impl.filter.FTPFileFilter" id="ftpFileFilter"/>
<!-- properties found in com.ge.digital.fleet.dataservice.impl.cfg under etc -->
<bean
class="com.ge.digital.fleet.dataservice.impl.route.ReplicatedDataRouteBuilder"
depends-on="ftpFileFilter" id="replicatedDataRouteBuilder">
<property name="transportSftp" value="${transportSftp}"/>
<property name="transportFs" value="${transportFs}"/>
<property name="username" value="${username}"/>
<property name="host" value="${host}"/>
<property name="port" value="${port}"/>
<property name="pathSftp" value="${pathSftp}"/>
<property name="pathFs" value="${pathFs}"/>
<property name="password" value="${password}"/>
<property name="moveToPath" value="${moveToPath}"/>
<property name="fileArchive" value="${fileArchive}"/>
<property name="readLockFile" value="${readLockFile}"/>
<property name="ftpFileFilter" value="ftpFileFilter"/>
</bean>
<camelContext id="com.ge.digital.fleet.dataServiceImplCamelContext"
trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<routeBuilder ref="replicatedDataRouteBuilder"/>
</camelContext>
</blueprint>
fleet.mt1.core
<reference id="pdxDataService" interface="com.ge.digital.fleet.dataservice.PDXDataService"/>
<bean
class="com.ge.digital.fleet.core.processors.DbAvailableProcessor" id="dbAvailableProcessor">
<property name="dataService" ref="pdxDataService"/>
</bean>
<reference id="tknDataService" interface="com.ge.digital.fleet.dataservice.TKNDataService"/>
<bean class="com.ge.digital.fleet.dataservice.impl.db.TKNDatabase"
id="tknDb" scope="singleton"/>
<bean
class="com.ge.digital.fleet.core.processors.AccessKeyMarsheler" id="accessKeyMarsheler">
<property name="tknDatabase" ref="tknDb"/>
</bean>
THIS IS WRONG AND I KNOW IT, THIS IS MY ISSUE, how can OR can this be referenced in the core module?
<bean class="com.ge.digital.fleet.dataservice.impl.db.TKNDatabase"
id="tknDb" scope="singleton"/>
thank you for you help! I'm struggling with this. I've tried reference the Bean, the Class but of course, this is Illegal syntax.
I'm working on another interface for the service to access this across modules, I guess I am hoping there is a way to do this in Spring, as a reference or dependency or something.
While waiting on an answer to see if this is possible with Spring I went ahead and created wrappers for the methods and interface, it works fine, but, I would love to know if this can be done in Spring with a reference or something. I need to study and bunker down on Spring.
thanks again.
public class TKNDataServiceImpl implements TKNDataService {
private static final Logger LOG = LoggerFactory.getLogger(TKNDataServiceImpl.class);
private TKNDatabase tknDb = null;
@Override
public boolean isTKNDataServiceAvailable() {
return tknDb.isAvailable();
}
@Override
public TknLocator getTokenLocatorForCustomerKey(String custkey) throws TKNDataServiceUnavailableException,
TKNDataServiceInvalidDataException {
if (null != custkey) {
final String token = tknDb.getAccessToken(custkey);
Timestamp expiry = tknDb.getExpiry(custkey);
LOG.info("ACCESS TOKEN: " + token);
LOG.info("EXPIRY: " + expiry);
TknLocator loc = new TknLocator();
loc.setAccess_token(token);
loc.setexpires_in(expiry);
return loc;
}
return null;
}
@Override
public boolean CustomerKeyExistsInTokenDb(String custkey) throws TKNDataServiceInvalidDataException,
TKNDataServiceUnavailableException {
boolean keyExists = tknDb.doesCustKeyExist(custkey);
return keyExists;
}
@Override
public void TknDbAddRow(String custkey, String access_token, int expires_in) {
if (null != custkey) {
tknDb.addRow(custkey, access_token, expires_in);
}
}
@Override
public void TknReplicationComplete() {
tknDb.replicationComplete();
}
@Override
public void TknDropRow(String custkey) {
if (null != custkey) {
tknDb.dropRow(custkey);
}
}
public Timestamp TknGetExpiry(String custkey) throws TKNDataServiceUnavailableException,
TKNDataServiceInvalidDataException {
return(tknDb.getExpiry(custkey));
}
public String TknGetAccessToken(String custkey) throws TKNDataServiceUnavailableException,
TKNDataServiceInvalidDataException {
return(tknDb.getAccessToken(custkey));
}
public void settknDatabase(TKNDatabase tknDb) {
this.tknDb = tknDb;
}
}