You are viewing a plain text version of this content. The canonical link for it is here.
Posted to stonehenge-commits@incubator.apache.org by ch...@apache.org on 2010/06/29 06:33:57 UTC
svn commit: r958838 [8/42] - in /incubator/stonehenge/trunk/stocktrader:
dotnet/ dotnet/setup_utilities/Util/ metro/ metro/active_sts/
metro/active_sts/etc/
metro/active_sts/src/org/apache/stonehenge/stocktrader/sts/
metro/business_service/ metro/busin...
Modified: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConfigServiceDAOImpl.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConfigServiceDAOImpl.java?rev=958838&r1=958837&r2=958838&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConfigServiceDAOImpl.java (original)
+++ incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConfigServiceDAOImpl.java Tue Jun 29 06:33:54 2010
@@ -1,306 +1,306 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- package org.apache.stonehenge.stocktrader.dal;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.datacontract.schemas._2004._07.trade.BSConfigResponse;
-import org.datacontract.schemas._2004._07.trade.ClientConfigResponse;
-import org.datacontract.schemas._2004._07.trade.OPSConfigResponse;
-import org.datacontract.schemas._2004._07.trade.ServiceLocation;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class ConfigServiceDAOImpl implements ConfigServiceDAO {
- private static Log logger = LogFactory.getLog(ConfigServiceDAOImpl.class);
-
- private Connection connection;
-
- public ConfigServiceDAOImpl() {
- }
-
- public void setConnection(Connection connection) {
- this.connection = connection;
- }
-
- private static final String SQL_SELECT_BSLOCATION_FROM_SERVICE = "SELECT servicename,url,sec FROM SERVICE WHERE SERVICENAME LIKE '%_BS%'";
- private static final String SQL_SELECT_OPSLOCATION_FROM_SERVICE = "SELECT servicename,url,sec FROM SERVICE WHERE SERVICENAME LIKE '%_OPS%'";
- private static final String SQL_INSERT_VALUE_INTO_CLIENT_TO_BS = "INSERT INTO CLIENTTOBS (CLIENT , BS) VALUES (?,?);";
- private static final String SQL_UPDATE_CLIENT_TO_BS = "UPDATE CLIENTTOBS SET BS=? WHERE CLIENT = ?;";
- private static final String SQL_INSERT_VALUE_INTO_BS_TO_OPS = "INSERT INTO BSTOOPS (BS, OPS) VALUES (?,?);";
- private static final String SQL_UPDATE_BS_TO_OPS = "UPDATE BSTOOPS SET OPS=? WHERE BS = ?;";
- private static final String SQL_SELECT_BSSERVICE_ADDRESS_BY_ClIENTNAME = "SELECT servicename,url,sec FROM SERVICE INNER JOIN CLIENTTOBS ON SERVICE.SERVICENAME = CLIENTTOBS.BS WHERE CLIENT=?";
- private static final String SQL_SELECT_OPSSERVICE_ADDRESS_BY_CLIENTNAME = "SELECT servicename,url,sec,DBNAME, HOSTNAME,PORT FROM SERVICE INNER JOIN BSTOOPS ON SERVICE.SERVICENAME = BSTOOPS.OPS CROSS JOIN DBCONFIG WHERE BSTOOPS.BS=?";
- private static final String SQL_SELECT_FROM_CLIENTTOBS = "SELECT * FROM CLIENTTOBS WHERE CLIENT = ?;";
- private static final String SQL_SELECT_FROM_BSTOOPS = "SELECT * FROM BSTOOPS WHERE BS = ?;";
- private static final String SQL_SELECT_OPS_CONFIG = "SELECT * FROM DBCONFIG;";
- private static final String SQL_UPDATE_SERVICE = "UPDATE SERVICE SET URL = ?, SEC = ? WHERE SERVICENAME = ?;";
- private static final String SQL_SELECT_SERVICE = "SELECT * FROM SERVICE WHERE SERVICENAME = ?;";
- private static final String SQL_INSERT_VALUE_INTO_SERVICE = "INSERT INTO SERVICE VALUES (?,?,?);";
-
- public List<ServiceLocation> getBSLocations() {
- return (List<ServiceLocation>) executeQuery(new SimpleStatementPopulator(SQL_SELECT_BSLOCATION_FROM_SERVICE),
- new ServiceResultSetExtractor());
- }
-
- public List<ServiceLocation> getOPSLocations() {
- return (List<ServiceLocation>) executeQuery(new SimpleStatementPopulator(SQL_SELECT_OPSLOCATION_FROM_SERVICE),
- new ServiceResultSetExtractor());
- }
-
- public ClientConfigResponse getClientConfig(String clientName) {
- return (ClientConfigResponse) executeQuery(
- new SimpleStatementPopulator(SQL_SELECT_BSSERVICE_ADDRESS_BY_ClIENTNAME, clientName),
- new ClientConfigResponseResultSetExtractor());
- }
-
- public BSConfigResponse getBSConfig(String bsName) {
- return (BSConfigResponse) executeQuery(
- new SimpleStatementPopulator(SQL_SELECT_OPSSERVICE_ADDRESS_BY_CLIENTNAME, bsName),
- new BSConfigResponseResultSetExtractor());
- }
-
- public OPSConfigResponse getOPSConfig(String opsName) {
- return (OPSConfigResponse) executeQuery(new SimpleStatementPopulator(SQL_SELECT_OPS_CONFIG),
- new OPSConfigResponseResultSetExtractor());
- }
-
- public boolean setClientToBS(String clientName, String bsName) {
- StatementPopulator queryStatement = new SimpleStatementPopulator(SQL_SELECT_FROM_CLIENTTOBS, clientName);
- StatementPopulator updateStatement = new SimpleStatementPopulator(SQL_UPDATE_CLIENT_TO_BS, bsName, clientName);
- StatementPopulator insertStatement = new SimpleStatementPopulator(SQL_INSERT_VALUE_INTO_CLIENT_TO_BS,
- clientName, bsName);
- return executeTransaction(
- new SaveOrUpdateTransactionCallback(queryStatement, updateStatement, insertStatement));
- }
-
- public boolean setBSToOPS(String bs, String ops) {
- StatementPopulator queryStatement = new SimpleStatementPopulator(SQL_SELECT_FROM_BSTOOPS, bs);
- StatementPopulator updateStatement = new SimpleStatementPopulator(SQL_UPDATE_BS_TO_OPS, ops, bs);
- StatementPopulator insertStatement = new SimpleStatementPopulator(SQL_INSERT_VALUE_INTO_BS_TO_OPS,
- bs, ops);
- return executeTransaction(
- new SaveOrUpdateTransactionCallback(queryStatement, updateStatement, insertStatement));
- }
-
- public boolean setServiceLocation(final String serviceName, final String serviceUrl, final Boolean isSec) {
- int sec = (isSec == true) ? 1 : 0;
- StatementPopulator queryStatement = new SimpleStatementPopulator(SQL_SELECT_SERVICE, serviceName);
- StatementPopulator updateStatement = new SimpleStatementPopulator(SQL_UPDATE_SERVICE, serviceUrl, sec,
- serviceName);
- StatementPopulator insertStatement = new SimpleStatementPopulator(SQL_INSERT_VALUE_INTO_SERVICE, serviceName,
- serviceUrl, sec);
- return executeTransaction(
- new SaveOrUpdateTransactionCallback(queryStatement, updateStatement, insertStatement));
- }
-
- class SaveOrUpdateTransactionCallback implements TransactionCallback {
- private final StatementPopulator queryStatementPopulator;
- private final StatementPopulator updateStatementPopulator;
- private final StatementPopulator insertStatementPopulator;
-
- SaveOrUpdateTransactionCallback(
- StatementPopulator queryStatementPopulator,
- StatementPopulator updateStatementPopulator,
- StatementPopulator insertStatementPopulator) {
- this.queryStatementPopulator = queryStatementPopulator;
- this.updateStatementPopulator = updateStatementPopulator;
- this.insertStatementPopulator = insertStatementPopulator;
- }
-
- public void executeTransaction(Connection connection) throws SQLException {
- boolean hasEntry = checkUpdateStatus(queryStatementPopulator, connection);
- if (hasEntry) {
- executeUpdate(updateStatementPopulator, connection);
- } else {
- executeInsert(insertStatementPopulator, connection);
- }
- }
-
- private boolean checkUpdateStatus(StatementPopulator statementPopulator, Connection connection) throws
- SQLException {
- PreparedStatement statement1 = statementPopulator.populateStatement(connection);
- ResultSet resultSet = statement1.executeQuery();
- boolean hasEntry = resultSet.next();
- return hasEntry;
- }
-
- private void executeUpdate(StatementPopulator updateStatementPopulator, Connection connection) throws
- SQLException {
- PreparedStatement statement2 = updateStatementPopulator.populateStatement(connection);
- statement2.executeUpdate();
- }
-
- private void executeInsert(StatementPopulator insertStatementPopulator, Connection connection) throws
- SQLException {
- PreparedStatement statement3 = insertStatementPopulator.populateStatement(connection);
- statement3.executeUpdate();
- }
- }
-
- private class SimpleStatementPopulator implements StatementPopulator {
- private final String sql;
- private final Object[] params;
-
- private SimpleStatementPopulator(String sql, Object... params) {
- this.sql = sql;
- this.params = params;
- }
-
- public PreparedStatement populateStatement(Connection connection) throws
- SQLException {
- PreparedStatement preparedStatement = connection.prepareStatement(sql);
- int index = 1;
- for (Object param : params) {
- preparedStatement.setObject(index++, param);
- }
- return preparedStatement;
- }
-
- }
-
- class ServiceResultSetExtractor implements ResultSetExtractor<List<ServiceLocation>> {
-
- public List<ServiceLocation> extractResultSet(ResultSet rs) throws SQLException {
- List<ServiceLocation> serviceLocations = new ArrayList<ServiceLocation>();
- while (rs.next()) {
- ServiceLocation serviceLocation = new ServiceLocation();
- serviceLocation.setServiceName(rs.getString("serviceName"));
- serviceLocation.setServiceURL(rs.getString("url"));
- serviceLocation.setSec(rs.getBoolean("sec"));
- serviceLocations.add(serviceLocation);
- }
- return serviceLocations;
- }
-
- }
-
- class OPSConfigResponseResultSetExtractor implements ResultSetExtractor<OPSConfigResponse> {
- public OPSConfigResponse extractResultSet(ResultSet rs) throws SQLException {
- OPSConfigResponse response = new OPSConfigResponse();
- while (rs.next()) {
- response.setDBName(rs.getString("dbname"));
- response.setDBHostName(rs.getString("hostname"));
- response.setDBPort(rs.getInt("port"));
- }
- return response;
- }
- }
-
- class ClientConfigResponseResultSetExtractor implements ResultSetExtractor<ClientConfigResponse> {
- public ClientConfigResponse extractResultSet(ResultSet rs) throws SQLException {
- ClientConfigResponse response = new ClientConfigResponse();
- while (rs.next()) {
- response.setBSName(rs.getString("serviceName"));
- response.setBS(rs.getString("url"));
- response.setSec(rs.getBoolean("sec"));
- }
- return response;
- }
- }
-
- class BSConfigResponseResultSetExtractor implements ResultSetExtractor<BSConfigResponse> {
-
- public BSConfigResponse extractResultSet(ResultSet rs) throws SQLException {
- BSConfigResponse response = new BSConfigResponse();
- while (rs.next()) {
- response.setOPSName(rs.getString("serviceName"));
- response.setOPS(rs.getString("url"));
- response.setSec(rs.getBoolean("sec"));
- response.setDBName(rs.getString("dbname"));
- response.setDBHostName(rs.getString("hostname"));
- response.setDBPort(rs.getInt("port"));
- }
- return response;
- }
- }
-
- private interface StatementPopulator {
- public PreparedStatement populateStatement(Connection connection) throws SQLException;
- }
-
- private interface ResultSetExtractor<T> {
- T extractResultSet(ResultSet rs) throws SQLException;
- }
-
- private Object executeQuery(StatementPopulator stPopulator, ResultSetExtractor rsExtractor) {
- Object result = null;
- ResultSet rs = null;
- try {
- PreparedStatement statement = stPopulator.populateStatement(connection);
- rs = statement.executeQuery();
- result = rsExtractor.extractResultSet(rs);
- } catch (SQLException exception) {
- logger.error(exception, exception);
- }
- finally {
- try {
- if (rs != null) {
- rs.close();
- }
- try {
- if (connection != null && !connection.isClosed()) {
- connection.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- } catch (SQLException exception) {
- logger.error(exception, exception);
- }
- }
- return result;
- }
-
- interface TransactionCallback {
- void executeTransaction(Connection connection) throws SQLException;
- }
-
- private boolean executeTransaction(TransactionCallback transactionCallback) {
- try {
- connection.setAutoCommit(false);
-
- transactionCallback.executeTransaction(connection);
-
- connection.commit();
- return true;
- } catch (SQLException e) {
- try {
- connection.rollback();
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- logger.error(e, e);
- return false;
- } finally {
- try {
- connection.setAutoCommit(true);
- if (connection != null && !connection.isClosed()) {
- connection.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package org.apache.stonehenge.stocktrader.dal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.datacontract.schemas._2004._07.trade.BSConfigResponse;
+import org.datacontract.schemas._2004._07.trade.ClientConfigResponse;
+import org.datacontract.schemas._2004._07.trade.OPSConfigResponse;
+import org.datacontract.schemas._2004._07.trade.ServiceLocation;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ConfigServiceDAOImpl implements ConfigServiceDAO {
+ private static Log logger = LogFactory.getLog(ConfigServiceDAOImpl.class);
+
+ private Connection connection;
+
+ public ConfigServiceDAOImpl() {
+ }
+
+ public void setConnection(Connection connection) {
+ this.connection = connection;
+ }
+
+ private static final String SQL_SELECT_BSLOCATION_FROM_SERVICE = "SELECT servicename,url,sec FROM SERVICE WHERE SERVICENAME LIKE '%_BS%'";
+ private static final String SQL_SELECT_OPSLOCATION_FROM_SERVICE = "SELECT servicename,url,sec FROM SERVICE WHERE SERVICENAME LIKE '%_OPS%'";
+ private static final String SQL_INSERT_VALUE_INTO_CLIENT_TO_BS = "INSERT INTO CLIENTTOBS (CLIENT , BS) VALUES (?,?);";
+ private static final String SQL_UPDATE_CLIENT_TO_BS = "UPDATE CLIENTTOBS SET BS=? WHERE CLIENT = ?;";
+ private static final String SQL_INSERT_VALUE_INTO_BS_TO_OPS = "INSERT INTO BSTOOPS (BS, OPS) VALUES (?,?);";
+ private static final String SQL_UPDATE_BS_TO_OPS = "UPDATE BSTOOPS SET OPS=? WHERE BS = ?;";
+ private static final String SQL_SELECT_BSSERVICE_ADDRESS_BY_ClIENTNAME = "SELECT servicename,url,sec FROM SERVICE INNER JOIN CLIENTTOBS ON SERVICE.SERVICENAME = CLIENTTOBS.BS WHERE CLIENT=?";
+ private static final String SQL_SELECT_OPSSERVICE_ADDRESS_BY_CLIENTNAME = "SELECT servicename,url,sec,DBNAME, HOSTNAME,PORT FROM SERVICE INNER JOIN BSTOOPS ON SERVICE.SERVICENAME = BSTOOPS.OPS CROSS JOIN DBCONFIG WHERE BSTOOPS.BS=?";
+ private static final String SQL_SELECT_FROM_CLIENTTOBS = "SELECT * FROM CLIENTTOBS WHERE CLIENT = ?;";
+ private static final String SQL_SELECT_FROM_BSTOOPS = "SELECT * FROM BSTOOPS WHERE BS = ?;";
+ private static final String SQL_SELECT_OPS_CONFIG = "SELECT * FROM DBCONFIG;";
+ private static final String SQL_UPDATE_SERVICE = "UPDATE SERVICE SET URL = ?, SEC = ? WHERE SERVICENAME = ?;";
+ private static final String SQL_SELECT_SERVICE = "SELECT * FROM SERVICE WHERE SERVICENAME = ?;";
+ private static final String SQL_INSERT_VALUE_INTO_SERVICE = "INSERT INTO SERVICE VALUES (?,?,?);";
+
+ public List<ServiceLocation> getBSLocations() {
+ return (List<ServiceLocation>) executeQuery(new SimpleStatementPopulator(SQL_SELECT_BSLOCATION_FROM_SERVICE),
+ new ServiceResultSetExtractor());
+ }
+
+ public List<ServiceLocation> getOPSLocations() {
+ return (List<ServiceLocation>) executeQuery(new SimpleStatementPopulator(SQL_SELECT_OPSLOCATION_FROM_SERVICE),
+ new ServiceResultSetExtractor());
+ }
+
+ public ClientConfigResponse getClientConfig(String clientName) {
+ return (ClientConfigResponse) executeQuery(
+ new SimpleStatementPopulator(SQL_SELECT_BSSERVICE_ADDRESS_BY_ClIENTNAME, clientName),
+ new ClientConfigResponseResultSetExtractor());
+ }
+
+ public BSConfigResponse getBSConfig(String bsName) {
+ return (BSConfigResponse) executeQuery(
+ new SimpleStatementPopulator(SQL_SELECT_OPSSERVICE_ADDRESS_BY_CLIENTNAME, bsName),
+ new BSConfigResponseResultSetExtractor());
+ }
+
+ public OPSConfigResponse getOPSConfig(String opsName) {
+ return (OPSConfigResponse) executeQuery(new SimpleStatementPopulator(SQL_SELECT_OPS_CONFIG),
+ new OPSConfigResponseResultSetExtractor());
+ }
+
+ public boolean setClientToBS(String clientName, String bsName) {
+ StatementPopulator queryStatement = new SimpleStatementPopulator(SQL_SELECT_FROM_CLIENTTOBS, clientName);
+ StatementPopulator updateStatement = new SimpleStatementPopulator(SQL_UPDATE_CLIENT_TO_BS, bsName, clientName);
+ StatementPopulator insertStatement = new SimpleStatementPopulator(SQL_INSERT_VALUE_INTO_CLIENT_TO_BS,
+ clientName, bsName);
+ return executeTransaction(
+ new SaveOrUpdateTransactionCallback(queryStatement, updateStatement, insertStatement));
+ }
+
+ public boolean setBSToOPS(String bs, String ops) {
+ StatementPopulator queryStatement = new SimpleStatementPopulator(SQL_SELECT_FROM_BSTOOPS, bs);
+ StatementPopulator updateStatement = new SimpleStatementPopulator(SQL_UPDATE_BS_TO_OPS, ops, bs);
+ StatementPopulator insertStatement = new SimpleStatementPopulator(SQL_INSERT_VALUE_INTO_BS_TO_OPS,
+ bs, ops);
+ return executeTransaction(
+ new SaveOrUpdateTransactionCallback(queryStatement, updateStatement, insertStatement));
+ }
+
+ public boolean setServiceLocation(final String serviceName, final String serviceUrl, final Boolean isSec) {
+ int sec = (isSec == true) ? 1 : 0;
+ StatementPopulator queryStatement = new SimpleStatementPopulator(SQL_SELECT_SERVICE, serviceName);
+ StatementPopulator updateStatement = new SimpleStatementPopulator(SQL_UPDATE_SERVICE, serviceUrl, sec,
+ serviceName);
+ StatementPopulator insertStatement = new SimpleStatementPopulator(SQL_INSERT_VALUE_INTO_SERVICE, serviceName,
+ serviceUrl, sec);
+ return executeTransaction(
+ new SaveOrUpdateTransactionCallback(queryStatement, updateStatement, insertStatement));
+ }
+
+ class SaveOrUpdateTransactionCallback implements TransactionCallback {
+ private final StatementPopulator queryStatementPopulator;
+ private final StatementPopulator updateStatementPopulator;
+ private final StatementPopulator insertStatementPopulator;
+
+ SaveOrUpdateTransactionCallback(
+ StatementPopulator queryStatementPopulator,
+ StatementPopulator updateStatementPopulator,
+ StatementPopulator insertStatementPopulator) {
+ this.queryStatementPopulator = queryStatementPopulator;
+ this.updateStatementPopulator = updateStatementPopulator;
+ this.insertStatementPopulator = insertStatementPopulator;
+ }
+
+ public void executeTransaction(Connection connection) throws SQLException {
+ boolean hasEntry = checkUpdateStatus(queryStatementPopulator, connection);
+ if (hasEntry) {
+ executeUpdate(updateStatementPopulator, connection);
+ } else {
+ executeInsert(insertStatementPopulator, connection);
+ }
+ }
+
+ private boolean checkUpdateStatus(StatementPopulator statementPopulator, Connection connection) throws
+ SQLException {
+ PreparedStatement statement1 = statementPopulator.populateStatement(connection);
+ ResultSet resultSet = statement1.executeQuery();
+ boolean hasEntry = resultSet.next();
+ return hasEntry;
+ }
+
+ private void executeUpdate(StatementPopulator updateStatementPopulator, Connection connection) throws
+ SQLException {
+ PreparedStatement statement2 = updateStatementPopulator.populateStatement(connection);
+ statement2.executeUpdate();
+ }
+
+ private void executeInsert(StatementPopulator insertStatementPopulator, Connection connection) throws
+ SQLException {
+ PreparedStatement statement3 = insertStatementPopulator.populateStatement(connection);
+ statement3.executeUpdate();
+ }
+ }
+
+ private class SimpleStatementPopulator implements StatementPopulator {
+ private final String sql;
+ private final Object[] params;
+
+ private SimpleStatementPopulator(String sql, Object... params) {
+ this.sql = sql;
+ this.params = params;
+ }
+
+ public PreparedStatement populateStatement(Connection connection) throws
+ SQLException {
+ PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ int index = 1;
+ for (Object param : params) {
+ preparedStatement.setObject(index++, param);
+ }
+ return preparedStatement;
+ }
+
+ }
+
+ class ServiceResultSetExtractor implements ResultSetExtractor<List<ServiceLocation>> {
+
+ public List<ServiceLocation> extractResultSet(ResultSet rs) throws SQLException {
+ List<ServiceLocation> serviceLocations = new ArrayList<ServiceLocation>();
+ while (rs.next()) {
+ ServiceLocation serviceLocation = new ServiceLocation();
+ serviceLocation.setServiceName(rs.getString("serviceName"));
+ serviceLocation.setServiceURL(rs.getString("url"));
+ serviceLocation.setSec(rs.getBoolean("sec"));
+ serviceLocations.add(serviceLocation);
+ }
+ return serviceLocations;
+ }
+
+ }
+
+ class OPSConfigResponseResultSetExtractor implements ResultSetExtractor<OPSConfigResponse> {
+ public OPSConfigResponse extractResultSet(ResultSet rs) throws SQLException {
+ OPSConfigResponse response = new OPSConfigResponse();
+ while (rs.next()) {
+ response.setDBName(rs.getString("dbname"));
+ response.setDBHostName(rs.getString("hostname"));
+ response.setDBPort(rs.getInt("port"));
+ }
+ return response;
+ }
+ }
+
+ class ClientConfigResponseResultSetExtractor implements ResultSetExtractor<ClientConfigResponse> {
+ public ClientConfigResponse extractResultSet(ResultSet rs) throws SQLException {
+ ClientConfigResponse response = new ClientConfigResponse();
+ while (rs.next()) {
+ response.setBSName(rs.getString("serviceName"));
+ response.setBS(rs.getString("url"));
+ response.setSec(rs.getBoolean("sec"));
+ }
+ return response;
+ }
+ }
+
+ class BSConfigResponseResultSetExtractor implements ResultSetExtractor<BSConfigResponse> {
+
+ public BSConfigResponse extractResultSet(ResultSet rs) throws SQLException {
+ BSConfigResponse response = new BSConfigResponse();
+ while (rs.next()) {
+ response.setOPSName(rs.getString("serviceName"));
+ response.setOPS(rs.getString("url"));
+ response.setSec(rs.getBoolean("sec"));
+ response.setDBName(rs.getString("dbname"));
+ response.setDBHostName(rs.getString("hostname"));
+ response.setDBPort(rs.getInt("port"));
+ }
+ return response;
+ }
+ }
+
+ private interface StatementPopulator {
+ public PreparedStatement populateStatement(Connection connection) throws SQLException;
+ }
+
+ private interface ResultSetExtractor<T> {
+ T extractResultSet(ResultSet rs) throws SQLException;
+ }
+
+ private Object executeQuery(StatementPopulator stPopulator, ResultSetExtractor rsExtractor) {
+ Object result = null;
+ ResultSet rs = null;
+ try {
+ PreparedStatement statement = stPopulator.populateStatement(connection);
+ rs = statement.executeQuery();
+ result = rsExtractor.extractResultSet(rs);
+ } catch (SQLException exception) {
+ logger.error(exception, exception);
+ }
+ finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ try {
+ if (connection != null && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ } catch (SQLException exception) {
+ logger.error(exception, exception);
+ }
+ }
+ return result;
+ }
+
+ interface TransactionCallback {
+ void executeTransaction(Connection connection) throws SQLException;
+ }
+
+ private boolean executeTransaction(TransactionCallback transactionCallback) {
+ try {
+ connection.setAutoCommit(false);
+
+ transactionCallback.executeTransaction(connection);
+
+ connection.commit();
+ return true;
+ } catch (SQLException e) {
+ try {
+ connection.rollback();
+ } catch (SQLException e1) {
+ e1.printStackTrace();
+ }
+ logger.error(e, e);
+ return false;
+ } finally {
+ try {
+ connection.setAutoCommit(true);
+ if (connection != null && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
Propchange: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConfigServiceDAOImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConnectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConnectionProvider.java?rev=958838&r1=958837&r2=958838&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConnectionProvider.java (original)
+++ incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConnectionProvider.java Tue Jun 29 06:33:54 2010
@@ -1,33 +1,33 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- package org.apache.stonehenge.stocktrader.dal;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Properties;
-
-public interface ConnectionProvider {
-
- String PROP_DB_HOST = "org.apache.stonehenge.stocktrader.database.host";
- String PROP_DB_PORT = "org.apache.stonehenge.stocktrader.database.port";
- String PROP_DB_NAME = "org.apache.stonehenge.stocktrader.database.db";
- String PROP_DB_USER = "org.apache.stonehenge.stocktrader.database.user";
- String PROP_DB_PASSWORD = "org.apache.stonehenge.stocktrader.database.password";
-
- Connection provide(Properties properties) throws SQLException;
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package org.apache.stonehenge.stocktrader.dal;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+public interface ConnectionProvider {
+
+ String PROP_DB_HOST = "org.apache.stonehenge.stocktrader.database.host";
+ String PROP_DB_PORT = "org.apache.stonehenge.stocktrader.database.port";
+ String PROP_DB_NAME = "org.apache.stonehenge.stocktrader.database.db";
+ String PROP_DB_USER = "org.apache.stonehenge.stocktrader.database.user";
+ String PROP_DB_PASSWORD = "org.apache.stonehenge.stocktrader.database.password";
+
+ Connection provide(Properties properties) throws SQLException;
+}
Propchange: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/ConnectionProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java?rev=958838&r1=958837&r2=958838&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java (original)
+++ incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java Tue Jun 29 06:33:54 2010
@@ -1,92 +1,92 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.stonehenge.stocktrader.dal;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stonehenge.stocktrader.mssql.MSSQLConnectionProvider;
-import org.apache.stonehenge.stocktrader.mysql.MySQLConnectionProvider;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Properties;
-
-public final class DAOFactory {
- private static final String PROP_DB_TYPE = "org.apache.stonehenge.stocktrader.database.type";
-
- private static Properties prop = null;
- private static ConnectionProvider connectionProvider;
- private static DAOFactory self;
- private ConfigServiceDAOImpl configServiceDAO;
-
- private DAOFactory() {
- configServiceDAO = new ConfigServiceDAOImpl();
- loadProperties();
- }
-
- public static DAOFactory getFacotry() {
- if (self == null) {
- self = new DAOFactory();
- }
- return self;
- }
-
- public ConfigServiceDAO getConfigServiceDAO() {
- if ("mysql".equals(prop.getProperty(PROP_DB_TYPE))) {
- connectionProvider = new MySQLConnectionProvider();
- } else if ("mssql".equals(prop.getProperty(PROP_DB_TYPE))) {
- connectionProvider = new MSSQLConnectionProvider();
- } else {
- throw new IllegalArgumentException("Unknown Database type " + prop.getProperty(PROP_DB_TYPE));
- }
- Connection connection;
- try {
- connection = connectionProvider.provide(prop);
- } catch (SQLException e) {
- e.printStackTrace();
- throw new RuntimeException(e.getMessage(), e);
- }
- configServiceDAO.setConnection(connection);
- return configServiceDAO;
- }
-
- private static void loadProperties() {
- Log logger = LogFactory.getLog(DAOFactory.class);
- if (prop == null) {
- prop = new Properties();
-
- InputStream is = DAOFactory.class.getClassLoader().getResourceAsStream("db.properties");
- if (is != null) {
- try {
- prop.load(is);
- } catch (IOException e) {
- logger.debug(
- "Unable to load mysql-db properties file and using [jdbc:mysql://localhost/stocktraderdb?user=trade&password=trade] as the default connection",
- e);
- }
- } else {
- logger.debug(
- "Unable to load mysql-db properties file and using [jdbc:mysql://localhost/stocktraderdb?user=trade&password=trade] as the default connection");
-
- }
- }
- }
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stonehenge.stocktrader.dal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stonehenge.stocktrader.mssql.MSSQLConnectionProvider;
+import org.apache.stonehenge.stocktrader.mysql.MySQLConnectionProvider;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+public final class DAOFactory {
+ private static final String PROP_DB_TYPE = "org.apache.stonehenge.stocktrader.database.type";
+
+ private static Properties prop = null;
+ private static ConnectionProvider connectionProvider;
+ private static DAOFactory self;
+ private ConfigServiceDAOImpl configServiceDAO;
+
+ private DAOFactory() {
+ configServiceDAO = new ConfigServiceDAOImpl();
+ loadProperties();
+ }
+
+ public static DAOFactory getFacotry() {
+ if (self == null) {
+ self = new DAOFactory();
+ }
+ return self;
+ }
+
+ public ConfigServiceDAO getConfigServiceDAO() {
+ if ("mysql".equals(prop.getProperty(PROP_DB_TYPE))) {
+ connectionProvider = new MySQLConnectionProvider();
+ } else if ("mssql".equals(prop.getProperty(PROP_DB_TYPE))) {
+ connectionProvider = new MSSQLConnectionProvider();
+ } else {
+ throw new IllegalArgumentException("Unknown Database type " + prop.getProperty(PROP_DB_TYPE));
+ }
+ Connection connection;
+ try {
+ connection = connectionProvider.provide(prop);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ configServiceDAO.setConnection(connection);
+ return configServiceDAO;
+ }
+
+ private static void loadProperties() {
+ Log logger = LogFactory.getLog(DAOFactory.class);
+ if (prop == null) {
+ prop = new Properties();
+
+ InputStream is = DAOFactory.class.getClassLoader().getResourceAsStream("db.properties");
+ if (is != null) {
+ try {
+ prop.load(is);
+ } catch (IOException e) {
+ logger.debug(
+ "Unable to load mysql-db properties file and using [jdbc:mysql://localhost/stocktraderdb?user=trade&password=trade] as the default connection",
+ e);
+ }
+ } else {
+ logger.debug(
+ "Unable to load mysql-db properties file and using [jdbc:mysql://localhost/stocktraderdb?user=trade&password=trade] as the default connection");
+
+ }
+ }
+ }
+
}
\ No newline at end of file
Propchange: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mssql/MSSQLConnectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mssql/MSSQLConnectionProvider.java?rev=958838&r1=958837&r2=958838&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mssql/MSSQLConnectionProvider.java (original)
+++ incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mssql/MSSQLConnectionProvider.java Tue Jun 29 06:33:54 2010
@@ -1,71 +1,71 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- package org.apache.stonehenge.stocktrader.mssql;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stonehenge.stocktrader.dal.ConnectionProvider;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Properties;
-
-public class MSSQLConnectionProvider implements ConnectionProvider {
- private static Log logger = LogFactory.getLog(MSSQLConnectionProvider.class);
- private Connection sqlConnection = null;
- private String connection = null;
-
- static {
- try {
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- logger.warn("Unable to load DBDrive class", e);
- }
- }
-
- private String getConnectionString(Properties prop) {
- if (connection == null) {
- if (prop == null) {
- connection = "jdbc:jtds:sqlserver://highlander:1433/StockTraderDB;user=trade;password=trade";
- } else {
- StringBuffer buf = new StringBuffer();
- buf.append("jdbc:jtds:sqlserver://");
- buf.append(prop.getProperty(PROP_DB_HOST));
- buf.append(":" + prop.getProperty(PROP_DB_PORT));
- buf.append("/" + prop.getProperty(PROP_DB_NAME));
- buf.append(";user=" + prop.getProperty(PROP_DB_USER));
- buf.append(";password=" + prop.getProperty(PROP_DB_PASSWORD));
- buf.append(";");
- connection = buf.toString();
- }
- }
- if (logger.isDebugEnabled()) {
- logger.debug("MSSQLDAOFactory.getConnectionString()\nConnection :" + connection);
- }
-
- return connection;
- }
-
- public Connection provide(Properties properties) throws SQLException {
- if (sqlConnection == null || sqlConnection.isClosed()) {
- sqlConnection = DriverManager.getConnection(getConnectionString(properties));
- }
- return sqlConnection;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package org.apache.stonehenge.stocktrader.mssql;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stonehenge.stocktrader.dal.ConnectionProvider;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+
+public class MSSQLConnectionProvider implements ConnectionProvider {
+ private static Log logger = LogFactory.getLog(MSSQLConnectionProvider.class);
+ private Connection sqlConnection = null;
+ private String connection = null;
+
+ static {
+ try {
+ Class.forName("net.sourceforge.jtds.jdbc.Driver");
+ } catch (ClassNotFoundException e) {
+ logger.warn("Unable to load DBDrive class", e);
+ }
+ }
+
+ private String getConnectionString(Properties prop) {
+ if (connection == null) {
+ if (prop == null) {
+ connection = "jdbc:jtds:sqlserver://highlander:1433/StockTraderDB;user=trade;password=trade";
+ } else {
+ StringBuffer buf = new StringBuffer();
+ buf.append("jdbc:jtds:sqlserver://");
+ buf.append(prop.getProperty(PROP_DB_HOST));
+ buf.append(":" + prop.getProperty(PROP_DB_PORT));
+ buf.append("/" + prop.getProperty(PROP_DB_NAME));
+ buf.append(";user=" + prop.getProperty(PROP_DB_USER));
+ buf.append(";password=" + prop.getProperty(PROP_DB_PASSWORD));
+ buf.append(";");
+ connection = buf.toString();
+ }
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("MSSQLDAOFactory.getConnectionString()\nConnection :" + connection);
+ }
+
+ return connection;
+ }
+
+ public Connection provide(Properties properties) throws SQLException {
+ if (sqlConnection == null || sqlConnection.isClosed()) {
+ sqlConnection = DriverManager.getConnection(getConnectionString(properties));
+ }
+ return sqlConnection;
+ }
+}
Propchange: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mssql/MSSQLConnectionProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mysql/MySQLConnectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mysql/MySQLConnectionProvider.java?rev=958838&r1=958837&r2=958838&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mysql/MySQLConnectionProvider.java (original)
+++ incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mysql/MySQLConnectionProvider.java Tue Jun 29 06:33:54 2010
@@ -1,71 +1,71 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- package org.apache.stonehenge.stocktrader.mysql;
-
-import org.apache.stonehenge.stocktrader.dal.ConnectionProvider;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.DriverManager;
-import java.util.Properties;
-
-public class MySQLConnectionProvider implements ConnectionProvider{
-
- private static Log logger = LogFactory.getLog(MySQLConnectionProvider.class);
- private Connection sqlConnection = null;
- private String connection = null;
-
- static {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- logger.warn("Unable to load DBDrive class", e);
- }
- }
-
- private String getConnectionString(Properties prop) {
- if (connection == null) {
- if (prop == null || prop.size()<=0) {
- connection = "jdbc:mysql://localhost:3306/stocktraderdb?user=trade&password=yyy";
- } else {
- StringBuffer buf = new StringBuffer();
- buf.append("jdbc:mysql://");
- buf.append(prop.getProperty(PROP_DB_HOST));
- buf.append(":" + prop.getProperty(PROP_DB_PORT));
- buf.append("/" + prop.getProperty(PROP_DB_NAME));
- buf.append("?user=" + prop.getProperty(PROP_DB_USER));
- buf.append("&password=" + prop.getProperty(PROP_DB_PASSWORD));
- connection = buf.toString();
- }
- }
-
- if (logger.isDebugEnabled()) {
- logger.debug("MySQLDAOFactory.getConnectionString()\nConnection :" + connection);
- }
- return connection;
- }
-
- public Connection provide(Properties prop) throws SQLException {
- if (sqlConnection == null || sqlConnection.isClosed()) {
- sqlConnection = DriverManager.getConnection(getConnectionString(prop));
- }
- return sqlConnection;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package org.apache.stonehenge.stocktrader.mysql;
+
+import org.apache.stonehenge.stocktrader.dal.ConnectionProvider;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.DriverManager;
+import java.util.Properties;
+
+public class MySQLConnectionProvider implements ConnectionProvider{
+
+ private static Log logger = LogFactory.getLog(MySQLConnectionProvider.class);
+ private Connection sqlConnection = null;
+ private String connection = null;
+
+ static {
+ try {
+ Class.forName("com.mysql.jdbc.Driver");
+ } catch (ClassNotFoundException e) {
+ logger.warn("Unable to load DBDrive class", e);
+ }
+ }
+
+ private String getConnectionString(Properties prop) {
+ if (connection == null) {
+ if (prop == null || prop.size()<=0) {
+ connection = "jdbc:mysql://localhost:3306/stocktraderdb?user=trade&password=yyy";
+ } else {
+ StringBuffer buf = new StringBuffer();
+ buf.append("jdbc:mysql://");
+ buf.append(prop.getProperty(PROP_DB_HOST));
+ buf.append(":" + prop.getProperty(PROP_DB_PORT));
+ buf.append("/" + prop.getProperty(PROP_DB_NAME));
+ buf.append("?user=" + prop.getProperty(PROP_DB_USER));
+ buf.append("&password=" + prop.getProperty(PROP_DB_PASSWORD));
+ connection = buf.toString();
+ }
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("MySQLDAOFactory.getConnectionString()\nConnection :" + connection);
+ }
+ return connection;
+ }
+
+ public Connection provide(Properties prop) throws SQLException {
+ if (sqlConnection == null || sqlConnection.isClosed()) {
+ sqlConnection = DriverManager.getConnection(getConnectionString(prop));
+ }
+ return sqlConnection;
+ }
+}
Propchange: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/mysql/MySQLConnectionProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/services/ConfigServiceServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/services/ConfigServiceServiceImpl.java?rev=958838&r1=958837&r2=958838&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/services/ConfigServiceServiceImpl.java (original)
+++ incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/services/ConfigServiceServiceImpl.java Tue Jun 29 06:33:54 2010
@@ -1,123 +1,123 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- package org.apache.stonehenge.stocktrader.services;
-
-import org.apache.stonehenge.stocktrader.dal.ConfigServiceDAO;
-import org.apache.stonehenge.stocktrader.dal.DAOFactory;
-import org.datacontract.schemas._2004._07.trade.*;
-import org.tempuri.ConfigServiceService;
-import traderconfighost.trade.*;
-
-import javax.jws.WebParam;
-import javax.jws.WebService;
-import java.util.List;
-
-@WebService(endpointInterface = "org.tempuri.ConfigServiceService")
-public class ConfigServiceServiceImpl implements ConfigServiceService {
- private final DAOFactory facotry;
-
- public ConfigServiceServiceImpl() {
- facotry = DAOFactory.getFacotry();
- }
-
- public ConfigServiceDAO getConfigServiceDAO() {
- return facotry.getConfigServiceDAO();
- }
-
- public GetClientConfigResponse getClientConfig(
- @WebParam(name = "GetClientConfig", targetNamespace = "http://Trade.TraderConfigHost",
- partName = "parameters") GetClientConfig getClientConfig) {
- GetClientConfigResponse clientConfigResponse = new GetClientConfigResponse();
- String clientName = getClientConfig.getClient().getClientName();
- ClientConfigResponse config = getConfigServiceDAO().getClientConfig(clientName);
- clientConfigResponse.setGetClientConfigResult(config);
- return clientConfigResponse;
- }
-
- public GetBSConfigResponse getBSConfig(
- @WebParam(name = "GetBSConfig", targetNamespace = "http://Trade.TraderConfigHost",
- partName = "parameters") GetBSConfig getBSConfig) {
- GetBSConfigResponse bsConfigResponse = new GetBSConfigResponse();
- BSConfigResponse configResponse = getConfigServiceDAO().getBSConfig(getBSConfig.getBs().getBSName());
- bsConfigResponse.setGetBSConfigResult(configResponse);
- return bsConfigResponse;
- }
-
- public GetOPSConfigResponse getOPSConfig(
- @WebParam(name = "GetOPSConfig", targetNamespace = "http://Trade.TraderConfigHost", partName =
- "parameters") GetOPSConfig parameters) {
- OPSConfigResponse opsConfigResponse = getConfigServiceDAO().getOPSConfig(parameters.getOps().getOPSName());
- GetOPSConfigResponse getOPSConfigResponse = new GetOPSConfigResponse();
- getOPSConfigResponse.setGetOPSConfigResult(opsConfigResponse);
- return getOPSConfigResponse;
- }
-
- public SetClientToBSResponse setClientToBS(
- @WebParam(name = "SetClientToBS", targetNamespace = "http://Trade.TraderConfigHost",
- partName = "parameters") SetClientToBS setClientToBS) {
- ClientToBS clientConfig = setClientToBS.getClientConfig();
- if (getConfigServiceDAO().setClientToBS(clientConfig.getClient(), clientConfig.getBs())) {
- return new SetClientToBSResponse();
- }
- return null;
- }
-
- public SetBSToOPSResponse setBSToOPS(
- @WebParam(name = "SetBSToOPS", targetNamespace = "http://Trade.TraderConfigHost",
- partName = "parameters") SetBSToOPS setBSToOPS) {
- BSToOPS bsConfig = setBSToOPS.getBsConfig();
- if (getConfigServiceDAO().setBSToOPS(bsConfig.getBs(), bsConfig.getOps())) {
- return new SetBSToOPSResponse();
- }
- return null;
- }
-
- public GetBSLocationsResponse getBSLocations(
- @WebParam(name = "GetBSLocations", targetNamespace = "http://Trade.TraderConfigHost",
- partName = "parameters") GetBSLocations getBSLocations) {
- final List<ServiceLocation> serviceLocations = getConfigServiceDAO().getBSLocations();
- GetBSLocationsResponse getBSLocationsResponse = new GetBSLocationsResponse();
- ArrayOfServiceLocation arrayOfServiceLocation = new ArrayOfServiceLocation();
- arrayOfServiceLocation.getServiceLocation().addAll(serviceLocations);
- getBSLocationsResponse.setGetBSLocationsResult(arrayOfServiceLocation);
- return getBSLocationsResponse;
- }
-
- public GetOPSLocationsResponse getOPSLocations(
- @WebParam(name = "GetOPSLocations", targetNamespace = "http://Trade.TraderConfigHost",
- partName = "parameters") GetOPSLocations getOPSLocations) {
- List<ServiceLocation> serviceLocations = getConfigServiceDAO().getOPSLocations();
- GetOPSLocationsResponse response = new GetOPSLocationsResponse();
- ArrayOfServiceLocation arrayOfServiceLocation = new ArrayOfServiceLocation();
- arrayOfServiceLocation.getServiceLocation().addAll(serviceLocations);
- response.setGetOPSLocationsResult(arrayOfServiceLocation);
- return response;
- }
-
- public SetServiceLocationResponse setServiceLocation(
- @WebParam(name = "SetServiceLocation", targetNamespace = "http://Trade.TraderConfigHost", partName =
- "parameters") SetServiceLocation parameters) {
- String serviceName = parameters.getLocation().getServiceName();
- String serviceUrl = parameters.getLocation().getServiceURL();
- Boolean isSec = parameters.getLocation().isSec();
- if (getConfigServiceDAO().setServiceLocation(serviceName, serviceUrl, isSec)) {
- return new SetServiceLocationResponse();
- }
- return null;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package org.apache.stonehenge.stocktrader.services;
+
+import org.apache.stonehenge.stocktrader.dal.ConfigServiceDAO;
+import org.apache.stonehenge.stocktrader.dal.DAOFactory;
+import org.datacontract.schemas._2004._07.trade.*;
+import org.tempuri.ConfigServiceService;
+import traderconfighost.trade.*;
+
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import java.util.List;
+
+@WebService(endpointInterface = "org.tempuri.ConfigServiceService")
+public class ConfigServiceServiceImpl implements ConfigServiceService {
+ private final DAOFactory facotry;
+
+ public ConfigServiceServiceImpl() {
+ facotry = DAOFactory.getFacotry();
+ }
+
+ public ConfigServiceDAO getConfigServiceDAO() {
+ return facotry.getConfigServiceDAO();
+ }
+
+ public GetClientConfigResponse getClientConfig(
+ @WebParam(name = "GetClientConfig", targetNamespace = "http://Trade.TraderConfigHost",
+ partName = "parameters") GetClientConfig getClientConfig) {
+ GetClientConfigResponse clientConfigResponse = new GetClientConfigResponse();
+ String clientName = getClientConfig.getClient().getClientName();
+ ClientConfigResponse config = getConfigServiceDAO().getClientConfig(clientName);
+ clientConfigResponse.setGetClientConfigResult(config);
+ return clientConfigResponse;
+ }
+
+ public GetBSConfigResponse getBSConfig(
+ @WebParam(name = "GetBSConfig", targetNamespace = "http://Trade.TraderConfigHost",
+ partName = "parameters") GetBSConfig getBSConfig) {
+ GetBSConfigResponse bsConfigResponse = new GetBSConfigResponse();
+ BSConfigResponse configResponse = getConfigServiceDAO().getBSConfig(getBSConfig.getBs().getBSName());
+ bsConfigResponse.setGetBSConfigResult(configResponse);
+ return bsConfigResponse;
+ }
+
+ public GetOPSConfigResponse getOPSConfig(
+ @WebParam(name = "GetOPSConfig", targetNamespace = "http://Trade.TraderConfigHost", partName =
+ "parameters") GetOPSConfig parameters) {
+ OPSConfigResponse opsConfigResponse = getConfigServiceDAO().getOPSConfig(parameters.getOps().getOPSName());
+ GetOPSConfigResponse getOPSConfigResponse = new GetOPSConfigResponse();
+ getOPSConfigResponse.setGetOPSConfigResult(opsConfigResponse);
+ return getOPSConfigResponse;
+ }
+
+ public SetClientToBSResponse setClientToBS(
+ @WebParam(name = "SetClientToBS", targetNamespace = "http://Trade.TraderConfigHost",
+ partName = "parameters") SetClientToBS setClientToBS) {
+ ClientToBS clientConfig = setClientToBS.getClientConfig();
+ if (getConfigServiceDAO().setClientToBS(clientConfig.getClient(), clientConfig.getBs())) {
+ return new SetClientToBSResponse();
+ }
+ return null;
+ }
+
+ public SetBSToOPSResponse setBSToOPS(
+ @WebParam(name = "SetBSToOPS", targetNamespace = "http://Trade.TraderConfigHost",
+ partName = "parameters") SetBSToOPS setBSToOPS) {
+ BSToOPS bsConfig = setBSToOPS.getBsConfig();
+ if (getConfigServiceDAO().setBSToOPS(bsConfig.getBs(), bsConfig.getOps())) {
+ return new SetBSToOPSResponse();
+ }
+ return null;
+ }
+
+ public GetBSLocationsResponse getBSLocations(
+ @WebParam(name = "GetBSLocations", targetNamespace = "http://Trade.TraderConfigHost",
+ partName = "parameters") GetBSLocations getBSLocations) {
+ final List<ServiceLocation> serviceLocations = getConfigServiceDAO().getBSLocations();
+ GetBSLocationsResponse getBSLocationsResponse = new GetBSLocationsResponse();
+ ArrayOfServiceLocation arrayOfServiceLocation = new ArrayOfServiceLocation();
+ arrayOfServiceLocation.getServiceLocation().addAll(serviceLocations);
+ getBSLocationsResponse.setGetBSLocationsResult(arrayOfServiceLocation);
+ return getBSLocationsResponse;
+ }
+
+ public GetOPSLocationsResponse getOPSLocations(
+ @WebParam(name = "GetOPSLocations", targetNamespace = "http://Trade.TraderConfigHost",
+ partName = "parameters") GetOPSLocations getOPSLocations) {
+ List<ServiceLocation> serviceLocations = getConfigServiceDAO().getOPSLocations();
+ GetOPSLocationsResponse response = new GetOPSLocationsResponse();
+ ArrayOfServiceLocation arrayOfServiceLocation = new ArrayOfServiceLocation();
+ arrayOfServiceLocation.getServiceLocation().addAll(serviceLocations);
+ response.setGetOPSLocationsResult(arrayOfServiceLocation);
+ return response;
+ }
+
+ public SetServiceLocationResponse setServiceLocation(
+ @WebParam(name = "SetServiceLocation", targetNamespace = "http://Trade.TraderConfigHost", partName =
+ "parameters") SetServiceLocation parameters) {
+ String serviceName = parameters.getLocation().getServiceName();
+ String serviceUrl = parameters.getLocation().getServiceURL();
+ Boolean isSec = parameters.getLocation().isSec();
+ if (getConfigServiceDAO().setServiceLocation(serviceName, serviceUrl, isSec)) {
+ return new SetServiceLocationResponse();
+ }
+ return null;
+ }
+}
Propchange: incubator/stonehenge/trunk/stocktrader/metro/config_service/src/org/apache/stonehenge/stocktrader/services/ConfigServiceServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/stonehenge/trunk/stocktrader/metro/config_service/test/org/apache/stonehenge/stocktrader/mssql/ConfigServiceDAOImplTest.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/metro/config_service/test/org/apache/stonehenge/stocktrader/mssql/ConfigServiceDAOImplTest.java?rev=958838&r1=958837&r2=958838&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/metro/config_service/test/org/apache/stonehenge/stocktrader/mssql/ConfigServiceDAOImplTest.java (original)
+++ incubator/stonehenge/trunk/stocktrader/metro/config_service/test/org/apache/stonehenge/stocktrader/mssql/ConfigServiceDAOImplTest.java Tue Jun 29 06:33:54 2010
@@ -1,103 +1,103 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- package org.apache.stonehenge.stocktrader.mssql;
-
-import org.apache.stonehenge.stocktrader.dal.ConfigServiceDAO;
-import org.apache.stonehenge.stocktrader.dal.DAOFactory;
-import org.datacontract.schemas._2004._07.trade.BSConfigResponse;
-import org.datacontract.schemas._2004._07.trade.ClientConfigResponse;
-import org.datacontract.schemas._2004._07.trade.ServiceLocation;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assume.assumeThat;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.List;
-
-public class ConfigServiceDAOImplTest {
- private DAOFactory facotry;
-
- public ConfigServiceDAO getConfigServiceDAO() {
- return facotry.getConfigServiceDAO();
- }
-
- @Before
- public void before() {
- facotry = DAOFactory.getFacotry();
- }
-
- @Test
- public void should_update_client_to_bs_when_entry_already_exists() {
- assumeThat(getConfigServiceDAO().getClientConfig("JAVA_CLIENT"), notNullValue());
- getConfigServiceDAO().setClientToBS("JAVA_CLIENT", "JAVA_BS");
- ClientConfigResponse response = getConfigServiceDAO().getClientConfig("JAVA_CLIENT");
- assertThat(response.getBSName(), equalTo("JAVA_BS"));
- }
-
- @Test
- public void should_insert_value_into_client_to_bs_when_entry_doesnot_exists() {
- assumeThat(getConfigServiceDAO().getClientConfig("RUBY_CLIENT").getBSName(), nullValue());
- getConfigServiceDAO().setClientToBS("RUBY_CLIENT", "JAVA_BS");
- ClientConfigResponse response = getConfigServiceDAO().getClientConfig("RUBY_CLIENT");
- assertThat(response.getBSName(), equalTo("JAVA_BS"));
- }
-
- @Test
- public void should_update_bs_to_ops_when_entry_already_exists() {
- assumeThat(getConfigServiceDAO().getBSConfig("JAVA_BS"), notNullValue());
- getConfigServiceDAO().setBSToOPS("JAVA_BS", "PHP_OPS");
- BSConfigResponse response = getConfigServiceDAO().getBSConfig("JAVA_BS");
- assertThat(response.getOPSName(), equalTo("PHP_OPS"));
- }
-
- @Test
- public void should_update_bs_to_ops_when_entry_doesnot_exists() {
- assumeThat(getConfigServiceDAO().getBSConfig("PHP_BS"), nullValue());
- getConfigServiceDAO().setBSToOPS("PHP_BS", "PHP_OPS");
- BSConfigResponse response = getConfigServiceDAO().getBSConfig("PHP_BS");
- assertThat(response.getOPSName(), equalTo("PHP_OPS"));
- }
-
- @Test
- public void should_update_bs_service() {
- getConfigServiceDAO().setBSToOPS("RUBY_BS", "RUBY_OPS");
- String serviceName = "RUBY_OPS";
- String serviceUrl = "http://localhost/ruby";
- getConfigServiceDAO().setServiceLocation(serviceName, serviceUrl, true);
- BSConfigResponse response = getConfigServiceDAO().getBSConfig("RUBY_BS");
- assertThat(response.getOPS(), equalTo(serviceUrl));
- assertThat(response.getOPSName(), equalTo(serviceName));
- assertThat(response.isSec(), equalTo(true));
- }
-
- @Test
- public void should_insert_values_into_service() {
- getConfigServiceDAO().setBSToOPS("AA_BS", "AA_OPS");
- String serviceName = "AA_OPS";
- String serviceUrl = "http://localhost/AA_OPS";
- getConfigServiceDAO().setServiceLocation(serviceName, serviceUrl, false);
- BSConfigResponse response = getConfigServiceDAO().getBSConfig("AA_BS");
- assertThat(response.getOPS(), equalTo(serviceUrl));
- assertThat(response.getOPSName(), equalTo(serviceName));
- assertThat(response.isSec(), equalTo(false));
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package org.apache.stonehenge.stocktrader.mssql;
+
+import org.apache.stonehenge.stocktrader.dal.ConfigServiceDAO;
+import org.apache.stonehenge.stocktrader.dal.DAOFactory;
+import org.datacontract.schemas._2004._07.trade.BSConfigResponse;
+import org.datacontract.schemas._2004._07.trade.ClientConfigResponse;
+import org.datacontract.schemas._2004._07.trade.ServiceLocation;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+
+public class ConfigServiceDAOImplTest {
+ private DAOFactory facotry;
+
+ public ConfigServiceDAO getConfigServiceDAO() {
+ return facotry.getConfigServiceDAO();
+ }
+
+ @Before
+ public void before() {
+ facotry = DAOFactory.getFacotry();
+ }
+
+ @Test
+ public void should_update_client_to_bs_when_entry_already_exists() {
+ assumeThat(getConfigServiceDAO().getClientConfig("JAVA_CLIENT"), notNullValue());
+ getConfigServiceDAO().setClientToBS("JAVA_CLIENT", "JAVA_BS");
+ ClientConfigResponse response = getConfigServiceDAO().getClientConfig("JAVA_CLIENT");
+ assertThat(response.getBSName(), equalTo("JAVA_BS"));
+ }
+
+ @Test
+ public void should_insert_value_into_client_to_bs_when_entry_doesnot_exists() {
+ assumeThat(getConfigServiceDAO().getClientConfig("RUBY_CLIENT").getBSName(), nullValue());
+ getConfigServiceDAO().setClientToBS("RUBY_CLIENT", "JAVA_BS");
+ ClientConfigResponse response = getConfigServiceDAO().getClientConfig("RUBY_CLIENT");
+ assertThat(response.getBSName(), equalTo("JAVA_BS"));
+ }
+
+ @Test
+ public void should_update_bs_to_ops_when_entry_already_exists() {
+ assumeThat(getConfigServiceDAO().getBSConfig("JAVA_BS"), notNullValue());
+ getConfigServiceDAO().setBSToOPS("JAVA_BS", "PHP_OPS");
+ BSConfigResponse response = getConfigServiceDAO().getBSConfig("JAVA_BS");
+ assertThat(response.getOPSName(), equalTo("PHP_OPS"));
+ }
+
+ @Test
+ public void should_update_bs_to_ops_when_entry_doesnot_exists() {
+ assumeThat(getConfigServiceDAO().getBSConfig("PHP_BS"), nullValue());
+ getConfigServiceDAO().setBSToOPS("PHP_BS", "PHP_OPS");
+ BSConfigResponse response = getConfigServiceDAO().getBSConfig("PHP_BS");
+ assertThat(response.getOPSName(), equalTo("PHP_OPS"));
+ }
+
+ @Test
+ public void should_update_bs_service() {
+ getConfigServiceDAO().setBSToOPS("RUBY_BS", "RUBY_OPS");
+ String serviceName = "RUBY_OPS";
+ String serviceUrl = "http://localhost/ruby";
+ getConfigServiceDAO().setServiceLocation(serviceName, serviceUrl, true);
+ BSConfigResponse response = getConfigServiceDAO().getBSConfig("RUBY_BS");
+ assertThat(response.getOPS(), equalTo(serviceUrl));
+ assertThat(response.getOPSName(), equalTo(serviceName));
+ assertThat(response.isSec(), equalTo(true));
+ }
+
+ @Test
+ public void should_insert_values_into_service() {
+ getConfigServiceDAO().setBSToOPS("AA_BS", "AA_OPS");
+ String serviceName = "AA_OPS";
+ String serviceUrl = "http://localhost/AA_OPS";
+ getConfigServiceDAO().setServiceLocation(serviceName, serviceUrl, false);
+ BSConfigResponse response = getConfigServiceDAO().getBSConfig("AA_BS");
+ assertThat(response.getOPS(), equalTo(serviceUrl));
+ assertThat(response.getOPSName(), equalTo(serviceName));
+ assertThat(response.isSec(), equalTo(false));
+ }
+}
+
Propchange: incubator/stonehenge/trunk/stocktrader/metro/config_service/test/org/apache/stonehenge/stocktrader/mssql/ConfigServiceDAOImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/stonehenge/trunk/stocktrader/metro/etc/active_sts/sts_schema.xsd
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/metro/etc/active_sts/sts_schema.xsd?rev=958838&r1=958837&r2=958838&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/metro/etc/active_sts/sts_schema.xsd (original)
+++ incubator/stonehenge/trunk/stocktrader/metro/etc/active_sts/sts_schema.xsd Tue Jun 29 06:33:54 2010
@@ -1,29 +1,29 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
--->
-
-<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.message.com/Message"
-xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.message.com/Message">
- <xs:complexType name="MessageBody">
- <xs:sequence>
- <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any"/>
- </xs:sequence>
- </xs:complexType>
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+-->
+
+<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.message.com/Message"
+xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.message.com/Message">
+ <xs:complexType name="MessageBody">
+ <xs:sequence>
+ <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any"/>
+ </xs:sequence>
+ </xs:complexType>
</xs:schema>
\ No newline at end of file
Propchange: incubator/stonehenge/trunk/stocktrader/metro/etc/active_sts/sts_schema.xsd
------------------------------------------------------------------------------
svn:eol-style = native