Search in sources :

Example 1 with ObjectIdentifier

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

the class GetDataObjectByGuidDatabaseAction method execute.

@Override
public DataObject execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    ObjectIdentifier objectIdentifier = null;
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        objectIdentifier = getDatabaseSession().getOidOfGuid(concreteRevision.getProject().getSchema(), guid, concreteRevision.getProject().getId(), concreteRevision.getId());
        if (objectIdentifier != null) {
            long oidOfGuid = objectIdentifier.getOid();
            if (oidOfGuid != -1) {
                break;
            }
        }
    }
    if (objectIdentifier == null) {
        throw new UserException("Guid " + guid + " not found in this revision/project");
    }
    return new GetDataObjectByOidDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), roid, objectIdentifier.getOid(), authorization).execute();
}
Also used : Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) UserException(org.bimserver.shared.exceptions.UserException) ObjectIdentifier(org.bimserver.database.ObjectIdentifier)

Example 2 with ObjectIdentifier

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

the class GetOidByGuidDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    ObjectIdentifier objectIdentifier = null;
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        objectIdentifier = getDatabaseSession().getOidOfGuid(concreteRevision.getProject().getSchema(), guid, concreteRevision.getProject().getId(), concreteRevision.getId());
        if (objectIdentifier != null) {
            long oidOfGuid = objectIdentifier.getOid();
            if (oidOfGuid != -1) {
                break;
            }
        }
    }
    if (objectIdentifier == null) {
        throw new UserException("Guid " + guid + " not found in this revision/project");
    }
    return objectIdentifier.getOid();
}
Also used : Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) UserException(org.bimserver.shared.exceptions.UserException) ObjectIdentifier(org.bimserver.database.ObjectIdentifier)

Example 3 with ObjectIdentifier

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

the class QueryClassificationsAndTypesStackFrame method getOids.

public List<ObjectIdentifier> getOids(EClass eClass, EStructuralFeature eStructuralFeature, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
    if (eStructuralFeature.getEAnnotation("singleindex") != null) {
        List<ObjectIdentifier> result = new ArrayList<>();
        String indexTableName = eStructuralFeature.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + eStructuralFeature.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 if (value instanceof Long) {
            queryBytes = BinUtils.longToByteArray((Long) value);
        } else {
            throw new BimserverDatabaseException("Unsupported type " + value);
        }
        ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
        valueBuffer.putInt(pid);
        valueBuffer.putInt(-rid);
        valueBuffer.put(queryBytes);
        List<byte[]> duplicates = databaseInterface.getDuplicates(indexTableName, valueBuffer.array());
        for (byte[] duplicate : duplicates) {
            ByteBuffer buffer = ByteBuffer.wrap(duplicate);
            // pid
            buffer.getInt();
            long oid = buffer.getLong();
            result.add(new ObjectIdentifier(oid, (short) oid));
        }
        return result;
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) ObjectIdentifier(org.bimserver.database.ObjectIdentifier)

Example 4 with ObjectIdentifier

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

the class QueryClassificationsAndTypesStackFrame method getOid.

public ObjectIdentifier getOid(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(eClass.getName() + "." + attribute.getName() + " does not have a singleindex");
    }
    return null;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ByteBuffer(java.nio.ByteBuffer) ObjectIdentifier(org.bimserver.database.ObjectIdentifier)

Example 5 with ObjectIdentifier

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

the class QueryGuidsAndTypesStackFrame 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("Attribute " + attribute.getName() + " does not have the \"singleindex\" annotation");
    }
    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