Skip to content

Commit

Permalink
simplifying service lookup in the cross-store example.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlong committed Apr 2, 2012
1 parent 3d9d1da commit 22f71da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
16 changes: 8 additions & 8 deletions cross-store/manifest.yml
@@ -1,18 +1,18 @@
---
applications:
target:
name: xs-survey
target/customer-survey-1.0.0-BUILD-SNAPSHOT/:
name: customer-survey
url: ${name}.${target-base}
framework:
name: spring
name: java_web
info:
mem: 512M
description: Java SpringSource Spring Application
description: Java Web Application
exec:
mem: 512M
instances: 1
services:
survey-mongo:
type: :mongodb
survey-mysql:
type: :mysql
mongodb-67f01:
type: mongodb
mysql-7bfaa:
type: mysql
@@ -1,8 +1,5 @@
package org.cloudfoundry.config;

import javax.sql.DataSource;


import org.cloudfoundry.runtime.env.CloudEnvironment;
import org.cloudfoundry.runtime.env.MongoServiceInfo;
import org.cloudfoundry.runtime.env.RdbmsServiceInfo;
Expand All @@ -28,24 +25,23 @@
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
@ComponentScan(basePackageClasses = CrossStoreCustomerRepository.class)
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
public class ServicesConfiguration {


private String mongoDatabaseServiceName = "survey-mongo";

private String mysqlDatabaseServiceName = "survey-mysql";

@Bean
public CloudEnvironment cloudEnvironment() {
return new CloudEnvironment();
}

@Bean
public MongoServiceInfo mongoServiceInfo() {
return cloudEnvironment().getServiceInfo(mongoDatabaseServiceName, MongoServiceInfo.class);
MongoServiceInfo mongoServiceInfo = cloudEnvironment().getServiceInfos( MongoServiceInfo.class).iterator().next();
assert null != mongoServiceInfo : "there needs to be at least one MongoDB instance bound to this application" ;
return mongoServiceInfo;
}

@Bean
Expand All @@ -56,10 +52,10 @@ public MongoDbFactory mongoDbFactory() {

@Bean
public DataSource dataSource() {
RdbmsServiceInfo rdbmsServiceInfo = cloudEnvironment().getServiceInfo(mysqlDatabaseServiceName, RdbmsServiceInfo.class);
RdbmsServiceInfo rdbmsServiceInfo = cloudEnvironment().getServiceInfos( RdbmsServiceInfo.class).iterator().next();
assert null != rdbmsServiceInfo : "there needs to be at least one MySQL RDBMS bound to this application";
RdbmsServiceCreator rdbmsServiceCreator = new RdbmsServiceCreator();
DataSource dataSource = rdbmsServiceCreator.createService(rdbmsServiceInfo);
return dataSource;
return rdbmsServiceCreator.createService(rdbmsServiceInfo);
}

@Bean
Expand Down

0 comments on commit 22f71da

Please sign in to comment.