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 [4/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-derby-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-derby-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-derby-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-derby-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml Sun Feb 27 18:28:26 2011
@@ -0,0 +1,44 @@
+<?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 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"
+ default-activation="eager">
+
+ <bean id="derbyXADataSource" class="org.apache.derby.jdbc.EmbeddedXADataSource">
+ <property name="databaseName" value="tradedb"/>
+ </bean>
+
+ <service id="TradeDataSource" ref="derbyXADataSource" interface="javax.sql.XADataSource">
+ <service-properties>
+ <entry key="osgi.jndi.service.name" value="jdbc/TradeDataSource"/>
+ </service-properties>
+ </service>
+
+
+ <bean id="derbyDataSource" class="org.apache.derby.jdbc.EmbeddedDataSource">
+ <property name="databaseName" value="tradedb"/>
+ </bean>
+
+ <service id="NoTxTradeDataSource" ref="derbyDataSource" interface="javax.sql.DataSource">
+ <service-properties>
+ <entry key="osgi.jndi.service.name" value="jdbc/NoTxTradeDataSource"/>
+ </service-properties>
+ </service>
+
+</blueprint>
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/pom.xml?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/pom.xml (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/pom.xml Sun Feb 27 18:28:26 2011
@@ -0,0 +1,138 @@
+<?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.entities</artifactId>
+ <packaging>bundle</packaging>
+ <name>AriesTrader :: Modules - Entities</name>
+ <description>AriesTrader JPA Enhanced Entities 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>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+<!--
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jpa_1.0_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+-->
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jpa_2.0_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <!-- OpenJPA PCEnhancer depends -->
+ <dependency>
+ <groupId>net.sourceforge.serp</groupId>
+ <artifactId>serp</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <!-- end OpenJPA PCEnhancer depends -->
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <configuration>
+ <tasks>
+ <path id="enhance.path.ref">
+ <fileset dir="${project.build.outputDirectory}">
+ <include name="*Bean*/*.class" />
+ </fileset>
+ </path>
+ <pathconvert property="enhance.files" refid="enhance.path.ref" pathsep=" " />
+ <java classname="org.apache.openjpa.enhance.PCEnhancer">
+ <arg line="-p persistence.xml" />
+ <arg line="${enhance.files}" />
+ <classpath>
+ <path refid="maven.dependency.classpath" />
+ <path refid="maven.compile.classpath" />
+ </classpath>
+ </java>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <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>
+ <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
+ <Export-Package>
+ org.apache.aries.samples.ariestrader.entities;version=${pom.version}
+ </Export-Package>
+ <Import-Package>
+ org.apache.openjpa.enhance;version="[1.0.0,2.1.0)",
+ org.apache.openjpa.util;version="[1.0.0,2.1.0)",
+ javax.persistence;version="[1.0.0,2.1.0)",
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/AccountDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/AccountDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/AccountDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/AccountDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,321 @@
+/**
+ * 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.entities;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+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;
+
+@Entity (name = "accountejb")
+@Table(name = "accountejb")
+@NamedQueries( {
+ @NamedQuery(name = "accountejb.findByCreationdate", query = "SELECT a FROM accountejb a WHERE a.creationDate = :creationdate"),
+ @NamedQuery(name = "accountejb.findByOpenbalance", query = "SELECT a FROM accountejb a WHERE a.openBalance = :openbalance"),
+ @NamedQuery(name = "accountejb.findByLogoutcount", query = "SELECT a FROM accountejb a WHERE a.logoutCount = :logoutcount"),
+ @NamedQuery(name = "accountejb.findByBalance", query = "SELECT a FROM accountejb a WHERE a.balance = :balance"),
+ @NamedQuery(name = "accountejb.findByAccountid", query = "SELECT a FROM accountejb a WHERE a.accountID = :accountid"),
+ @NamedQuery(name = "accountejb.findByAccountid_eager", query = "SELECT a FROM accountejb a LEFT JOIN FETCH a.profile WHERE a.accountID = :accountid"),
+ @NamedQuery(name = "accountejb.findByAccountid_eagerholdings", query = "SELECT a FROM accountejb a LEFT JOIN FETCH a.holdings WHERE a.accountID = :accountid"),
+ @NamedQuery(name = "accountejb.findByLastlogin", query = "SELECT a FROM accountejb a WHERE a.lastLogin = :lastlogin"),
+ @NamedQuery(name = "accountejb.findByLogincount", query = "SELECT a FROM accountejb a WHERE a.loginCount = :logincount")
+ })
+public class AccountDataBeanImpl implements AccountDataBean, Serializable {
+
+ /* Accessor methods for persistent fields */
+ @TableGenerator(
+ name="accountIdGen",
+ table="KEYGENEJB",
+ pkColumnName="KEYNAME",
+ valueColumnName="KEYVAL",
+ pkColumnValue="account",
+ allocationSize=1000)
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.TABLE, generator="accountIdGen")
+ @Column(name = "ACCOUNTID", nullable = false)
+ private Integer accountID; /* accountID */
+
+ @Column(name = "LOGINCOUNT", nullable = false)
+ private int loginCount; /* loginCount */
+
+ @Column(name = "LOGOUTCOUNT", nullable = false)
+ private int logoutCount; /* logoutCount */
+
+ @Column(name = "LASTLOGIN")
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date lastLogin; /* lastLogin Date */
+
+ @Column(name = "CREATIONDATE")
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date creationDate; /* creationDate */
+
+ @Column(name = "BALANCE")
+ private BigDecimal balance; /* balance */
+
+ @Column(name = "OPENBALANCE")
+ private BigDecimal openBalance; /* open balance */
+
+ @OneToMany(mappedBy = "account", fetch=FetchType.LAZY)
+ private Collection<OrderDataBeanImpl> orders;
+
+ @OneToMany(mappedBy = "account", fetch=FetchType.LAZY)
+ private Collection<HoldingDataBeanImpl> holdings;
+
+ @OneToOne(fetch=FetchType.LAZY)
+ @JoinColumn(name="PROFILE_USERID")
+ private AccountProfileDataBeanImpl profile;
+
+ /* Accessor methods for relationship fields are only included for the AccountProfile profileID */
+ @Transient
+ 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() {
+ Collection orderDataBeans = new ArrayList();
+ for (OrderDataBeanImpl o : orders ) {
+ orderDataBeans.add( (OrderDataBean) o);
+ }
+ return orderDataBeans;
+ }
+
+ public void setOrders(Collection<OrderDataBeanImpl> orders) {
+ this.orders = orders;
+ }
+
+ public Collection<HoldingDataBean> getHoldings() {
+ Collection holdingDataBeans = new ArrayList();
+ for (HoldingDataBeanImpl h : holdings ) {
+ holdingDataBeans.add( (HoldingDataBean) h);
+ }
+ return holdingDataBeans;
+ }
+
+ public void setHoldings(Collection<HoldingDataBeanImpl> holdings) {
+ this.holdings = holdings;
+ }
+
+ public AccountProfileDataBean getProfile() {
+ return profile;
+ }
+
+ public void setProfile(AccountProfileDataBean profile) {
+ this.profile = (AccountProfileDataBeanImpl) 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-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/AccountProfileDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/AccountProfileDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/AccountProfileDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/AccountProfileDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,193 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+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;
+
+@Entity(name = "accountprofileejb")
+@Table(name = "accountprofileejb")
+@NamedQueries( {
+ @NamedQuery(name = "accountprofileejb.findByAddress", query = "SELECT a FROM accountprofileejb a WHERE a.address = :address"),
+ @NamedQuery(name = "accountprofileejb.findByPasswd", query = "SELECT a FROM accountprofileejb a WHERE a.passwd = :passwd"),
+ @NamedQuery(name = "accountprofileejb.findByUserid", query = "SELECT a FROM accountprofileejb a WHERE a.userID = :userid"),
+ @NamedQuery(name = "accountprofileejb.findByEmail", query = "SELECT a FROM accountprofileejb a WHERE a.email = :email"),
+ @NamedQuery(name = "accountprofileejb.findByCreditcard", query = "SELECT a FROM accountprofileejb a WHERE a.creditCard = :creditcard"),
+ @NamedQuery(name = "accountprofileejb.findByFullname", query = "SELECT a FROM accountprofileejb a WHERE a.fullName = :fullname")
+ })
+public class AccountProfileDataBeanImpl implements AccountProfileDataBean, java.io.Serializable {
+
+ @Id
+ @Column(name = "USERID", nullable = false)
+ private String userID; /* userID */
+
+ @Column(name = "PASSWD")
+ private String passwd; /* password */
+
+ @Column(name = "FULLNAME")
+ private String fullName; /* fullName */
+
+ @Column(name = "ADDRESS")
+ private String address; /* address */
+
+ @Column(name = "email")
+ private String email; /* email */
+
+ @Column(name = "creditcard")
+ //why was it credit?
+ private String creditCard; /* creditCard */
+
+ @OneToOne(mappedBy="profile", fetch=FetchType.LAZY)
+ private AccountDataBeanImpl 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 = (AccountDataBeanImpl) 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-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/HoldingDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/HoldingDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/HoldingDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/HoldingDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,214 @@
+/**
+ * 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.entities;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.Transient;
+
+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;
+
+@Entity(name = "holdingejb")
+@Table(name = "holdingejb")
+@NamedQueries( {
+ @NamedQuery(name = "holdingejb.findByPurchaseprice", query = "SELECT h FROM holdingejb h WHERE h.purchasePrice = :purchaseprice"),
+ @NamedQuery(name = "holdingejb.findByHoldingid", query = "SELECT h FROM holdingejb h WHERE h.holdingID = :holdingid"),
+ @NamedQuery(name = "holdingejb.findByQuantity", query = "SELECT h FROM holdingejb h WHERE h.quantity = :quantity"),
+ @NamedQuery(name = "holdingejb.findByPurchasedate", query = "SELECT h FROM holdingejb h WHERE h.purchaseDate = :purchasedate"),
+ @NamedQuery(name = "holdingejb.holdingsByUserID", query = "SELECT h FROM holdingejb h where h.account.profile.userID = :userID") })
+public class HoldingDataBeanImpl implements HoldingDataBean, Serializable {
+
+ /* persistent/relationship fields */
+
+ @TableGenerator(name = "holdingIdGen", table = "KEYGENEJB", pkColumnName = "KEYNAME", valueColumnName = "KEYVAL", pkColumnValue = "holding", allocationSize = 1000)
+ @Id
+ @GeneratedValue(strategy = GenerationType.TABLE, generator = "holdingIdGen")
+ @Column(name = "HOLDINGID", nullable = false)
+ private Integer holdingID; /* holdingID */
+
+ @Column(name = "QUANTITY", nullable = false)
+ private double quantity; /* quantity */
+
+ @Column(name = "PURCHASEPRICE")
+ private BigDecimal purchasePrice; /* purchasePrice */
+
+ @Column(name = "PURCHASEDATE")
+ private Date purchaseDate; /* purchaseDate */
+ @Transient
+ private String quoteID; /* Holding() ---> Quote(1) */
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "ACCOUNT_ACCOUNTID")
+ private AccountDataBeanImpl account;
+
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinColumn(name = "QUOTE_SYMBOL")
+ private QuoteDataBeanImpl 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 = (AccountDataBeanImpl) account;
+ }
+
+ /*
+ * Disabled for D185273 public String getSymbol() { return getQuoteID(); }
+ */
+
+ public QuoteDataBean getQuote() {
+ return quote;
+ }
+
+ public void setQuote(QuoteDataBean quote) {
+ this.quote = (QuoteDataBeanImpl) 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-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/OrderDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/OrderDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/OrderDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/OrderDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,344 @@
+/**
+ * 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.entities;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+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;
+
+@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"),
+ @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 OrderDataBeanImpl implements OrderDataBean, 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, canceled)
+ */
+ @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 AccountDataBeanImpl account;
+
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinColumn(name = "QUOTE_SYMBOL")
+ private QuoteDataBeanImpl quote;
+
+ @OneToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "HOLDING_HOLDINGID")
+ private HoldingDataBeanImpl holding;
+
+
+ @Transient
+ 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 = (AccountDataBeanImpl) account;
+ }
+
+ public QuoteDataBean getQuote() {
+ return quote;
+ }
+
+ public void setQuote(QuoteDataBean quote) {
+ this.quote = (QuoteDataBeanImpl) quote;
+ }
+
+ public HoldingDataBean getHolding() {
+ return holding;
+ }
+
+ public void setHolding(HoldingDataBean holding) {
+ this.holding = (HoldingDataBeanImpl) 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-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/QuoteDataBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/QuoteDataBeanImpl.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/QuoteDataBeanImpl.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/java/org/apache/aries/samples/ariestrader/entities/QuoteDataBeanImpl.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,230 @@
+/**
+ * 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.entities;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.NamedNativeQueries;
+import javax.persistence.NamedNativeQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+
+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;
+
+@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.aries.samples.ariestrader.entities.QuoteDataBeanImpl.class)
+})
+
+public class QuoteDataBeanImpl implements QuoteDataBean, Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8476917690278143517L;
+
+ @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 */
+
+
+
+ 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-entities/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/resources/META-INF/persistence.xml?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/resources/META-INF/persistence.xml (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-entities/src/main/resources/META-INF/persistence.xml Sun Feb 27 18:28:26 2011
@@ -0,0 +1,70 @@
+<?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="RESOURCE_LOCAL" name="ariestrader-am">
+ <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+ <jta-data-source>aries:services/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/TradeDataSource)</jta-data-source>
+ <non-jta-data-source>aries:services/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/NoTxTradeDataSource)</non-jta-data-source>
+
+ <class>org.apache.aries.samples.ariestrader.entities.AccountDataBeanImpl</class>
+ <class>org.apache.aries.samples.ariestrader.entities.AccountProfileDataBeanImpl</class>
+ <class>org.apache.aries.samples.ariestrader.entities.HoldingDataBeanImpl</class>
+ <class>org.apache.aries.samples.ariestrader.entities.OrderDataBeanImpl</class>
+ <class>org.apache.aries.samples.ariestrader.entities.QuoteDataBeanImpl</class>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+
+ <properties>
+ <property name="openjpa.BrokerImpl" value="non-finalizing" />
+ <property name="openjpa.Sequence" value="table(Table=OPENJPASEQ, Increment=100)"/>
+ <property name="openjpa.jdbc.UpdateManager" value="org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager"/>
+ </properties>
+ </persistence-unit>
+
+ <persistence-unit transaction-type="JTA" name="ariestrader-cm">
+ <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+ <jta-data-source>aries:services/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/TradeDataSource)</jta-data-source>
+ <non-jta-data-source>aries:services/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/NoTxTradeDataSource)</non-jta-data-source>
+
+ <class>org.apache.aries.samples.ariestrader.entities.AccountDataBeanImpl</class>
+ <class>org.apache.aries.samples.ariestrader.entities.AccountProfileDataBeanImpl</class>
+ <class>org.apache.aries.samples.ariestrader.entities.HoldingDataBeanImpl</class>
+ <class>org.apache.aries.samples.ariestrader.entities.OrderDataBeanImpl</class>
+ <class>org.apache.aries.samples.ariestrader.entities.QuoteDataBeanImpl</class>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+
+ <properties>
+ <property name="openjpa.BrokerImpl" value="non-finalizing" />
+ <property name="openjpa.Sequence" value="table(Table=OPENJPASEQ, Increment=100)"/>
+ <property name="openjpa.jdbc.UpdateManager" value="org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager"/>
+ </properties>
+ </persistence-unit>
+
+ <!--
+ <properties>
+ <property name="openjpa.jdbc.DBDictionary" value="derby" />
+ <property name="openjpa.ConnectionProperties" value="DriverClassName=com.ibm.db2.jcc.DB2Driver,URL=jdbc:db2://9.12.24.171:50000/TRADE61,MaxActive=50,MaxWait=10000,Username=db2inst1,Password=db2inst1"/>
+ <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
+ <property name="openjpa.jdbc.DBDictionary" value="db2(batchLimit=600)"/>
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
+ <property name="openjpa.Multithreaded" value="true"/>
+ <property name="openjpa.Compatibility" value="flushBeforeDetach=false"/>
+ <property name="openjpa.jdbc.UpdateManager" value="com.ibm.ws.persistence.jdbc.kernel.OperationOrderUpdateManager(batchLimit=0)" />
+ </properties>
+ -->
+</persistence>
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-persist-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-persist-jdbc/pom.xml?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-persist-jdbc/pom.xml (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-persist-jdbc/pom.xml Sun Feb 27 18:28:26 2011
@@ -0,0 +1,67 @@
+<?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.persist.jdbc</artifactId>
+ <packaging>bundle</packaging>
+ <name>AriesTrader :: Modules - Persist JDBC</name>
+ <description>AriesTrader Persist JDBC 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>
+ <dependency>
+ <groupId>org.apache.aries.samples.ariestrader</groupId>
+ <artifactId>org.apache.aries.samples.ariestrader.beans</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.persist.jdbc.*</Private-Package>
+ <Export-Package>!org.apache.aries.samples.ariestrader.persist.jdbc.*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-persist-jdbc/src/main/java/org/apache/aries/samples/ariestrader/persist/jdbc/KeySequenceDirect.java
URL: http://svn.apache.org/viewvc/aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-persist-jdbc/src/main/java/org/apache/aries/samples/ariestrader/persist/jdbc/KeySequenceDirect.java?rev=1075106&view=auto
==============================================================================
--- aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-persist-jdbc/src/main/java/org/apache/aries/samples/ariestrader/persist/jdbc/KeySequenceDirect.java (added)
+++ aries/tags/samples-0.1-incubating/ariestrader/modules/ariestrader-persist-jdbc/src/main/java/org/apache/aries/samples/ariestrader/persist/jdbc/KeySequenceDirect.java Sun Feb 27 18:28:26 2011
@@ -0,0 +1,109 @@
+/**
+ * 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.persist.jdbc;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.HashMap;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.aries.samples.ariestrader.util.*;
+
+public class KeySequenceDirect {
+
+ private static HashMap keyMap = new HashMap();
+
+ public static synchronized Integer getNextID(Connection conn, String keyName, boolean inSession, boolean inGlobalTxn)
+ throws Exception {
+ Integer nextID = null;
+ // First verify we have allocated a block of keys
+ // for this key name
+ // Then verify the allocated block has not been depleted
+ // allocate a new block if necessary
+ if (keyMap.containsKey(keyName) == false)
+ allocNewBlock(conn, keyName, inSession, inGlobalTxn);
+ Collection block = (Collection) keyMap.get(keyName);
+
+ Iterator ids = block.iterator();
+ if (ids.hasNext() == false)
+ ids = allocNewBlock(conn, keyName, inSession, inGlobalTxn).iterator();
+ // get and return a new unique key
+ nextID = (Integer) ids.next();
+
+ if (Log.doTrace())
+ Log.trace("KeySequenceDirect:getNextID inSession(" + inSession + ") - return new PK ID for Entity type: "
+ + keyName + " ID=" + nextID);
+ return nextID;
+ }
+
+ private static Collection allocNewBlock(Connection conn, String keyName, boolean inSession, boolean inGlobalTxn)
+ throws Exception {
+ try {
+ if (inGlobalTxn == false && !inSession)
+ conn.commit(); // commit any pending txns
+ PreparedStatement stmt = conn.prepareStatement(getKeyForUpdateSQL);
+ stmt.setString(1, keyName);
+ ResultSet rs = stmt.executeQuery();
+ if (!rs.next()) {
+ // No keys found for this name - create a new one
+ PreparedStatement stmt2 = conn.prepareStatement(createKeySQL);
+ int keyVal = 0;
+ stmt2.setString(1, keyName);
+ stmt2.setInt(2, keyVal);
+ stmt2.executeUpdate();
+ stmt2.close();
+ stmt.close();
+ stmt = conn.prepareStatement(getKeyForUpdateSQL);
+ stmt.setString(1, keyName);
+ rs = stmt.executeQuery();
+ rs.next();
+ }
+
+ int keyVal = rs.getInt("keyval");
+
+ stmt.close();
+
+ stmt = conn.prepareStatement(updateKeyValueSQL);
+ stmt.setInt(1, keyVal + TradeConfig.KEYBLOCKSIZE);
+ stmt.setString(2, keyName);
+ stmt.executeUpdate();
+ stmt.close();
+
+ Collection block = new KeyBlock(keyVal, keyVal + TradeConfig.KEYBLOCKSIZE - 1);
+ keyMap.put(keyName, block);
+ if (inGlobalTxn == false && !inSession)
+ conn.commit();
+ return block;
+ } catch (Exception e) {
+ String error =
+ "KeySequenceDirect:allocNewBlock - failure to allocate new block of keys for Entity type: " + keyName;
+ Log.error(e, error);
+ throw new Exception(error + e.toString());
+ }
+ }
+
+ private static final String getKeyForUpdateSQL = "select * from keygenejb kg where kg.keyname = ? for update";
+
+ private static final String createKeySQL =
+ "insert into keygenejb " + "( keyname, keyval ) " + "VALUES ( ? , ? )";
+
+ private static final String updateKeyValueSQL = "update keygenejb set keyval = ? " + "where keyname = ?";
+
+}