mirror of https://github.com/apache/openjpa.git
Delete redundant classes
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@992533 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7569f437db
commit
238beccbfd
|
@ -28,6 +28,7 @@ import org.apache.openjpa.trader.domain.Tradable;
|
|||
import org.apache.openjpa.trader.domain.Trade;
|
||||
import org.apache.openjpa.trader.domain.Trader;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
|
@ -101,9 +102,10 @@ public class TradeHistoryPanel extends ScrollableTable<Trade>
|
|||
*/
|
||||
public void onTradeCommitted(ServiceEvent.TradeCommitted event) {
|
||||
Trader trader = session.getTrader();
|
||||
if ((trader.equals(event.getPayload().getSeller()) && _type == Ask.class)
|
||||
|| (trader.equals(event.getPayload().getBuyer()) && _type == Bid.class)) {
|
||||
insert(event.getPayload());
|
||||
Trade trade = event.getPayload();
|
||||
if ((trader.equals(trade.getSeller()) && _type == Ask.class)
|
||||
|| (trader.equals(trade.getBuyer()) && _type == Bid.class)) {
|
||||
insert(trade);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.openjpa.trader.domain.Match;
|
|||
import org.apache.openjpa.trader.domain.Stock;
|
||||
import org.apache.openjpa.trader.domain.Tradable;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
|
@ -63,7 +64,7 @@ public class TradingWindow extends ScrollableTable<Tradable>
|
|||
ServiceEventHandler.UpdateStockHandler {
|
||||
private final OpenTrader session;
|
||||
private Timer refreshTimer;
|
||||
private int refreshInterval = 60*1000;
|
||||
private int refreshInterval = 15*1000;
|
||||
|
||||
public TradingWindow(final OpenTrader session, final int w, final int h) {
|
||||
super("Trading Window for " + session.getTrader().getName(), w, h, true);
|
||||
|
@ -142,14 +143,14 @@ public class TradingWindow extends ScrollableTable<Tradable>
|
|||
if (refreshTimer != null)
|
||||
return;
|
||||
// Setup timer to refresh list automatically.
|
||||
Timer refreshTimer = new Timer() {
|
||||
refreshTimer = new Timer() {
|
||||
@Override
|
||||
public void run() {
|
||||
int n = getRowCount();
|
||||
for (int i = 0; i < n; i++) {
|
||||
Tradable t = get(i);
|
||||
if (t != null) {
|
||||
session.getService().refresh(t, new RefreshTradableCallback(t));
|
||||
session.getService().refresh(t, new RefreshTradableCallback());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +212,7 @@ public class TradingWindow extends ScrollableTable<Tradable>
|
|||
}
|
||||
|
||||
public class MatchCallback implements AsyncCallback<List<Match>>, ClickHandler {
|
||||
final Tradable tradable;
|
||||
private final Tradable tradable;
|
||||
|
||||
public MatchCallback(Tradable tradable) {
|
||||
super();
|
||||
|
@ -237,21 +238,12 @@ public class TradingWindow extends ScrollableTable<Tradable>
|
|||
}
|
||||
|
||||
public class RefreshTradableCallback implements AsyncCallback<Tradable> {
|
||||
final Tradable tradable;
|
||||
public RefreshTradableCallback(Tradable tradable) {
|
||||
super();
|
||||
this.tradable = tradable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Tradable result) {
|
||||
if (result == null) {
|
||||
remove(tradable);
|
||||
} else if (result.isTraded()) {
|
||||
if (result.isTraded()) {
|
||||
remove(result);
|
||||
session.fireEvent(new ServiceEvent.TradeCommitted(result.getTrade()));
|
||||
} else {
|
||||
update(result, new Integer[]{1,4});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ public abstract class Tradable implements Serializable {
|
|||
@ManyToOne(cascade={CascadeType.MERGE,CascadeType.DETACH,CascadeType.REFRESH},optional=false)
|
||||
private Stock stock;
|
||||
|
||||
@OneToOne(cascade={CascadeType.MERGE,CascadeType.DETACH}, optional=true, fetch=FetchType.LAZY)
|
||||
@OneToOne(cascade={CascadeType.MERGE,CascadeType.DETACH, CascadeType.REFRESH}, optional=true,
|
||||
fetch=FetchType.LAZY)
|
||||
private Trade trade;
|
||||
|
||||
|
||||
|
@ -174,8 +175,6 @@ public abstract class Tradable implements Serializable {
|
|||
}
|
||||
|
||||
public Trade getTrade() {
|
||||
if (trade == null)
|
||||
throw new IllegalStateException(this + " is not yet traded");
|
||||
return trade;
|
||||
}
|
||||
|
||||
|
@ -221,8 +220,7 @@ public abstract class Tradable implements Serializable {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
String type = this.getClass().getName();
|
||||
return type.substring(type.lastIndexOf('.'))+ ":" + id;
|
||||
String typeName = getClass().getName();
|
||||
return typeName.substring(typeName.lastIndexOf('.')+1) + "-" + id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,15 +44,6 @@ public class Trade implements Serializable {
|
|||
private double price;
|
||||
private int volume;
|
||||
|
||||
// @ManyToOne(cascade={CascadeType.MERGE,CascadeType.DETACH}, optional=false)
|
||||
// private Stock stock;
|
||||
//
|
||||
// @ManyToOne(cascade={CascadeType.MERGE,CascadeType.DETACH}, optional=false)
|
||||
// private Trader buyer;
|
||||
//
|
||||
// @ManyToOne(cascade={CascadeType.MERGE,CascadeType.DETACH}, optional=false)
|
||||
// private Trader seller;
|
||||
|
||||
@OneToOne(cascade={CascadeType.MERGE,CascadeType.DETACH}, optional=false)
|
||||
private Ask ask;
|
||||
|
||||
|
@ -78,9 +69,6 @@ public class Trade implements Serializable {
|
|||
throw new IllegalArgumentException("Stock (ask) " + a.getStock()
|
||||
+ " does not match Stock (bid) " + b.getStock());
|
||||
}
|
||||
// buyer = b.getBuyer();
|
||||
// seller = a.getSeller();
|
||||
// stock = a.getStock();
|
||||
ask = a;
|
||||
bid = b;
|
||||
ask.setTrade(this);
|
||||
|
@ -137,4 +125,8 @@ public class Trade implements Serializable {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Trade-"+id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* 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.openjpa.util;
|
||||
|
||||
|
||||
/**
|
||||
* {@link OpenJPAId} subclass appropriate for long fields.
|
||||
*
|
||||
* @author Steve Kim
|
||||
*/
|
||||
public final class LongId extends OpenJPAId {
|
||||
|
||||
private final long key;
|
||||
|
||||
public LongId() {
|
||||
key = 0;
|
||||
}
|
||||
|
||||
public LongId(Class cls, Long key) {
|
||||
this(cls, (key == null) ? 0L : key.longValue());
|
||||
}
|
||||
|
||||
public LongId(Class cls, String key) {
|
||||
this(cls, (key == null) ? 0L : Long.parseLong(key));
|
||||
}
|
||||
|
||||
public LongId(Class cls, long key) {
|
||||
super(cls);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public LongId(Class cls, long key, boolean subs) {
|
||||
super(cls, subs);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getIdObject() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(key);
|
||||
}
|
||||
|
||||
protected int idHash() {
|
||||
return (int) (key ^ (key >>> 32));
|
||||
}
|
||||
|
||||
protected boolean idEquals(OpenJPAId o) {
|
||||
return key == ((LongId) o).key;
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* 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.openjpa.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.HashMap;
|
||||
/**
|
||||
* Identity class extended by built-in OpenJPA identity objects.
|
||||
*
|
||||
* @author Steve Kim
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class OpenJPAId
|
||||
implements Comparable, Serializable {
|
||||
public static final char TYPE_VALUE_SEP = '-';
|
||||
|
||||
// cache the types' generated hash codes
|
||||
private static HashMap _typeCache = new HashMap();
|
||||
|
||||
protected Class type;
|
||||
protected boolean subs = true;
|
||||
|
||||
// type hash is based on the least-derived non-object class so that
|
||||
// user-given ids with non-exact types match ids with exact types
|
||||
private transient int _typeHash = 0;
|
||||
|
||||
protected OpenJPAId() {
|
||||
}
|
||||
|
||||
protected OpenJPAId(Class type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
protected OpenJPAId(Class type, boolean subs) {
|
||||
this.type = type;
|
||||
this.subs = subs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the persistent class which this id instance represents.
|
||||
*/
|
||||
public Class getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this oid might be for a subclass of the given type.
|
||||
* Defaults to true.
|
||||
*/
|
||||
public boolean hasSubclasses() {
|
||||
return subs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the exact type of the described instance once it is known.
|
||||
*/
|
||||
public void setManagedInstanceType(Class type) {
|
||||
setManagedInstanceType(type, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the exact type of the described instance once it is known.
|
||||
*/
|
||||
public void setManagedInstanceType(Class type, boolean subs) {
|
||||
this.type = type;
|
||||
this.subs = subs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the identity value as an object.
|
||||
*/
|
||||
public abstract Object getIdObject();
|
||||
|
||||
/**
|
||||
* Return the id's hash code.
|
||||
*/
|
||||
protected abstract int idHash();
|
||||
|
||||
/**
|
||||
* Compare the id to the id of the given instance.
|
||||
*/
|
||||
protected abstract boolean idEquals(OpenJPAId other);
|
||||
|
||||
/**
|
||||
* Generate the hash code for this Id. Cache the type's generated hash code
|
||||
* so that it doesn't have to be generated each time.
|
||||
*/
|
||||
public int hashCode() {
|
||||
if (_typeHash == 0) {
|
||||
Integer typeHashInt = (Integer) _typeCache.get(type);
|
||||
if (typeHashInt == null) {
|
||||
Class base = type;
|
||||
Class superclass = base.getSuperclass();
|
||||
while (superclass != null && superclass != Object.class) {
|
||||
base = base.getSuperclass();
|
||||
superclass = base.getSuperclass();
|
||||
}
|
||||
_typeHash = base.hashCode();
|
||||
_typeCache.put(type, Integer.valueOf(_typeHash));
|
||||
} else {
|
||||
_typeHash = typeHashInt.intValue();
|
||||
}
|
||||
}
|
||||
return _typeHash ^ idHash();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
OpenJPAId id = (OpenJPAId) o;
|
||||
return idEquals(id);
|
||||
//&& (id.type.isAssignableFrom(type)
|
||||
// || (subs && type.isAssignableFrom(id.type)));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return type.getName() + TYPE_VALUE_SEP + getIdObject();
|
||||
}
|
||||
|
||||
public int compareTo(Object other) {
|
||||
if (other == this)
|
||||
return 0;
|
||||
if (other == null)
|
||||
return 1;
|
||||
return ((Comparable) getIdObject()).compareTo(((OpenJPAId) other).getIdObject ());
|
||||
}
|
||||
}
|
|
@ -125,6 +125,9 @@ public class Exchange extends PersistenceService implements TradingService {
|
|||
EntityManager em = getEntityManager();
|
||||
begin();
|
||||
t = em.find(t.getClass(), t.getId());
|
||||
if (t != null) {
|
||||
em.refresh(t);
|
||||
}
|
||||
commit();
|
||||
return t;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue