protected void log(Object obj, int level, StringBuffer log) { EObject object = (EObject) obj; List properties = object.eClass().getEAllStructuralFeatures(); for (Iterator p = properties.iterator(); p.hasNext(); ) { EStructuralFeature property = (EStructuralFeature) p.next(); Object value = object.eGet(property); // skip empty properties if (value == null || (value instanceof Collection && ((Collection) value).isEmpty()) || (value instanceof Map && ((Map) value).isEmpty())) { continue; } log.append("\n"); for (int i = 0; i < level; i++) log.append(" "); if (value instanceof EObject && (level < 3)) { log.append(property.getName()); log.append(":"); log((EObject) value, level + 1, log); } else if (value instanceof Collection) { log(property.getName(), (Collection) value, level + 1, log); } else { log.append(property.getName()); log.append(" = " + value); } } }
private int calculateUnsettedLength(EClass eClass, EAttribute skipAttribute) { int fieldCounter = 0; for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) { if (feature == skipAttribute) { continue; } if (this.useForDatabaseStorage(eClass, feature)) { fieldCounter++; } } int unsettedLength = (int) Math.ceil(fieldCounter / 8.0); unsettedLengths.put(eClass, unsettedLength); return unsettedLength; }
private Map<String, EStructuralFeature> getFieldFeatureMap(EClass eClass) { Map<String, EStructuralFeature> map = jsonMetadataCache.get(eClass); if (map != null) { return map; } synchronized (jsonMetadataCache) { map = new HashMap<String, EStructuralFeature>(); for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) { String key = getJsonFieldName(feature); map.put(key, feature); } jsonMetadataCache.put(eClass, Collections.unmodifiableMap(map)); } return map; }
/** * Method which looks up structural features of an eobject by type. * * @param eobject The eobject. * @param propertyType The type of the properties. * @return The list of structure features, or an empty list if none are found. */ public static List /*<EStructuralFeature>*/ features(EObject eobject, Class propertyType) { List match = new ArrayList(); List features = eobject.eClass().getEAllStructuralFeatures(); for (Iterator itr = features.iterator(); itr.hasNext(); ) { EStructuralFeature feature = (EStructuralFeature) itr.next(); if (feature.getEType().getInstanceClass().isAssignableFrom(propertyType)) { match.add(feature); } } return match; }
/** * Method which looks up a structure feature of an eobject, first doing an exact name match, * then a case insensitive one. * * @param eobject The eobject. * @param property The property * @return The structure feature, or <code>null</code> if not found. */ public static EStructuralFeature feature(EObject eobject, String property) { EStructuralFeature feature = eobject.eClass().getEStructuralFeature(property); if (feature != null) { return feature; } // do a case insentive check, need to do the walk up the type hierarchy for (Iterator itr = eobject.eClass().getEAllStructuralFeatures().iterator(); itr.hasNext(); ) { feature = (EStructuralFeature) itr.next(); if (feature.getName().equalsIgnoreCase(property)) { return feature; } } return null; }
private void compareEClass(EClass eClass1, EClass eClass2) throws SchemaCompareException { if (eClass1.getEAllStructuralFeatures().size() != eClass2.getEAllStructuralFeatures().size()) { throw new SchemaCompareException("Not the same amount of features in " + eClass1.getName()); } Iterator<EStructuralFeature> iterator1 = eClass1.getEAllStructuralFeatures().iterator(); Iterator<EStructuralFeature> iterator2 = eClass2.getEAllStructuralFeatures().iterator(); while (iterator1.hasNext()) { EStructuralFeature structuralFeature1 = iterator1.next(); EStructuralFeature structuralFeature2 = iterator2.next(); if (!structuralFeature1.getName().equals(structuralFeature2.getName())) { throw new SchemaCompareException("Features not the same name"); } if (!structuralFeature1.getEType().getName().equals(structuralFeature2.getEType().getName())) { throw new SchemaCompareException("Features not of the same type"); } } }
public EAttribute createEAttribute(EClass eClass, String name, EDataType eDataType, Multiplicity multiplicity) { EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName(name); if (multiplicity == Multiplicity.MANY) { eAttribute.setUpperBound(-1); } if (!isNew(eClass)) { changes.add(new NewAttributeChange(this, eClass.getEAllStructuralFeatures().size(), eAttribute)); } eAttribute.setEType(eDataType); eClass.getEStructuralFeatures().add(eAttribute); return eAttribute; }
public EReference createEReference(EClass eClass, String name, EClass type, Multiplicity multiplicity) { EReference eReference = EcoreFactory.eINSTANCE.createEReference(); eReference.setName(name); if (multiplicity == Multiplicity.MANY) { eReference.setUpperBound(-1); } if (!isNew(eClass)) { changes.add(new NewReferenceChange(this, eClass.getEAllStructuralFeatures().size(), eReference)); } eReference.setEType(type); eClass.getEStructuralFeatures().add(eReference); return eReference; }
private void writeEmbedded(IdEObject object) throws IOException { print("{"); print("\"_t\":\"" + object.eClass().getName() + "\","); for (EStructuralFeature eStructuralFeature : object.eClass().getEAllStructuralFeatures()) { print("\"" + eStructuralFeature.getName() + "\":"); writePrimitive(eStructuralFeature, object.eGet(eStructuralFeature)); if (object.eClass().getEAllStructuralFeatures().get(object.eClass().getEAllStructuralFeatures().size()-1) != eStructuralFeature) { print(","); } } print("}"); }
for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) { if (packageMetaData.useForDatabaseStorage(eClass, feature)) { fieldCounter++; fieldCounter = 0; for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) { boolean isUnsetted = (unsetted[fieldCounter / 8] & (1 << (fieldCounter % 8))) != 0; if (isUnsetted) {
private void buildUseForSerializationSet(EClass eClass) { if (this.getSchemaDefinition() != null) { if (!useForSerialization.containsKey(eClass)) { HashSet<EStructuralFeature> set = new HashSet<>(); for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) { EntityDefinition entityBN = this.getSchemaDefinition().getEntityBN(eClass.getName()); // if (eStructuralFeature.getEAnnotation("hidden") != null) { // if (eStructuralFeature.getEAnnotation("asstring") == null) { // } else { // if (entityBN.isDerived(eStructuralFeature.getName().substring(0, eStructuralFeature.getName().length() - 8))) { // } else { // set.add(eStructuralFeature); // } // } // } if (entityBN != null) { Attribute attribute = entityBN.getAttributeBNWithSuper(eStructuralFeature.getName()); if (attribute != null && attribute instanceof ExplicitAttribute) { if (!entityBN.isDerived(eStructuralFeature.getName()) || entityBN.isDerivedOverride(eStructuralFeature.getName())) { set.add(eStructuralFeature); } } } } useForSerialization.put(eClass, set); } } }
private void writeWrappedValue(int pid, int rid, WrappedVirtualObject wrappedValue, ByteBuffer buffer, PackageMetaData packageMetaData) throws BimserverDatabaseException { Short cid = getDatabaseInterface().getCidOfEClass(wrappedValue.eClass()); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putShort((short) -cid); buffer.order(ByteOrder.BIG_ENDIAN); for (EStructuralFeature eStructuralFeature : wrappedValue.eClass().getEAllStructuralFeatures()) { Object val = wrappedValue.eGet(eStructuralFeature); if (eStructuralFeature.isMany()) { List list = (List)val; buffer.putInt(list.size()); for (Object o : list) { if (o instanceof HashMapWrappedVirtualObject) { writeWrappedValue(pid, rid, (VirtualObject) o, buffer, packageMetaData); } } } else { if (eStructuralFeature.getEType() instanceof EDataType) { writePrimitiveValue(eStructuralFeature, val, buffer); } else { writeWrappedValue(pid, rid, (HashMapWrappedVirtualObject) val, buffer, packageMetaData); } } } }
private void writeEmbeddedValue(int pid, int rid, Object value, ByteBuffer buffer, PackageMetaData packageMetaData) throws BimserverDatabaseException { IdEObject wrappedValue = (IdEObject) value; Short cid = database.getCidOfEClass(wrappedValue.eClass()); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putShort((short) -cid); buffer.order(ByteOrder.BIG_ENDIAN); for (EStructuralFeature eStructuralFeature : wrappedValue.eClass().getEAllStructuralFeatures()) { if (eStructuralFeature.isMany()) { writeList(wrappedValue, buffer, packageMetaData, eStructuralFeature); } else { Object val = wrappedValue.eGet(eStructuralFeature); if (eStructuralFeature.getEType() instanceof EClass) { writeEmbeddedValue(pid, rid, val, buffer, packageMetaData); } else { writePrimitiveValue(eStructuralFeature, val, buffer); } } } }
for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) { if (eStructuralFeature.getEAnnotation("singleindex") != null) { String indexTableName = eClass.getEPackage().getName() + "_" + eClass.getName() + "_" + eStructuralFeature.getName();
private HashMapWrappedVirtualObject readEmbeddedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass) throws BimserverDatabaseException { HashMapWrappedVirtualObject eObject = new HashMapWrappedVirtualObject(eClass); for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) { if (eStructuralFeature.isMany()) { } else { if (eStructuralFeature.getEType() instanceof EDataType) { Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer); eObject.setAttribute(eStructuralFeature, primitiveValue); } else { buffer.order(ByteOrder.LITTLE_ENDIAN); short cid = buffer.getShort(); buffer.order(ByteOrder.BIG_ENDIAN); if (cid == -1) { // null, do nothing } else if (cid < 0) { // negative cid means value is embedded in // record EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid)); eObject.setAttribute(eStructuralFeature, readEmbeddedValue(eStructuralFeature, buffer, referenceClass)); } } } } return eObject; }
private IdEObject readEmbeddedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass, QueryInterface query) throws BimserverDatabaseException { IdEObject eObject = createInternal(eClass, query); for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) { if (eStructuralFeature.isMany()) { // Not implemented } else { if (eStructuralFeature.getEType() instanceof EDataType) { Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer, query); ((IdEObjectImpl) eObject).setLoaded(); eObject.eSet(eStructuralFeature, primitiveValue); } else { buffer.order(ByteOrder.LITTLE_ENDIAN); short cid = buffer.getShort(); buffer.order(ByteOrder.BIG_ENDIAN); if (cid == -1) { // null, do nothing } else if (cid < 0) { // non minus one and negative cid means value is embedded in record EClass referenceClass = database.getEClassForCid((short) (-cid)); eObject.eSet(eStructuralFeature, readEmbeddedValue(eStructuralFeature, buffer, referenceClass, query)); } } } } return eObject; }
private int estimateBufferSize(EClass eClass) { int size = 0; for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) { if (eStructuralFeature instanceof EAttribute) { EAttribute eAttribute = (EAttribute)eStructuralFeature; if (eAttribute.isMany()) { size += 2 + AVERAGE_PRIMITIVE_LIST_SIZE * getPrimitiveSize((EDataType) eAttribute.getEType()); } else { size += getPrimitiveSize((EDataType) eAttribute.getEType()); } } else if (eStructuralFeature instanceof EReference) { EReference eReference = (EReference)eStructuralFeature; if (eReference.isMany()) { size += 2 + AVERAGE_REFERENCE_LIST_SIZE * 10; } else { size += 10; } } } return size; }
@Override public int compare(IdEObject o1, IdEObject o2) { int i = 1; for (EStructuralFeature eStructuralFeature : type.getEAllStructuralFeatures()) { if (objectIDM.shouldFollowReference(originalQueryClass, type, eStructuralFeature)) { Object val1 = o1.eGet(eStructuralFeature); Object val2 = o2.eGet(eStructuralFeature); if (val1 != null && val2 != null) { if (eStructuralFeature.getEType() instanceof EClass) { if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) { int compare = comparePrimitives((IdEObject) val1, (IdEObject) val2); if (compare != 0) { return compare * i; } } } } i++; } } return 0; } });
@SuppressWarnings("unchecked") public void sortAllAggregates(ObjectIDM objectIDM, IdEObject ifcRoot) { for (EStructuralFeature eStructuralFeature : ifcRoot.eClass().getEAllStructuralFeatures()) { if (objectIDM.shouldFollowReference(ifcRoot.eClass(), ifcRoot.eClass(), eStructuralFeature)) { if (eStructuralFeature.getUpperBound() == -1 || eStructuralFeature.getUpperBound() > 1) { if (eStructuralFeature.getEType() instanceof EClass) { if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) { EList<IdEObject> list = (EList<IdEObject>) ifcRoot.eGet(eStructuralFeature); sortPrimitiveList(list); } else { EList<IdEObject> list = (EList<IdEObject>) ifcRoot.eGet(eStructuralFeature); sortComplexList(objectIDM, ifcRoot.eClass(), list, eStructuralFeature); } } } } } }
int lastSize = 0; for (EStructuralFeature eStructuralFeature : eClass().getEAllStructuralFeatures()) { if (getPackageMetaData().useForDatabaseStorage(eClass, eStructuralFeature)) { if (!useUnsetBit(eStructuralFeature)) {