You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dw...@apache.org on 2009/08/31 20:48:45 UTC
svn commit: r809686 [5/6] - in /geronimo/daytrader/trunk/modules: ./ beans/
beans/src/ beans/src/main/ beans/src/main/java/ beans/src/main/java/org/
beans/src/main/java/org/apache/ beans/src/main/java/org/apache/geronimo/
beans/src/main/java/org/apache...
Added: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/OrderDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/OrderDataBean.java?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/OrderDataBean.java (added)
+++ geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/OrderDataBean.java Mon Aug 31 18:48:41 2009
@@ -0,0 +1,365 @@
+/**
+ * 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.geronimo.samples.daytrader;
+
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import javax.persistence.*;
+
+import org.apache.geronimo.samples.daytrader.util.Log;
+import org.apache.geronimo.samples.daytrader.util.TradeConfig;
+
+@Entity(name="orderejb")
+@Table(name = "orderejb")
+@NamedQueries( {
+ @NamedQuery(name = "orderejb.findByOrderfee", query = "SELECT o FROM orderejb o WHERE o.orderFee = :orderfee"),
+ @NamedQuery(name = "orderejb.findByCompletiondate", query = "SELECT o FROM orderejb o WHERE o.completionDate = :completiondate"),
+ @NamedQuery(name = "orderejb.findByOrdertype", query = "SELECT o FROM orderejb o WHERE o.orderType = :ordertype"),
+ @NamedQuery(name = "orderejb.findByOrderstatus", query = "SELECT o FROM orderejb o WHERE o.orderStatus = :orderstatus"),
+ @NamedQuery(name = "orderejb.findByPrice", query = "SELECT o FROM orderejb o WHERE o.price = :price"),
+ @NamedQuery(name = "orderejb.findByQuantity", query = "SELECT o FROM orderejb o WHERE o.quantity = :quantity"),
+ @NamedQuery(name = "orderejb.findByOpendate", query = "SELECT o FROM orderejb o WHERE o.openDate = :opendate"),
+ @NamedQuery(name = "orderejb.findByOrderid", query = "SELECT o FROM orderejb o WHERE o.orderID = :orderid"),
+ @NamedQuery(name = "orderejb.findByAccountAccountid", query = "SELECT o FROM orderejb o WHERE o.account.accountID = :accountAccountid"),
+ @NamedQuery(name = "orderejb.findByQuoteSymbol", query = "SELECT o FROM orderejb o WHERE o.quote.symbol = :quoteSymbol"),
+ // Never used query related to FK constraint on holdingejb. the FK constraint will cause EJB3 runtime mode failure. So comment it.
+ //@NamedQuery(name = "orderejb.findByHoldingHoldingid", query = "SELECT o FROM orderejb o WHERE o.holding.holdingID = :holdingHoldingid"),
+ @NamedQuery(name = "orderejb.closedOrders", query = "SELECT o FROM orderejb o WHERE o.orderStatus = 'closed' AND o.account.profile.userID = :userID"),
+ @NamedQuery(name = "orderejb.completeClosedOrders", query = "UPDATE orderejb o SET o.orderStatus = 'completed' WHERE o.orderStatus = 'closed' AND o.account.profile.userID = :userID")
+})
+public class OrderDataBean implements Serializable
+{
+
+ @TableGenerator(
+ name="orderIdGen",
+ table="KEYGENEJB",
+ pkColumnName="KEYNAME",
+ valueColumnName="KEYVAL",
+ pkColumnValue="order",
+ allocationSize=1000)
+ @Id
+ @GeneratedValue(strategy=GenerationType.TABLE, generator="orderIdGen")
+ @Column(name = "ORDERID", nullable = false)
+ private Integer orderID; /* orderID */
+
+ @Column(name = "ORDERTYPE")
+ private String orderType; /* orderType (buy, sell, etc.) */
+
+ @Column(name = "ORDERSTATUS")
+ private String orderStatus; /* orderStatus (open, processing, completed, closed, cancelled) */
+
+ @Column(name = "OPENDATE")
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date openDate; /* openDate (when the order was entered) */
+
+ @Column(name = "COMPLETIONDATE")
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date completionDate; /* completionDate */
+
+ @Column(name = "QUANTITY", nullable = false)
+ private double quantity; /* quantity */
+
+ @Column(name = "PRICE")
+ private BigDecimal price; /* price */
+
+ @Column(name = "ORDERFEE")
+ private BigDecimal orderFee; /* price */
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(name="ACCOUNT_ACCOUNTID")
+ private AccountDataBean account;
+
+ @ManyToOne(fetch=FetchType.EAGER)
+ @JoinColumn(name="QUOTE_SYMBOL")
+ private QuoteDataBean quote;
+
+ // Cause sell operation failed, see JIRA DAYTRADER-63 for details.
+ //@OneToOne(fetch=FetchType.LAZY)
+ //@JoinColumn(name = "HOLDING_HOLDINGID")
+ // Cause sell operation failed, see JIRA DAYTRADER-63 for details.
+ @Transient
+ private HoldingDataBean holding;
+
+// @Version
+// private Integer optLock;
+
+ /* Fields for relationship fields are not kept in the Data Bean */
+ @Transient
+ private String symbol;
+
+ public OrderDataBean() {
+ }
+
+ public OrderDataBean(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 OrderDataBean(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 OrderDataBean(
+ 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 OrderDataBean)) {
+ return false;
+ }
+ OrderDataBean other = (OrderDataBean)object;
+ if (this.orderID != other.orderID && (this.orderID == null || !this.orderID.equals(other.orderID))) return false;
+ return true;
+ }
+}
+
Propchange: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/OrderDataBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/QuoteDataBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/QuoteDataBean.java?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/QuoteDataBean.java (added)
+++ geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/QuoteDataBean.java Mon Aug 31 18:48:41 2009
@@ -0,0 +1,225 @@
+/**
+ * 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.geronimo.samples.daytrader;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Collection;
+
+import javax.persistence.*;
+
+import org.apache.geronimo.samples.daytrader.util.Log;
+import org.apache.geronimo.samples.daytrader.util.TradeConfig;
+
+@Entity(name = "quoteejb")
+@Table(name = "quoteejb")
+@NamedQueries({
+ @NamedQuery(name = "quoteejb.allQuotes",query = "SELECT q FROM quoteejb q"),
+ @NamedQuery(name = "quoteejb.quotesByChange",query = "SELECT q FROM quoteejb q WHERE q.symbol LIKE 's:1__' ORDER BY q.change1 DESC"),
+ @NamedQuery(name = "quoteejb.findByLow", query = "SELECT q FROM quoteejb q WHERE q.low = :low"),
+ @NamedQuery(name = "quoteejb.findByOpen1", query = "SELECT q FROM quoteejb q WHERE q.open1 = :open1"),
+ @NamedQuery(name = "quoteejb.findByVolume", query = "SELECT q FROM quoteejb q WHERE q.volume = :volume"),
+ @NamedQuery(name = "quoteejb.findByPrice", query = "SELECT q FROM quoteejb q WHERE q.price = :price"),
+ @NamedQuery(name = "quoteejb.findByHigh", query = "SELECT q FROM quoteejb q WHERE q.high = :high"),
+ @NamedQuery(name = "quoteejb.findByCompanyname", query = "SELECT q FROM quoteejb q WHERE q.companyName = :companyname"),
+ @NamedQuery(name = "quoteejb.findBySymbol", query = "SELECT q FROM quoteejb q WHERE q.symbol = :symbol"),
+ @NamedQuery(name = "quoteejb.findByChange1", query = "SELECT q FROM quoteejb q WHERE q.change1 = :change1")
+})
+@NamedNativeQueries({
+ @NamedNativeQuery(name="quoteejb.quoteForUpdate", query="select * from quoteejb q where q.symbol=? for update",resultClass=org.apache.geronimo.samples.daytrader.QuoteDataBean.class)
+})
+public class QuoteDataBean implements Serializable {
+
+ /* Accessor methods for persistent fields */
+
+ @Id
+ @Column(name = "SYMBOL", nullable = false)
+ private String symbol; /* symbol */
+
+ @Column(name = "COMPANYNAME")
+ private String companyName; /* companyName */
+
+ @Column(name = "VOLUME", nullable = false)
+ private double volume; /* volume */
+
+ @Column(name = "PRICE")
+ private BigDecimal price; /* price */
+
+ @Column(name = "OPEN1")
+ private BigDecimal open1; /* open1 price */
+
+ @Column(name = "LOW")
+ private BigDecimal low; /* low price */
+
+ @Column(name = "HIGH")
+ private BigDecimal high; /* high price */
+
+ @Column(name = "CHANGE1", nullable = false)
+ private double change1; /* price change */
+
+ /*@OneToMany(mappedBy = "quote")
+ private Collection<OrderDataBean> orders;*/
+
+// @Version
+// private Integer optLock;
+
+ /* Accessor methods for relationship fields are not kept in the DataBean */
+
+ public QuoteDataBean() {
+ }
+
+ public QuoteDataBean(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 QuoteDataBean(
+ 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 quoteDataBean for the given symbol
+ public QuoteDataBean(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 QuoteDataBean)) {
+ return false;
+ }
+ QuoteDataBean other = (QuoteDataBean)object;
+ if (this.symbol != other.symbol && (this.symbol == null || !this.symbol.equals(other.symbol))) return false;
+ return true;
+ }
+}
Propchange: geronimo/daytrader/trunk/modules/entities/src/main/java/org/apache/geronimo/samples/daytrader/QuoteDataBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/LICENSE?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/LICENSE (added)
+++ geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/LICENSE Mon Aug 31 18:48:41 2009
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
Added: geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/NOTICE?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/NOTICE (added)
+++ geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/NOTICE Mon Aug 31 18:48:41 2009
@@ -0,0 +1,9 @@
+Apache Geronimo
+Copyright 2003-2009 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+Portions of this software were developed at IBM and donated to the
+ASF under the Apache 2.0 license. The former work was referred to
+as Trade 6.
Added: geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml (added)
+++ geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml Mon Aug 31 18:48:41 2009
@@ -0,0 +1,41 @@
+<?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.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+
+ <persistence-unit transaction-type="JTA" name="daytrader">
+ <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+ <jta-data-source>jdbc/TradeDataSource</jta-data-source>
+ <non-jta-data-source>jdbc/NoTxTradeDataSource</non-jta-data-source>
+
+ <class>org.apache.geronimo.samples.daytrader.AccountDataBean</class>
+ <class>org.apache.geronimo.samples.daytrader.AccountProfileDataBean</class>
+ <class>org.apache.geronimo.samples.daytrader.HoldingDataBean</class>
+ <class>org.apache.geronimo.samples.daytrader.OrderDataBean</class>
+ <class>org.apache.geronimo.samples.daytrader.QuoteDataBean</class>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+
+ <properties>
+ <property name="openjpa.jdbc.DBDictionary" value="derby" />
+ <property name="openjpa.BrokerImpl" value="non-finalizing" />
+ <!-- To enable OpenJPA to generate foreign key constraints, comment out this line -->
+ <!-- <property name="openjpa.jdbc.MappingDefaults" value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict"/> -->
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+ <property name="openjpa.Sequence" value="table(Table=OPENJPASEQ, Increment=100)"/>
+ </properties>
+ </persistence-unit>
+</persistence>
Propchange: geronimo/daytrader/trunk/modules/entities/src/main/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: geronimo/daytrader/trunk/modules/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/pom.xml?rev=809686&r1=809685&r2=809686&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/pom.xml (original)
+++ geronimo/daytrader/trunk/modules/pom.xml Mon Aug 31 18:48:41 2009
@@ -31,6 +31,9 @@
<packaging>pom</packaging>
<modules>
+ <module>util</module>
+ <module>beans</module>
+ <module>entities</module>
<module>core</module>
<module>ejb3</module>
<module>wsappclient</module>
Modified: geronimo/daytrader/trunk/modules/soap/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/soap/pom.xml?rev=809686&r1=809685&r2=809686&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/soap/pom.xml (original)
+++ geronimo/daytrader/trunk/modules/soap/pom.xml Mon Aug 31 18:48:41 2009
@@ -25,7 +25,7 @@
</parent>
<groupId>org.apache.geronimo.daytrader.modules</groupId>
- <artifactId>soap</artifactId>
+ <artifactId>daytrader-soap</artifactId>
<name>DayTrader :: Modules - SOAP</name>
<packaging>jar</packaging>
<description>Daytrader SOAP Module</description>
@@ -39,7 +39,17 @@
<dependencies>
<dependency>
<groupId>org.apache.geronimo.daytrader.modules</groupId>
- <artifactId>core</artifactId>
+ <artifactId>daytrader-util</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.daytrader.modules</groupId>
+ <artifactId>daytrader-entities</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.daytrader.modules</groupId>
+ <artifactId>daytrader-core</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
Modified: geronimo/daytrader/trunk/modules/streamer/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/streamer/pom.xml?rev=809686&r1=809685&r2=809686&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/streamer/pom.xml (original)
+++ geronimo/daytrader/trunk/modules/streamer/pom.xml Mon Aug 31 18:48:41 2009
@@ -40,7 +40,23 @@
<dependencies>
<dependency>
<groupId>org.apache.geronimo.daytrader.modules</groupId>
- <artifactId>ejb3</artifactId>
+ <artifactId>daytrader-util</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.daytrader.modules</groupId>
+ <artifactId>daytrader-core</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.daytrader.modules</groupId>
+ <artifactId>daytrader-entities</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.daytrader.modules</groupId>
+ <artifactId>daytrader-ejb3</artifactId>
<version>${pom.version}</version>
<type>ejb</type>
</dependency>
@@ -80,7 +96,7 @@
<configuration>
<archive>
<manifestEntries>
- <class-path>core.jar web.jar dt-ejb.jar</class-path>
+ <class-path>util.jar core.jar entities.jar web.jar dt-ejb.jar</class-path>
</manifestEntries>
<manifest>
<main-class>org.apache.geronimo.samples.daytrader.client.TradeClient</main-class>
Added: geronimo/daytrader/trunk/modules/util/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/util/pom.xml?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/util/pom.xml (added)
+++ geronimo/daytrader/trunk/modules/util/pom.xml Mon Aug 31 18:48:41 2009
@@ -0,0 +1,60 @@
+<?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.geronimo.daytrader</groupId>
+ <artifactId>modules</artifactId>
+ <version>2.2-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.geronimo.daytrader.modules</groupId>
+ <artifactId>daytrader-util</artifactId>
+ <packaging>jar</packaging>
+ <name>DayTrader :: Modules - Util</name>
+ <description>Daytrader Util Module</description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/geronimo/daytrader/trunk/modules/util</connection>
+ <developerConnection>scm:svn:http://svn.apache.org/repos/asf/geronimo/daytrader/trunk/modules/util</developerConnection>
+ <url>http://svn.apache.org/viewcvs.cgi/geronimo/daytrader/trunk/modules/util</url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </build>
+</project>
Propchange: geronimo/daytrader/trunk/modules/util/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/KeyBlock.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/KeyBlock.java?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/KeyBlock.java (added)
+++ geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/KeyBlock.java Mon Aug 31 18:48:41 2009
@@ -0,0 +1,129 @@
+/**
+ * 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.geronimo.samples.daytrader.util;
+
+import java.util.AbstractSequentialList;
+import java.util.ListIterator;
+public class KeyBlock extends AbstractSequentialList
+{
+
+ // min and max provide range of valid primary keys for this KeyBlock
+ private int min = 0;
+ private int max = 0;
+ private int index = 0;
+
+ /**
+ * Constructor for KeyBlock
+ */
+ public KeyBlock() {
+ super();
+ min = 0;
+ max = 0;
+ index = min;
+ }
+
+ /**
+ * Constructor for KeyBlock
+ */
+ public KeyBlock(int min, int max) {
+ super();
+ this.min = min;
+ this.max = max;
+ index = min;
+ }
+
+ /**
+ * @see AbstractCollection#size()
+ */
+ public int size() {
+ return (max - min) + 1;
+ }
+
+ /**
+ * @see AbstractSequentialList#listIterator(int)
+ */
+ public ListIterator listIterator(int arg0) {
+ return new KeyBlockIterator();
+ }
+
+ class KeyBlockIterator implements ListIterator {
+
+ /**
+ * @see ListIterator#hasNext()
+ */
+ public boolean hasNext() {
+ return index <= max;
+ }
+
+ /**
+ * @see ListIterator#next()
+ */
+ public synchronized Object next() {
+ if (index > max)
+ throw new java.lang.RuntimeException("KeyBlock:next() -- Error KeyBlock depleted");
+ return new Integer(index++);
+ }
+
+ /**
+ * @see ListIterator#hasPrevious()
+ */
+ public boolean hasPrevious() {
+ return index > min;
+ }
+
+ /**
+ * @see ListIterator#previous()
+ */
+ public Object previous() {
+ return new Integer(--index);
+ }
+
+ /**
+ * @see ListIterator#nextIndex()
+ */
+ public int nextIndex() {
+ return index-min;
+ }
+
+ /**
+ * @see ListIterator#previousIndex()
+ */
+ public int previousIndex() {
+ throw new UnsupportedOperationException("KeyBlock: previousIndex() not supported");
+ }
+
+ /**
+ * @see ListIterator#add()
+ */
+ public void add(Object o) {
+ throw new UnsupportedOperationException("KeyBlock: add() not supported");
+ }
+
+ /**
+ * @see ListIterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException("KeyBlock: remove() not supported");
+ }
+
+ /**
+ * @see ListIterator#set(Object)
+ */
+ public void set(Object arg0) {
+ }
+ }
+}
\ No newline at end of file
Propchange: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/KeyBlock.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/Log.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/Log.java?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/Log.java (added)
+++ geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/Log.java Mon Aug 31 18:48:41 2009
@@ -0,0 +1,211 @@
+/**
+ * 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.geronimo.samples.daytrader.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+import org.apache.commons.logging.*;
+import org.apache.geronimo.samples.daytrader.*;
+
+public class Log {
+ private final static org.apache.commons.logging.Log log = LogFactory.getLog(Log.class);
+//A general purpose, high performance logging, tracing, statistic service
+
+ public static void log(String message)
+ {
+ log.debug("DayTrader Log:" + new java.util.Date() + "------\n\t ");
+ log.debug(message);
+ }
+ public static void log(String msg1, String msg2)
+ {
+ log(msg1+msg2);
+ }
+ public static void log(String msg1, String msg2, String msg3)
+ {
+ log(msg1+msg2+msg3);
+ }
+
+ public static void error(String message)
+ {
+ message = "Error: " + message;
+ log.error(message);
+ }
+ public static void error(String message, Throwable e)
+ {
+ error(message+"\n\t"+e.toString());
+ e.printStackTrace(System.out);
+ }
+ public static void error(String msg1, String msg2, Throwable e)
+ {
+ error(msg1+"\n"+msg2+"\n\t", e);
+ }
+ public static void error(String msg1, String msg2, String msg3, Throwable e)
+ {
+ error(msg1+"\n"+msg2+"\n"+msg3+"\n\t", e);
+ }
+ public static void error(Throwable e, String message)
+ {
+ error(message+"\n\t",e);
+ e.printStackTrace(System.out);
+ }
+ public static void error(Throwable e, String msg1, String msg2)
+ {
+ error(msg1+"\n"+msg2+"\n\t",e);
+ }
+ public static void error(Throwable e, String msg1, String msg2, String msg3)
+ {
+ error(msg1+"\n"+msg2+"\n"+msg3+"\n\t", e);
+ }
+
+
+ public static void trace(String message)
+ {
+ log.trace(message + " threadID="+ Thread.currentThread());
+ }
+
+ public static void trace(String message, Object parm1)
+ {
+ trace(message+"("+parm1+")");
+ }
+
+ public static void trace(String message, Object parm1, Object parm2)
+ {
+ trace(message+"("+parm1+", "+parm2+")");
+ }
+
+ public static void trace(String message, Object parm1, Object parm2, Object parm3)
+ {
+ trace(message+"("+parm1+", "+parm2+", "+parm3+")");
+ }
+ public static void trace(String message, Object parm1, Object parm2, Object parm3, Object parm4)
+ {
+ trace(message+"("+parm1+", "+parm2+", "+parm3+")"+", "+parm4);
+ }
+ public static void trace(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5)
+ {
+ trace(message+"("+parm1+", "+parm2+", "+parm3+")"+", "+parm4+", "+parm5);
+ }
+ public static void trace(String message, Object parm1, Object parm2, Object parm3, Object parm4,
+ Object parm5, Object parm6)
+ {
+ trace(message+"("+parm1+", "+parm2+", "+parm3+")"+", "+parm4+", "+parm5+", "+parm6);
+ }
+ public static void trace(String message, Object parm1, Object parm2, Object parm3, Object parm4,
+ Object parm5, Object parm6, Object parm7)
+ {
+ trace(message+"("+parm1+", "+parm2+", "+parm3+")"+", "+parm4+", "+parm5+", "+parm6+", "+parm7);
+ }
+ public static void traceEnter(String message)
+ {
+ log.trace("Method enter --" + message);
+ }
+ public static void traceExit(String message)
+ {
+ log.trace("Method exit --" + message);
+ }
+
+
+ public static void stat(String message)
+ {
+ log(message);
+ }
+
+ public static void debug(String message)
+ {
+ log.debug(message);
+ }
+
+ public static void print(String message)
+ {
+ log(message);
+ }
+
+ public static void printObject(Object o)
+ {
+ log("\t"+o.toString());
+ }
+
+ public static void printCollection(Collection c)
+ {
+ log("\t---Log.printCollection -- collection size=" + c.size());
+ Iterator it = c.iterator();
+ while ( it.hasNext() )
+ {
+ log("\t\t"+it.next().toString());
+ }
+ log("\t---Log.printCollection -- complete");
+ }
+
+ public static void printCollection(String message, Collection c)
+ {
+ log(message);
+ printCollection(c);
+ }
+
+ public static boolean doActionTrace()
+ {
+ return getTrace() || getActionTrace();
+ }
+
+ public static boolean doTrace()
+ {
+ return getTrace();
+ }
+
+ public static boolean doDebug()
+ {
+ return true;
+ }
+
+ public static boolean doStat()
+ {
+ return true;
+ }
+
+ /**
+ * Gets the trace
+ * @return Returns a boolean
+ */
+ public static boolean getTrace() {
+ return TradeConfig.getTrace();
+ }
+ /**
+ * Gets the trace value for Trade actions only
+ * @return Returns a boolean
+ */
+ public static boolean getActionTrace() {
+ return TradeConfig.getActionTrace();
+ }
+
+ /**
+ * Sets the trace
+ * @param trace The trace to set
+ */
+ public static void setTrace(boolean traceValue)
+ {
+ TradeConfig.setTrace(traceValue);
+ }
+ /**
+ * Sets the trace value for Trade actions only
+ * @param trace The trace to set
+ */
+ public static void setActionTrace(boolean traceValue)
+ {
+ TradeConfig.setActionTrace(traceValue);
+ }
+}
+
Propchange: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/Log.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/MDBStats.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/MDBStats.java?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/MDBStats.java (added)
+++ geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/MDBStats.java Mon Aug 31 18:48:41 2009
@@ -0,0 +1,72 @@
+/**
+ * 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.geronimo.samples.daytrader.util;
+
+
+/**
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class MDBStats extends java.util.HashMap {
+
+
+ //Singleton class
+ private static MDBStats mdbStats = null;
+ private MDBStats()
+ {
+ }
+
+ public static synchronized MDBStats getInstance()
+ {
+ if (mdbStats == null)
+ mdbStats = new MDBStats();
+ return mdbStats;
+ }
+
+ public TimerStat addTiming(String type, long sendTime, long recvTime)
+ {
+ TimerStat stats = null;
+ synchronized (type)
+ {
+
+ stats = (TimerStat) get(type);
+ if (stats == null) stats = new TimerStat();
+
+ long time = recvTime - sendTime;
+ if ( time > stats.getMax() ) stats.setMax(time);
+ if ( time < stats.getMin() ) stats.setMin(time);
+ stats.setCount(stats.getCount()+1);
+ stats.setTotalTime(stats.getTotalTime() + time);
+
+ put(type, stats);
+ }
+ return stats;
+ }
+
+
+
+ public synchronized void reset()
+ {
+ clear();
+ }
+
+
+
+}
Propchange: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/MDBStats.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TimerStat.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TimerStat.java?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TimerStat.java (added)
+++ geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TimerStat.java Mon Aug 31 18:48:41 2009
@@ -0,0 +1,121 @@
+/**
+ * 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.geronimo.samples.daytrader.util;
+
+/**
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class TimerStat {
+
+ private double min=1000000000.0, max=0.0, totalTime=0.0;
+ private int count;
+ /**
+ * Returns the count.
+ * @return int
+ */
+ public int getCount() {
+ return count;
+ }
+
+ /**
+ * Returns the max.
+ * @return double
+ */
+ public double getMax() {
+ return max;
+ }
+
+ /**
+ * Returns the min.
+ * @return double
+ */
+ public double getMin() {
+ return min;
+ }
+
+ /**
+ * Sets the count.
+ * @param count The count to set
+ */
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ /**
+ * Sets the max.
+ * @param max The max to set
+ */
+ public void setMax(double max) {
+ this.max = max;
+ }
+
+ /**
+ * Sets the min.
+ * @param min The min to set
+ */
+ public void setMin(double min) {
+ this.min = min;
+ }
+
+ /**
+ * Returns the totalTime.
+ * @return double
+ */
+ public double getTotalTime() {
+ return totalTime;
+ }
+
+ /**
+ * Sets the totalTime.
+ * @param totalTime The totalTime to set
+ */
+ public void setTotalTime(double totalTime) {
+ this.totalTime = totalTime;
+ }
+
+ /**
+ * Returns the max in Secs
+ * @return double
+ */
+ public double getMaxSecs() {
+ return max/1000.0;
+ }
+
+ /**
+ * Returns the min in Secs
+ * @return double
+ */
+ public double getMinSecs() {
+ return min/1000.0;
+ }
+
+ /**
+ * Returns the average time in Secs
+ * @return double
+ */
+ public double getAvgSecs() {
+
+ double avg = (double)getTotalTime() / (double)getCount();
+ return avg / 1000.0;
+ }
+
+
+}
Propchange: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TimerStat.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TradeConfig.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TradeConfig.java?rev=809686&view=auto
==============================================================================
--- geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TradeConfig.java (added)
+++ geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TradeConfig.java Mon Aug 31 18:48:41 2009
@@ -0,0 +1,894 @@
+/**
+ * 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.geronimo.samples.daytrader.util;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Random;
+
+
+/**
+ * TradeConfig is a JavaBean holding all configuration and runtime parameters for the Trade application
+ * TradeConfig sets runtime parameters such as the RunTimeMode (EJB3, DIRECT, SESSION3, JPA)
+ *
+ */
+
+public class TradeConfig {
+
+ /* Trade Runtime Configuration Parameters */
+
+ /* Trade Runtime Mode parameters */
+ public static String[] runTimeModeNames = {"Full EJB3", "Direct (JDBC)", "Session (EJB3) To Direct", "Direct (JPA)"};
+ public static final int EJB3 = 0;
+ public static final int DIRECT = 1;
+ public static final int SESSION3 = 2;
+ public static final int JPA = 3;
+ public static int runTimeMode = DIRECT;
+
+ /* Trade JPA Layer parameters */
+ public static String[] jpaLayerNames = {"OpenJPA", "Hibernate"};
+ public static final int OPENJPA = 0;
+ public static final int HIBERNATE = 1;
+ public static int jpaLayer = OPENJPA;
+
+ public static String[] orderProcessingModeNames =
+ { "Synchronous", "Asynchronous_2-Phase" };
+ public static final int SYNCH = 0;
+ public static final int ASYNCH_2PHASE = 1;
+ public static int orderProcessingMode = SYNCH;
+
+ public static String[] accessModeNames = { "Standard", "WebServices" };
+ public static final int STANDARD = 0;
+ public static final int WEBSERVICES = 1;
+ private static int accessMode = STANDARD;
+
+ /* Trade Scenario Workload parameters */
+ public static String[] workloadMixNames = { "Standard", "High-Volume", };
+ public final static int SCENARIOMIX_STANDARD = 0;
+ public final static int SCENARIOMIX_HIGHVOLUME = 1;
+ public static int workloadMix = SCENARIOMIX_STANDARD;
+
+ /* Trade Web Interface parameters */
+ public static String[] webInterfaceNames = { "JSP", "JSP-Images" };
+ public static final int JSP = 0;
+ public static final int JSP_Images = 1;
+ public static int webInterface = JSP;
+
+ /* Trade Caching Type parameters */
+ public static String[] cachingTypeNames = { "DistributedMap", "Command Caching", "No Caching" };
+ public static final int DISTRIBUTEDMAP = 0;
+ public static final int COMMAND_CACHING = 1;
+ public static final int NO_CACHING = 2;
+ public static int cachingType = NO_CACHING;
+
+ /* Trade Database Scaling parameters*/
+ private static int MAX_USERS = 500;
+ private static int MAX_QUOTES = 1000;
+
+ /* Trade Database specific paramters */
+ public static String JDBC_UID = null;
+ public static String JDBC_PWD = null;
+ public static String DS_NAME = "java:comp/env/jdbc/TradeDataSource";
+
+ /*Trade SOAP specific parameters */
+ private static String SoapURL =
+ "http://localhost:8080/daytrader/services/TradeWSServices";
+
+ /*Trade XA Datasource specific parameters */
+ public static boolean JDBCDriverNeedsGlobalTransaction = false;
+
+ /* Trade Config Miscellaneous itmes */
+ public static String DATASOURCE = "java:comp/env/jdbc/TradeDataSource";
+ public static int KEYBLOCKSIZE = 1000;
+ public static int QUOTES_PER_PAGE = 10;
+ public static boolean RND_USER = true;
+ //public static int RND_SEED = 0;
+ private static int MAX_HOLDINGS = 10;
+ private static int count = 0;
+ private static Object userID_count_semaphore = new Object();
+ private static int userID_count = 0;
+ private static String hostName = null;
+ private static Random r0 = new Random(System.currentTimeMillis());
+ //private static Random r1 = new Random(RND_SEED);
+ private static Random randomNumberGenerator = r0;
+ public static final String newUserPrefix = "ru:";
+ public static final int verifyPercent = 5;
+ private static boolean trace = false;
+ private static boolean actionTrace = false;
+ private static boolean updateQuotePrices = true;
+ private static int primIterations = 1;
+ private static boolean longRun = true;
+ private static boolean publishQuotePriceChange = false;
+
+ /**
+ * -1 means every operation
+ * 0 means never perform a market summary
+ * > 0 means number of seconds between summaries. These will be
+ * synchronized so only one transaction in this period will create a summary and
+ * will cache its results.
+ */
+ private static int marketSummaryInterval = 20;
+
+ /*
+ * Penny stocks is a problem where the random price change factor gets a stock
+ * down to $.01. In this case trade jumpstarts the price back to $6.00 to
+ * keep the math interesting.
+ */
+ public static BigDecimal PENNY_STOCK_PRICE;
+ public static BigDecimal PENNY_STOCK_RECOVERY_MIRACLE_MULTIPLIER;
+ static {
+ PENNY_STOCK_PRICE = new BigDecimal(0.01);
+ PENNY_STOCK_PRICE =
+ PENNY_STOCK_PRICE.setScale(2, BigDecimal.ROUND_HALF_UP);
+ PENNY_STOCK_RECOVERY_MIRACLE_MULTIPLIER = new BigDecimal(600.0);
+ PENNY_STOCK_RECOVERY_MIRACLE_MULTIPLIER.setScale(
+ 2,
+ BigDecimal.ROUND_HALF_UP);
+ }
+
+ /* CJB (DAYTRADER-25) - Also need to impose a ceiling on the quote price to ensure
+ * prevent account and holding balances from exceeding the databases decimal precision.
+ * At some point, this maximum value can be used to trigger a stock split.
+ */
+
+ public static BigDecimal MAXIMUM_STOCK_PRICE;
+ public static BigDecimal MAXIMUM_STOCK_SPLIT_MULTIPLIER;
+ static {
+ MAXIMUM_STOCK_PRICE = new BigDecimal(400);
+ MAXIMUM_STOCK_PRICE.setScale(2, BigDecimal.ROUND_HALF_UP);
+ MAXIMUM_STOCK_SPLIT_MULTIPLIER = new BigDecimal(0.5);
+ MAXIMUM_STOCK_SPLIT_MULTIPLIER.setScale(2, BigDecimal.ROUND_HALF_UP);
+ }
+
+ /* Trade Scenario actions mixes. Each of the array rows represents a specific Trade Scenario Mix.
+ The columns give the percentages for each action in the column header. Note: "login" is always 0.
+ logout represents both login and logout (because each logout operation will cause a new login when
+ the user context attempts the next action.
+ */
+ /* Trade Scenario Workload parameters */
+ public final static int HOME_OP = 0;
+ public final static int QUOTE_OP = 1;
+ public final static int LOGIN_OP = 2;
+ public final static int LOGOUT_OP = 3;
+ public final static int REGISTER_OP = 4;
+ public final static int ACCOUNT_OP = 5;
+ public final static int PORTFOLIO_OP = 6;
+ public final static int BUY_OP = 7;
+ public final static int SELL_OP = 8;
+ public final static int UPDATEACCOUNT_OP = 9;
+
+ private static int scenarioMixes[][] = {
+ // h q l o r a p b s u
+ { 20, 40, 0, 4, 2, 10, 12, 4, 4, 4 }, //STANDARD
+ {
+ 20, 40, 0, 4, 2, 7, 7, 7, 7, 6 }, //High Volume
+ };
+ private static char actions[] =
+ { 'h', 'q', 'l', 'o', 'r', 'a', 'p', 'b', 's', 'u' };
+ private static int sellDeficit = 0;
+ //Tracks the number of buys over sell when a users portfolio is empty
+ // Used to maintain the correct ratio of buys/sells
+
+ /* JSP pages for all Trade Actions */
+
+ public final static int WELCOME_PAGE = 0;
+ public final static int REGISTER_PAGE = 1;
+ public final static int PORTFOLIO_PAGE = 2;
+ public final static int QUOTE_PAGE = 3;
+ public final static int HOME_PAGE = 4;
+ public final static int ACCOUNT_PAGE = 5;
+ public final static int ORDER_PAGE = 6;
+ public final static int CONFIG_PAGE = 7;
+ public final static int STATS_PAGE = 8;
+
+ //FUTURE Add XML/XSL View
+ public static String webUI[][] =
+ {
+ {
+ "/welcome.jsp",
+ "/register.jsp",
+ "/portfolio.jsp",
+ "/quote.jsp",
+ "/tradehome.jsp",
+ "/account.jsp",
+ "/order.jsp",
+ "/config.jsp",
+ "/runStats.jsp" },
+ //JSP Interface
+ {
+ "/welcomeImg.jsp",
+ "/registerImg.jsp",
+ "/portfolioImg.jsp",
+ "/quoteImg.jsp",
+ "/tradehomeImg.jsp",
+ "/accountImg.jsp",
+ "/orderImg.jsp",
+ "/config.jsp",
+ "/runStats.jsp" },
+ //JSP Interface
+ };
+
+ // These are the property settings the VAJ access beans look for.
+ private static final String NAMESERVICE_TYPE_PROPERTY =
+ "java.naming.factory.initial";
+ private static final String NAMESERVICE_PROVIDER_URL_PROPERTY =
+ "java.naming.provider.url";
+
+ // FUTURE:
+ // If a "trade2.properties" property file is supplied, reset the default values
+ // to match those specified in the file. This provides a persistent runtime
+ // property mechanism during server startup
+
+ /**
+ * Return the hostname for this system
+ * Creation date: (2/16/2000 9:02:25 PM)
+ */
+
+ private static String getHostname() {
+ try {
+ if (hostName == null) {
+ hostName = java.net.InetAddress.getLocalHost().getHostName();
+ //Strip of fully qualifed domain if necessary
+ try {
+ hostName = hostName.substring(0, hostName.indexOf('.'));
+ } catch (Exception e) {
+ }
+ }
+ } catch (Exception e) {
+ Log.error(
+ "Exception getting local host name using 'localhost' - ",
+ e);
+ hostName = "localhost";
+ }
+ return hostName;
+ }
+
+ /**
+ * Return a Trade UI Web page based on the current configuration
+ * This may return a JSP page or a Servlet page
+ * Creation date: (3/14/2000 9:08:34 PM)
+ */
+
+ public static String getPage(int pageNumber) {
+ return webUI[webInterface][pageNumber];
+ }
+
+ /**
+ * Return the list of run time mode names
+ * Creation date: (3/8/2000 5:58:34 PM)
+ * @return java.lang.String[]
+ */
+ public static java.lang.String[] getRunTimeModeNames() {
+ return runTimeModeNames;
+ }
+
+ private static int scenarioCount = 0;
+
+ /**
+ * Return a Trade Scenario Operation based on the setting of the current mix (TradeScenarioMix)
+ * Creation date: (2/10/2000 9:08:34 PM)
+ */
+
+ public static char getScenarioAction(boolean newUser) {
+ int r = rndInt(100); //0 to 99 = 100
+ int i = 0;
+ int sum = scenarioMixes[workloadMix][i];
+ while (sum <= r) {
+ i++;
+ sum += scenarioMixes[workloadMix][i];
+ }
+
+ incrementScenarioCount();
+
+ /* In TradeScenarioServlet, if a sell action is selected, but the users portfolio is empty,
+ * a buy is executed instead and sellDefecit is incremented. This allows the number of buy/sell
+ * operations to stay in sync w/ the given Trade mix.
+ */
+
+ if ((!newUser) && (actions[i] == 'b')) {
+ synchronized (TradeConfig.class) {
+ if (sellDeficit > 0) {
+ sellDeficit--;
+ return 's';
+ //Special case for TradeScenarioServlet to note this is a buy switched to a sell to fix sellDeficit
+ }
+ }
+ }
+
+ return actions[i];
+ }
+
+ public static String getUserID() {
+ String userID;
+ if (RND_USER) {
+ userID = rndUserID();
+ } else {
+ userID = nextUserID();
+ }
+ return userID;
+ }
+ private static final BigDecimal orderFee = new BigDecimal("24.95");
+ private static final BigDecimal cashFee = new BigDecimal("0.0");
+ public static BigDecimal getOrderFee(String orderType) {
+ if ((orderType.compareToIgnoreCase("BUY") == 0)
+ || (orderType.compareToIgnoreCase("SELL") == 0))
+ return orderFee;
+
+ return cashFee;
+
+ }
+
+ /**
+ * Increment the sell deficit counter
+ * Creation date: (6/21/2000 11:33:45 AM)
+ */
+ public synchronized static void incrementSellDeficit() {
+ sellDeficit++;
+ }
+
+ public static String nextUserID() {
+ String userID;
+ synchronized (userID_count_semaphore) {
+ userID = "uid:" + userID_count;
+ userID_count++;
+ if (userID_count % MAX_USERS == 0) {
+ userID_count = 0;
+ }
+ }
+ return userID;
+ }
+ public static double random() {
+ return randomNumberGenerator.nextDouble();
+ }
+ public static String rndAddress() {
+ return rndInt(1000) + " Oak St.";
+ }
+ public static String rndBalance() {
+ //Give all new users a cool mill in which to trade
+ return "1000000";
+ }
+ public static String rndCreditCard() {
+ return rndInt(100)
+ + "-"
+ + rndInt(1000)
+ + "-"
+ + rndInt(1000)
+ + "-"
+ + rndInt(1000);
+ }
+ public static String rndEmail(String userID) {
+ return userID + "@" + rndInt(100) + ".com";
+ }
+ public static String rndFullName() {
+ return "first:" + rndInt(1000) + " last:" + rndInt(5000);
+ }
+ public static int rndInt(int i) {
+ return (new Float(random() * i)).intValue();
+ }
+ public static float rndFloat(int i) {
+ return (new Float(random() * i)).floatValue();
+ }
+ public static BigDecimal rndBigDecimal(float f) {
+ return (new BigDecimal(random() * f)).setScale(
+ 2,
+ BigDecimal.ROUND_HALF_UP);
+ }
+
+ public static boolean rndBoolean() {
+ return randomNumberGenerator.nextBoolean();
+ }
+
+ /**
+ * Returns a new Trade user
+ * Creation date: (2/16/2000 8:50:35 PM)
+ */
+ public synchronized static String rndNewUserID() {
+
+ return newUserPrefix
+ + getHostname()
+ + System.currentTimeMillis()
+ + count++;
+ }
+
+ public static float rndPrice() {
+ return ((new Integer(rndInt(200))).floatValue()) + 1.0f;
+ }
+ private final static BigDecimal ONE = new BigDecimal(1.0);
+ public static BigDecimal getRandomPriceChangeFactor() {
+ // CJB (DAYTRADER-25) - Vary change factor between 1.2 and 0.8
+ double percentGain = rndFloat(1) * 0.2;
+ if (random() < .5)
+ percentGain *= -1;
+ percentGain += 1;
+
+ // change factor is between +/- 20%
+ BigDecimal percentGainBD =
+ (new BigDecimal(percentGain)).setScale(2, BigDecimal.ROUND_HALF_UP);
+ if (percentGainBD.doubleValue() <= 0.0)
+ percentGainBD = ONE;
+
+ return percentGainBD;
+ }
+
+ public static float rndQuantity() {
+ return ((new Integer(rndInt(200))).floatValue()) + 1.0f;
+ }
+
+ public static String rndSymbol() {
+ return "s:" + rndInt(MAX_QUOTES - 1);
+ }
+ public static String rndSymbols() {
+
+ String symbols = "";
+ int num_symbols = rndInt(QUOTES_PER_PAGE);
+
+ for (int i = 0; i <= num_symbols; i++) {
+ symbols += "s:" + rndInt(MAX_QUOTES - 1);
+ if (i < num_symbols)
+ symbols += ",";
+ }
+ return symbols;
+ }
+
+ public static String rndUserID() {
+ String nextUser = getNextUserIDFromDeck();
+ if (Log.doTrace())
+ Log.trace("TradeConfig:rndUserID -- new trader = " + nextUser);
+
+ return nextUser;
+ }
+
+ private static synchronized String getNextUserIDFromDeck() {
+ int numUsers = getMAX_USERS();
+ if (deck == null) {
+ deck = new ArrayList(numUsers);
+ for (int i = 0; i < numUsers; i++)
+ deck.add(i, new Integer(i));
+ java.util.Collections.shuffle(deck, r0);
+ }
+ if (card >= numUsers)
+ card = 0;
+ return "uid:" + deck.get(card++);
+
+ }
+
+ //Trade implements a card deck approach to selecting
+ // users for trading with tradescenarioservlet
+ private static ArrayList deck = null;
+ private static int card = 0;
+
+ /**
+ * Set the list of run time mode names
+ * Creation date: (3/8/2000 5:58:34 PM)
+ * @param newRunTimeModeNames java.lang.String[]
+ */
+ public static void setRunTimeModeNames(
+ java.lang.String[] newRunTimeModeNames) {
+ runTimeModeNames = newRunTimeModeNames;
+ }
+ /**
+ * This is a convenience method for servlets to set Trade configuration parameters
+ * from servlet initialization parameters. The servlet provides the init param and its
+ * value as strings. This method then parses the parameter, converts the value to the
+ * correct type and sets the corresponding TradeConfig parameter to the converted value
+ *
+ */
+ public static void setConfigParam(String parm, String value) {
+ Log.log("TradeConfig setting parameter: " + parm + "=" + value);
+ // Compare the parm value to valid TradeConfig parameters that can be set
+ // by servlet initialization
+
+ // First check the proposed new parm and value - if empty or null ignore it
+ if (parm == null)
+ return;
+ parm = parm.trim();
+ if (parm.length() <= 0)
+ return;
+ if (value == null)
+ return;
+ value = value.trim();
+
+ if (parm.equalsIgnoreCase("runTimeMode")) {
+ try {
+ for (int i = 0; i < runTimeModeNames.length; i++) {
+ if (value.equalsIgnoreCase(runTimeModeNames[i])) {
+ runTimeMode = i;
+ break;
+ }
+ }
+ } catch (Exception e) {
+ //>>rjm
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "trying to set runtimemode to "
+ + value
+ + "reverting to current value: "
+ + runTimeModeNames[runTimeMode],
+ e);
+ } // If the value is bad, simply revert to current
+ } else if (parm.equalsIgnoreCase("orderProcessingMode")) {
+ try {
+ for (int i = 0; i < orderProcessingModeNames.length; i++) {
+ if (value.equalsIgnoreCase(orderProcessingModeNames[i])) {
+ orderProcessingMode = i;
+ break;
+ }
+ }
+ } catch (Exception e) {
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "trying to set orderProcessingMode to "
+ + value
+ + "reverting to current value: "
+ + orderProcessingModeNames[orderProcessingMode],
+ e);
+ } // If the value is bad, simply revert to current
+ } else if (parm.equalsIgnoreCase("accessMode")) {
+ try {
+ for (int i = 0; i < accessModeNames.length; i++) {
+ if (value.equalsIgnoreCase(accessModeNames[i])) {
+ accessMode = i;
+ break;
+ }
+ }
+ }
+ catch (Exception e) {
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "trying to set accessMode to "
+ + value
+ + "reverting to current value: "
+ + accessModeNames[accessMode],
+ e);
+ }
+ } else if (parm.equalsIgnoreCase("webServicesEndpoint")) {
+ try {
+ setSoapURL(value);
+ } catch (Exception e) {
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "Setting web services endpoint",
+ e);
+ } //On error, revert to saved
+ } else if (parm.equalsIgnoreCase("workloadMix")) {
+ try {
+ for (int i = 0; i < workloadMixNames.length; i++) {
+ if (value.equalsIgnoreCase(workloadMixNames[i])) {
+ workloadMix = i;
+ break;
+ }
+ }
+ } catch (Exception e) {
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "trying to set workloadMix to "
+ + value
+ + "reverting to current value: "
+ + workloadMixNames[workloadMix],
+ e);
+ } // If the value is bad, simply revert to current
+ } else if (parm.equalsIgnoreCase("WebInterface")) {
+ try {
+ for (int i = 0; i < webInterfaceNames.length; i++) {
+ if (value.equalsIgnoreCase(webInterfaceNames[i])) {
+ webInterface = i;
+ break;
+ }
+ }
+ } catch (Exception e) {
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "trying to set WebInterface to "
+ + value
+ + "reverting to current value: "
+ + webInterfaceNames[webInterface],
+ e);
+
+ } // If the value is bad, simply revert to current
+ } else if (parm.equalsIgnoreCase("CachingType")) {
+ try {
+ for (int i = 0; i < cachingTypeNames.length; i++) {
+ if (value.equalsIgnoreCase(cachingTypeNames[i])) {
+ cachingType = i;
+ break;
+ }
+ }
+ } catch (Exception e) {
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "trying to set CachingType to "
+ + value
+ + "reverting to current value: "
+ + cachingTypeNames[cachingType],
+ e);
+ } // If the value is bad, simply revert to current
+ } else if (parm.equalsIgnoreCase("maxUsers")) {
+ try {
+ MAX_USERS = Integer.parseInt(value);
+ } catch (Exception e) {
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "Setting maxusers, error parsing string to int:"
+ + value
+ + "revering to current value: "
+ + MAX_USERS,
+ e);
+ } //On error, revert to saved
+ } else if (parm.equalsIgnoreCase("maxQuotes")) {
+ try {
+ MAX_QUOTES = Integer.parseInt(value);
+ } catch (Exception e) {
+ //>>rjm
+ Log.error(
+ "TradeConfig.setConfigParm(...) minor exception caught"
+ + "Setting max_quotes, error parsing string to int "
+ + value
+ + "reverting to current value: "
+ + MAX_QUOTES,
+ e);
+ //<<rjm
+ } //On error, revert to saved
+ } else if (parm.equalsIgnoreCase("primIterations")) {
+ try {
+ primIterations = Integer.parseInt(value);
+ } catch (Exception e) {
+ Log.error(
+ "TradeConfig.setConfigParm(..): minor exception caught"
+ + "Setting primIterations, error parsing string to int:"
+ + value
+ + "revering to current value: "
+ + primIterations,
+ e);
+ } //On error, revert to saved
+ }
+ }
+
+ /**
+ * Gets the orderProcessingModeNames
+ * @return Returns a String[]
+ */
+ public static String[] getOrderProcessingModeNames() {
+ return orderProcessingModeNames;
+ }
+
+ /**
+ * Gets the workloadMixNames
+ * @return Returns a String[]
+ */
+ public static String[] getWorkloadMixNames() {
+ return workloadMixNames;
+ }
+
+ /**
+ * Gets the webInterfaceNames
+ * @return Returns a String[]
+ */
+ public static String[] getWebInterfaceNames() {
+ return webInterfaceNames;
+ }
+
+ /**
+ * Gets the webInterfaceNames
+ * @return Returns a String[]
+ */
+ public static String[] getCachingTypeNames() {
+ return cachingTypeNames;
+ }
+
+ /**
+ * Gets the scenarioMixes
+ * @return Returns a int[][]
+ */
+ public static int[][] getScenarioMixes() {
+ return scenarioMixes;
+ }
+
+ /**
+ * Gets the trace
+ * @return Returns a boolean
+ */
+ public static boolean getTrace() {
+ return trace;
+ }
+ /**
+ * Sets the trace
+ * @param trace The trace to set
+ */
+ public static void setTrace(boolean traceValue) {
+ trace = traceValue;
+ }
+
+ /**
+ * Gets the mAX_USERS.
+ * @return Returns a int
+ */
+ public static int getMAX_USERS() {
+ return MAX_USERS;
+ }
+
+ /**
+ * Sets the mAX_USERS.
+ * @param mAX_USERS The mAX_USERS to set
+ */
+ public static void setMAX_USERS(int mAX_USERS) {
+ MAX_USERS = mAX_USERS;
+ deck = null; // reset the card deck for selecting users
+ }
+
+ /**
+ * Gets the mAX_QUOTES.
+ * @return Returns a int
+ */
+ public static int getMAX_QUOTES() {
+ return MAX_QUOTES;
+ }
+
+ /**
+ * Sets the mAX_QUOTES.
+ * @param mAX_QUOTES The mAX_QUOTES to set
+ */
+ public static void setMAX_QUOTES(int mAX_QUOTES) {
+ MAX_QUOTES = mAX_QUOTES;
+ }
+
+ /**
+ * Gets the mAX_HOLDINGS.
+ * @return Returns a int
+ */
+ public static int getMAX_HOLDINGS() {
+ return MAX_HOLDINGS;
+ }
+
+ /**
+ * Sets the mAX_HOLDINGS.
+ * @param mAX_HOLDINGS The mAX_HOLDINGS to set
+ */
+ public static void setMAX_HOLDINGS(int mAX_HOLDINGS) {
+ MAX_HOLDINGS = mAX_HOLDINGS;
+ }
+
+ /**
+ * Gets the actionTrace.
+ * @return Returns a boolean
+ */
+ public static boolean getActionTrace() {
+ return actionTrace;
+ }
+
+ /**
+ * Sets the actionTrace.
+ * @param actionTrace The actionTrace to set
+ */
+ public static void setActionTrace(boolean actionTrace) {
+ TradeConfig.actionTrace = actionTrace;
+ }
+
+ /**
+ * Gets the scenarioCount.
+ * @return Returns a int
+ */
+ public static int getScenarioCount() {
+ return scenarioCount;
+ }
+
+ /**
+ * Sets the scenarioCount.
+ * @param scenarioCount The scenarioCount to set
+ */
+ public static void setScenarioCount(int scenarioCount) {
+ TradeConfig.scenarioCount = scenarioCount;
+ }
+
+ public static synchronized void incrementScenarioCount() {
+ scenarioCount++;
+ }
+
+ /**
+ * Gets the jdbc driver needs global transaction
+ * Some XA Drivers require a global transaction to be started
+ * for all SQL calls. To work around this, set this to true
+ * to cause the direct mode to start a user transaction.
+ * @return Returns a boolean
+ */
+ public static boolean getJDBCDriverNeedsGlobalTransaction() {
+ return JDBCDriverNeedsGlobalTransaction;
+ }
+
+ /**
+ * Sets the jdbc driver needs global transaction
+ * @param JDBCDriverNeedsGlobalTransactionVal the value
+ */
+ public static void setJDBCDriverNeedsGlobalTransaction(boolean JDBCDriverNeedsGlobalTransactionVal) {
+ JDBCDriverNeedsGlobalTransaction = JDBCDriverNeedsGlobalTransactionVal;
+ }
+
+ /**
+ * Gets the updateQuotePrices.
+ * @return Returns a boolean
+ */
+ public static boolean getUpdateQuotePrices() {
+ return updateQuotePrices;
+ }
+
+ /**
+ * Sets the updateQuotePrices.
+ * @param updateQuotePrices The updateQuotePrices to set
+ */
+ public static void setUpdateQuotePrices(boolean updateQuotePrices) {
+ TradeConfig.updateQuotePrices = updateQuotePrices;
+ }
+
+ public static String getSoapURL() {
+ return SoapURL;
+ }
+
+ public static void setSoapURL(String value) {
+ SoapURL = value;
+// TradeWebSoapProxy.updateServicePort();
+ }
+
+ public static int getAccessMode() {
+ return accessMode;
+ }
+
+ public static void setAccessMode(int value) {
+ accessMode = value;
+// TradeWebSoapProxy.updateServicePort();
+ }
+
+ public static int getPrimIterations() {
+ return primIterations;
+ }
+
+ public static void setPrimIterations(int iter) {
+ primIterations = iter;
+ }
+
+ public static boolean getLongRun() {
+ return longRun;
+ }
+
+ public static void setLongRun(boolean longRun) {
+ TradeConfig.longRun = longRun;
+ }
+
+ public static void setPublishQuotePriceChange(boolean publishQuotePriceChange) {
+ TradeConfig.publishQuotePriceChange = publishQuotePriceChange;
+ }
+
+ public static boolean getPublishQuotePriceChange() {
+ return publishQuotePriceChange;
+ }
+
+ public static void setMarketSummaryInterval(int seconds) {
+ TradeConfig.marketSummaryInterval = seconds;
+ }
+
+ public static int getMarketSummaryInterval() {
+ return TradeConfig.marketSummaryInterval;
+ }
+
+ /**
+ * Return the list of JPA Layer names
+ * Creation date: (01/10/2009)
+ * @return java.lang.String[]
+ */
+ public static java.lang.String[] getJPALayerNames() {
+ return jpaLayerNames;
+ }
+
+}
Propchange: geronimo/daytrader/trunk/modules/util/src/main/java/org/apache/geronimo/samples/daytrader/util/TradeConfig.java
------------------------------------------------------------------------------
svn:eol-style = native