Search in sources :

Example 11 with SDODataObject

use of org.eclipse.persistence.sdo.SDODataObject in project eclipselink by eclipse-ee4j.

the class SDOTestCase method assertSequencesCopiedAndSwappedAfterFirstModifyOperation.

protected void assertSequencesCopiedAndSwappedAfterFirstModifyOperation(DataObject aRootObject, Sequence aCurrentSequenceAfterLoggingFirstOnParam) {
    // verify logging is on
    assertTrue(aRootObject.getChangeSummary().isLogging());
    assertNotNull(aCurrentSequenceAfterLoggingFirstOnParam);
    Sequence anOriginalSequenceAfterOperation = (Sequence) ((SDOChangeSummary) aRootObject.getChangeSummary()).getOriginalSequences().get(aRootObject);
    Sequence aCurrentSequenceAfterOperation = ((SDODataObject) aRootObject).getSequence();
    assertNotNull(anOriginalSequenceAfterOperation);
    assertNotNull(aCurrentSequenceAfterOperation);
    assertTrue(anOriginalSequenceAfterOperation == aCurrentSequenceAfterLoggingFirstOnParam);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) Sequence(commonj.sdo.Sequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 12 with SDODataObject

use of org.eclipse.persistence.sdo.SDODataObject in project eclipselink by eclipse-ee4j.

the class JAXBList method add.

@Override
public void add(int index, Object element) {
    Object container = getContainer();
    if (container instanceof List) {
        List list = (List) container;
        if (!property.getType().isDataType()) {
            JAXBHelperContext jaxbHelperContext = jaxbValueStore.getJAXBHelperContext();
            Object unwrappedElement = jaxbHelperContext.unwrap((DataObject) element);
            jaxbHelperContext.putWrapperDataObject(unwrappedElement, (SDODataObject) element);
            list.add(index, unwrappedElement);
        } else {
            list.add(index, element);
        }
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) List(java.util.List)

Example 13 with SDODataObject

use of org.eclipse.persistence.sdo.SDODataObject in project eclipselink by eclipse-ee4j.

the class XPathHelper method processComplexQuery.

/**
 * Evaluate the query represented by the XPath Expression fragment against
 * the DataObject. A complex query contains logical operators.
 *
 * @param dataObject
 * @param reference
 * @param bracketContents
 * @return
 */
private Object processComplexQuery(DataObject dataObject, String reference, String bracketContents) {
    // convert the expression to postfix notation
    OPStack opStack = new OPStack();
    List expressionParts = opStack.processExpression(bracketContents);
    ArrayList queryParts = new ArrayList();
    // position of any 'and' / 'or'
    for (int i = 0; i < expressionParts.size(); i++) {
        Token tok = (Token) expressionParts.get(i);
        if (tok.getName().equals(AND_STR) || tok.getName().equals(OR_STR)) {
            queryParts.add(tok.getName());
        } else {
            // assume next three entries make up a query part
            String propertyName = ((Token) expressionParts.get(i)).getName();
            String queryValue = ((Token) expressionParts.get(++i)).getName();
            int operator = getOperandFromString(((Token) expressionParts.get(++i)).getName());
            queryParts.add(new QueryPart(propertyName.trim(), queryValue, operator));
        }
    }
    // get the DataObject(s) to execute the query against
    Property prop = dataObject.getInstanceProperty(reference);
    List objects;
    if (prop.isMany()) {
        objects = dataObject.getList(prop);
    } else {
        objects = new ArrayList();
        DataObject obj = dataObject.getDataObject(prop);
        if (obj != null) {
            objects.add(obj);
        }
    }
    List valuesToReturn = new ArrayList();
    Iterator iterObjects = objects.iterator();
    while (iterObjects.hasNext()) {
        SDODataObject cur = (SDODataObject) iterObjects.next();
        // this iteration, evaluate each QueryPart against the current DataObject
        ArrayList booleanValues = new ArrayList();
        for (int j = 0; j < queryParts.size(); j++) {
            if (queryParts.get(j).equals(AND_STR) || queryParts.get(j).equals(OR_STR)) {
                // add 'and'/'or' keeping in correct order
                booleanValues.add(queryParts.get(j));
            } else {
                // assume QueryPart - evaluate and add the result
                QueryPart qp = (QueryPart) queryParts.get(j);
                booleanValues.add(qp.evaluate(cur));
            }
        }
        // single result is achieved
        for (int k = 0; k < booleanValues.size(); k++) {
            if (booleanValues.get(k).equals(AND_STR) || booleanValues.get(k).equals(OR_STR)) {
                if (k >= 2) {
                    Boolean b1 = (Boolean) booleanValues.get(k - 1);
                    Boolean b2 = (Boolean) booleanValues.get(k - 2);
                    int logicalOp = getOperandFromString((String) booleanValues.get(k));
                    booleanValues.remove(k);
                    booleanValues.remove(k - 1);
                    booleanValues.set(k - 2, evaluate(b1, b2, logicalOp));
                    k = 0;
                }
            }
        }
        // if there isn't a single result something went wrong...
        if (booleanValues.size() == 1) {
            if ((Boolean) booleanValues.get(0)) {
                valuesToReturn.add(cur);
            }
        }
    }
    return valuesToReturn;
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 14 with SDODataObject

use of org.eclipse.persistence.sdo.SDODataObject in project eclipselink by eclipse-ee4j.

the class SDOEqualityHelperTest method testDeepEqualWithSetNullComplexChild.

// TODO: process non-containment side of bidirectionals see #5853175
public void testDeepEqualWithSetNullComplexChild() {
    // clear complex child
    root.set("rootproperty2-notdatatype", null);
    SDODataObject copyOfRoot = (SDODataObject) copyHelper.copy(root);
    assertFalse(root.isSet("rootproperty2-notdatatype"));
    assertNotNull(copyOfRoot);
    // this assertion previously failed before fix for #5852525
    assertTrue(equalityHelper.equal(root, copyOfRoot));
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 15 with SDODataObject

use of org.eclipse.persistence.sdo.SDODataObject in project eclipselink by eclipse-ee4j.

the class UserSetContextMapTestCases method testResolveWithHelperContextSetInUserMap.

/**
 * Test should serialize/deserialize successfully/
 */
public void testResolveWithHelperContextSetInUserMap() {
    // First overwrite the existing context with an empty one
    SDOHelperContext.putHelperContext(Thread.currentThread().getContextClassLoader(), new SDOHelperContext());
    String xsdString = getXSDString(CONTEXT1_DATAOBJECT_XSD_PATH);
    localCtx = new SDOHelperContext("customId");
    localCtx.getXSDHelper().define(xsdString);
    localDObj = load(CONTEXT1_DATAOBJECT_XML_PATH, localCtx);
    SDOHelperContext.putHelperContext(Thread.currentThread().getContextClassLoader(), localCtx);
    serialize(localDObj, FILE_NAME);
    SDODataObject dobj = (SDODataObject) deserialize(FILE_NAME);
    String dobjImplClassName = dobj.getType().getInstanceClassName();
    assertTrue("Expected [" + implClassname + "] but was [" + dobjImplClassName + "]", dobjImplClassName.equals(implClassname));
    SDOHelperContext.removeHelperContext(Thread.currentThread().getContextClassLoader());
}
Also used : SDOHelperContext(org.eclipse.persistence.sdo.helper.SDOHelperContext) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Aggregations

SDODataObject (org.eclipse.persistence.sdo.SDODataObject)301 DataObject (commonj.sdo.DataObject)118 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)99 ArrayList (java.util.ArrayList)79 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)76 SDOType (org.eclipse.persistence.sdo.SDOType)70 List (java.util.List)65 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)64 Property (commonj.sdo.Property)52 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)51 ValueStore (org.eclipse.persistence.sdo.ValueStore)22 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)21 ChangeSummary (commonj.sdo.ChangeSummary)20 SDOMarshalListener (org.eclipse.persistence.sdo.helper.SDOMarshalListener)20 Iterator (java.util.Iterator)18 Type (commonj.sdo.Type)9 XMLDocument (commonj.sdo.helper.XMLDocument)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)5 Map (java.util.Map)5