Search in sources :

Example 11 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class SDOChangeSummary method undoChanges.

/**
 * This method is intended for use by service implementations only.
 * Undoes all changes in the log to restore the tree of
 * DataObjects to its original state when logging began.
 * isLogging() is unchanged.  The log is cleared.
 * @see #beginLogging
 * @see #endLogging
 * @see #isLogging
 */
@Override
public void undoChanges() {
    /**
     * See Jira SDO-109/107 and 125/225 for open issues with move optimization
     * See bug#5882923 for smart local undo via set()/unset()
     */
    Property oldProp = getOldContainmentProperty(rootDataObject);
    String oldName = null;
    if (oldProp != null) {
        oldName = oldProp.getName();
    }
    rootDataObject.undoChanges(true, this, getOldContainer(rootDataObject), oldName);
    resetChanges();
    rootDataObject.resetChanges();
}
Also used : Property(commonj.sdo.Property)

Example 12 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class SDOTypeHelperDelegate method defineOpenContentProperty.

/**
 *    Define the DataObject as a Property for setting open content.
 *    The new property or, if already defined, an existing property is returned.
 *    The containing Type of the open property is not specified by SDO.
 *    If the specified uri is not null the defined property is accessible through
 *    TypeHelper.getOpenProperty(uri, propertyName).
 *    If a null uri is specified, the location and management of the open property
 *    is not specified by SDO.
 *    @param uri the namespace URI of the open Property or null.
 *    @return the defined open Property.
 *    @throws IllegalArgumentException if the Property could not be defined.
 */
@Override
public Property defineOpenContentProperty(String uri, DataObject propertyDO) {
    if (propertyDO == null) {
        throw new IllegalArgumentException(SDOException.cannotPerformOperationWithNullInputParameter("defineOpenContentProperty", "propertyDO"));
    }
    String name = propertyDO.getString("name");
    Property propertyToReturn = aHelperContext.getXSDHelper().getGlobalProperty(uri, name, true);
    if (propertyToReturn == null) {
        propertyToReturn = aHelperContext.getXSDHelper().getGlobalProperty(uri, name, false);
    }
    if (propertyToReturn == null) {
        List types = new ArrayList();
        propertyToReturn = buildPropertyFromDataObject(propertyDO, null, types);
        initializeTypes(types);
        defineOpenContentProperty(uri, name, propertyToReturn);
    }
    if (propertyToReturn != null) {
        Object propDOType = propertyDO.get("type");
        SDOType existingType = (SDOType) propertyToReturn.getType();
        boolean typeMismatch = false;
        if (propDOType instanceof SDOType) {
            SDOType newType = (SDOType) propDOType;
            if (!newType.getQName().equals(existingType.getQName())) {
                typeMismatch = true;
            }
        } else if (propDOType instanceof DataObject) {
            DataObject newTypeDO = (DataObject) propDOType;
            if (!newTypeDO.get("name").equals(existingType.getName()) || !newTypeDO.get("uri").equals(existingType.getURI())) {
                typeMismatch = true;
            }
        }
        if (typeMismatch) {
            throw new IllegalArgumentException("Should not be able to redefine a Property with a different Type.");
        }
    }
    return propertyToReturn;
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ArrayList(java.util.ArrayList) SDOType(org.eclipse.persistence.sdo.SDOType) ArrayList(java.util.ArrayList) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property)

Example 13 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class XPathEngine method getDataObjectFromQuery.

// extract value from query and acquire dataobject that meets this requirement
/**
 *Access the DataObject value by using the fragment containing query informations.
 *
 * @param frag                  one string fragment in the path
 * @param openBracketIndex      the index of open bracket in a fragment
 * @param closeBracketIndex     the index of close bracket in a fragment
 * @param equalsignIndex        the index of equalsign in string fragment quoted by brackets
 * @param caller                the DataObject that passes the path information in
 * @param callerProperty        the name of the property
 * @return                      the DataObject as value of the property having name as the above callerProperty
 */
private DataObject getDataObjectFromQuery(String frag, int openBracketIndex, int closeBracketIndex, int equalsignIndex, DataObject caller, String callerProperty) {
    try {
        // trim off any whitespace for property names
        String propertyNameOfQryDataObject = frag.substring(openBracketIndex + 1, equalsignIndex + openBracketIndex).trim();
        List objects = caller.getList(caller.getInstanceProperty(callerProperty));
        String query = frag.substring(equalsignIndex + openBracketIndex + 1, closeBracketIndex);
        String value = null;
        int firstQuoteIndex = query.indexOf('\'');
        int lastQuoteIndex = query.lastIndexOf('\'');
        if ((firstQuoteIndex == -1) && (lastQuoteIndex == -1)) {
            // !! note: case: [number=1'23'] is assume not to happen !!
            firstQuoteIndex = query.indexOf('\"');
            lastQuoteIndex = query.lastIndexOf('\"');
        }
        if ((firstQuoteIndex != -1) && (lastQuoteIndex != -1) && (firstQuoteIndex < lastQuoteIndex)) {
            // quoted string existed
            value = query.substring(firstQuoteIndex + 1, lastQuoteIndex);
        } else {
            // if the value is not enclosed on quotes, trim off any whitespace
            value = query.trim();
        }
        Iterator iterObjects = objects.iterator();
        Object queryValue = value;
        Object actualValue = null;
        while (iterObjects.hasNext()) {
            DataObject cur = (DataObject) iterObjects.next();
            Property p = cur.getInstanceProperty(propertyNameOfQryDataObject);
            if (p != null) {
                try {
                    queryValue = XMLConversionManager.getDefaultXMLManager().convertObject(queryValue, p.getType().getInstanceClass());
                } catch (ConversionException e) {
                // do nothing, skip
                }
                if (!p.isMany()) {
                    actualValue = cur.get(p);
                    if (actualValue.equals(queryValue)) {
                        return cur;
                    }
                } else {
                    // case p is many type
                    List values = cur.getList(p);
                    Iterator iterValues = values.iterator();
                    while (iterValues.hasNext()) {
                        actualValue = iterValues.next();
                        if (actualValue.equals(queryValue)) {
                            return cur;
                        }
                    }
                }
            }
        }
        return null;
    } catch (IllegalArgumentException e) {
        return null;
    }
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) Iterator(java.util.Iterator) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) Property(commonj.sdo.Property)

Example 14 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class SDOTestCase method assertChildrenUnset.

protected void assertChildrenUnset(DataObject dataobject) {
    // verify all properties are unset and all many properties are size 0
    Iterator anIterator = dataobject.getType().getProperties().iterator();
    while (anIterator.hasNext()) {
        Property aProperty = (Property) anIterator.next();
        Object aPropertyValue = dataobject.get(aProperty);
        assertFalse(dataobject.isSet(aProperty));
        // all properties must be unset
        if (aProperty.isMany()) {
            assertSame(((List) aPropertyValue).size(), 0);
        } else {
            if (!aProperty.getType().isDataType()) {
                assertEquals(aProperty.getDefault(), aPropertyValue);
            // assertSame(aProperty.getDefault(), dataobject.get(aProperty));
            } else {
                // JIRA-253: we return a wrapped numeric primitive when it has no default
                Type aType = aProperty.getType();
                if (aType.equals(SDO_BOOLEAN)) {
                    assertEquals(false, ((Boolean) aPropertyValue).booleanValue());
                } else if (aType.equals(SDO_BYTE)) {
                    assertEquals(0, ((Byte) aPropertyValue).byteValue());
                } else if (aType.equals(SDO_CHARACTER)) {
                    assertEquals(0, ((Character) aPropertyValue).charValue());
                } else if (aType.equals(SDO_DOUBLE)) {
                    assertEquals(0, aPropertyValue);
                } else if (aType.equals(SDO_FLOAT)) {
                    assertEquals(0, aPropertyValue);
                } else if (aType.equals(SDO_INT)) {
                    assertEquals(0, ((Integer) aPropertyValue).intValue());
                } else if (aType.equals(SDO_SHORT)) {
                    assertEquals(0, ((Short) aPropertyValue).shortValue());
                } else if (aType.equals(SDO_LONG)) {
                    assertEquals(0, ((Long) aPropertyValue).longValue());
                }
            }
        }
    }
}
Also used : Type(commonj.sdo.Type) Iterator(java.util.Iterator) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property)

Example 15 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class SDOTestCase method compareSequences.

/**
 * INTERNAL: Return whether the 2 sequences are equal. Element properties
 * and unstructured text will be compared - attributes are out of scope.
 * <p>
 * For shallow equal - only dataType=true objects are compared, DataObject
 * values are ignored but should be defaults. Note: A setting object should
 * handle its own isEqual() behavior
 */
public boolean compareSequences(SDOSequence aSequence, SDOSequence aSequenceCopy, boolean isDeep) {
    // sequence
    if (null == aSequence && null == aSequenceCopy) {
        return true;
    }
    // both sequences must be null
    if (null == aSequence || null == aSequenceCopy) {
        return false;
    }
    // value=null for shallow copies
    if (aSequence.size() != aSequenceCopy.size()) {
        return false;
    }
    // the settings inside the sequence must be new objects
    SDOSetting originalSetting = null;
    SDOSetting copySetting = null;
    List<? super Setting> originalSettingsList = aSequence.getSettings();
    List<? super Setting> copySettingsList = aSequenceCopy.getSettings();
    if (null == originalSettingsList || null == copySettingsList) {
        return false;
    }
    Property originalProperty = null;
    Property copyProperty = null;
    /**
     * For shallow equal when dataType is false we do not check this
     * setting, the value will be unset (default value) in the shallow copy.
     * orig v1=String v2=DataObject v3=String shallowcopy v1=String
     * v2=null(default) v3=String deepcopy v1=String v2=DataObject v3=String
     */
    for (int index = 0, size = aSequence.size(); index < size; index++) {
        originalSetting = (SDOSetting) originalSettingsList.get(index);
        copySetting = (SDOSetting) copySettingsList.get(index);
        originalProperty = originalSetting.getProperty();
        copyProperty = copySetting.getProperty();
        // both !null = valid state (check equality)
        if ((null == originalProperty && null != copyProperty) || (null != originalProperty && null == copyProperty)) {
            return false;
        }
        // handle both properties == null
        if (originalProperty != copyProperty) {
            return false;
        }
        Object originalValue = originalSetting.getValue();
        Object copyValue = copySetting.getValue();
        // check equality directly
        if (null == originalProperty || originalProperty.getType().isDataType()) {
            // if one of the values is null return false
            if (// 
            ((null == originalValue) && (null != copyValue)) || ((null != originalValue) && (null == copyValue))) {
                return false;
            }
            // we can also use !.equals
            if ((null != originalValue) && !originalValue.equals(copyValue)) {
                return false;
            }
        } else {
            // only compare DataObjects when in a deep equal
            if (isDeep) {
                if (null != originalValue && null != copyValue) {
                    // instead of a CCE
                    if (originalValue instanceof DataObject && copyValue instanceof DataObject) {
                        if (!equalityHelper.equal((DataObject) originalValue, (DataObject) copyValue)) {
                            return false;
                        }
                    } else {
                        return false;
                    }
                } else {
                    // both values must be null to be equal
                    if ((null == originalValue && null != copyValue) || (null == copyValue && null != originalValue)) {
                        return false;
                    }
                }
            } else {
            /**
             * For DataObjects in general anything that is deep equal is
             * also shallow equal - but not the reverse. In the case of
             * shallow equal on sequences. We can ignore the state of
             * the 2 complex objects. UC1: if aSequenceCopy setting was
             * from a shallowCopy then it will be unset. UC2: if
             * aSequenceCopy setting was from a deepCopy or a reversed
             * argument shallowCopy then it may be unset or set. We will
             * not check for a default value on either sequence setting.
             */
            }
        }
    }
    return true;
}
Also used : SDOSetting(org.eclipse.persistence.sdo.SDOSetting) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property)

Aggregations

Property (commonj.sdo.Property)354 DataObject (commonj.sdo.DataObject)204 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)194 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)124 List (java.util.List)99 Type (commonj.sdo.Type)87 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)76 ArrayList (java.util.ArrayList)73 ChangeSummary (commonj.sdo.ChangeSummary)56 SDOType (org.eclipse.persistence.sdo.SDOType)54 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)47 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)37 SDOException (org.eclipse.persistence.exceptions.SDOException)35 Iterator (java.util.Iterator)24 QName (javax.xml.namespace.QName)12 InputStream (java.io.InputStream)11 SDOSetting (org.eclipse.persistence.sdo.SDOSetting)11 Map (java.util.Map)5 XMLDocument (commonj.sdo.helper.XMLDocument)4 SequencedObject (org.eclipse.persistence.oxm.sequenced.SequencedObject)4