use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method writeWrappedValue.
private void writeWrappedValue(int pid, int rid, Object value, ByteBuffer buffer, PackageMetaData packageMetaData) throws BimserverDatabaseException {
IdEObject wrappedValue = (IdEObject) value;
EStructuralFeature eStructuralFeature = wrappedValue.eClass().getEStructuralFeature("wrappedValue");
Short cid = database.getCidOfEClass(wrappedValue.eClass());
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) -cid);
buffer.order(ByteOrder.BIG_ENDIAN);
writePrimitiveValue(eStructuralFeature, wrappedValue.eGet(eStructuralFeature), buffer);
if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
EStructuralFeature fe = wrappedValue.eClass().getEStructuralFeature("wrappedValueAsString");
writePrimitiveValue(fe, wrappedValue.eGet(fe), buffer);
}
if (wrappedValue.eClass().getName().equals("IfcGloballyUniqueId")) {
EClass eClass = packageMetaData.getEClass("IfcGloballyUniqueId");
if (wrappedValue.getOid() == -1) {
((IdEObjectImpl) wrappedValue).setOid(newOid(eClass));
}
ByteBuffer valueBuffer = convertObjectToByteArray(wrappedValue, ByteBuffer.allocate(getExactSize(wrappedValue, packageMetaData, true)), packageMetaData);
ByteBuffer keyBuffer = createKeyBuffer(pid, wrappedValue.getOid(), rid);
try {
database.getKeyValueStore().storeNoOverwrite(eClass.getEPackage().getName() + "_" + eClass.getName(), keyBuffer.array(), valueBuffer.array(), this);
database.incrementCommittedWrites(1);
} catch (BimserverLockConflictException e) {
LOGGER.error("", e);
}
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method getExactSize.
private int getExactSize(IdEObject idEObject, PackageMetaData packageMetaData, boolean useUnsetBits) {
int size = 0;
int bits = 0;
for (EStructuralFeature eStructuralFeature : idEObject.eClass().getEAllStructuralFeatures()) {
if (packageMetaData.useForDatabaseStorage(idEObject.eClass(), eStructuralFeature)) {
bits++;
if (!useUnsetBits || !useUnsetBit(eStructuralFeature, idEObject)) {
Object val = idEObject.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EAttribute) {
EAttribute eAttribute = (EAttribute) eStructuralFeature;
if (eAttribute.isMany()) {
size += 4;
for (Object v : ((List<?>) val)) {
size += getPrimitiveSize(eAttribute.getEAttributeType(), v);
}
} else {
size += getPrimitiveSize(eAttribute.getEAttributeType(), val);
}
} else if (eStructuralFeature instanceof EReference) {
EReference eReference = (EReference) eStructuralFeature;
if (eReference.isMany()) {
size += 4;
for (Object v : ((List<?>) val)) {
size += getWrappedValueSize(v, eReference, packageMetaData);
}
} else {
size += getWrappedValueSize(val, eReference, packageMetaData);
}
}
}
}
}
if (useUnsetBits) {
size += (int) Math.ceil(bits / 8.0);
}
return size;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method processTodoList.
private void processTodoList(IfcModelInterface model, TodoList todoList, QueryInterface query) throws BimserverDatabaseException {
IdEObject idEObject = todoList.poll();
while (idEObject != null) {
IdEObject result = get(idEObject, idEObject.getOid(), model, query, todoList);
if (result == null) {
throw new BimserverDatabaseException("Object not found: " + query.getPid() + " " + query.getRid() + " " + idEObject.getOid() + " " + idEObject.eClass().getName());
}
if (!model.contains(result.getOid())) {
try {
model.addAllowMultiModel(result.getOid(), result);
} catch (IfcModelInterfaceException e) {
throw new BimserverDatabaseException(e);
}
}
idEObject = todoList.poll();
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method create.
@SuppressWarnings("unchecked")
public <T> T create(EClass eClass, int pid, int rid) throws BimserverDatabaseException {
checkOpen();
IdEObject idEObject = createInternal(eClass, null);
store(idEObject, pid, rid);
return (T) idEObject;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method readEmbeddedValue.
private IdEObject readEmbeddedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass, QueryInterface query) {
IdEObject eObject = createInternal(eClass, query);
for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
if (eStructuralFeature.isMany()) {
// Not implemented
} else {
Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer, query);
((IdEObjectImpl) eObject).setLoaded();
eObject.eSet(eStructuralFeature, primitiveValue);
}
}
return eObject;
}
Aggregations