DataServiceMetaStoreUtil { public void clearReferences( TransMeta transMeta ) { MetaStoreFactory<ServiceTrans> serviceTransFactory = getServiceTransFactory( transMeta.getMetaStore() ); try { FluentIterable<String> names = FluentIterable.from( serviceTransFactory.getElements() ) .filter( ServiceTrans.isReferenceTo( transMeta ) ) .transform( ServiceTrans.getName ); for ( String name : names ) { serviceTransFactory.deleteElement( name ); } } catch ( MetaStoreException e ) { getLogChannel().logError( "Unable to remove orphaned data service", e ); } } protected  DataServiceMetaStoreUtil( DataServiceContext context, Cache<Integer, String> cache ); protected  DataServiceMetaStoreUtil( DataServiceMetaStoreUtil metaStoreUtil ); static DataServiceMetaStoreUtil create( DataServiceContext context ); DataServiceMeta getDataService( String serviceName, Repository repository, IMetaStore metaStore ); DataServiceMeta getDataService( String serviceName, TransMeta serviceTrans ); Iterable<DataServiceMeta> getDataServices( final Repository repository, IMetaStore metaStore,
                                                    final Function<Exception, Void> exceptionHandler ); Iterable<DataServiceMeta> getDataServices( TransMeta transMeta ); List<String> getDataServiceNames( TransMeta transMeta ); List<String> getDataServiceNames( IMetaStore metaStore ); DataServiceMeta getDataServiceByStepName( TransMeta transMeta, String stepName ); DataServiceMeta checkDefined( DataServiceMeta dataServiceMeta ); DataServiceMeta checkConflict( DataServiceMeta dataServiceMeta, String ignored ); void save( DataServiceMeta dataService ); void removeDataService( DataServiceMeta dataService ); void deleteDataServiceElementAndCleanCache( DataServiceMeta dataService, TransMeta transMeta ); @Deprecated( ) void sync( TransMeta transMeta, Function<? super Exception, ?> exceptionHandler ); ImmutableMap<String, ServiceTrans> getServiceTransMap( TransMeta transMeta ); void clearReferences( TransMeta transMeta ); LogChannelInterface getLogChannel(); List<PushDownFactory> getPushDownFactories(); Function<Exception, Void> logErrors( final String message ); DataServiceContext getContext(); Cache<Integer, String> getStepCache();  }
@Test public void testClearReferences() throws Exception { MetaStoreFactory<DataServiceMeta> dataServiceFactory = metaStoreUtil.getDataServiceFactory( transMeta ); MetaStoreFactory<ServiceTrans> serviceTransFactory = metaStoreUtil.getServiceTransFactory( metaStore ); String otherName = "OTHER"; DataServiceMeta other = createDataService( otherName, transMeta ); dataServiceFactory.saveElement( dataService ); dataServiceFactory.saveElement( other ); serviceTransFactory.saveElement( ServiceTrans.create( dataService ) ); serviceTransFactory.saveElement( ServiceTrans.create( other.getName(), mock( TransMeta.class ) ) ); assertThat( metaStoreUtil.getDataServiceNames( transMeta ), containsInAnyOrder( DATA_SERVICE_NAME, otherName ) ); assertThat( metaStoreUtil.getDataServiceNames( metaStore ), containsInAnyOrder( DATA_SERVICE_NAME, otherName ) ); metaStoreUtil.clearReferences( transMeta ); assertThat( metaStoreUtil.getDataServiceNames( transMeta ), containsInAnyOrder( DATA_SERVICE_NAME, otherName ) ); assertThat( metaStoreUtil.getDataServiceNames( metaStore ), contains( otherName ) ); }