org.hypergraphdb.HGPersistentHandle - java examples

Here are the examples of the java api org.hypergraphdb.HGPersistentHandle taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : IntPrimitiveArrayType.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    byte[] data = hg.getStore().getData(handle);
    if (data == null)
        throw new HGException("Could not find value for int array, handle=" + handle.toString());
    int[] A = new int[(data.length - 1) / 4];
    for (int i = 0; i < A.length; i++) {
        int offset = i * 4 + 1;
        int ch1 = data[offset];
        int ch2 = data[offset + 1];
        int ch3 = data[offset + 2];
        int ch4 = data[offset + 3];
        A[i] = ((ch1 & 0xFF) << 24) | ((ch2 & 0xFF) << 16) | ((ch3 & 0xFF) << 8) | (ch4 & 0xFF);
    }
    return A;
}

19 View Complete Implementation : LmdbStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
// @Override
public void addIncidenceLinks(HGPersistentHandle linkHandle, Set<HGPersistentHandle> newTargets) {
    if (newTargets.size() <= 0) {
        return;
    }
    try {
        byte[] value = linkHandle.toByteArray();
        for (HGPersistentHandle newTarget : newTargets) {
            byte[] key = newTarget.toByteArray();
            byte[] orgValue = incidence_db.put(txn().getDbTransaction(), key, value, NODUPDATA);
        // System.out.println("IncidencePut." + key.length + ","
        // + value.length);
        // if (result != OperationStatus.SUCCESS && result !=
        // OperationStatus.KEYEXIST)
        // throw new Exception("OperationStatus: " + result);
        }
    }// incidence_db.stat(txn().getDbTransaction())
     catch (Exception ex) {
        throw new HGException("Failed to update incidence set for handle " + linkHandle + ": " + ex.toString(), ex);
    }
}

19 View Complete Implementation : MapTypeConstructor.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    MapType result = null;
    String clreplacedName = new String(hg.getStore().getData(handle));
    try {
        Clreplaced clazz = Clreplaced.forName(clreplacedName);
        GenericObjectFactory factory = new GenericObjectFactory(clazz);
        result = new MapType(factory);
    } catch (Throwable t) {
        throw new HGException(t);
    }
    return result;
}

19 View Complete Implementation : JavaBeanBinding.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    Object bean = null;
    try {
        // We construct a link of the clreplaced is a HGLink and the target set is not-empty
        // or if we don't have a default constructor at all.
        if (isLinkInstance && targetSet != null && targetSet.deref().length > 0 || defaultConstructor == null)
            bean = makeLink(targetSet.deref());
        else if (defaultConstructor != null)
            bean = defaultConstructor.newInstance();
        else
            throw new RuntimeException("Can't construct object of type " + javaClreplaced.getName() + " no default constructor and/or no HGHandle array-based constructor.");
        TypeUtils.setValueFor(graph, handle, bean);
        Record record = (Record) hgType.make(handle, targetSet, null);
        RecordType recordType = (RecordType) hgType;
        for (HGHandle slotHandle : recordType.getSlots()) {
            Slot slot = (Slot) graph.get(slotHandle);
            Object value = record.get(slot);
            if (value != null && recordType.getReferenceMode(slotHandle) != null)
                value = graph.get(((HGAtomRef) value).getReferent());
            try {
                BonesOfBeans.setProperty(bean, slot.getLabel(), value);
            } catch (Throwable t) {
                throw new HGException("Failed to replacedign property: " + slot.getLabel() + " to bean " + bean.getClreplaced(), t);
            }
        }
    } catch (InstantiationException ex) {
        throw new HGException("Unable to instantiate bean of type '" + javaClreplaced.getName() + "', make sure that bean has a default constructor declared.", ex);
    } catch (HGException t) {
        throw new HGException("JavaBeanBinding.make[" + this.getJavaClreplaced().getName() + "]:" + t.toString(), t);
    } catch (Throwable t) {
        throw new HGException("JavaBeanBinding.make[" + this.getJavaClreplaced().getName() + "]:" + t.toString(), t);
    }
    return bean;
}

19 View Complete Implementation : DataTxTests.java
Copyright Apache License 2.0
Author : hypergraphdb
private void increment(final HGPersistentHandle atomX) {
    final HGTransactionManager txman = graph.getTransactionManager();
    SimpleData committed = txman.ensureTransaction(new Callable<SimpleData>() {

        public SimpleData call() {
            final SimpleData l = graph.get(atomX);
            if (log && l.getIdx() == 0)
                T.getLogger("DataTxTests").info("Increment " + l + ":" + atomX);
            SimpleData newBean = new SimpleData(l.getIdx(), l.getValue() + 1);
            graph.replace(atomX, newBean);
            if (log && l.getIdx() == 0)
                T.getLogger("DataTxTests").info("After increment " + l);
            return newBean;
        }
    });
    localMap.get().put(committed.getIdx(), committed);
}

19 View Complete Implementation : DoublePrimitiveArrayType.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    byte[] data = hg.getStore().getData(handle);
    if (data == null)
        throw new HGException("Could not find value for double array, handle=" + handle.toString());
    double[] result = new double[(data.length - 1) / 8];
    for (int i = 0; i < result.length; i++) {
        int l = 8 * i + 1;
        long lv = ((long) data[l] << 56) + ((long) (data[l + 1] & 255) << 48) + ((long) (data[l + 2] & 255) << 40) + ((long) (data[l + 3] & 255) << 32) + ((long) (data[l + 4] & 255) << 24) + ((data[l + 5] & 255) << 16) + ((data[l + 6] & 255) << 8) + ((data[l + 7] & 255) << 0);
        result[i] = Double.longBitsToDouble(lv);
    }
    return result;
}

19 View Complete Implementation : CharPrimitiveArrayType.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    byte[] data = hg.getStore().getData(handle);
    if (data == null)
        throw new HGException("Could not find value for char array, handle=" + handle.toString());
    char[] result = new char[(data.length - 1) / 2];
    for (int i = 0; i < result.length; i++) {
        int ch1 = data[2 * i + 1];
        int ch2 = data[2 * i + 1 + 1];
        result[i] = (char) ((ch1 << 8) + (ch2 << 0));
    }
    return result;
}

19 View Complete Implementation : LongPrimitiveArrayType.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    byte[] data = hg.getStore().getData(handle);
    if (data == null)
        throw new HGException("Could not find value for long array, handle=" + handle.toString());
    long[] result = new long[(data.length - 1) / 8];
    for (int i = 0; i < result.length; i++) {
        int l = 8 * i + 1;
        long lv = ((long) data[l] << 56) + ((long) (data[l + 1] & 255) << 48) + ((long) (data[l + 2] & 255) << 40) + ((long) (data[l + 3] & 255) << 32) + ((long) (data[l + 4] & 255) << 24) + ((data[l + 5] & 255) << 16) + ((data[l + 6] & 255) << 8) + ((data[l + 7] & 255) << 0);
        result[i] = lv;
    }
    return result;
}

19 View Complete Implementation : HGConverter.java
Copyright Apache License 2.0
Author : hypergraphdb
public static String convertHandleArrayToString(HGPersistentHandle[] link, int handleSize) {
    String resultstring = null;
    try {
        byte[] buffer = new byte[link.length * handleSize];
        for (int i = 0; i < link.length; i++) {
            HGPersistentHandle handle = (HGPersistentHandle) link[i];
            System.arraycopy(handle.toByteArray(), 0, buffer, i * handleSize, handleSize);
        }
        resultstring = new String(buffer);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return resultstring;
}

19 View Complete Implementation : PairType.java
Copyright Apache License 2.0
Author : hypergraphdb
public void release(HGPersistentHandle handle) {
    HGPersistentHandle[] layout = graph.getStore().getLink(handle);
    for (int i = 0; i < layout.length; i += 2) {
        HGPersistentHandle typeHandle = layout[i];
        HGPersistentHandle valueHandle = layout[i + 1];
        if (typeHandle.equals(graph.getHandleFactory().nullHandle()))
            continue;
        if (!TypeUtils.isValueReleased(graph, valueHandle)) {
            HGAtomType type = graph.get(typeHandle);
            TypeUtils.releaseValue(graph, type, valueHandle);
        // 2012.01.25 hilpold Bugfix removed: type.release(valueHandle);
        }
    }
    graph.getStore().removeLink(handle);
}

19 View Complete Implementation : FloatPrimitiveArrayType.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    byte[] data = hg.getStore().getData(handle);
    if (data == null)
        throw new HGException("Could not find value for float array, handle=" + handle.toString());
    float[] result = new float[(data.length - 1) / 4];
    for (int i = 0; i < result.length; i++) {
        int j = 4 * i + 1;
        int fi = ((data[j + 3] & 0xFF) << 0) + ((data[j + 2] & 0xFF) << 8) + ((data[j + 1] & 0xFF) << 16) + ((data[j + 0]) << 24);
        result[i] = Float.intBitsToFloat(fi);
    }
    return result;
}

19 View Complete Implementation : HGLoadPredefinedTypeEvent.java
Copyright Apache License 2.0
Author : hypergraphdb
/**
 * <p>
 * This event is triggered by the type system when the run-time instance of a
 * predefined type needs to be loaded in the cache. Applications should listen
 * to this event whenever predefined need to be loaded on demand and HyperGraph
 * cannot perform this task alone.
 * </p>
 *
 * <p>
 * A listener is expected to add the predefined refered by the <code>typeHandle</code>
 * attribute of the event instance. Predefined types are added through a call to the
 * <code>HGTypeSystem.addPredefinedType</code> method.
 * </p>
 *
 * @author Borislav Iordanov
 */
public clreplaced HGLoadPredefinedTypeEvent extends HGEventBase {

    private HGPersistentHandle typeHandle;

    public HGLoadPredefinedTypeEvent(HGPersistentHandle typeHandle) {
        this.typeHandle = typeHandle;
    }

    public HGPersistentHandle getTypeHandle() {
        return typeHandle;
    }
}

19 View Complete Implementation : RememberTaskClient.java
Copyright Apache License 2.0
Author : hypergraphdb
private Iterator<Object> getTargets(HGPersistentHandle handle) {
    // if (targetPeer == null)
    // {
    // evaluator.setHandle(handle);
    // peerFilter.filterTargets();
    // 
    // return peerFilter.iterator();
    // }else{
    // ArrayList<Object> targets = new ArrayList<Object>();
    // targets.add(targetPeer);
    // 
    // return targets.iterator();
    // }
    return null;
}

19 View Complete Implementation : JavaObjectBinding.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    Object result = null;
    try {
        if (targetSet != null && targetSet.deref().length > 0)
            if (linkConstructor != null)
                result = linkConstructor.newInstance(new Object[] { targetSet.deref() });
            else
                throw new RuntimeException("Can't construct link with Java type " + javaClreplaced.getName() + " please include a (HGHandle [] ) constructor.");
        else
            result = javaClreplaced.newInstance();
        TypeUtils.setValueFor(graph, handle, result);
        replacedignFields(handle, result);
    } catch (InstantiationException ex) {
        throw new HGException("Unable to instantiate bean of type '" + javaClreplaced.getName() + "', make sure that bean has a default constructor declared.");
    } catch (Throwable t) {
        throw new HGException("JavaTypeBinding.make: " + t.toString(), t);
    }
    return result;
}

19 View Complete Implementation : JavaBeanBinding.java
Copyright Apache License 2.0
Author : hypergraphdb
public HGPersistentHandle store(final Object instance) {
    HGPersistentHandle result = TypeUtils.getHandleFor(graph, instance);
    if (result == null) {
        final Record record = new BeanRecord(typeHandle, instance);
        RecordType recordType = (RecordType) hgType;
        for (HGHandle slotHandle : recordType.getSlots()) {
            Slot slot = (Slot) graph.get(slotHandle);
            Object value = BonesOfBeans.getProperty(instance, slot.getLabel());
            HGAtomRef.Mode refMode = recordType.getReferenceMode(slotHandle);
            if (refMode != null && value != null) {
                HGHandle valueAtomHandle = graph.getHandle(value);
                if (valueAtomHandle == null) {
                    HGAtomType valueType = (HGAtomType) graph.get(slot.getValueType());
                    valueAtomHandle = graph.getPersistentHandle(graph.add(value, valueType instanceof HGAbstractType ? graph.getTypeSystem().getTypeHandle(value.getClreplaced()) : slot.getValueType()));
                }
                value = new HGAtomRef(valueAtomHandle, refMode);
            }
            record.set(slot, value);
        }
        result = hgType.store(record);
    }
    return result;
}

19 View Complete Implementation : TypeUtils.java
Copyright Apache License 2.0
Author : hypergraphdb
public static HGPersistentHandle storeValue(HyperGraph graph, Object value, HGAtomType type) {
    boolean topCall = initThreadLocals();
    try {
        HGPersistentHandle result = null;
        if (!(type instanceof HGRefCountedType))
            result = JAVA_REF_MAP.get().get(value);
        if (result == null) {
            result = type.store(value);
            JAVA_REF_MAP.get().put(value, result);
        }
        HANDLE_REF_MAP.get().put(result, value);
        return result;
    } finally {
        releaseThreadLocals(topCall);
    }
}

19 View Complete Implementation : ArrayTypeConstructor.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    Object result = null;
    String clreplacedName = new String(hg.getStore().getData(handle));
    try {
        Clreplaced<?> clazz = Clreplaced.forName(clreplacedName);
        result = new ArrayType(clazz);
    } catch (Throwable t) {
        throw new HGException(t);
    }
    return result;
}

19 View Complete Implementation : ShortPrimitiveArrayType.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    byte[] data = hg.getStore().getData(handle);
    if (data == null)
        throw new HGException("Could not find value for short array, handle=" + handle.toString());
    short[] A = new short[(data.length - 1) / 2];
    for (int i = 0; i < A.length; i++) {
        int offset = 2 * i + 1;
        A[i] = (short) (((data[offset + 1] & 0xFF) << 0) + ((data[offset]) << 8));
    }
    return A;
}

19 View Complete Implementation : EnumTypeConstructor.java
Copyright Apache License 2.0
Author : hypergraphdb
public HGPersistentHandle store(Object instance) {
    EnumType et = (EnumType) instance;
    if (!et.getEnumType().isEnum())
        throw new HGException("Attempting to store non Enum clreplaced " + et.getEnumType().getClreplaced() + " as an enum.");
    HGPersistentHandle[] layout = new HGPersistentHandle[1 + et.getEnumType().getEnumConstants().length];
    HGAtomType stringType = graph.getTypeSystem().getAtomType(String.clreplaced);
    layout[0] = stringType.store(et.getEnumType().getName());
    Enum<?>[] constants = (Enum[]) et.getEnumType().getEnumConstants();
    for (int i = 0; i < constants.length; i++) {
        layout[i + 1] = stringType.store(constants[i].name());
    }
    return graph.getStore().store(layout);
}

18 View Complete Implementation : EnumTypeConstructor.java
Copyright Apache License 2.0
Author : hypergraphdb
// public static final HGPersistentHandle HGHANDLE =
// HGHandleFactory.makeHandle("4e3c44ec-da21-11db-84d5-cf67a5f089dc");
@SuppressWarnings("unchecked")
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    EnumType result = new EnumType();
    result.setHyperGraph(graph);
    // We are pretty sure that this is an atom, so we can find its handle with the by value
    // index. And we use that to get Java clreplaced of the enum, instead of the stored one
    // so we can gracefully handle clreplaced name changes.
    HGPersistentHandle typeHandle = (HGPersistentHandle) graph.getIndexManager().getIndexByValue().findFirst(handle);
    Clreplaced<Enum<?>> cl = (Clreplaced<Enum<?>>) graph.getTypeSystem().getClreplacedForType(typeHandle);
    result.setEnumType(cl);
    // HGPersistentHandle [] layout = graph.getStore().getLink(handle);
    // HGAtomType stringType = graph.getTypeSystem().getAtomType(String.clreplaced);
    // String clreplacedname = (String)stringType.make(layout[0], null, null);
    // try
    // {
    // cl = HGUtils.loadClreplaced(getHyperGraph(), clreplacedname);
    // result.setEnumType(cl);
    // }
    // catch (ClreplacedNotFoundException ex)
    // {
    // throw new HGException("Unable to load enum clreplaced " + clreplacedname, ex);
    // }
    return result;
}

18 View Complete Implementation : BJEStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
public void removeData(HGPersistentHandle handle) {
    if (handle == null)
        throw new NullPointerException("HGStore.remove called with a null handle.");
    try {
        DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
        primitive_db.delete(txn().getBJETransaction(), key);
    } catch (Exception ex) {
        throw new HGException("Failed to remove value with handle " + handle + ": " + ex.toString(), ex);
    }
}

18 View Complete Implementation : LinkBinding.java
Copyright Apache License 2.0
Author : hypergraphdb
public HGPersistentHandle[] readHandles(byte[] buffer, int offset, int length) {
    if (length == 0) {
        return HyperGraph.EMPTY_PERSISTENT_HANDLE_SET;
    }
    int handle_count = length / handleSize;
    HGPersistentHandle[] handles = new HGPersistentHandle[handle_count];
    for (int i = 0; i < handle_count; i++) {
        handles[i] = handleFactory.makeHandle(buffer, offset + i * handleSize);
    }
    return handles;
}

18 View Complete Implementation : ArrayType.java
Copyright Apache License 2.0
Author : hypergraphdb
public HGPersistentHandle store(Object instance) {
    HGPersistentHandle result = TypeUtils.getNewHandleFor(graph, instance);
    Object[] array = (Object[]) instance;
    HGPersistentHandle[] layout = new HGPersistentHandle[array.length * 2];
    int pos = 0;
    for (int i = 0; i < array.length; i++) {
        Object curr = array[i];
        if (curr == null) {
            layout[pos++] = graph.getHandleFactory().nullHandle();
            layout[pos++] = graph.getHandleFactory().nullHandle();
        } else {
            HGHandle typeHandle = graph.getTypeSystem().getTypeHandle(curr.getClreplaced());
            layout[pos++] = graph.getPersistentHandle(typeHandle);
            layout[pos++] = TypeUtils.storeValue(graph, curr, graph.getTypeSystem().getType(typeHandle));
        }
    }
    graph.getStore().store(result, layout);
    return result;
}

18 View Complete Implementation : TypeUtils.java
Copyright Apache License 2.0
Author : hypergraphdb
public static Object makeValue(HyperGraph graph, HGPersistentHandle h, HGAtomType type) {
    boolean topCall = initThreadLocals();
    try {
        Map<HGPersistentHandle, Object> refMap = HANDLE_REF_MAP.get();
        Object result = refMap.get(h);
        if (result == null) {
            result = type.make(h, null, null);
            refMap.put(h, result);
        }
        return result;
    } finally {
        releaseThreadLocals(topCall);
    }
}

18 View Complete Implementation : PairType.java
Copyright Apache License 2.0
Author : hypergraphdb
public HGPersistentHandle store(Object instance) {
    Pair<?, ?> p = (Pair<?, ?>) instance;
    HGPersistentHandle result = TypeUtils.getNewHandleFor(graph, instance);
    HGPersistentHandle[] layout = new HGPersistentHandle[] { graph.getHandleFactory().nullHandle(), graph.getHandleFactory().nullHandle(), graph.getHandleFactory().nullHandle(), graph.getHandleFactory().nullHandle() };
    if (p.getFirst() != null) {
        layout[0] = graph.getPersistentHandle(graph.getTypeSystem().getTypeHandle(p.getFirst()));
        layout[1] = TypeUtils.storeValue(graph, p.getFirst(), (HGAtomType) graph.get(layout[0]));
    }
    if (p.getSecond() != null) {
        layout[2] = graph.getPersistentHandle(graph.getTypeSystem().getTypeHandle(p.getSecond()));
        layout[3] = TypeUtils.storeValue(graph, p.getSecond(), (HGAtomType) graph.get(layout[2]));
    }
    graph.getStore().store(result, layout);
    return result;
}

18 View Complete Implementation : LmdbStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
@Override
public boolean containsLink(HGPersistentHandle handle) {
    byte[] key = handle.toByteArray();
    byte[] value;
    try {
        value = data_db.get(txn().getDbTransaction(), key);
        if (value != null) {
            // System.out.println(value.toString());
            return true;
        }
    } catch (LMDBException ex) {
        throw new HGException("Failed to retrieve link with handle " + handle + ": " + ex.toString(), ex);
    }
    return false;
}

18 View Complete Implementation : IncidentToQuery.java
Copyright Apache License 2.0
Author : hypergraphdb
public QueryMetaData getMetaData(HyperGraph graph, HGQueryCondition c) {
    QueryMetaData x = QueryMetaData.ORACCESS.clone(c);
    x.predicateCost = 1;
    IncidentCondition ic = (IncidentCondition) c;
    if (hg.isVar(ic.getTargetRef())) {
        // incidence sets are usually small...
        x.sizeExpected = 1000;
    } else {
        final HGPersistentHandle handle = graph.getPersistentHandle(((IncidentCondition) c).getTarget());
        x.sizeLB = x.sizeExpected = x.sizeUB = graph.getIncidenceSet(handle).size();
    }
    return x;
}

18 View Complete Implementation : BJEStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
public void removeLink(HGPersistentHandle handle) {
    if (handle == null) {
        throw new NullPointerException("HGStore.remove called with a null handle.");
    }
    try {
        DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
        data_db.delete(txn().getBJETransaction(), key);
    } catch (Exception ex) {
        throw new HGException("Failed to remove value with handle " + handle + ": " + ex.toString(), ex);
    }
}

18 View Complete Implementation : ArrayType.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    HGPersistentHandle[] layout = graph.getStore().getLink(handle);
    Object result;
    if (targetSet == null || targetSet.deref().length == 0)
        result = Array.newInstance(clazz, layout.length / 2);
    else {
        if (linkConstructor == null)
            throw new HGException("Unable to construct a link of type " + clazz.getName() + ", the clreplaced doesn't have a HGHandle [] based constructor.");
        try {
            result = linkConstructor.newInstance(new Object[] { targetSet });
        } catch (Throwable t) {
            throw new HGException(t);
        }
    }
    TypeUtils.setValueFor(graph, handle, result);
    for (int i = 0; i < layout.length; i += 2) {
        Object current = null;
        HGPersistentHandle typeHandle = layout[i];
        HGPersistentHandle valueHandle = layout[i + 1];
        if (!typeHandle.equals(graph.getHandleFactory().nullHandle())) {
            HGAtomType type = graph.getTypeSystem().getType(typeHandle);
            current = TypeUtils.makeValue(graph, valueHandle, type);
        }
        ((Object[]) result)[i / 2] = current;
    }
    return result;
}

18 View Complete Implementation : JavaObjectBinding.java
Copyright Apache License 2.0
Author : hypergraphdb
private void replacedignFields(HGPersistentHandle valueHandle, Object instance) {
    HGHandle superSlot = JavaTypeFactory.getSuperSlot(graph);
    RecordType hgType = (RecordType) this.hgType;
    Clreplaced<?> clazz = javaClreplaced;
    while (true) {
        Record record = (Record) hgType.make(valueHandle, null, null);
        HGPersistentHandle ss = null;
        for (HGHandle slotHandle : hgType.getSlots()) {
            Slot slot = (Slot) graph.get(slotHandle);
            if (slotHandle.equals(superSlot)) {
                ss = (HGPersistentHandle) record.get(slot);
                continue;
            }
            Object value = record.get(slot);
            if (value != null && hgType.getReferenceMode(slotHandle) != null)
                value = graph.get(((HGAtomRef) value).getReferent());
            JavaTypeFactory.replacedignPrivate(clazz, instance, slot.getLabel(), value);
        }
        if (ss != null) {
            clazz = clazz.getSuperclreplaced();
            JavaAbstractBinding superType = (JavaAbstractBinding) graph.getTypeSystem().getAtomType(clazz);
            hgType = (RecordType) superType.getHGType();
            valueHandle = ss;
        } else
            break;
    }
}

18 View Complete Implementation : BJEStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
public HGPersistentHandle store(HGPersistentHandle handle, byte[] data) {
    try {
        OperationStatus result = primitive_db.put(txn().getBJETransaction(), new DatabaseEntry(handle.toByteArray()), new DatabaseEntry(data));
        if (result != OperationStatus.SUCCESS)
            throw new Exception("OperationStatus: " + result);
        return handle;
    } catch (Exception ex) {
        throw new HGException("Failed to store hypergraph raw byte []: " + ex.toString(), ex);
    }
}

18 View Complete Implementation : BDBStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
public HGPersistentHandle[] getLink(HGPersistentHandle handle) {
    try {
        DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
        DatabaseEntry value = new DatabaseEntry();
        if (data_db.get(txn().getBDBTransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)
            return (HGPersistentHandle[]) linkBinding.entryToObject(value);
        else
            return null;
    } catch (Exception ex) {
        throw new HGException("Failed to retrieve link with handle " + handle, ex);
    }
}

18 View Complete Implementation : RAMStorageGraph.java
Copyright Apache License 2.0
Author : hypergraphdb
public void translateHandles(Map<HGHandle, HGHandle> subst) {
    Map<HGPersistentHandle, Object> translated = new HashMap<HGPersistentHandle, Object>();
    for (Map.Entry<HGPersistentHandle, Object> e : map.entrySet()) {
        if (e.getValue() instanceof HGPersistentHandle[]) {
            HGPersistentHandle[] A = (HGPersistentHandle[]) e.getValue();
            for (int i = 0; i < A.length; i++) {
                HGHandle h = subst.get(A[i]);
                if (h != null)
                    A[i] = h.getPersistent();
            }
        }
        HGHandle h = subst.get(e.getKey());
        if (h == null)
            h = e.getKey();
        translated.put(h.getPersistent(), e.getValue());
    }
    map = translated;
}

18 View Complete Implementation : PairType.java
Copyright Apache License 2.0
Author : hypergraphdb
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    HGPersistentHandle[] layout = graph.getStore().getLink(handle);
    Pair<?, ?> result = (Pair<?, ?>) TypeUtils.getValueFor(graph, handle);
    if (result != null)
        return result;
    Object first = null, second = null;
    if (!layout[0].equals(graph.getHandleFactory().nullHandle())) {
        HGAtomType type = graph.getTypeSystem().getType(layout[0]);
        first = TypeUtils.makeValue(graph, layout[1], type);
    }
    if (!layout[2].equals(graph.getHandleFactory().nullHandle())) {
        HGAtomType type = graph.getTypeSystem().getType(layout[2]);
        // 2012.01.24 hilpold BUGFIX old: first = TypeUtils.makeValue(graph, layout[3], type);
        second = TypeUtils.makeValue(graph, layout[3], type);
    }
    result = new Pair<Object, Object>(first, second);
    return result;
}

18 View Complete Implementation : DefaultAtomCache.java
Copyright Apache License 2.0
Author : hypergraphdb
/**
 * <p>replacedociate an atom instance and a persistent handle with a live handle.</p>
 */
public HGLiveHandle atomRead(final HGPersistentHandle pHandle, final Object atom, final HGAtomAttrib attrib) {
    LiveHandle lHandle = null;
    if ((attrib.getFlags() & HGSystemFlags.MANAGED) != 0)
        lHandle = new LiveHandle(atom, pHandle, attrib.getFlags(), attrib.getRetrievalCount(), attrib.getLastAccessTime());
    else
        lHandle = new LiveHandle(atom, pHandle, attrib.getFlags());
    insert(lHandle);
    return lHandle;
}

18 View Complete Implementation : TypedIncidentToQuery.java
Copyright Apache License 2.0
Author : hypergraphdb
public QueryMetaData getMetaData(HyperGraph graph, HGQueryCondition c) {
    QueryMetaData x = QueryMetaData.ORACCESS.clone(c);
    x.predicateCost = 1;
    TypedIncidentCondition ic = (TypedIncidentCondition) c;
    if (hg.isVar(ic.getTargetRef())) {
        // incidence sets are usually small...
        x.sizeExpected = 1000;
    } else {
        final HGPersistentHandle handle = graph.getPersistentHandle(((TypedIncidentCondition) c).getTargetRef().get());
        x.sizeLB = x.sizeExpected = x.sizeUB = graph.getIncidenceSet(handle).size();
    }
    return x;
}

18 View Complete Implementation : BDBStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
public byte[] getData(HGPersistentHandle handle) {
    try {
        DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
        DatabaseEntry value = new DatabaseEntry();
        if (primitive_db.get(txn().getBDBTransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            final byte[] data = value.getData();
            return data == null ? new byte[] {} : data;
        } else
            return null;
    } catch (Exception ex) {
        throw new HGException("Failed to retrieve link with handle " + handle, ex);
    }
}

18 View Complete Implementation : TypeUtils.java
Copyright Apache License 2.0
Author : hypergraphdb
public static void setValueFor(HyperGraph graph, HGPersistentHandle h, Object value) {
    boolean topCall = initThreadLocals();
    try {
        Map<HGPersistentHandle, Object> refMap = HANDLE_REF_MAP.get();
        if (!refMap.containsKey(h))
            refMap.put(h, value);
    } finally {
        releaseThreadLocals(topCall);
    }
}

18 View Complete Implementation : LmdbStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
@Override
public boolean containsData(HGPersistentHandle handle) {
    byte[] key = handle.toByteArray();
    byte[] value;
    try {
        value = this.primitive_db.get(txn().getDbTransaction(), key);
        if (value != null) {
            // System.out.println(value.toString());
            return true;
        }
    } catch (LMDBException ex) {
        throw new HGException("Failed to retrieve link with handle " + handle + ": " + ex.toString(), ex);
    }
    return false;
}

18 View Complete Implementation : CollectionTypeConstructor.java
Copyright Apache License 2.0
Author : hypergraphdb
@SuppressWarnings("unchecked")
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet) {
    CollectionType result = null;
    String clreplacedName = new String(graph.getStore().getData(handle));
    try {
        Clreplaced<?> clazz = Clreplaced.forName(clreplacedName);
        GenericObjectFactory factory = new GenericObjectFactory(clazz);
        result = new CollectionType(factory);
    } catch (Throwable t) {
        throw new HGException(t);
    }
    return result;
}

18 View Complete Implementation : TypeUtils.java
Copyright Apache License 2.0
Author : hypergraphdb
public static HGPersistentHandle getNewHandleFor(HyperGraph hg, Object value) {
    boolean topCall = initThreadLocals();
    try {
        HGPersistentHandle result = hg.getHandleFactory().makeHandle();
        if (value instanceof WrappedRuntimeInstance)
            value = ((WrappedRuntimeInstance) value).getRealInstance();
        JAVA_REF_MAP.get().put(value, result);
        return result;
    } finally {
        releaseThreadLocals(topCall);
    }
}

18 View Complete Implementation : DefaultAtomCache.java
Copyright Apache License 2.0
Author : hypergraphdb
/**
 * <p>Lookup in the cache for a live handle corresponding to a persistent
 * handle.</p>
 */
public HGLiveHandle get(final HGPersistentHandle pHandle) {
    LiveHandle result = liveHandles.get(pHandle);
    if (result == null)
        return null;
    result.accessed();
    retrievalCount++;
    lastAccessTime = System.currentTimeMillis();
    queueThread.addAction(new AtomAccessedAction(result));
    return result;
}

18 View Complete Implementation : DefaultIndexImpl.java
Copyright Apache License 2.0
Author : hypergraphdb
int keyBucket(KeyType keyType) {
    if (isSplitIndex()) {
        if (keyType instanceof HGPersistentHandle) {
            HGPersistentHandle handle = (HGPersistentHandle) keyType;
            String hdlStr = handle.toString();
            char lastChar = hdlStr.charAt(hdlStr.length() - 1);
            if (lastChar == '1' || lastChar == '3' || lastChar == '5' || lastChar == '7' || lastChar == '9') {
                return 1;
            }
        }
        if (keyType instanceof HGPersistentHandle[]) {
            HGPersistentHandle[] handles = (HGPersistentHandle[]) keyType;
            HGPersistentHandle handle = handles[0];
            String hdlStr = handle.toString();
            char lastChar = hdlStr.charAt(hdlStr.length() - 1);
            if (lastChar == '1' || lastChar == '3' || lastChar == '5' || lastChar == '7' || lastChar == '9') {
                return 1;
            }
        }
    }
    return 0;
}

18 View Complete Implementation : BJEStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
public HGPersistentHandle[] getLink(HGPersistentHandle handle) {
    try {
        DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
        DatabaseEntry value = new DatabaseEntry();
        if (data_db.get(txn().getBJETransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)
            return (HGPersistentHandle[]) linkBinding.entryToObject(value);
        else
            return null;
    } catch (Exception ex) {
        throw new HGException("Failed to retrieve link with handle " + handle, ex);
    }
}

17 View Complete Implementation : MapType.java
Copyright Apache License 2.0
Author : hypergraphdb
public void release(HGPersistentHandle handle) {
    // TypeUtils.releaseValue(hg, handle);
    HGTypeSystem ts = hg.getTypeSystem();
    HGPersistentHandle[] layout = hg.getStore().getLink(handle);
    for (int i = 0; i < layout.length; ) {
        HGPersistentHandle hType = layout[i++];
        HGPersistentHandle hValue = layout[i++];
        if (!TypeUtils.isValueReleased(hg, hValue)) {
            HGAtomType type = ts.getType(hType);
            TypeUtils.releaseValue(hg, type, hValue);
        // type.release(hValue);
        }
        hType = layout[i++];
        hValue = layout[i++];
        if (!hType.equals(hg.getHandleFactory().nullHandle()) && !TypeUtils.isValueReleased(hg, hValue)) {
            HGAtomType type = ts.getType(hType);
            TypeUtils.releaseValue(hg, type, hValue);
        // type.release(hValue);
        }
    }
    hg.getStore().removeLink(handle);
}

17 View Complete Implementation : BDBStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
public void removeLink(HGPersistentHandle handle) {
    if (handle == null)
        throw new NullPointerException("HGStore.remove called with a null handle.");
    try {
        DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
        data_db.delete(txn().getBDBTransaction(), key);
    } catch (Exception ex) {
        throw new HGException("Failed to remove value with handle " + handle + ": " + ex.toString(), ex);
    }
}

17 View Complete Implementation : UUIDSetBench.java
Copyright Apache License 2.0
Author : hypergraphdb
private static double lookupAll(HGHandleFactory handleFactory, Set<HGPersistentHandle> baseSet, Set<HGHandle> destination) {
    long start = System.currentTimeMillis();
    // int cnt = 0;
    for (int i = 0; i < 30; i++) for (HGPersistentHandle x : baseSet) {
        destination.contains(x);
        destination.contains(handleFactory.makeHandle());
    /*			System.out.println(x);
			if (cnt % 100 == 0)
				System.out.println("cnt=" + cnt);
			cnt++; */
    }
    return (System.currentTimeMillis() - start) / 1000.0;
}

17 View Complete Implementation : LmdbStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
@Override
public HGPersistentHandle store(HGPersistentHandle handle, byte[] data) {
    try {
        // System.out.println("Adding, key:" +
        // ctString.hexDump(handle.toByteArray()) + ",data:" +
        // ctString.hexDump(data));
        byte[] key = handle.toByteArray();
        primitive_db.put(txn().getDbTransaction(), key, data);
        // System.out.println("PrimitivePut." + key.length + "," +
        // data.length);
        if (handleFactory instanceof LongHandleFactory) {
            txn().setLastId(((LongHandleFactory) handleFactory).getNext());
        }
        // if (result != OperationStatus.SUCCESS)
        // throw new Exception("OperationStatus: " + result);
        return handle;
    } catch (Exception ex) {
        throw new HGException("Failed to store hypergraph raw byte []: " + data, ex);
    }
}

17 View Complete Implementation : LmdbStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
@Override
public HGPersistentHandle[] getLink(HGPersistentHandle handle) {
    try {
        byte[] key = handle.toByteArray();
        byte[] ba = data_db.get(txn().getDbTransaction(), key);
        if (ba != null) {
            DatabaseEntry value = new DatabaseEntry(ba);
            return linkBinding.entryToObject(value);
        } else
            return null;
    } catch (Exception ex) {
        throw new HGException("Failed to retrieve link with handle " + handle, ex);
    }
}

17 View Complete Implementation : BDBStorageImplementation.java
Copyright Apache License 2.0
Author : hypergraphdb
public boolean containsLink(HGPersistentHandle handle) {
    DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
    DatabaseEntry value = new DatabaseEntry();
    value.setPartial(0, 0, true);
    try {
        if (data_db.get(txn().getBDBTransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            // System.out.println(value.toString());
            return true;
        }
    } catch (DatabaseException ex) {
        throw new HGException("Failed to retrieve link with handle " + handle + ": " + ex.toString(), ex);
    }
    return false;
}