本文共 2003 字,大约阅读时间需要 6 分钟。
转载须注明出自:,
货币,Cointrader中基本实体。我们通过代码来学习该实体:
package org.cryptocoinpartners.schema;import java.util.List;import javax.persistence.Cacheable;import javax.persistence.Entity;import javax.persistence.NoResultException;import org.cryptocoinpartners.util.PersistUtil;/** * @author Tim Olson */@Entity //实体@Cacheablepublic class Currency extends Asset {//货币是资产的一种,继承关系 public boolean isFiat() {//是否为法定货币 return fiat; } public static Currency forSymbol(String symbol) { return PersistUtil.queryOne(Currency.class, "select c from Currency c where symbol=?1", symbol); } public static Listmultiplier乘数是一个比较生疏的一个概念。它的介绍见wikipedia:allSymbols() { return PersistUtil.queryList(String.class, "select symbol from Currency"); } // JPA protected Currency() { } protected void setFiat(boolean fiat) { this.fiat = fiat; } // used by Currencies static Currency forSymbolOrCreate(String symbol, boolean isFiat, double basis) { try { return forSymbol(symbol); } catch (NoResultException e) { final Currency currency = new Currency(isFiat, symbol, basis); PersistUtil.insert(currency); return currency; } } // used by Currencies static Currency forSymbolOrCreate(String symbol, boolean isFiat, double basis, double multiplier) { try { return forSymbol(symbol); } catch (NoResultException e) { final Currency currency = new Currency(isFiat, symbol, basis, multiplier); PersistUtil.insert(currency); return currency; } } private Currency(boolean fiat, String symbol, double basis) { super(symbol, basis); this.fiat = fiat; } private Currency(boolean fiat, String symbol, double basis, double multiplier) { super(symbol, basis); this.fiat = fiat; this.multiplier = multiplier; } private boolean fiat;//是否为法定货币 private double multiplier;//乘数}
还是一个比较难的概念。