Search in sources :

Example 6 with ObjectIdentifier

use of org.bimserver.database.ObjectIdentifier in project BIMserver by opensourceBIM.

the class QueryNamesAndTypesStackFrame method getOidOfGuidAlternative.

public ObjectIdentifier getOidOfGuidAlternative(EClass eClass, EAttribute attribute, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
    if (attribute.getEAnnotation("singleindex") != null) {
        String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + attribute.getName();
        byte[] queryBytes = null;
        if (value instanceof String) {
            queryBytes = ((String) value).getBytes(Charsets.UTF_8);
        } else if (value instanceof Integer) {
            queryBytes = BinUtils.intToByteArray((Integer) value);
        } else {
            throw new BimserverDatabaseException("Unsupported type " + value);
        }
        ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
        valueBuffer.putInt(pid);
        valueBuffer.putInt(-rid);
        valueBuffer.put(queryBytes);
        byte[] firstDuplicate = databaseInterface.get(indexTableName, valueBuffer.array());
        if (firstDuplicate != null) {
            ByteBuffer buffer = ByteBuffer.wrap(firstDuplicate);
            // pid
            buffer.getInt();
            long oid = buffer.getLong();
            return new ObjectIdentifier(oid, (short) oid);
        }
    } else {
        throw new UnsupportedOperationException();
    }
    return null;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ByteBuffer(java.nio.ByteBuffer) ObjectIdentifier(org.bimserver.database.ObjectIdentifier)

Aggregations

ObjectIdentifier (org.bimserver.database.ObjectIdentifier)6 ByteBuffer (java.nio.ByteBuffer)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)2 Revision (org.bimserver.models.store.Revision)2 UserException (org.bimserver.shared.exceptions.UserException)2 ArrayList (java.util.ArrayList)1