Merge pull request #18 from scottfrederick/oracle

Add ServiceInfo and DataSourceCreator for Oracle.
This commit is contained in:
Ramnivas Laddad
2014-02-11 18:10:03 -08:00
6 changed files with 86 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
package org.springframework.cloud.service.common;
import org.springframework.cloud.service.ServiceInfo;
@ServiceInfo.ServiceLabel("oracle")
public class OracleServiceInfo extends RelationalServiceInfo {
public OracleServiceInfo(String id, String url) {
super(id, url, "oracle");
}
@Override
public String getJdbcUrl() {
return String.format("jdbc:%s:thin:%s/%s@%s:%d/%s",
jdbcUrlDatabaseType, getUserName(), getPassword(),
getHost(), getPort(), getPath());
}
}

View File

@@ -9,13 +9,13 @@ import org.springframework.cloud.service.UriBasedServiceInfo;
*/
public abstract class RelationalServiceInfo extends UriBasedServiceInfo {
private String jdbcUrlDatabaseType;
protected String jdbcUrlDatabaseType;
public RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType) {
public RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType) {
super(id, uriString);
this.jdbcUrlDatabaseType = jdbcUrlDatabaseType;
}
@ServiceProperty(category="connection")
public String getJdbcUrl() {
return String.format("jdbc:%s://%s:%d/%s?user=%s&password=%s",

View File

@@ -0,0 +1,13 @@
package org.springframework.cloud.service.relational;
import org.springframework.cloud.service.common.OracleServiceInfo;
public class OracleDataSourceCreator extends DataSourceCreator<OracleServiceInfo> {
private static final String[] DRIVERS = new String[]{"oracle.jdbc.OracleDriver"};
private static final String VALIDATION_QUERY = "SELECT 'Y' from dual";
public OracleDataSourceCreator() {
super("spring-cloud.oracle.driver", DRIVERS, VALIDATION_QUERY);
}
}

View File

@@ -0,0 +1,9 @@
package org.springframework.cloud.service.relational;
import org.springframework.cloud.service.common.OracleServiceInfo;
public class OracleDataSourceFactoryTest extends AbstractDataSourceFactoryTest<OracleServiceInfo> {
public OracleServiceInfo getTestServiceInfo(String id) {
return new OracleServiceInfo(id, "oracle://username:pass@host:port/db");
}
}

View File

@@ -0,0 +1,41 @@
package org.springframework.cloud.service.relational;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.cloud.service.common.OracleServiceInfo;
public class OracleServiceCreatorTest extends AbstractDataSourceCreatorTest<OracleDataSourceCreator, OracleServiceInfo> {
@Mock private OracleServiceInfo mockOracleServiceInfo;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
// set a dummy JDBC driver since we can't include a real Oracle driver in the project due to licensing restrictions
System.setProperty("spring-cloud.oracle.driver", "com.example.Driver");
}
@Override
public OracleServiceInfo createServiceInfo() {
when(mockOracleServiceInfo.getJdbcUrl()).thenReturn("oracle://myuser:mypassword@10.20.30.40:5432/database-123");
return mockOracleServiceInfo;
}
@Override
public String getDriverName() {
return "com.example.Driver";
}
@Override
public OracleDataSourceCreator getCreator() {
return new OracleDataSourceCreator();
}
@Override
public String getValidationQueryStart() {
return "SELECT 'Y' from dual";
}
}

View File

@@ -8,7 +8,7 @@ import org.mockito.MockitoAnnotations;
import org.springframework.cloud.service.common.PostgresqlServiceInfo;
/**
*
*
* @author Ramnivas Laddad
*
*/