You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by zo...@apache.org on 2011/02/27 19:28:41 UTC
svn commit: r1075106 [3/18] - in /aries/tags/samples-0.1-incubating: ./
ariestrader/ ariestrader/assemblies/
ariestrader/assemblies/ariestrader-all-eba/
ariestrader/assemblies/ariestrader-jdbc-eba/
ariestrader/assemblies/equinox-test-harness/ ariestrad...
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-api/src/main/java/org/apache/aries/samples/ariestrader/api/persistence/QuoteDataBean.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-api/src/main/java/org/apache/aries/samples/ariestrader/api/persistence/QuoteDataBean.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-api/src/main/java/org/apache/aries/samples/ariestrader/api/persistence/QuoteDataBean.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-api/src/main/java/org/apache/aries/samples/ariestrader/api/persistence/QuoteDataBean.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,59 @@
+/**
+ * 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.aries.samples.ariestrader.api.persistence;
+
+import java.math.BigDecimal;
+
+public interface QuoteDataBean {
+
+ public String toString();
+
+ public String toHTML();
+
+ public String getSymbol();
+
+ public void setSymbol(String symbol);
+
+ public String getCompanyName();
+
+ public void setCompanyName(String companyName);
+
+ public BigDecimal getPrice();
+
+ public void setPrice(BigDecimal price);
+
+ public BigDecimal getOpen();
+
+ public void setOpen(BigDecimal open);
+
+ public BigDecimal getLow();
+
+ public void setLow(BigDecimal low);
+
+ public BigDecimal getHigh();
+
+ public void setHigh(BigDecimal high);
+
+ public double getChange();
+
+ public void setChange(double change);
+
+ public double getVolume();
+
+ public void setVolume(double volume);
+
+}
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-api/src/main/java/org/apache/aries/samples/ariestrader/api/persistence/RunStatsDataBean.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-api/src/main/java/org/apache/aries/samples/ariestrader/api/persistence/RunStatsDataBean.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-api/src/main/java/org/apache/aries/samples/ariestrader/api/persistence/RunStatsDataBean.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-api/src/main/java/org/apache/aries/samples/ariestrader/api/persistence/RunStatsDataBean.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,255 @@
+/**
+ * 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.aries.samples.ariestrader.api.persistence;
+
+
+import java.io.Serializable;
+
+public class RunStatsDataBean implements Serializable
+{
+ //Constructors
+ public RunStatsDataBean(){ }
+
+ // count of trade users in the database (users w/ userID like 'uid:%')
+ private int tradeUserCount;
+ // count of trade stocks in the database (stocks w/ symbol like 's:%')
+ private int tradeStockCount;
+
+ // count of new registered users in this run (users w/ userID like 'ru:%') -- random user
+ private int newUserCount;
+
+ // sum of logins by trade users
+ private int sumLoginCount;
+ // sum of logouts by trade users
+ private int sumLogoutCount;
+
+ // count of holdings of trade users
+ private int holdingCount;
+
+ // count of orders of trade users
+ private int orderCount;
+ // count of buy orders of trade users
+ private int buyOrderCount;
+ // count of sell orders of trade users
+ private int sellOrderCount;
+ // count of canceled orders of trade users
+ private int cancelledOrderCount;
+ // count of open orders of trade users
+ private int openOrderCount;
+ // count of orders deleted during this trade Reset
+ private int deletedOrderCount;
+
+ public String toString()
+ {
+ return "\n\tRunStatsData for reset at " + new java.util.Date()
+ + "\n\t\t tradeUserCount: " + getTradeUserCount()
+ + "\n\t\t newUserCount: " + getNewUserCount()
+ + "\n\t\t sumLoginCount: " + getSumLoginCount()
+ + "\n\t\t sumLogoutCount: " + getSumLogoutCount()
+ + "\n\t\t holdingCount: " + getHoldingCount()
+ + "\n\t\t orderCount: " + getOrderCount()
+ + "\n\t\t buyOrderCount: " + getBuyOrderCount()
+ + "\n\t\t sellOrderCount: " + getSellOrderCount()
+ + "\n\t\t cancelledOrderCount: " + getCancelledOrderCount()
+ + "\n\t\t openOrderCount: " + getOpenOrderCount()
+ + "\n\t\t deletedOrderCount: " + getDeletedOrderCount()
+ ;
+ }
+
+
+ /**
+ * Gets the tradeUserCount
+ * @return Returns a int
+ */
+ public int getTradeUserCount() {
+ return tradeUserCount;
+ }
+ /**
+ * Sets the tradeUserCount
+ * @param tradeUserCount The tradeUserCount to set
+ */
+ public void setTradeUserCount(int tradeUserCount) {
+ this.tradeUserCount = tradeUserCount;
+ }
+
+ /**
+ * Gets the newUserCount
+ * @return Returns a int
+ */
+ public int getNewUserCount() {
+ return newUserCount;
+ }
+ /**
+ * Sets the newUserCount
+ * @param newUserCount The newUserCount to set
+ */
+ public void setNewUserCount(int newUserCount) {
+ this.newUserCount = newUserCount;
+ }
+
+ /**
+ * Gets the sumLoginCount
+ * @return Returns a int
+ */
+ public int getSumLoginCount() {
+ return sumLoginCount;
+ }
+ /**
+ * Sets the sumLoginCount
+ * @param sumLoginCount The sumLoginCount to set
+ */
+ public void setSumLoginCount(int sumLoginCount) {
+ this.sumLoginCount = sumLoginCount;
+ }
+
+ /**
+ * Gets the sumLogoutCount
+ * @return Returns a int
+ */
+ public int getSumLogoutCount() {
+ return sumLogoutCount;
+ }
+ /**
+ * Sets the sumLogoutCount
+ * @param sumLogoutCount The sumLogoutCount to set
+ */
+ public void setSumLogoutCount(int sumLogoutCount) {
+ this.sumLogoutCount = sumLogoutCount;
+ }
+
+ /**
+ * Gets the holdingCount
+ * @return Returns a int
+ */
+ public int getHoldingCount() {
+ return holdingCount;
+ }
+ /**
+ * Sets the holdingCount
+ * @param holdingCount The holdingCount to set
+ */
+ public void setHoldingCount(int holdingCount) {
+ this.holdingCount = holdingCount;
+ }
+
+ /**
+ * Gets the buyOrderCount
+ * @return Returns a int
+ */
+ public int getBuyOrderCount() {
+ return buyOrderCount;
+ }
+ /**
+ * Sets the buyOrderCount
+ * @param buyOrderCount The buyOrderCount to set
+ */
+ public void setBuyOrderCount(int buyOrderCount) {
+ this.buyOrderCount = buyOrderCount;
+ }
+
+ /**
+ * Gets the sellOrderCount
+ * @return Returns a int
+ */
+ public int getSellOrderCount() {
+ return sellOrderCount;
+ }
+ /**
+ * Sets the sellOrderCount
+ * @param sellOrderCount The sellOrderCount to set
+ */
+ public void setSellOrderCount(int sellOrderCount) {
+ this.sellOrderCount = sellOrderCount;
+ }
+
+ /**
+ * Gets the cancelledOrderCount
+ * @return Returns a int
+ */
+ public int getCancelledOrderCount() {
+ return cancelledOrderCount;
+ }
+ /**
+ * Sets the cancelledOrderCount
+ * @param cancelledOrderCount The cancelledOrderCount to set
+ */
+ public void setCancelledOrderCount(int cancelledOrderCount) {
+ this.cancelledOrderCount = cancelledOrderCount;
+ }
+
+ /**
+ * Gets the openOrderCount
+ * @return Returns a int
+ */
+ public int getOpenOrderCount() {
+ return openOrderCount;
+ }
+ /**
+ * Sets the openOrderCount
+ * @param openOrderCount The openOrderCount to set
+ */
+ public void setOpenOrderCount(int openOrderCount) {
+ this.openOrderCount = openOrderCount;
+ }
+
+ /**
+ * Gets the deletedOrderCount
+ * @return Returns a int
+ */
+ public int getDeletedOrderCount() {
+ return deletedOrderCount;
+ }
+ /**
+ * Sets the deletedOrderCount
+ * @param deletedOrderCount The deletedOrderCount to set
+ */
+ public void setDeletedOrderCount(int deletedOrderCount) {
+ this.deletedOrderCount = deletedOrderCount;
+ }
+
+ /**
+ * Gets the orderCount
+ * @return Returns a int
+ */
+ public int getOrderCount() {
+ return orderCount;
+ }
+ /**
+ * Sets the orderCount
+ * @param orderCount The orderCount to set
+ */
+ public void setOrderCount(int orderCount) {
+ this.orderCount = orderCount;
+ }
+
+ /**
+ * Gets the tradeStockCount
+ * @return Returns a int
+ */
+ public int getTradeStockCount() {
+ return tradeStockCount;
+ }
+ /**
+ * Sets the tradeStockCount
+ * @param tradeStockCount The tradeStockCount to set
+ */
+ public void setTradeStockCount(int tradeStockCount) {
+ this.tradeStockCount = tradeStockCount;
+ }
+
+}
+
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/pom.xml?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/pom.xml (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/pom.xml Sun Feb 27 18:28:26 2011
@@ -0,0 +1,62 @@
+<?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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>modules</artifactId>
+ <version>0.1-incubating</version>
+ </parent>
+
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>org.apache.aries.samples.ariestrader.beans</artifactId>
+ <packaging>bundle</packaging>
+ <name>AriesTrader :: Modules - Beans</name>
+ <description>AriesTrader UnEnhanced Enttities Module</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>org.apache.aries.samples.ariestrader.api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>org.apache.aries.samples.ariestrader.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${pom.version}</Bundle-Version>
+ <Export-Package>
+ org.apache.aries.samples.ariestrader.beans;version=${pom.version}
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/AccountDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/AccountDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/AccountDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/AccountDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,269 @@
+/**
+ * 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.aries.samples.ariestrader.beans;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+
+import org.apache.aries.samples.ariestrader.util.Log;
+import org.apache.aries.samples.ariestrader.util.TradeConfig;
+import org.apache.aries.samples.ariestrader.api.persistence.AccountDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.AccountProfileDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.HoldingDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.OrderDataBean;
+
+
+public class AccountDataBeanImpl implements AccountDataBean, Serializable {
+
+ private Integer accountID; /* accountID */
+
+
+ private int loginCount; /* loginCount */
+
+
+ private int logoutCount; /* logoutCount */
+
+
+ private Date lastLogin; /* lastLogin Date */
+
+
+ private Date creationDate; /* creationDate */
+
+
+ private BigDecimal balance; /* balance */
+
+
+ private BigDecimal openBalance; /* open balance */
+
+
+ private Collection<OrderDataBean> orders;
+
+
+ private Collection<HoldingDataBean> holdings;
+
+
+ private AccountProfileDataBean profile;
+
+
+ /* Accessor methods for relationship fields are only included for the AccountProfile profileID */
+
+ private String profileID;
+
+ public AccountDataBeanImpl() {
+ }
+
+ public AccountDataBeanImpl(Integer accountID,
+ int loginCount,
+ int logoutCount,
+ Date lastLogin,
+ Date creationDate,
+ BigDecimal balance,
+ BigDecimal openBalance,
+ String profileID) {
+ setAccountID(accountID);
+ setLoginCount(loginCount);
+ setLogoutCount(logoutCount);
+ setLastLogin(lastLogin);
+ setCreationDate(creationDate);
+ setBalance(balance);
+ setOpenBalance(openBalance);
+ setProfileID(profileID);
+ }
+
+ public AccountDataBeanImpl(int loginCount,
+ int logoutCount,
+ Date lastLogin,
+ Date creationDate,
+ BigDecimal balance,
+ BigDecimal openBalance,
+ String profileID) {
+ setLoginCount(loginCount);
+ setLogoutCount(logoutCount);
+ setLastLogin(lastLogin);
+ setCreationDate(creationDate);
+ setBalance(balance);
+ setOpenBalance(openBalance);
+ setProfileID(profileID);
+ }
+
+ public static AccountDataBean getRandomInstance() {
+ return new AccountDataBeanImpl(new Integer(TradeConfig.rndInt(100000)), //accountID
+ TradeConfig.rndInt(10000), //loginCount
+ TradeConfig.rndInt(10000), //logoutCount
+ new java.util.Date(), //lastLogin
+ new java.util.Date(TradeConfig.rndInt(Integer.MAX_VALUE)), //creationDate
+ TradeConfig.rndBigDecimal(1000000.0f), //balance
+ TradeConfig.rndBigDecimal(1000000.0f), //openBalance
+ TradeConfig.rndUserID() //profileID
+ );
+ }
+
+ public String toString() {
+ return "\n\tAccount Data for account: " + getAccountID()
+ + "\n\t\t loginCount:" + getLoginCount()
+ + "\n\t\t logoutCount:" + getLogoutCount()
+ + "\n\t\t lastLogin:" + getLastLogin()
+ + "\n\t\t creationDate:" + getCreationDate()
+ + "\n\t\t balance:" + getBalance()
+ + "\n\t\t openBalance:" + getOpenBalance()
+ + "\n\t\t profileID:" + getProfileID()
+ ;
+ }
+
+ public String toHTML() {
+ return "<BR>Account Data for account: <B>" + getAccountID() + "</B>"
+ + "<LI> loginCount:" + getLoginCount() + "</LI>"
+ + "<LI> logoutCount:" + getLogoutCount() + "</LI>"
+ + "<LI> lastLogin:" + getLastLogin() + "</LI>"
+ + "<LI> creationDate:" + getCreationDate() + "</LI>"
+ + "<LI> balance:" + getBalance() + "</LI>"
+ + "<LI> openBalance:" + getOpenBalance() + "</LI>"
+ + "<LI> profileID:" + getProfileID() + "</LI>"
+ ;
+ }
+
+ public void print() {
+ Log.log(this.toString());
+ }
+
+ public Integer getAccountID() {
+ return accountID;
+ }
+
+ public void setAccountID(Integer accountID) {
+ this.accountID = accountID;
+ }
+
+ public int getLoginCount() {
+ return loginCount;
+ }
+
+ public void setLoginCount(int loginCount) {
+ this.loginCount = loginCount;
+ }
+
+ public int getLogoutCount() {
+ return logoutCount;
+ }
+
+ public void setLogoutCount(int logoutCount) {
+ this.logoutCount = logoutCount;
+ }
+
+ public Date getLastLogin() {
+ return lastLogin;
+ }
+
+ public void setLastLogin(Date lastLogin) {
+ this.lastLogin = lastLogin;
+ }
+
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ public void setCreationDate(Date creationDate) {
+ this.creationDate = creationDate;
+ }
+
+ public BigDecimal getBalance() {
+ return balance;
+ }
+
+ public void setBalance(BigDecimal balance) {
+ this.balance = balance;
+ }
+
+ public BigDecimal getOpenBalance() {
+ return openBalance;
+ }
+
+ public void setOpenBalance(BigDecimal openBalance) {
+ this.openBalance = openBalance;
+ }
+
+ public String getProfileID() {
+ return profileID;
+ }
+
+ public void setProfileID(String profileID) {
+ this.profileID = profileID;
+ }
+
+ public Collection<OrderDataBean> getOrders() {
+ return orders;
+ }
+
+ public void setOrders(Collection<OrderDataBean> orders) {
+ this.orders = orders;
+ }
+
+ public Collection<HoldingDataBean> getHoldings() {
+ return holdings;
+ }
+
+ public void setHoldings(Collection<HoldingDataBean> holdings) {
+ this.holdings = holdings;
+ }
+
+ public AccountProfileDataBean getProfile() {
+ return profile;
+ }
+
+ public void setProfile(AccountProfileDataBean profile) {
+ this.profile = profile;
+ }
+
+ public void login(String password) {
+ AccountProfileDataBean profile = getProfile();
+ if ((profile == null) || (profile.getPassword().equals(password) == false)) {
+ String error = "AccountBean:Login failure for account: " + getAccountID() +
+ ((profile == null) ? "null AccountProfile" :
+ "\n\tIncorrect password-->" + profile.getUserID() + ":" + profile.getPassword());
+ throw new RuntimeException(error);
+
+ }
+
+ setLastLogin(new Timestamp(System.currentTimeMillis()));
+ setLoginCount(getLoginCount() + 1);
+ }
+
+ public void logout() {
+ setLogoutCount(getLogoutCount() + 1);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ hash += (this.accountID != null ? this.accountID.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ // TODO: Warning - this method won't work in the case the id fields are not set
+ if (!(object instanceof AccountDataBeanImpl)) {
+ return false;
+ }
+ AccountDataBeanImpl other = (AccountDataBeanImpl)object;
+ if (this.accountID != other.accountID && (this.accountID == null || !this.accountID.equals(other.accountID))) return false;
+ return true;
+ }
+}
\ No newline at end of file
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/AccountProfileDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/AccountProfileDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/AccountProfileDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/AccountProfileDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,173 @@
+/**
+ * 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.aries.samples.ariestrader.beans;
+
+import org.apache.aries.samples.ariestrader.util.Log;
+import org.apache.aries.samples.ariestrader.util.TradeConfig;
+import org.apache.aries.samples.ariestrader.api.persistence.AccountDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.AccountProfileDataBean;
+
+
+public class AccountProfileDataBeanImpl implements AccountProfileDataBean, java.io.Serializable {
+
+
+ private String userID; /* userID */
+
+
+ private String passwd; /* password */
+
+
+ private String fullName; /* fullName */
+
+
+ private String address; /* address */
+
+
+ private String email; /* email */
+
+
+ private String creditCard; /* creditCard */
+
+
+ private AccountDataBean account;
+
+ public AccountProfileDataBeanImpl() {
+ }
+
+ public AccountProfileDataBeanImpl(String userID,
+ String password,
+ String fullName,
+ String address,
+ String email,
+ String creditCard) {
+ setUserID(userID);
+ setPassword(password);
+ setFullName(fullName);
+ setAddress(address);
+ setEmail(email);
+ setCreditCard(creditCard);
+ }
+
+ public static AccountProfileDataBean getRandomInstance() {
+ return new AccountProfileDataBeanImpl(
+ TradeConfig.rndUserID(), // userID
+ TradeConfig.rndUserID(), // passwd
+ TradeConfig.rndFullName(), // fullname
+ TradeConfig.rndAddress(), // address
+ TradeConfig.rndEmail(TradeConfig.rndUserID()), //email
+ TradeConfig.rndCreditCard() // creditCard
+ );
+ }
+
+ public String toString() {
+ return "\n\tAccount Profile Data for userID:" + getUserID()
+ + "\n\t\t passwd:" + getPassword()
+ + "\n\t\t fullName:" + getFullName()
+ + "\n\t\t address:" + getAddress()
+ + "\n\t\t email:" + getEmail()
+ + "\n\t\t creditCard:" + getCreditCard()
+ ;
+ }
+
+ public String toHTML() {
+ return "<BR>Account Profile Data for userID: <B>" + getUserID() + "</B>"
+ + "<LI> passwd:" + getPassword() + "</LI>"
+ + "<LI> fullName:" + getFullName() + "</LI>"
+ + "<LI> address:" + getAddress() + "</LI>"
+ + "<LI> email:" + getEmail() + "</LI>"
+ + "<LI> creditCard:" + getCreditCard() + "</LI>"
+ ;
+ }
+
+ public void print() {
+ Log.log(this.toString());
+ }
+
+ public String getUserID() {
+ return userID;
+ }
+
+ public void setUserID(String userID) {
+ this.userID = userID;
+ }
+
+ public String getPassword() {
+ return passwd;
+ }
+
+ public void setPassword(String password) {
+ this.passwd = password;
+ }
+
+ public String getFullName() {
+ return fullName;
+ }
+
+ public void setFullName(String fullName) {
+ this.fullName = fullName;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getCreditCard() {
+ return creditCard;
+ }
+
+ public void setCreditCard(String creditCard) {
+ this.creditCard = creditCard;
+ }
+
+ public AccountDataBean getAccount() {
+ return account;
+ }
+
+ public void setAccount(AccountDataBean account) {
+ this.account = account;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ hash += (this.userID != null ? this.userID.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ // TODO: Warning - this method won't work in the case the id fields are not set
+ if (!(object instanceof AccountProfileDataBeanImpl)) {
+ return false;
+ }
+ AccountProfileDataBeanImpl other = (AccountProfileDataBeanImpl)object;
+ if (this.userID != other.userID && (this.userID == null || !this.userID.equals(other.userID))) return false;
+ return true;
+ }
+}
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/HoldingDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/HoldingDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/HoldingDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/HoldingDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,190 @@
+/**
+ * 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.aries.samples.ariestrader.beans;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.aries.samples.ariestrader.util.Log;
+import org.apache.aries.samples.ariestrader.util.TradeConfig;
+import org.apache.aries.samples.ariestrader.api.persistence.AccountDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.HoldingDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.QuoteDataBean;
+
+
+public class HoldingDataBeanImpl implements HoldingDataBean, Serializable {
+
+ /* persistent/relationship fields */
+
+
+ private Integer holdingID; /* holdingID */
+
+
+ private double quantity; /* quantity */
+
+
+ private BigDecimal purchasePrice; /* purchasePrice */
+
+
+ private Date purchaseDate; /* purchaseDate */
+
+
+ private String quoteID; /* Holding(*) ---> Quote(1) */
+
+
+ private AccountDataBean account;
+
+
+ private QuoteDataBean quote;
+
+ public HoldingDataBeanImpl() {
+ }
+
+ public HoldingDataBeanImpl(Integer holdingID,
+ double quantity,
+ BigDecimal purchasePrice,
+ Date purchaseDate,
+ String quoteID) {
+ setHoldingID(holdingID);
+ setQuantity(quantity);
+ setPurchasePrice(purchasePrice);
+ setPurchaseDate(purchaseDate);
+ setQuoteID(quoteID);
+ }
+
+ public HoldingDataBeanImpl(double quantity,
+ BigDecimal purchasePrice,
+ Date purchaseDate,
+ AccountDataBean account,
+ QuoteDataBean quote) {
+ setQuantity(quantity);
+ setPurchasePrice(purchasePrice);
+ setPurchaseDate(purchaseDate);
+ setAccount(account);
+ setQuote(quote);
+ }
+
+ public static HoldingDataBean getRandomInstance() {
+ return new HoldingDataBeanImpl(
+ new Integer(TradeConfig.rndInt(100000)), //holdingID
+ TradeConfig.rndQuantity(), //quantity
+ TradeConfig.rndBigDecimal(1000.0f), //purchasePrice
+ new java.util.Date(TradeConfig.rndInt(Integer.MAX_VALUE)), //purchaseDate
+ TradeConfig.rndSymbol() // symbol
+ );
+ }
+
+ public String toString() {
+ return "\n\tHolding Data for holding: " + getHoldingID()
+ + "\n\t\t quantity:" + getQuantity()
+ + "\n\t\t purchasePrice:" + getPurchasePrice()
+ + "\n\t\t purchaseDate:" + getPurchaseDate()
+ + "\n\t\t quoteID:" + getQuoteID()
+ ;
+ }
+
+ public String toHTML() {
+ return "<BR>Holding Data for holding: " + getHoldingID() + "</B>"
+ + "<LI> quantity:" + getQuantity() + "</LI>"
+ + "<LI> purchasePrice:" + getPurchasePrice() + "</LI>"
+ + "<LI> purchaseDate:" + getPurchaseDate() + "</LI>"
+ + "<LI> quoteID:" + getQuoteID() + "</LI>"
+ ;
+ }
+
+ public void print() {
+ Log.log(this.toString());
+ }
+
+ public Integer getHoldingID() {
+ return holdingID;
+ }
+
+ public void setHoldingID(Integer holdingID) {
+ this.holdingID = holdingID;
+ }
+
+ public double getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(double quantity) {
+ this.quantity = quantity;
+ }
+
+ public BigDecimal getPurchasePrice() {
+ return purchasePrice;
+ }
+
+ public void setPurchasePrice(BigDecimal purchasePrice) {
+ this.purchasePrice = purchasePrice;
+ }
+
+ public Date getPurchaseDate() {
+ return purchaseDate;
+ }
+
+ public void setPurchaseDate(Date purchaseDate) {
+ this.purchaseDate = purchaseDate;
+ }
+
+ public String getQuoteID() {
+ if (quote != null) {
+ return quote.getSymbol();
+ }
+ return quoteID;
+ }
+
+ public void setQuoteID(String quoteID) {
+ this.quoteID = quoteID;
+ }
+
+ public AccountDataBean getAccount() {
+ return account;
+ }
+
+ public void setAccount(AccountDataBean account) {
+ this.account = account;
+ }
+
+ public QuoteDataBean getQuote() {
+ return quote;
+ }
+
+ public void setQuote(QuoteDataBean quote) {
+ this.quote = quote;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ hash += (this.holdingID != null ? this.holdingID.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ // TODO: Warning - this method won't work in the case the id fields are not set
+ if (!(object instanceof HoldingDataBeanImpl)) {
+ return false;
+ }
+ HoldingDataBeanImpl other = (HoldingDataBeanImpl) object;
+ if (this.holdingID != other.holdingID && (this.holdingID == null || !this.holdingID.equals(other.holdingID))) return false;
+ return true;
+ }
+}
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/OrderDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/OrderDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/OrderDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/OrderDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,326 @@
+/**
+ * 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.aries.samples.ariestrader.beans;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import org.apache.aries.samples.ariestrader.util.Log;
+import org.apache.aries.samples.ariestrader.util.TradeConfig;
+import org.apache.aries.samples.ariestrader.api.persistence.AccountDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.HoldingDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.OrderDataBean;
+import org.apache.aries.samples.ariestrader.api.persistence.QuoteDataBean;
+
+
+public class OrderDataBeanImpl implements OrderDataBean, Serializable {
+
+
+ private Integer orderID; /* orderID */
+
+
+ private String orderType; /* orderType (buy, sell, etc.) */
+
+
+ private String orderStatus; /* orderStatus (open, processing, completed, closed, cancelled) */
+
+
+ private Date openDate; /* openDate (when the order was entered) */
+
+
+ private Date completionDate; /* completionDate */
+
+
+ private double quantity; /* quantity */
+
+
+ private BigDecimal price; /* price */
+
+
+ private BigDecimal orderFee; /* price */
+
+
+ private AccountDataBean account;
+
+
+ private QuoteDataBean quote;
+
+
+ private HoldingDataBean holding;
+
+ private String symbol;
+
+ public OrderDataBeanImpl() {
+ }
+
+ public OrderDataBeanImpl(Integer orderID,
+ String orderType,
+ String orderStatus,
+ Date openDate,
+ Date completionDate,
+ double quantity,
+ BigDecimal price,
+ BigDecimal orderFee,
+ String symbol
+ ) {
+ setOrderID(orderID);
+ setOrderType(orderType);
+ setOrderStatus(orderStatus);
+ setOpenDate(openDate);
+ setCompletionDate(completionDate);
+ setQuantity(quantity);
+ setPrice(price);
+ setOrderFee(orderFee);
+ setSymbol(symbol);
+ }
+
+ public OrderDataBeanImpl(String orderType,
+ String orderStatus,
+ Date openDate,
+ Date completionDate,
+ double quantity,
+ BigDecimal price,
+ BigDecimal orderFee,
+ AccountDataBean account,
+ QuoteDataBean quote, HoldingDataBean holding) {
+ setOrderType(orderType);
+ setOrderStatus(orderStatus);
+ setOpenDate(openDate);
+ setCompletionDate(completionDate);
+ setQuantity(quantity);
+ setPrice(price);
+ setOrderFee(orderFee);
+ setAccount(account);
+ setQuote(quote);
+ setHolding(holding);
+ }
+
+ public static OrderDataBean getRandomInstance() {
+ return new OrderDataBeanImpl(
+ new Integer(TradeConfig.rndInt(100000)),
+ TradeConfig.rndBoolean() ? "buy" : "sell",
+ "open",
+ new java.util.Date(TradeConfig.rndInt(Integer.MAX_VALUE)),
+ new java.util.Date(TradeConfig.rndInt(Integer.MAX_VALUE)),
+ TradeConfig.rndQuantity(),
+ TradeConfig.rndBigDecimal(1000.0f),
+ TradeConfig.rndBigDecimal(1000.0f),
+ TradeConfig.rndSymbol()
+ );
+ }
+
+ public String toString()
+ {
+ return "Order " + getOrderID()
+ + "\n\t orderType: " + getOrderType()
+ + "\n\t orderStatus: " + getOrderStatus()
+ + "\n\t openDate: " + getOpenDate()
+ + "\n\t completionDate: " + getCompletionDate()
+ + "\n\t quantity: " + getQuantity()
+ + "\n\t price: " + getPrice()
+ + "\n\t orderFee: " + getOrderFee()
+ + "\n\t symbol: " + getSymbol()
+ ;
+ }
+ public String toHTML()
+ {
+ return "<BR>Order <B>" + getOrderID() + "</B>"
+ + "<LI> orderType: " + getOrderType() + "</LI>"
+ + "<LI> orderStatus: " + getOrderStatus() + "</LI>"
+ + "<LI> openDate: " + getOpenDate() + "</LI>"
+ + "<LI> completionDate: " + getCompletionDate() + "</LI>"
+ + "<LI> quantity: " + getQuantity() + "</LI>"
+ + "<LI> price: " + getPrice() + "</LI>"
+ + "<LI> orderFee: " + getOrderFee() + "</LI>"
+ + "<LI> symbol: " + getSymbol() + "</LI>"
+ ;
+ }
+
+ public void print()
+ {
+ Log.log( this.toString() );
+ }
+
+ public Integer getOrderID() {
+ return orderID;
+ }
+
+ public void setOrderID(Integer orderID) {
+ this.orderID = orderID;
+ }
+
+ public String getOrderType() {
+ return orderType;
+ }
+
+ public void setOrderType(String orderType) {
+ this.orderType = orderType;
+ }
+
+ public String getOrderStatus() {
+ return orderStatus;
+ }
+
+ public void setOrderStatus(String orderStatus) {
+ this.orderStatus = orderStatus;
+ }
+
+ public Date getOpenDate() {
+ return openDate;
+ }
+
+ public void setOpenDate(Date openDate) {
+ this.openDate = openDate;
+ }
+
+ public Date getCompletionDate() {
+ return completionDate;
+ }
+
+ public void setCompletionDate(Date completionDate) {
+ this.completionDate = completionDate;
+ }
+
+ public double getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(double quantity) {
+ this.quantity = quantity;
+ }
+
+
+ public BigDecimal getPrice() {
+ return price;
+ }
+
+ public void setPrice(BigDecimal price) {
+ this.price = price;
+ }
+
+ public BigDecimal getOrderFee() {
+ return orderFee;
+ }
+
+ public void setOrderFee(BigDecimal orderFee) {
+ this.orderFee = orderFee;
+ }
+
+ public String getSymbol() {
+ if (quote != null) {
+ return quote.getSymbol();
+ }
+ return symbol;
+ }
+
+ public void setSymbol(String symbol) {
+ this.symbol = symbol;
+ }
+
+ public AccountDataBean getAccount() {
+ return account;
+ }
+
+ public void setAccount(AccountDataBean account) {
+ this.account = account;
+ }
+
+ public QuoteDataBean getQuote() {
+ return quote;
+ }
+
+ public void setQuote(QuoteDataBean quote) {
+ this.quote = quote;
+ }
+
+ public HoldingDataBean getHolding() {
+ return holding;
+ }
+
+ public void setHolding(HoldingDataBean holding) {
+ this.holding = holding;
+ }
+
+ public boolean isBuy()
+ {
+ String orderType = getOrderType();
+ if ( orderType.compareToIgnoreCase("buy") == 0 )
+ return true;
+ return false;
+ }
+
+ public boolean isSell()
+ {
+ String orderType = getOrderType();
+ if ( orderType.compareToIgnoreCase("sell") == 0 )
+ return true;
+ return false;
+ }
+
+ public boolean isOpen()
+ {
+ String orderStatus = getOrderStatus();
+ if ( (orderStatus.compareToIgnoreCase("open") == 0) ||
+ (orderStatus.compareToIgnoreCase("processing") == 0) )
+ return true;
+ return false;
+ }
+
+ public boolean isCompleted()
+ {
+ String orderStatus = getOrderStatus();
+ if ( (orderStatus.compareToIgnoreCase("completed") == 0) ||
+ (orderStatus.compareToIgnoreCase("alertcompleted") == 0) ||
+ (orderStatus.compareToIgnoreCase("cancelled") == 0) )
+ return true;
+ return false;
+ }
+
+ public boolean isCancelled()
+ {
+ String orderStatus = getOrderStatus();
+ if (orderStatus.compareToIgnoreCase("cancelled") == 0)
+ return true;
+ return false;
+ }
+
+
+ public void cancel()
+ {
+ setOrderStatus("cancelled");
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ hash += (this.orderID != null ? this.orderID.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ // TODO: Warning - this method won't work in the case the id fields are not set
+ if (!(object instanceof OrderDataBeanImpl)) {
+ return false;
+ }
+ OrderDataBeanImpl other = (OrderDataBeanImpl)object;
+ if (this.orderID != other.orderID && (this.orderID == null || !this.orderID.equals(other.orderID))) return false;
+ return true;
+ }
+}
+
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/QuoteDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/QuoteDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/QuoteDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-beans/src/main/java/org/apache/aries/samples/ariestrader/beans/QuoteDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,196 @@
+/**
+ * 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.aries.samples.ariestrader.beans;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import org.apache.aries.samples.ariestrader.util.Log;
+import org.apache.aries.samples.ariestrader.util.TradeConfig;
+import org.apache.aries.samples.ariestrader.api.persistence.QuoteDataBean;
+
+
+public class QuoteDataBeanImpl implements QuoteDataBean, Serializable {
+
+ private String symbol; /* symbol */
+
+
+ private String companyName; /* companyName */
+
+
+ private double volume; /* volume */
+
+
+ private BigDecimal price; /* price */
+
+
+ private BigDecimal open1; /* open1 price */
+
+
+ private BigDecimal low; /* low price */
+
+
+ private BigDecimal high; /* high price */
+
+
+ private double change1; /* price change */
+
+
+
+ public QuoteDataBeanImpl() {
+ }
+
+ public QuoteDataBeanImpl(String symbol, String companyName, double volume,
+ BigDecimal price, BigDecimal open, BigDecimal low,
+ BigDecimal high, double change) {
+ setSymbol(symbol);
+ setCompanyName(companyName);
+ setVolume(volume);
+ setPrice(price);
+ setOpen(open);
+ setLow(low);
+ setHigh(high);
+ setChange(change);
+ }
+
+ public static QuoteDataBean getRandomInstance() {
+ return new QuoteDataBeanImpl(
+ TradeConfig.rndSymbol(), //symbol
+ TradeConfig.rndSymbol() + " Incorporated", //Company Name
+ TradeConfig.rndFloat(100000), //volume
+ TradeConfig.rndBigDecimal(1000.0f), //price
+ TradeConfig.rndBigDecimal(1000.0f), //open1
+ TradeConfig.rndBigDecimal(1000.0f), //low
+ TradeConfig.rndBigDecimal(1000.0f), //high
+ TradeConfig.rndFloat(100000) //volume
+ );
+ }
+
+ //Create a "zero" value QuoteDataBeanImpl for the given symbol
+ public QuoteDataBeanImpl(String symbol) {
+ setSymbol(symbol);
+ }
+
+ public String toString() {
+ return "\n\tQuote Data for: " + getSymbol()
+ + "\n\t\t companyName: " + getCompanyName()
+ + "\n\t\t volume: " + getVolume()
+ + "\n\t\t price: " + getPrice()
+ + "\n\t\t open1: " + getOpen()
+ + "\n\t\t low: " + getLow()
+ + "\n\t\t high: " + getHigh()
+ + "\n\t\t change1: " + getChange()
+ ;
+ }
+
+ public String toHTML() {
+ return "<BR>Quote Data for: " + getSymbol()
+ + "<LI> companyName: " + getCompanyName() + "</LI>"
+ + "<LI> volume: " + getVolume() + "</LI>"
+ + "<LI> price: " + getPrice() + "</LI>"
+ + "<LI> open1: " + getOpen() + "</LI>"
+ + "<LI> low: " + getLow() + "</LI>"
+ + "<LI> high: " + getHigh() + "</LI>"
+ + "<LI> change1: " + getChange() + "</LI>"
+ ;
+ }
+
+ public void print() {
+ Log.log(this.toString());
+ }
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public void setSymbol(String symbol) {
+ this.symbol = symbol;
+ }
+
+ public String getCompanyName() {
+ return companyName;
+ }
+
+ public void setCompanyName(String companyName) {
+ this.companyName = companyName;
+ }
+
+ public BigDecimal getPrice() {
+ return price;
+ }
+
+ public void setPrice(BigDecimal price) {
+ this.price = price;
+ }
+
+ public BigDecimal getOpen() {
+ return open1;
+ }
+
+ public void setOpen(BigDecimal open) {
+ this.open1 = open;
+ }
+
+ public BigDecimal getLow() {
+ return low;
+ }
+
+ public void setLow(BigDecimal low) {
+ this.low = low;
+ }
+
+ public BigDecimal getHigh() {
+ return high;
+ }
+
+ public void setHigh(BigDecimal high) {
+ this.high = high;
+ }
+
+ public double getChange() {
+ return change1;
+ }
+
+ public void setChange(double change) {
+ this.change1 = change;
+ }
+
+ public double getVolume() {
+ return volume;
+ }
+
+ public void setVolume(double volume) {
+ this.volume = volume;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ hash += (this.symbol != null ? this.symbol.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ // TODO: Warning - this method won't work in the case the id fields are not set
+ if (!(object instanceof QuoteDataBeanImpl)) {
+ return false;
+ }
+ QuoteDataBeanImpl other = (QuoteDataBeanImpl)object;
+ if (this.symbol != other.symbol && (this.symbol == null || !this.symbol.equals(other.symbol))) return false;
+ return true;
+ }
+}
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/pom.xml?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/pom.xml (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/pom.xml Sun Feb 27 18:28:26 2011
@@ -0,0 +1,62 @@
+<?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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>modules</artifactId>
+ <version>0.1-incubating</version>
+ </parent>
+
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>org.apache.aries.samples.ariestrader.core</artifactId>
+ <packaging>bundle</packaging>
+ <name>AriesTrader :: Modules - Core</name>
+ <description>AriesTrader Core Module</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>org.apache.aries.samples.ariestrader.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>org.apache.aries.samples.ariestrader.api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${pom.version}</Bundle-Version>
+ <Private-Package>org.apache.aries.samples.ariestrader.core.*</Private-Package>
+ <Export-Package>!org.apache.aries.samples.ariestrader.core.*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeDBManagerImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeDBManagerImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeDBManagerImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeDBManagerImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,457 @@
+/**
+ * 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.aries.samples.ariestrader.core;
+
+import javax.sql.DataSource;
+
+import org.apache.aries.samples.ariestrader.api.persistence.RunStatsDataBean;
+import org.apache.aries.samples.ariestrader.util.Log;
+import org.apache.aries.samples.ariestrader.util.MDBStats;
+import org.apache.aries.samples.ariestrader.util.ServiceUtilities;
+import org.apache.aries.samples.ariestrader.util.TradeConfig;
+import org.apache.aries.samples.ariestrader.api.TradeDBManager;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+
+/**
+ * TradeDBManagerImpl centralizes and simplifies the DB
+ * configuration methods that are shared by some TradeServices
+ * implementations.
+ *
+ * @see
+ * org.apache.aries.samples.ariestrader.api.TradeDBManager
+ */
+
+public class TradeDBManagerImpl implements TradeDBManager {
+
+ private DataSource dataSource = null;
+
+ private static boolean initialized = false;
+
+ private static int connCount = 0;
+
+ private static Integer lock = new Integer(0);
+
+ /**
+ * Zero arg constructor for TradeDBManagerImpl
+ */
+ public TradeDBManagerImpl() {
+ }
+
+ /**
+ * set data source
+ */
+ public void setDataSource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+
+ /**
+ * Return a String containing the DBProductName configured for
+ * the current DataSource
+ *
+ * used by TradeBuildDB
+ *
+ * @return A String of the currently configured DataSource
+ *
+ */
+ public String checkDBProductName() throws Exception {
+ Connection conn = null;
+ String dbProductName = null;
+
+ try {
+ if (Log.doTrace())
+ Log.traceEnter("TradeDBManagerImpl:checkDBProductName");
+
+ conn = getConn();
+ DatabaseMetaData dbmd = conn.getMetaData();
+ dbProductName = dbmd.getDatabaseProductName();
+ }
+ catch (SQLException e) {
+ Log.error(e, "TradeDBManagerImpl:checkDBProductName() -- Error checking the AriesTrader Database Product Name");
+ }
+ finally {
+ releaseConn(conn);
+ }
+ return dbProductName;
+ }
+
+ /**
+ * Recreate DataBase Tables for AriesTrader
+ *
+ * used by TradeBuildDB
+ *
+ * @return boolean of success/failure in recreate of DB tables
+ *
+ */
+ public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out) throws Exception {
+ // Clear MDB Statistics
+ MDBStats.getInstance().reset();
+
+ Connection conn = null;
+ boolean success = false;
+ try {
+ if (Log.doTrace())
+ Log.traceEnter("TradeDBManagerImpl:recreateDBTables");
+
+ conn = getConn();
+ Statement stmt = conn.createStatement();
+ int bufferLength = sqlBuffer.length;
+ for (int i = 0; i < bufferLength; i++) {
+ try {
+ stmt.executeUpdate((String) sqlBuffer[i]);
+ }
+ catch (SQLException ex) {
+ // Ignore DROP statements as tables won't always exist.
+ if (((String) sqlBuffer[i]).indexOf("DROP TABLE") < 0) {
+ Log.error("TradeDBManagerImpl:recreateDBTables SQL Exception thrown on executing the foll sql command: "
+ + sqlBuffer[i], ex);
+ out.println("<BR>SQL Exception thrown on executing the foll sql command: <I>" + sqlBuffer[i]
+ + "</I> . Check log for details.</BR>");
+ }
+ }
+ }
+ stmt.close();
+ commit(conn);
+ success = true;
+ }
+ catch (Exception e) {
+ Log.error(e, "TradeDBManagerImpl:recreateDBTables() -- Error dropping and recreating the database tables");
+ }
+ finally {
+ releaseConn(conn);
+ }
+ return success;
+ }
+
+ /**
+ * Reset the statistics for the Test AriesTrader Scenario
+ *
+ * used by TradeConfigServlet
+ *
+ * @return the RunStatsDataBean
+ *
+ */
+ public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
+ // Clear MDB Statistics
+ MDBStats.getInstance().reset();
+
+ // Reset Trade
+
+ RunStatsDataBean runStatsData = new RunStatsDataBean();
+ Connection conn = null;
+ try {
+ if (Log.doTrace())
+ Log.traceEnter("TradeDBManagerImpl:resetTrade deleteAll rows=" + deleteAll);
+
+ conn = getConn();
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+
+ if (deleteAll) {
+ try {
+ stmt = getStatement(conn, "delete from quoteejb");
+ stmt.executeUpdate();
+ stmt.close();
+ stmt = getStatement(conn, "delete from accountejb");
+ stmt.executeUpdate();
+ stmt.close();
+ stmt = getStatement(conn, "delete from accountprofileejb");
+ stmt.executeUpdate();
+ stmt.close();
+ stmt = getStatement(conn, "delete from holdingejb");
+ stmt.executeUpdate();
+ stmt.close();
+ stmt = getStatement(conn, "delete from orderejb");
+ stmt.executeUpdate();
+ stmt.close();
+ // FUTURE: - DuplicateKeyException - For now, don't start at
+ // zero as KeySequenceDirect and KeySequenceBean will still
+ // give out
+ // the cached Block and then notice this change. Better
+ // solution is
+ // to signal both classes to drop their cached blocks
+ // stmt = getStatement(conn, "delete from keygenejb");
+ // stmt.executeUpdate();
+ // stmt.close();
+ commit(conn);
+ }
+ catch (Exception e) {
+ Log.error(e, "TradeDBManagerImpl:resetTrade(deleteAll) -- Error deleting Trade users and stock from the Trade database");
+ }
+ return runStatsData;
+ }
+
+ stmt = getStatement(conn, "delete from holdingejb where holdingejb.account_accountid is null");
+ stmt.executeUpdate();
+ stmt.close();
+
+ // Count and Delete newly registered users (users w/ id that start
+ // "ru:%":
+ stmt = getStatement(conn, "delete from accountprofileejb where userid like 'ru:%'");
+ stmt.executeUpdate();
+ stmt.close();
+
+ stmt = getStatement(conn,
+ "delete from orderejb where account_accountid in (select accountid from accountejb a where a.profile_userid like 'ru:%')");
+ stmt.executeUpdate();
+ stmt.close();
+
+ stmt = getStatement(conn,
+ "delete from holdingejb where account_accountid in (select accountid from accountejb a where a.profile_userid like 'ru:%')");
+ stmt.executeUpdate();
+ stmt.close();
+
+ stmt = getStatement(conn, "delete from accountejb where profile_userid like 'ru:%'");
+ int newUserCount = stmt.executeUpdate();
+ runStatsData.setNewUserCount(newUserCount);
+ stmt.close();
+
+ // Count of trade users
+ stmt = getStatement(conn,
+ "select count(accountid) as \"tradeUserCount\" from accountejb a where a.profile_userid like 'uid:%'");
+ rs = stmt.executeQuery();
+ rs.next();
+ int tradeUserCount = rs.getInt("tradeUserCount");
+ runStatsData.setTradeUserCount(tradeUserCount);
+ stmt.close();
+
+ rs.close();
+ // Count of trade stocks
+ stmt = getStatement(conn,
+ "select count(symbol) as \"tradeStockCount\" from quoteejb a where a.symbol like 's:%'");
+ rs = stmt.executeQuery();
+ rs.next();
+ int tradeStockCount = rs.getInt("tradeStockCount");
+ runStatsData.setTradeStockCount(tradeStockCount);
+ stmt.close();
+
+ // Count of trade users login, logout
+ stmt = getStatement(conn,
+ "select sum(loginCount) as \"sumLoginCount\", sum(logoutCount) as \"sumLogoutCount\" from accountejb a where a.profile_userID like 'uid:%'");
+ rs = stmt.executeQuery();
+ rs.next();
+ int sumLoginCount = rs.getInt("sumLoginCount");
+ int sumLogoutCount = rs.getInt("sumLogoutCount");
+ runStatsData.setSumLoginCount(sumLoginCount);
+ runStatsData.setSumLogoutCount(sumLogoutCount);
+ stmt.close();
+
+ rs.close();
+ // Update logoutcount and loginCount back to zero
+
+ stmt =
+ getStatement(conn, "update accountejb set logoutCount=0,loginCount=0 where profile_userID like 'uid:%'");
+ stmt.executeUpdate();
+ stmt.close();
+
+ // count holdings for trade users
+ stmt = getStatement(conn,
+ "select count(holdingid) as \"holdingCount\" from holdingejb h where h.account_accountid in "
+ + "(select accountid from accountejb a where a.profile_userid like 'uid:%')");
+
+ rs = stmt.executeQuery();
+ rs.next();
+ int holdingCount = rs.getInt("holdingCount");
+ runStatsData.setHoldingCount(holdingCount);
+ stmt.close();
+ rs.close();
+
+ // count orders for trade users
+ stmt = getStatement(conn,
+ "select count(orderid) as \"orderCount\" from orderejb o where o.account_accountid in "
+ + "(select accountid from accountejb a where a.profile_userid like 'uid:%')");
+
+ rs = stmt.executeQuery();
+ rs.next();
+ int orderCount = rs.getInt("orderCount");
+ runStatsData.setOrderCount(orderCount);
+ stmt.close();
+ rs.close();
+
+ // count orders by type for trade users
+ stmt = getStatement(conn,
+ "select count(orderid) \"buyOrderCount\"from orderejb o where (o.account_accountid in "
+ + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
+ + " (o.orderType='buy')");
+
+ rs = stmt.executeQuery();
+ rs.next();
+ int buyOrderCount = rs.getInt("buyOrderCount");
+ runStatsData.setBuyOrderCount(buyOrderCount);
+ stmt.close();
+ rs.close();
+
+ // count orders by type for trade users
+ stmt = getStatement(conn,
+ "select count(orderid) \"sellOrderCount\"from orderejb o where (o.account_accountid in "
+ + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
+ + " (o.orderType='sell')");
+
+ rs = stmt.executeQuery();
+ rs.next();
+ int sellOrderCount = rs.getInt("sellOrderCount");
+ runStatsData.setSellOrderCount(sellOrderCount);
+ stmt.close();
+ rs.close();
+
+ // Delete cancelled orders
+ stmt = getStatement(conn, "delete from orderejb where orderStatus='cancelled'");
+ int cancelledOrderCount = stmt.executeUpdate();
+ runStatsData.setCancelledOrderCount(cancelledOrderCount);
+ stmt.close();
+ rs.close();
+
+ // count open orders by type for trade users
+ stmt = getStatement(conn,
+ "select count(orderid) \"openOrderCount\"from orderejb o where (o.account_accountid in "
+ + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
+ + " (o.orderStatus='open')");
+
+ rs = stmt.executeQuery();
+ rs.next();
+ int openOrderCount = rs.getInt("openOrderCount");
+ runStatsData.setOpenOrderCount(openOrderCount);
+
+ stmt.close();
+ rs.close();
+ // Delete orders for holding which have been purchased and sold
+ stmt = getStatement(conn, "delete from orderejb where holding_holdingid is null");
+ int deletedOrderCount = stmt.executeUpdate();
+ runStatsData.setDeletedOrderCount(deletedOrderCount);
+ stmt.close();
+ rs.close();
+
+ commit(conn);
+
+ System.out.println("TradeDBManagerImpl:reset Run stats data\n\n" + runStatsData);
+ }
+ catch (Exception e) {
+ Log.error(e, "Failed to reset Trade");
+ rollBack(conn, e);
+ throw e;
+ }
+ finally {
+ releaseConn(conn);
+ }
+ return runStatsData;
+
+ }
+
+ private void releaseConn(Connection conn) throws Exception {
+ try {
+ if (conn != null) {
+ conn.close();
+ if (Log.doTrace()) {
+ synchronized (lock) {
+ connCount--;
+ }
+ Log.trace("TradeDBManagerImpl:releaseConn -- connection closed, connCount=" + connCount);
+ }
+ }
+ }
+ catch (Exception e) {
+ Log.error("TradeDBManagerImpl:releaseConnection -- failed to close connection", e);
+ }
+ }
+
+ /*
+ * Lookup the TradeData DataSource
+ */
+ private void lookupDataSource() throws Exception {
+ if (dataSource == null) {
+ dataSource = (DataSource) ServiceUtilities.getOSGIService(DataSource.class.getName(),TradeConfig.OSGI_DS_NAME_FILTER);
+ }
+ }
+
+ /*
+ * Allocate a new connection to the datasource
+ */
+ private Connection getConn() throws Exception {
+
+ Connection conn = null;
+ lookupDataSource();
+ conn = dataSource.getConnection();
+ conn.setAutoCommit(false);
+ if (Log.doTrace()) {
+ synchronized (lock) {
+ connCount++;
+ }
+ Log.trace("TradeDBManagerImpl:getConn -- new connection allocated, IsolationLevel="
+ + conn.getTransactionIsolation() + " connectionCount = " + connCount);
+ }
+
+ return conn;
+ }
+
+ /*
+ * Commit the provided connection
+ */
+ private void commit(Connection conn) throws Exception {
+ if (conn != null)
+ conn.commit();
+ }
+
+ /*
+ * Rollback the statement for the given connection
+ */
+ private void rollBack(Connection conn, Exception e) throws Exception {
+ Log.log("TradeDBManagerImpl:rollBack -- rolling back conn due to previously caught exception");
+ if (conn != null)
+ conn.rollback();
+ else
+ throw e; // Throw the exception
+ }
+
+ /*
+ * Allocate a new prepared statement for this connection
+ */
+ private PreparedStatement getStatement(Connection conn, String sql) throws Exception {
+ return conn.prepareStatement(sql);
+ }
+
+
+ public void init() {
+ if (initialized)
+ return;
+ if (Log.doTrace())
+ Log.trace("TradeDBManagerImpl:init -- *** initializing");
+
+ if (Log.doTrace())
+ Log.trace("TradeDBManagerImpl:init -- +++ initialized");
+
+ initialized = true;
+ }
+
+ public void destroy() {
+ try {
+ Log.trace("TradeDBManagerImpl:destroy");
+ if (!initialized)
+ return;
+ }
+ catch (Exception e) {
+ Log.error("TradeDBManagerImpl:destroy", e);
+ }
+ }
+
+}
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeServicesManagerImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeServicesManagerImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeServicesManagerImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/java/org/apache/aries/samples/ariestrader/core/TradeServicesManagerImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,197 @@
+/**
+ * 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.aries.samples.ariestrader.core;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.samples.ariestrader.api.persistence.MarketSummaryDataBean;
+import org.apache.aries.samples.ariestrader.util.Log;
+import org.apache.aries.samples.ariestrader.util.TradeConfig;
+import org.apache.aries.samples.ariestrader.api.TradeServicesManager;
+import org.apache.aries.samples.ariestrader.api.TradeServices;
+
+
+/**
+ * TradeServicesManagerImpl coordinates access to the currently
+ * selected TradeServices implementation and manages the list of
+ * currently available TradeServices implementations.
+ *
+ * @see
+ * org.apache.geronimo.samples.daytrader.api.TradeServicesManager
+ *
+ */
+
+public class TradeServicesManagerImpl implements TradeServicesManager {
+
+ private static TradeServices[] tradeServicesList = new TradeServices[TradeConfig.runTimeModeNames.length] ;
+
+ // This lock is used to serialize market summary operations.
+ private static final Integer marketSummaryLock = new Integer(0);
+ private static long nextMarketSummary = System.currentTimeMillis();
+ private static MarketSummaryDataBean cachedMSDB = null;
+
+ /**
+ * TradeServicesManagerImpl null constructor
+ */
+ public TradeServicesManagerImpl() {
+ if (Log.doTrace())
+ Log.trace("TradeServicesManagerImpl()");
+ }
+
+ /**
+ * init
+ */
+ public void init() {
+ if (Log.doTrace())
+ Log.trace("TradeServicesManagerImpl:init()");
+ }
+
+
+ /**
+ * Get CurrentModes that are registered
+ */
+ public ArrayList<Integer> getCurrentModes() {
+ if (Log.doTrace())
+ Log.trace("TradeServicesManagerImpl:getCurrentModes()");
+ ArrayList<Integer> modes = new ArrayList<Integer>();
+ for (int i=0; i<tradeServicesList.length; i++) {
+ TradeServices tradeServicesRef = tradeServicesList[i];
+ if (tradeServicesRef != null) {
+ modes.add(i);
+ }
+ }
+ return modes;
+ }
+
+ /**
+ * Get TradeServices reference
+ */
+ public TradeServices getTradeServices() {
+ if (Log.doTrace())
+ Log.trace("TradeServicesManagerImpl:getTradeServices()");
+ return tradeServicesList[TradeConfig.getRunTimeMode().ordinal()];
+ }
+
+ /**
+ * Bind a new TradeServices implementation
+ */
+ public void bindService(TradeServices tradeServices, Map props) {
+ if (Log.doTrace())
+ Log.trace("TradeServicesManagerImpl:bindService()", tradeServices, props);
+ if (tradeServices != null) {
+ String mode = (String) props.get("mode");
+ tradeServicesList[Enum.valueOf(TradeConfig.ModeType.class, mode).ordinal()] = tradeServices;
+ }
+ }
+
+ /**
+ * Unbind a TradeServices implementation
+ */
+ public void unbindService(TradeServices tradeServices, Map props) {
+ if (Log.doTrace())
+ Log.trace("TradeServicesManagerImpl:unbindService()", tradeServices, props);
+ if (tradeServices != null) {
+ String mode = (String) props.get("mode");
+ tradeServicesList[Enum.valueOf(TradeConfig.ModeType.class, mode).ordinal()] = null;
+ }
+ }
+
+ /**
+ * Market Summary is inherently a heavy database operation. For servers that have a caching
+ * story this is a great place to cache data that is good for a period of time. In order to
+ * provide a flexible framework for this we allow the market summary operation to be
+ * invoked on every transaction, time delayed or never. This is configurable in the
+ * configuration panel.
+ *
+ * @return An instance of the market summary
+ */
+ public MarketSummaryDataBean getMarketSummary() throws Exception {
+
+ if (Log.doActionTrace()) {
+ Log.trace("TradeAction:getMarketSummary()");
+ }
+
+ if (Log.doTrace())
+ Log.trace("TradeServicesManagerImpl:getMarketSummary()");
+
+ if (TradeConfig.getMarketSummaryInterval() == 0) return getMarketSummaryInternal();
+ if (TradeConfig.getMarketSummaryInterval() < 0) return cachedMSDB;
+
+ /**
+ * This is a little funky. If its time to fetch a new Market summary then we'll synchronize
+ * access to make sure only one requester does it. Others will merely return the old copy until
+ * the new MarketSummary has been executed.
+ */
+ long currentTime = System.currentTimeMillis();
+
+ if (currentTime > nextMarketSummary) {
+ long oldNextMarketSummary = nextMarketSummary;
+ boolean fetch = false;
+
+ synchronized (marketSummaryLock) {
+ /**
+ * Is it still ahead or did we miss lose the race? If we lost then let's get out
+ * of here as the work has already been done.
+ */
+ if (oldNextMarketSummary == nextMarketSummary) {
+ fetch = true;
+ nextMarketSummary += TradeConfig.getMarketSummaryInterval()*1000;
+
+ /**
+ * If the server has been idle for a while then its possible that nextMarketSummary
+ * could be way off. Rather than try and play catch up we'll simply get in sync with the
+ * current time + the interval.
+ */
+ if (nextMarketSummary < currentTime) {
+ nextMarketSummary = currentTime + TradeConfig.getMarketSummaryInterval()*1000;
+ }
+ }
+ }
+
+ /**
+ * If we're the lucky one then let's update the MarketSummary
+ */
+ if (fetch) {
+ cachedMSDB = getMarketSummaryInternal();
+ }
+ }
+
+ return cachedMSDB;
+ }
+
+ /**
+ * Compute and return a snapshot of the current market conditions This
+ * includes the TSIA - an index of the price of the top 100 Trade stock
+ * quotes The openTSIA ( the index at the open) The volume of shares traded,
+ * Top Stocks gain and loss
+ *
+ * @return A snapshot of the current market summary
+ */
+ private MarketSummaryDataBean getMarketSummaryInternal() throws Exception {
+ if (Log.doActionTrace()) {
+ Log.trace("TradeAction:getMarketSummaryInternal()");
+ }
+ MarketSummaryDataBean marketSummaryData = null;
+ marketSummaryData = tradeServicesList[TradeConfig.getRunTimeMode().ordinal()].getMarketSummary();
+ return marketSummaryData;
+ }
+
+
+}
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml Sun Feb 27 18:28:26 2011
@@ -0,0 +1,42 @@
+<?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.
+
+-->
+<blueprint default-activation="lazy"
+ xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="tradeServicesManagerBean" class="org.apache.aries.samples.ariestrader.core.TradeServicesManagerImpl" init-method="init">
+ </bean>
+
+ <service id="TradeServicesManager" ref="tradeServicesManagerBean" interface="org.apache.aries.samples.ariestrader.api.TradeServicesManager"/>
+
+ <bean id="tradeDBManagerBean" class="org.apache.aries.samples.ariestrader.core.TradeDBManagerImpl" init-method="init">
+ </bean>
+
+ <service id="TradeDBManager" ref="tradeDBManagerBean" interface="org.apache.aries.samples.ariestrader.api.TradeDBManager">
+ </service>
+
+ <reference-list id="tradeServicesList" availability="optional" activation="eager" interface="org.apache.aries.samples.ariestrader.api.TradeServices">
+ <reference-listener ref="tradeServicesManagerBean" bind-method="bindService" unbind-method="unbindService" />
+ </reference-list>
+
+
+</blueprint>
+
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-derby-ds/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-derby-ds/pom.xml?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-derby-ds/pom.xml (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-derby-ds/pom.xml Sun Feb 27 18:28:26 2011
@@ -0,0 +1,63 @@
+<?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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>modules</artifactId>
+ <version>0.1-incubating</version>
+ </parent>
+
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>org.apache.aries.samples.ariestrader.derby.ds</artifactId>
+ <packaging>bundle</packaging>
+ <name>AriesTrader :: Modules - Derby DataSource</name>
+ <description>AriesTrader Derby DataSource</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.blueprint</artifactId>
+ <version>${ariesTransactionVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.components</groupId>
+ <artifactId>geronimo-transaction</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${pom.version}</Bundle-Version>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>