Package org.ofbiz.entity

Examples of org.ofbiz.entity.GenericPK


        }
        Map paramMap = UtilHttp.getParameterMap(request);
        String entityName = (String)paramMap.get("entityName");
        if (UtilValidate.isEmpty(entityName))
            entityName = (String)request.getAttribute("entityName");
        GenericPK cachedPK = null;
        if (UtilValidate.isNotEmpty(entityName))
            cachedPK = (GenericPK)currentEntityMap.get(entityName);
        getCurrentValueWithCachedPK( request, delegator, cachedPK, entityName);
        GenericPK currentPK = (GenericPK)request.getAttribute("currentPK");
        currentEntityMap.put(entityName, currentPK);
    }
View Full Code Here


    public static void getCurrentValueWithCachedPK(HttpServletRequest request, GenericDelegator delegator, GenericPK cachedPK, String entityName) {

        Map paramMap = UtilHttp.getParameterMap(request);
        // Build the primary key that may have been passed in as key values
        GenericValue v = delegator.makeValue(entityName);
        GenericPK passedPK = v.getPrimaryKey();
        Collection keyColl = passedPK.getAllKeys();
        Iterator keyIt = keyColl.iterator();
        while (keyIt.hasNext()) {
            String attrName = (String)keyIt.next();
            String attrVal = (String)request.getAttribute(attrName);
            if (UtilValidate.isEmpty(attrVal)) {
                attrVal = (String)paramMap.get(attrName);
            }
            if (UtilValidate.isNotEmpty(attrVal)) {
                passedPK.put(attrName,attrVal);
            }
        }

        // If a full passed primary key exists, it takes precedence over a cached key
        // I cannot determine if the key testing utils of GenericEntity take into account
        // whether or not a field is populated.
        boolean useCached = false;
        boolean usePassed = true;
        if (cachedPK != null ) {
            useCached = true;
            keyColl = cachedPK.getPrimaryKey().getAllKeys();
            keyIt = keyColl.iterator();
            while (keyIt.hasNext()) {
                String sCached = null;
                String sPassed = null;
                Object oPassed = null;
                Object oCached = null;
                String ky = (String)keyIt.next();
                oPassed = passedPK.get(ky);
                if (oPassed != null) {
                    sPassed = oPassed.toString();
                    if (UtilValidate.isEmpty(sPassed)) {
                        // If any part of passed key is not available, it can't be used
                        usePassed = false;
                    } else {
                        oCached = cachedPK.get(ky);
                        if (oCached != null) {
                            sCached = oCached.toString();
                            if (UtilValidate.isEmpty(sCached)) {
                                useCached = false;
                            } else {
                            }
                        } else {
                            useCached = false;
                        }
                    }
                } else {
                    //useCached = false;
                    usePassed = false;
                }
            }
        }

        GenericPK currentPK = null;
        if (usePassed && useCached) {
            currentPK = passedPK;
        } else if (usePassed && !useCached) {
            currentPK = passedPK;
        } else if (!usePassed && useCached) {
            currentPK = cachedPK;
        }

        if (currentPK != null) {
            request.setAttribute("currentPK", currentPK);
            GenericValue currentValue = null;
            try {
                currentValue = delegator.findOne(currentPK.getEntityName(), currentPK, false);
            } catch (GenericEntityException e) {
            }
            request.setAttribute("currentValue", currentValue);
        }
View Full Code Here

public class StatsUpdater {
    private static final Updater UPDATER = new Updater();

    public static void updateStats(GenericDelegator delegator, String entityName, Map<String, ? extends Object> keyFields, Map<String, ? extends Long> updateCountFields) throws GenericEntityException {
        GenericPK pk = delegator.makePK(entityName, keyFields);
        Map<String, Long> value = UPDATER.getValue(pk);
        synchronized (value) {
            for (Map.Entry<String, ? extends Long> entry: updateCountFields.entrySet()) {
                Long oldValue = value.get(entry.getKey());
                if (oldValue != null) {
View Full Code Here

        //GenericDelegator delegator = dctx.getDelegator();
        //LocalDispatcher dispatcher = dctx.getDispatcher();
        //HttpServletRequest request = (HttpServletRequest)context.get("request");
        //String suffix = (String) context.get("suffix");
        GenericValue val = (GenericValue)context.get("pk");
        GenericPK pk = val.getPrimaryKey();
        HttpSession session = (HttpSession)context.get("session");

        ContentManagementWorker.mruAdd(session, pk);
        return ServiceUtil.returnSuccess();
    }
View Full Code Here

            while (checkOrderAdjustments != null && checkOrderAdjustments.hasNext()) {
                GenericValue checkOrderAdjustment = (GenericValue) checkOrderAdjustments.next();
                if (UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoId")) &&
                        UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoRuleId")) &&
                        UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoActionSeqId"))) {
                    GenericPK productPromoActionPk = delegator.makeValidValue("ProductPromoAction", checkOrderAdjustment).getPrimaryKey();
                    cart.setDesiredAlternateGiftByAction(productPromoActionPk, alternateGwpProductId);
                    if (cart.getOrderType().equals("SALES_ORDER")) {
                        org.ofbiz.order.shoppingcart.product.ProductPromoWorker.doPromotions(cart, dispatcher);
                    }
                    return "success";
View Full Code Here

            GenericEntity dummyPK = (GenericEntity) context.get("dummyPK");
            if (Debug.infoOn()) Debug.logInfo("Got a clear cache line by dummyPK service call; entityName: " + dummyPK.getEntityName(), module);
            if (Debug.verboseOn()) Debug.logVerbose("Got a clear cache line by dummyPK service call; dummyPK: " + dummyPK, module);
            delegator.clearCacheLineFlexible(dummyPK, distribute);
        } else if (context.containsKey("primaryKey")) {
            GenericPK primaryKey = (GenericPK) context.get("primaryKey");
            if (Debug.infoOn()) Debug.logInfo("Got a clear cache line by primaryKey service call; entityName: " + primaryKey.getEntityName(), module);
            if (Debug.verboseOn()) Debug.logVerbose("Got a clear cache line by primaryKey service call; primaryKey: " + primaryKey, module);
            delegator.clearCacheLine(primaryKey, distribute);
        } else if (context.containsKey("condition")) {
            String entityName = (String) context.get("entityName");
            EntityCondition condition = (EntityCondition) context.get("condition");
View Full Code Here

            throw new IllegalArgumentException("Error in entity-one definition, cannot specify select-field elements when use-cache is set to true");
        }

        try {
            GenericValue valueOut = null;
            GenericPK entityPK = delegator.makePK(modelEntity.getEntityName(), entityContext);

            // make sure we have a full primary key, if any field is null then just log a warning and return null instead of blowing up
            if (entityPK.containsPrimaryKey(true)) {
                if (useCache) {
                    valueOut = delegator.findOne(entityPK.getEntityName(), entityPK, true);
                } else {
                    if (fieldsToSelect != null) {
                        valueOut = delegator.findByPrimaryKeyPartial(entityPK, fieldsToSelect);
                    } else {
                        valueOut = delegator.findOne(entityPK.getEntityName(), entityPK, false);
                    }
                }
            } else {
                if (Debug.infoOn()) Debug.logInfo("Returning null because found incomplete primary key in find: " + entityPK, module);
            }
View Full Code Here

                element.appendChild(serializeSingle(iter.next(), document));
            }
            return element;
        } else if (object instanceof GenericPK) {
            // Do GenericEntity objects as a special case, use std XML import/export routines
            GenericPK value = (GenericPK) object;

            return value.makeXmlElement(document, "eepk-");
        } else if (object instanceof GenericValue) {
            GenericValue value = (GenericValue) object;

            return value.makeXmlElement(document, "eeval-");
        } else if (object instanceof Map) {
            // - Maps -
            String elementName = null;

            // these ARE order sensitive; for instance Properties extends Hashtable, so if Hashtable were first we would lose the Properties part
            if (object instanceof HashMap) {
                elementName = "map-HashMap";
            } else if (object instanceof Properties) {
                elementName = "map-Properties";
            } else if (object instanceof Hashtable) {
                elementName = "map-Hashtable";
            } else if (object instanceof WeakHashMap) {
                elementName = "map-WeakHashMap";
            } else if (object instanceof TreeMap) {
                elementName = "map-TreeMap";
            } else {
                // serialize as a simple Map implementation if nothing else applies, these will deserialize as a HashMap
                elementName = "map-Map";
            }

            Element element = document.createElement(elementName);
            Map value = (Map) object;
            Iterator iter = value.entrySet().iterator();

            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();

                Element entryElement = document.createElement("map-Entry");
View Full Code Here

        if (checkValue == null) {
            errorMessages.add("Got a value to check was null");
            return;
        }
        // to check get the PK, find by that, compare all fields
        GenericPK checkPK = null;

        try {
            checkPK = checkValue.getPrimaryKey();
            GenericValue currentValue = delegator.findOne(checkPK.getEntityName(), checkPK, false);
            if (currentValue == null) {
                errorMessages.add("Entity [" + checkPK.getEntityName() + "] record not found for pk: " + checkPK);
                return;
            }

            ModelEntity modelEntity = checkValue.getModelEntity();
            for (String nonpkFieldName: modelEntity.getNoPkFieldNames()) {
                // skip the fields the entity engine maintains
                if (ModelEntity.CREATE_STAMP_FIELD.equals(nonpkFieldName) || ModelEntity.CREATE_STAMP_TX_FIELD.equals(nonpkFieldName) ||
                        ModelEntity.STAMP_FIELD.equals(nonpkFieldName) || ModelEntity.STAMP_TX_FIELD.equals(nonpkFieldName)) {
                    continue;
                }

                Object checkField = checkValue.get(nonpkFieldName);
                Object currentField = currentValue.get(nonpkFieldName);

                if (checkField != null && !checkField.equals(currentField)) {
                    errorMessages.add("Field [" + modelEntity.getEntityName() + "." + nonpkFieldName +
                            "] did not match; file value [" + checkField + "], db value [" + currentField + "] pk [" + checkPK + "]");
                }
            }
        } catch (GenericEntityException e) {
            throw e;
        } catch (Throwable t) {
            String errMsg;
            if (checkPK == null) {
                errMsg = "Error checking value [" + checkValue + "]: " + t.toString();
            } else {
                errMsg = "Error checking entity [" + checkPK.getEntityName() + "] with pk [" + checkPK.getAllFields() + "]: " + t.toString();
            }
            errorMessages.add(errMsg);
            Debug.logError(t, errMsg, module);
        }
    }
View Full Code Here

        //
        EntityCondition isRoot = EntityCondition.makeCondition("primaryParentNodeId", EntityOperator.EQUALS, GenericEntity.NULL_FIELD);
        List<GenericValue> rootValues = delegator.findList("TestingNode", isRoot, UtilMisc.toSet("testingNodeId"), null, null, false);

        for (GenericValue value: rootValues) {
            GenericPK pk = value.getPrimaryKey();
            int del = delegator.removeByPrimaryKey(pk);
            TestCase.assertEquals("Removing Root by primary key", del, 1);
        }

        // no more TestingNode should be in the data base anymore.
View Full Code Here

TOP

Related Classes of org.ofbiz.entity.GenericPK

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.