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