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();
}
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();
}
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();
}
}
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;
}
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;
}
Aggregations