Skip to content

Commit

Permalink
Improve the KAM store API; see OpenBEL#40
Browse files Browse the repository at this point in the history
Summary:
* KamStore -> KAMStore
* KamStoreImpl -> KAMStoreImpl
* KamStoreException -> KAMStoreException
* KAMStore API changes (aims to be as backwards compatible as possible)
    - added exists methods to check for KAM availability
    - readCatalog -> getCatalog
    - getCatalog never throws exceptions
    - KAMStoreException is an unchecked exception to indicate a severe
      problem vice the old use of these exceptions which was admittedly
      poor
    - Improved documentation; which arguments are optional, which
      required, specific behavior, etc.
  • Loading branch information
Nick Bargnesi committed Aug 10, 2012
1 parent a61af2e commit 83b85d0
Show file tree
Hide file tree
Showing 31 changed files with 1,553 additions and 1,530 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.openbel.framework.api.Kam.KamNode;
import org.openbel.framework.api.internal.KAMCatalogDao.KamInfo;
import org.openbel.framework.api.internal.KAMStoreDaoImpl.BelTerm;
import org.openbel.framework.api.KamStore;
import org.openbel.framework.api.KAMStore;
import org.openbel.framework.common.bel.parser.BELParser;
import org.openbel.framework.common.model.Term;

Expand All @@ -62,7 +62,7 @@
public class DefaultDialect implements Dialect {

private final KamInfo kamInfo;
private final KamStore kamStore;
private final KAMStore kAMStore;
private final boolean displayLongForm;

private Map<String, String> labelCache =
Expand All @@ -71,11 +71,11 @@ public class DefaultDialect implements Dialect {
/**
* Package constructor
* @param kamInfo
* @param kamStore
* @param kAMStore
*/
public DefaultDialect(KamInfo kamInfo, KamStore kamStore, boolean displayLongForm) {
public DefaultDialect(KamInfo kamInfo, KAMStore kAMStore, boolean displayLongForm) {
this.kamInfo = kamInfo;
this.kamStore = kamStore;
this.kAMStore = kAMStore;
this.displayLongForm = displayLongForm;
}

Expand All @@ -88,7 +88,7 @@ public String getLabel(KamNode kamNode) {
if (label == null) {
label = kamNode.getLabel();
try {
List<BelTerm> terms = kamStore.getSupportingTerms(kamNode);
List<BelTerm> terms = kAMStore.getSupportingTerms(kamNode);
if (!terms.isEmpty()) {
BelTerm bt = terms.get(0);
Term t = BELParser.parseTerm(bt.getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,24 @@ public class DefaultKamCacheService implements KamCacheService {
// Maps filtered KAMs to handles
private final Map<FilteredKAMKey, String> fltrdMap;

/** {@link KamStore} */
protected final KamStore kamStore;
/** {@link KAMStore} */
protected final KAMStore kAMStore;

private final ReadLock read;
private final WriteLock write;
private final ExecutorService execSvc;

/**
* Creates a default KAM cache service with a supplied {@link KamStore}.
* Creates a default KAM cache service with a supplied {@link KAMStore}.
*
* @param kamStore {@link KamStore}
* @param kAMStore {@link KAMStore}
* @throws InvalidArgument Thrown if {@code kamStore} is null
*/
public DefaultKamCacheService(KamStore kamStore) {
if (kamStore == null) {
throw new InvalidArgument("kamStore", kamStore);
public DefaultKamCacheService(KAMStore kAMStore) {
if (kAMStore == null) {
throw new InvalidArgument("kamStore", kAMStore);
}
this.kamStore = kamStore;
this.kAMStore = kAMStore;

kamMap = new HashMap<String, Kam>();
unfltrdMap = new HashMap<KamInfo, String>();
Expand Down Expand Up @@ -386,7 +386,7 @@ private class CacheCallable implements Callable<String> {
* {@inheritDoc}
*/
@Override
public String call() throws KamStoreException {
public String call() throws KAMStoreException {
String ret = null;

if (kf != null) {
Expand All @@ -402,7 +402,7 @@ public String call() throws KamStoreException {
return ret;
}

Kam k = kamStore.getKam(ki, kf);
Kam k = kAMStore.getKam(ki, kf);

write.lock();
try {
Expand Down Expand Up @@ -432,7 +432,7 @@ public String call() throws KamStoreException {
}

// get an unfiltered KAM
Kam k = kamStore.getKam(ki);
Kam k = kAMStore.getKam(ki);

write.lock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@
*/
public class DefaultSpeciesDialect implements SpeciesDialect {

private final KamStore kamStore;
private final KAMStore kAMStore;
private final Map<String, Namespace> nsmap;
private final List<Namespace> speciesNs;
private final Map<String, String> labelCache;
private final boolean displayLongForm;

public DefaultSpeciesDialect(final KamInfo info, final KamStore kamStore,
public DefaultSpeciesDialect(final KamInfo info, final KAMStore kAMStore,
final int taxId, final boolean displayLongForm) {
this.kamStore = kamStore;
this.kAMStore = kAMStore;
this.labelCache = new HashMap<String, String>();
try {
Namespaces ns = Namespaces.loadNamespaces();

List<KAMStoreDaoImpl.Namespace> nsl = kamStore.getNamespaces(info);
List<KAMStoreDaoImpl.Namespace> nsl = kAMStore.getNamespaces(info);
nsmap = constrainedHashMap(nsl.size());
for (final KAMStoreDaoImpl.Namespace n : nsl) {
nsmap.put(n.getPrefix(),
Expand Down Expand Up @@ -105,7 +105,7 @@ public String getLabel(KamNode kamNode, TermParameter speciesParam) {

try {
// find first term and convert to species namespaces
final List<BelTerm> terms = kamStore
final List<BelTerm> terms = kAMStore
.getSupportingTerms(kamNode);
if (hasItems(terms)) {
final BelTerm term = terms.get(0);
Expand All @@ -121,7 +121,7 @@ public String getLabel(KamNode kamNode, TermParameter speciesParam) {
// if there are no supporting terms, return node label,
// should never be true
return nodeLabel;
} catch (KamStoreException e) {
} catch (KAMStoreException e) {
// error returns original label
return nodeLabel;
}
Expand Down
Loading

0 comments on commit 83b85d0

Please sign in to comment.