protected void clearReference(EObject obj, EReference ref) { if (!ref.isContainment() && !ref.isContainer() && !ref.isDerived() && ref.isChangeable() && !ref.isTransient()) obj.eUnset(ref); }
public void testCustomDefaultLiteral() throws CommitException { // valid default literal att.setDefaultValueLiteral("1;2"); EObject obj = EcoreUtil.create(cls); obj.eUnset(att); { CDOSession session = openSession(); session.getPackageRegistry().putEPackage(pkg); CDOTransaction tx = session.openTransaction(); CDOResource res = tx.createResource(getResourcePath("/test")); res.getContents().add(obj); tx.commit(); tx.close(); session.close(); } clearCache(getRepository().getRevisionManager()); { CDOSession session = openSession(); session.getPackageRegistry().putEPackage(pkg); CDOView v = session.openView(); CDOResource res = v.getResource(getResourcePath("/test")); EObject persistent = res.getContents().get(0); CustomType pCustom = (CustomType) persistent.eGet(att); assertEquals(1, pCustom.getA()); assertEquals(2, pCustom.getB()); v.close(); session.close(); } }
/** * Converts the value of an EAttribute with isMany==false, the value is converted ( {@link * #convertEAttributeValue(Object, EDataType)}) and set in the correct feature in the eObject. * * @param modelObject the modelObject from which the value is retrieved. * @param eObject the eObject in which the value is set (after it has been converted) * @param eAttribute the EAttribute which is converted * @see #convertEAttributeValue(Object, EDataType) */ protected void convertSingleEAttribute( final ModelObject<?> modelObject, final EObject eObject, final EAttribute eAttribute) { final Object value = modelObject.eGet(eAttribute); // don't set the eObject if the value is null and the attribute is unsettable. // unsettable is modelled with null in Texo. if (value == null && ModelUtils.isUnsettable(eAttribute)) { eObject.eUnset(eAttribute); return; } final Object newValue = convertEAttributeValue(value, eAttribute.getEAttributeType()); ((InternalEObject) eObject).eSet(eAttribute, newValue); }
/** * @see org.teiid.designer.core.util.ModelVisitor#visit(org.eclipse.emf.ecore.EObject) * @since 4.3 */ @Override public boolean visit(final EObject object) { // Find all references ... final EClass eclass = object.eClass(); final Collection allRefs = eclass.getEAllReferences(); for (final Iterator i = allRefs.iterator(); i.hasNext(); ) { final EReference reference = (EReference) i.next(); // Process only non-containment references ... if (!reference.isContainment() && !reference.isContainer() && !reference.isVolatile()) { final Object value = object.eGet(reference, false); if (reference.isMany()) { // There may be many values ... boolean removeRefdValue = false; for (Iterator j = ((List) value).iterator(); j.hasNext(); ) { final Object valueInList = j.next(); if (valueInList instanceof EObject && valueInList == refdObject) { removeRefdValue = true; } } if (removeRefdValue && reference.isChangeable()) { ((List) value).remove(refdObject); this.affectedObjects.add(object); } } else { // There may be 0..1 value ... if (value instanceof EObject && value == refdObject) { if (reference.isChangeable()) { object.eUnset(reference); this.affectedObjects.add(object); } } } } } return true; }
public static void eUnsetOrRemove(EObject obj, EStructuralFeature feature, Object value) { if (feature == null || feature.isMany()) ((List) obj.eGet(feature)).remove(value); else obj.eUnset(feature); }