Examples of UtilTimer


Examples of org.ofbiz.base.util.UtilTimer

        }
        if (rname.indexOf('/') > 0) {
            rname = rname.substring(0, rname.indexOf('/'));
        }

        UtilTimer timer = null;
        if (Debug.timingOn()) {
            timer = new UtilTimer();
            timer.setLog(true);
            timer.timerString("[" + rname + "] Request Begun, encoding=[" + charset + "]", module);
        }

        // Setup the CONTROL_PATH for JSP dispatching.
        String contextPath = request.getContextPath();
        if (contextPath == null || "/".equals(contextPath)) {
            contextPath = "";
        }
        request.setAttribute("_CONTROL_PATH_", contextPath + request.getServletPath());
        if (Debug.verboseOn())
            Debug.logVerbose("Control Path: " + request.getAttribute("_CONTROL_PATH_"), module);

        // for convenience, and necessity with event handlers, make security and delegator available in the request:
        // try to get it from the session first so that we can have a delegator/dispatcher/security for a certain user if desired
        GenericDelegator delegator = null;
        String delegatorName = (String) session.getAttribute("delegatorName");
        if (UtilValidate.isNotEmpty(delegatorName)) {
            delegator = GenericDelegator.getGenericDelegator(delegatorName);
        }
        if (delegator == null) {
            delegator = (GenericDelegator) getServletContext().getAttribute("delegator");
        }
        if (delegator == null) {
            Debug.logError("[ControlServlet] ERROR: delegator not found in ServletContext", module);
        } else {
            request.setAttribute("delegator", delegator);
            // always put this in the session too so that session events can use the delegator
            session.setAttribute("delegatorName", delegator.getDelegatorName());
        }

        LocalDispatcher dispatcher = (LocalDispatcher) session.getAttribute("dispatcher");
        if (dispatcher == null) {
            dispatcher = (LocalDispatcher) getServletContext().getAttribute("dispatcher");
        }
        if (dispatcher == null) {
            Debug.logError("[ControlServlet] ERROR: dispatcher not found in ServletContext", module);
        }
        request.setAttribute("dispatcher", dispatcher);

        Security security = (Security) session.getAttribute("security");
        if (security == null) {
            security = (Security) getServletContext().getAttribute("security");
        }
        if (security == null) {
            Debug.logError("[ControlServlet] ERROR: security not found in ServletContext", module);
        }
        request.setAttribute("security", security);

        request.setAttribute("_REQUEST_HANDLER_", requestHandler);

        // setup some things that should always be there
        UtilHttp.setInitialRequestInfo(request);
        VisitHandler.getVisitor(request, response);

        // set the Entity Engine user info if we have a userLogin
        String visitId = VisitHandler.getVisitId(session);
        if (UtilValidate.isNotEmpty(visitId)) {
            GenericDelegator.pushSessionIdentifier(visitId);
        }

        // display details on the servlet objects
        if (Debug.verboseOn()) {
            logRequestInfo(request);
        }

        // some containers call filters on EVERY request, even forwarded ones, so let it know that it came from the control servlet
        request.setAttribute(ContextFilter.FORWARDED_FROM_SERVLET, Boolean.TRUE);

        String errorPage = null;
        try {
            // the ServerHitBin call for the event is done inside the doRequest method
            requestHandler.doRequest(request, response, null, userLogin, delegator);
        } catch (RequestHandlerException e) {
            Throwable throwable = e.getNested() != null ? e.getNested() : e;
            Debug.logError(throwable, "Error in request handler: ", module);
            StringUtil.HtmlEncoder encoder = new StringUtil.HtmlEncoder();
            request.setAttribute("_ERROR_MESSAGE_", encoder.encode(throwable.toString()));
            errorPage = requestHandler.getDefaultErrorPage(request);
        } catch (Exception e) {
            Debug.logError(e, "Error in request handler: ", module);
            StringUtil.HtmlEncoder encoder = new StringUtil.HtmlEncoder();
            request.setAttribute("_ERROR_MESSAGE_", encoder.encode(e.toString()));
            errorPage = requestHandler.getDefaultErrorPage(request);
        }

        // Forward to the JSP
        // if (Debug.infoOn()) Debug.logInfo("[" + rname + "] Event done, rendering page: " + nextPage, module);
        // if (Debug.timingOn()) timer.timerString("[" + rname + "] Event done, rendering page: " + nextPage, module);

        if (errorPage != null) {
            Debug.logError("An error occurred, going to the errorPage: " + errorPage, module);

            RequestDispatcher rd = request.getRequestDispatcher(errorPage);

            // use this request parameter to avoid infinite looping on errors in the error page...
            if (request.getAttribute("_ERROR_OCCURRED_") == null && rd != null) {
                request.setAttribute("_ERROR_OCCURRED_", Boolean.TRUE);
                Debug.logError("Including errorPage: " + errorPage, module);

                // NOTE DEJ20070727 after having trouble with all of these, try to get the page out and as a last resort just send something back
                try {
                    rd.include(request, response);
                } catch (Throwable t) {
                    Debug.logWarning("Error while trying to send error page using rd.include (will try response.getOutputStream or response.getWriter): " + t.toString(), module);

                    String errorMessage = "ERROR rendering error page [" + errorPage + "], but here is the error text: " + request.getAttribute("_ERROR_MESSAGE_");
                    try {
                        if (UtilJ2eeCompat.useOutputStreamNotWriter(getServletContext())) {
                            response.getOutputStream().print(errorMessage);
                        } else {
                            response.getWriter().print(errorMessage);
                        }
                    } catch (Throwable t2) {
                        try {
                            int errorToSend = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                            Debug.logWarning("Error while trying to write error message using response.getOutputStream or response.getWriter: " + t.toString() + "; sending error code [" + errorToSend + "], and message [" + errorMessage + "]", module);
                            response.sendError(errorToSend, errorMessage);
                        } catch (Throwable t3) {
                            // wow, still bad... just throw an IllegalStateException with the message and let the servlet container handle it
                            throw new IllegalStateException(errorMessage);
                        }
                    }
                }

            } else {
                if (rd == null) {
                    Debug.logError("Could not get RequestDispatcher for errorPage: " + errorPage, module);
                }

                String errorMessage = "<html><body>ERROR in error page, (infinite loop or error page not found with name [" + errorPage + "]), but here is the text just in case it helps you: " + request.getAttribute("_ERROR_MESSAGE_") + "</body></html>";
                if (UtilJ2eeCompat.useOutputStreamNotWriter(getServletContext())) {
                    response.getOutputStream().print(errorMessage);
                } else {
                    response.getWriter().print(errorMessage);
                }
            }
        }

        // sanity check: make sure we don't have any transactions in place
        try {
            // roll back current TX first
            if (TransactionUtil.isTransactionInPlace()) {
                Debug.logWarning("*** NOTICE: ControlServlet finished w/ a transaction in place! Rolling back.", module);
                TransactionUtil.rollback();
            }

            // now resume/rollback any suspended txs
            if (TransactionUtil.suspendedTransactionsHeld()) {
                int suspended = TransactionUtil.cleanSuspendedTransactions();
                Debug.logWarning("Resumed/Rolled Back [" + suspended + "] transactions.", module);
            }
        } catch (GenericTransactionException e) {
            Debug.logWarning(e, module);
        }

        // run these two again before the ServerHitBin.countRequest call because on a logout this will end up creating a new visit
        if (response.isCommitted() && request.getSession(false) == null) {
            // response committed and no session, and we can't get a new session, what to do!
            // without a session we can't log the hit, etc; so just do nothing; this should NOT happen much!
            Debug.logError("Error in ControlServlet output where response isCommitted and there is no session (probably because of a logout); not saving ServerHit/Bin information because there is no session and as the response isCommitted we can't get a new one. The output was successful, but we just can't save ServerHit/Bin info.", module);
        } else {
            try {
                UtilHttp.setInitialRequestInfo(request);
                VisitHandler.getVisitor(request, response);
                if (requestHandler.trackStats(request)) {
                    ServerHitBin.countRequest(webappName + "." + rname, request, requestStartTime, System.currentTimeMillis() - requestStartTime, userLogin, delegator);
                }
            } catch (Throwable t) {
                Debug.logError(t, "Error in ControlServlet saving ServerHit/Bin information; the output was successful, but can't save this tracking information. The error was: " + t.toString(), module);
            }
        }
        if (Debug.timingOn()) timer.timerString("[" + rname + "] Request Done", module);

        // sanity check 2: make sure there are no user or session infos in the delegator, ie clear the thread
        GenericDelegator.clearUserIdentifierStack();
        GenericDelegator.clearSessionIdentifierStack();
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

            synchronized (ModelDataFileReader.class) {
                // must check if null again as one of the blocked threads can still enter
                if (modelDataFiles == null) { // now it's safe
                    modelDataFiles = new HashMap<String, ModelDataFile>();

                    UtilTimer utilTimer = new UtilTimer();

                    utilTimer.timerString("Before getDocument in file " + readerURL);
                    Document document = getDocument(readerURL);

                    if (document == null) {
                        modelDataFiles = null;
                        return null;
                    }

                    utilTimer.timerString("Before getDocumentElement in file " + readerURL);
                    Element docElement = document.getDocumentElement();

                    if (docElement == null) {
                        modelDataFiles = null;
                        return null;
                    }
                    docElement.normalize();
                    Node curChild = docElement.getFirstChild();

                    int i = 0;

                    if (curChild != null) {
                        utilTimer.timerString("Before start of dataFile loop in file " + readerURL);
                        do {
                            if (curChild.getNodeType() == Node.ELEMENT_NODE && "data-file".equals(curChild.getNodeName())) {
                                i++;
                                Element curDataFile = (Element) curChild;
                                String dataFileName = UtilXml.checkEmpty(curDataFile.getAttribute("name"));

                                // check to see if dataFile with same name has already been read
                                if (modelDataFiles.containsKey(dataFileName)) {
                                    Debug.logWarning("WARNING: DataFile " + dataFileName +
                                        " is defined more than once, most recent will over-write previous definition(s)", module);
                                }

                                // utilTimer.timerString("  After dataFileName -- " + i + " --");
                                ModelDataFile dataFile = createModelDataFile(curDataFile);

                                // utilTimer.timerString("  After createModelDataFile -- " + i + " --");
                                if (dataFile != null) {
                                    modelDataFiles.put(dataFileName, dataFile);
                                    // utilTimer.timerString("  After modelDataFiles.put -- " + i + " --");
                                    if (Debug.infoOn()) Debug.logInfo("-- getModelDataFile: #" + i + " Loaded dataFile: " + dataFileName, module);
                                } else
                                    Debug.logWarning("-- -- SERVICE ERROR:getModelDataFile: Could not create dataFile for dataFileName: " + dataFileName, module);

                            }
                        } while ((curChild = curChild.getNextSibling()) != null);
                    } else {
                        Debug.logWarning("No child nodes found.", module);
                    }
                    utilTimer.timerString("Finished file " + readerURL + " - Total Flat File Defs: " + i + " FINISHED");
                }
            }
        }
        return modelDataFiles;
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    public void checkDb(Map<String, ModelEntity> modelEntities, List<String> colWrongSize, List<String> messages, boolean checkPks, boolean checkFks, boolean checkFkIdx, boolean addMissing) {
        if (isLegacy) {
            throw new RuntimeException("Cannot run checkDb on a legacy database connection; configure a database helper (entityengine.xml)");
        }
        UtilTimer timer = new UtilTimer();
        timer.timerString("Start - Before Get Database Meta Data");

        // get ALL tables from this database
        TreeSet<String> tableNames = this.getTableNames(messages);
        TreeSet<String> fkTableNames = tableNames == null ? null : new TreeSet<String>(tableNames);
        TreeSet<String> indexTableNames = tableNames == null ? null : new TreeSet<String>(tableNames);

        if (tableNames == null) {
            String message = "Could not get table name information from the database, aborting.";
            if (messages != null) messages.add(message);
            Debug.logError(message, module);
            return;
        }
        timer.timerString("After Get All Table Names");

        // get ALL column info, put into hashmap by table name
        Map<String, Map<String, ColumnCheckInfo>> colInfo = this.getColumnInfo(tableNames, checkPks, messages);
        if (colInfo == null) {
            String message = "Could not get column information from the database, aborting.";
            if (messages != null) messages.add(message);
            Debug.logError(message, module);
            return;
        }
        timer.timerString("After Get All Column Info");

        // -make sure all entities have a corresponding table
        // -list all tables that do not have a corresponding entity
        // -display message if number of table columns does not match number of entity fields
        // -list all columns that do not have a corresponding field
        // -make sure each corresponding column is of the correct type
        // -list all fields that do not have a corresponding column

        timer.timerString("Before Individual Table/Column Check");

        ArrayList<ModelEntity> modelEntityList = new ArrayList<ModelEntity>(modelEntities.values());
        // sort using compareTo method on ModelEntity
        Collections.sort(modelEntityList);
        int curEnt = 0;
        int totalEnt = modelEntityList.size();
        List<ModelEntity> entitiesAdded = FastList.newInstance();
        for (ModelEntity entity: modelEntityList) {
            curEnt++;

            // if this is a view entity, do not check it...
            if (entity instanceof ModelViewEntity) {
                String entMessage = "(" + timer.timeSinceLast() + "ms) NOT Checking #" + curEnt + "/" + totalEnt + " View Entity " + entity.getEntityName();
                Debug.logVerbose(entMessage, module);
                if (messages != null) messages.add(entMessage);
                continue;
            }

            String entMessage = "(" + timer.timeSinceLast() + "ms) Checking #" + curEnt + "/" + totalEnt +
                " Entity " + entity.getEntityName() + " with table " + entity.getTableName(datasourceInfo);

            Debug.logVerbose(entMessage, module);
            if (messages != null) messages.add(entMessage);

            // -make sure all entities have a corresponding table
            if (tableNames.contains(entity.getTableName(datasourceInfo))) {
                tableNames.remove(entity.getTableName(datasourceInfo));

                if (colInfo != null) {
                    Map<String, ModelField> fieldColNames = FastMap.newInstance();
                    Iterator<ModelField> fieldIter = entity.getFieldsIterator();
                    while (fieldIter.hasNext()) {
                        ModelField field = fieldIter.next();
                        fieldColNames.put(field.getColName(), field);
                    }

                    Map<String, ColumnCheckInfo> colMap = colInfo.get(entity.getTableName(datasourceInfo));
                    if (colMap != null) {
                        for (ColumnCheckInfo ccInfo: colMap.values()) {
                            // -list all columns that do not have a corresponding field
                            if (fieldColNames.containsKey(ccInfo.columnName)) {
                                ModelField field = null;

                                field = fieldColNames.remove(ccInfo.columnName);
                                ModelFieldType modelFieldType = modelFieldTypeReader.getModelFieldType(field.getType());

                                if (modelFieldType != null) {
                                    // make sure each corresponding column is of the correct type
                                    String fullTypeStr = modelFieldType.getSqlType();
                                    String typeName;
                                    int columnSize = -1;
                                    int decimalDigits = -1;

                                    int openParen = fullTypeStr.indexOf('(');
                                    int closeParen = fullTypeStr.indexOf(')');
                                    int comma = fullTypeStr.indexOf(',');

                                    if (openParen > 0 && closeParen > 0 && closeParen > openParen) {
                                        typeName = fullTypeStr.substring(0, openParen);
                                        if (comma > 0 && comma > openParen && comma < closeParen) {
                                            String csStr = fullTypeStr.substring(openParen + 1, comma);
                                            try {
                                                columnSize = Integer.parseInt(csStr);
                                            } catch (NumberFormatException e) {
                                                Debug.logError(e, module);
                                            }

                                            String ddStr = fullTypeStr.substring(comma + 1, closeParen);
                                            try {
                                                decimalDigits = Integer.parseInt(ddStr);
                                            } catch (NumberFormatException e) {
                                                Debug.logError(e, module);
                                            }
                                        } else {
                                            String csStr = fullTypeStr.substring(openParen + 1, closeParen);
                                            try {
                                                columnSize = Integer.parseInt(csStr);
                                            } catch (NumberFormatException e) {
                                                Debug.logError(e, module);
                                            }
                                        }
                                    } else {
                                        typeName = fullTypeStr;
                                    }

                                    // override the default typeName with the sqlTypeAlias if it is specified
                                    if (UtilValidate.isNotEmpty(modelFieldType.getSqlTypeAlias())) {
                                        typeName = modelFieldType.getSqlTypeAlias();
                                    }

                                    // NOTE: this may need a toUpperCase in some cases, keep an eye on it, okay just compare with ignore case
                                    if (!ccInfo.typeName.equalsIgnoreCase(typeName)) {
                                        String message = "WARNING: Column [" + ccInfo.columnName + "] of table [" + entity.getTableName(datasourceInfo) + "] of entity [" +
                                            entity.getEntityName() + "] is of type [" + ccInfo.typeName + "] in the database, but is defined as type [" +
                                            typeName + "] in the entity definition.";
                                        Debug.logError(message, module);
                                        if (messages != null) messages.add(message);
                                    }
                                    if (columnSize != -1 && ccInfo.columnSize != -1 && columnSize != ccInfo.columnSize && (columnSize * 3) != ccInfo.columnSize) {
                                        String message = "WARNING: Column [" + ccInfo.columnName + "] of table [" + entity.getTableName(datasourceInfo) + "] of entity [" +
                                            entity.getEntityName() + "] has a column size of [" + ccInfo.columnSize +
                                            "] in the database, but is defined to have a column size of [" + columnSize + "] in the entity definition.";
                                        Debug.logWarning(message, module);
                                        if (messages != null) messages.add(message);
                                        if (columnSize > ccInfo.columnSize && colWrongSize != null) {
                                            // add item to list of wrong sized columns; only if the entity is larger
                                            colWrongSize.add(entity.getEntityName() + "." + field.getName());
                                        }
                                    }
                                    if (decimalDigits != -1 && decimalDigits != ccInfo.decimalDigits) {
                                        String message = "WARNING: Column [" + ccInfo.columnName + "] of table [" + entity.getTableName(datasourceInfo) + "] of entity [" +
                                            entity.getEntityName() + "] has a decimalDigits of [" + ccInfo.decimalDigits +
                                            "] in the database, but is defined to have a decimalDigits of [" + decimalDigits + "] in the entity definition.";
                                        Debug.logWarning(message, module);
                                        if (messages != null) messages.add(message);
                                    }

                                    // do primary key matching check
                                    if (checkPks && ccInfo.isPk && !field.getIsPk()) {
                                        String message = "WARNING: Column [" + ccInfo.columnName + "] of table [" + entity.getTableName(datasourceInfo) + "] of entity [" +
                                            entity.getEntityName() + "] IS a primary key in the database, but IS NOT a primary key in the entity definition. The primary key for this table needs to be re-created or modified so that this column is NOT part of the primary key.";
                                        Debug.logError(message, module);
                                        if (messages != null) messages.add(message);
                                    }
                                    if (checkPks && !ccInfo.isPk && field.getIsPk()) {
                                        String message = "WARNING: Column [" + ccInfo.columnName + "] of table [" + entity.getTableName(datasourceInfo) + "] of entity [" +
                                            entity.getEntityName() + "] IS NOT a primary key in the database, but IS a primary key in the entity definition. The primary key for this table needs to be re-created or modified to add this column to the primary key. Note that data may need to be added first as a primary key column cannot have an null values.";
                                        Debug.logError(message, module);
                                        if (messages != null) messages.add(message);
                                    }
                                } else {
                                    String message = "Column [" + ccInfo.columnName + "] of table [" + entity.getTableName(datasourceInfo) + "] of entity [" + entity.getEntityName() +
                                        "] has a field type name of [" + field.getType() + "] which is not found in the field type definitions";
                                    Debug.logError(message, module);
                                    if (messages != null) messages.add(message);
                                }
                            } else {
                                String message = "Column [" + ccInfo.columnName + "] of table [" + entity.getTableName(datasourceInfo) + "] of entity [" + entity.getEntityName() + "] exists in the database but has no corresponding field" + ((checkPks && ccInfo.isPk) ? " (and it is a PRIMARY KEY COLUMN)" : "");
                                Debug.logWarning(message, module);
                                if (messages != null) messages.add(message);
                            }
                        }

                        // -display message if number of table columns does not match number of entity fields
                        if (colMap.size() != entity.getFieldsSize()) {
                            String message = "Entity [" + entity.getEntityName() + "] has " + entity.getFieldsSize() + " fields but table [" + entity.getTableName(datasourceInfo) + "] has " + colMap.size() + " columns.";
                            Debug.logWarning(message, module);
                            if (messages != null) messages.add(message);
                        }
                    }

                    // -list all fields that do not have a corresponding column
                    for (String colName: fieldColNames.keySet()) {
                        ModelField field = (ModelField) fieldColNames.get(colName);
                        String message = "Field [" + field.getName() + "] of entity [" + entity.getEntityName() + "] is missing its corresponding column [" + field.getColName() + "]" + (field.getIsPk() ? " (and it is a PRIMARY KEY FIELD)" : "");

                        Debug.logWarning(message, module);
                        if (messages != null) messages.add(message);

                        if (addMissing) {
                            // add the column
                            String errMsg = addColumn(entity, field);

                            if (errMsg != null && errMsg.length() > 0) {
                                message = "Could not add column [" + field.getColName() + "] to table [" + entity.getTableName(datasourceInfo) + "]: " + errMsg;
                                Debug.logError(message, module);
                                if (messages != null) messages.add(message);
                            } else {
                                message = "Added column [" + field.getColName() + "] to table [" + entity.getTableName(datasourceInfo) + "]" + (field.getIsPk() ? " (NOTE: this is a PRIMARY KEY FIELD, but the primary key was not updated automatically (not considered a safe operation), be sure to fill in any needed data and re-create the primary key)" : "");
                                Debug.logImportant(message, module);
                                if (messages != null) messages.add(message);
                            }
                        }
                    }
                }
            } else {
                String message = "Entity [" + entity.getEntityName() + "] has no table in the database";
                Debug.logWarning(message, module);
                if (messages != null) messages.add(message);

                if (addMissing) {
                    // create the table
                    String errMsg = createTable(entity, modelEntities, false);
                    if (errMsg != null && errMsg.length() > 0) {
                        message = "Could not create table [" + entity.getTableName(datasourceInfo) + "]: " + errMsg;
                        Debug.logError(message, module);
                        if (messages != null) messages.add(message);
                    } else {
                        entitiesAdded.add(entity);
                        message = "Created table [" + entity.getTableName(datasourceInfo) + "]";
                        Debug.logImportant(message, module);
                        if (messages != null) messages.add(message);
                    }
                }
            }
        }

        timer.timerString("After Individual Table/Column Check");

        // -list all tables that do not have a corresponding entity
        for (String tableName: tableNames) {
            String message = "Table named [" + tableName + "] exists in the database but has no corresponding entity";
            Debug.logWarning(message, module);
            if (messages != null) messages.add(message);
        }

        // for each newly added table, add fk indices
        if (datasourceInfo.useFkIndices) {
            int totalFkIndices = 0;
            for (ModelEntity curEntity: entitiesAdded) {
                if (curEntity.getRelationsOneSize() > 0) {
                    totalFkIndices += this.createForeignKeyIndices(curEntity, datasourceInfo.constraintNameClipLength, messages);
                }
            }
            if (totalFkIndices > 0) Debug.logImportant("==== TOTAL Foreign Key Indices Created: " + totalFkIndices, module);
        }

        // for each newly added table, add fks
        if (datasourceInfo.useFks) {
            int totalFks = 0;
            for (ModelEntity curEntity: entitiesAdded) {
                totalFks += this.createForeignKeys(curEntity, modelEntities, datasourceInfo.constraintNameClipLength, datasourceInfo.fkStyle, datasourceInfo.useFkInitiallyDeferred, messages);
            }
            if (totalFks > 0) Debug.logImportant("==== TOTAL Foreign Keys Created: " + totalFks, module);
        }

        // for each newly added table, add declared indexes
        if (datasourceInfo.useIndices) {
            int totalDis = 0;
            for (ModelEntity curEntity: entitiesAdded) {
                if (curEntity.getIndexesSize() > 0) {
                    totalDis += this.createDeclaredIndices(curEntity, messages);
                }
            }
            if (totalDis > 0) Debug.logImportant("==== TOTAL Declared Indices Created: " + totalDis, module);
        }

        // make sure each one-relation has an FK
        if (checkFks) {
        //if (!justColumns && datasourceInfo.useFks && datasourceInfo.checkForeignKeysOnStart) {
            // NOTE: This ISN'T working for Postgres or MySQL, who knows about others, may be from JDBC driver bugs...
            int numFksCreated = 0;
            // TODO: check each key-map to make sure it exists in the FK, if any differences warn and then remove FK and recreate it

            // get ALL column info, put into hashmap by table name
            Map<String, Map<String, ReferenceCheckInfo>> refTableInfoMap = this.getReferenceInfo(fkTableNames, messages);

            // Debug.logVerbose("Ref Info Map: " + refTableInfoMap, module);

            if (refTableInfoMap == null) {
                // uh oh, something happened while getting info...
                if (Debug.verboseOn()) Debug.logVerbose("Ref Table Info Map is null", module);
            } else {
                for (ModelEntity entity: modelEntityList) {
                    String entityName = entity.getEntityName();
                    // if this is a view entity, do not check it...
                    if (entity instanceof ModelViewEntity) {
                        String entMessage = "NOT Checking View Entity " + entity.getEntityName();
                        Debug.logVerbose(entMessage, module);
                        if (messages != null) {
                            messages.add(entMessage);
                        }
                        continue;
                    }

                    // get existing FK map for this table
                    Map<String, ReferenceCheckInfo> rcInfoMap = refTableInfoMap.get(entity.getTableName(datasourceInfo));
                    // Debug.logVerbose("Got ref info for table " + entity.getTableName(datasourceInfo) + ": " + rcInfoMap, module);

                    // go through each relation to see if an FK already exists
                    Iterator<ModelRelation> relations = entity.getRelationsIterator();
                    boolean createdConstraints = false;
                    while (relations.hasNext()) {
                        ModelRelation modelRelation = relations.next();
                        if (!"one".equals(modelRelation.getType())) {
                            continue;
                        }

                        ModelEntity relModelEntity = modelEntities.get(modelRelation.getRelEntityName());
                        if (relModelEntity == null) {
                            Debug.logError("No such relation: " + entity.getEntityName() + " -> " + modelRelation.getRelEntityName(), module);
                            continue;
                        }
                        String relConstraintName = makeFkConstraintName(modelRelation, datasourceInfo.constraintNameClipLength);
                        ReferenceCheckInfo rcInfo = null;

                        if (rcInfoMap != null) {
                            rcInfo = rcInfoMap.get(relConstraintName);
                        }

                        if (rcInfo != null) {
                            rcInfoMap.remove(relConstraintName);
                        } else {
                            // if not, create one
                            String noFkMessage = "No Foreign Key Constraint [" + relConstraintName + "] found for entity [" + entityName + "]";
                            if (messages != null) messages.add(noFkMessage);
                            if (Debug.infoOn()) Debug.logInfo(noFkMessage, module);

                            if (addMissing) {
                                String errMsg = createForeignKey(entity, modelRelation, relModelEntity, datasourceInfo.constraintNameClipLength, datasourceInfo.fkStyle, datasourceInfo.useFkInitiallyDeferred);
                                if (errMsg != null && errMsg.length() > 0) {
                                    String message = "Could not create foreign key " + relConstraintName + " for entity [" + entity.getEntityName() + "]: " + errMsg;
                                    Debug.logError(message, module);
                                    if (messages != null) messages.add(message);
                                } else {
                                    String message = "Created foreign key " + relConstraintName + " for entity [" + entity.getEntityName() + "]";
                                    Debug.logVerbose(message, module);
                                    if (messages != null) messages.add(message);
                                    createdConstraints = true;
                                    numFksCreated++;
                                }
                            }
                        }
                    }
                    if (createdConstraints) {
                        String message = "Created foreign key(s) for entity [" + entity.getEntityName() + "]";
                        Debug.logImportant(message, module);
                        if (messages != null) messages.add(message);
                    }

                    // show foreign key references that exist but are unknown
                    if (rcInfoMap != null) {
                        for (String rcKeyLeft: rcInfoMap.keySet()) {
                            String message = "Unknown Foreign Key Constraint " + rcKeyLeft + " found in table " + entity.getTableName(datasourceInfo);
                            Debug.logImportant(message, module);
                            if (messages != null) messages.add(message);
                        }
                    }
                }
            }
            if (Debug.infoOn()) Debug.logInfo("Created " + numFksCreated + " fk refs", module);
        }

        // make sure each one-relation has an index
        if (checkFkIdx) {
        //if (!justColumns && datasourceInfo.useFkIndices && datasourceInfo.checkFkIndicesOnStart) {
            int numIndicesCreated = 0;
            // TODO: check each key-map to make sure it exists in the index, if any differences warn and then remove the index and recreate it

            // get ALL column info, put into hashmap by table name
            Map<String, Set<String>> tableIndexListMap = this.getIndexInfo(indexTableNames, messages);

            // Debug.logVerbose("Ref Info Map: " + refTableInfoMap, module);

            if (tableIndexListMap == null) {
                // uh oh, something happened while getting info...
                if (Debug.verboseOn()) Debug.logVerbose("Ref Table Info Map is null", module);
            } else {
                for (ModelEntity entity: modelEntityList) {
                    String entityName = entity.getEntityName();
                    // if this is a view entity, do not check it...
                    if (entity instanceof ModelViewEntity) {
                        String entMessage = "NOT Checking View Entity " + entity.getEntityName();
                        Debug.logVerbose(entMessage, module);
                        if (messages != null) messages.add(entMessage);
                        continue;
                    }

                    // get existing index list for this table
                    Set<String> tableIndexList = tableIndexListMap.get(entity.getTableName(datasourceInfo));

                    // Debug.logVerbose("Got ind info for table " + entity.getTableName(datasourceInfo) + ": " + tableIndexList, module);

                    if (tableIndexList == null) {
                        // evidently no indexes in the database for this table, do the create all
                        this.createForeignKeyIndices(entity, datasourceInfo.constraintNameClipLength, messages);
                    } else {
                        // go through each relation to see if an FK already exists
                        boolean createdConstraints = false;
                        Iterator<ModelRelation> relations = entity.getRelationsIterator();
                        while (relations.hasNext()) {
                            ModelRelation modelRelation = relations.next();
                            if (!"one".equals(modelRelation.getType())) {
                                continue;
                            }

                            String relConstraintName = makeFkConstraintName(modelRelation, datasourceInfo.constraintNameClipLength);
                            if (tableIndexList.contains(relConstraintName)) {
                                tableIndexList.remove(relConstraintName);
                            } else {
                                // if not, create one
                                String noIdxMessage = "No Index [" + relConstraintName + "] found for entity [" + entityName + "]";
                                if (messages != null) messages.add(noIdxMessage);
                                if (Debug.infoOn()) Debug.logInfo(noIdxMessage, module);

                                if (addMissing) {
                                    String errMsg = createForeignKeyIndex(entity, modelRelation, datasourceInfo.constraintNameClipLength);
                                    if (errMsg != null && errMsg.length() > 0) {
                                        String message = "Could not create foreign key index " + relConstraintName + " for entity [" + entity.getEntityName() + "]: " + errMsg;
                                        Debug.logError(message, module);
                                        if (messages != null) messages.add(message);
                                    } else {
                                        String message = "Created foreign key index " + relConstraintName + " for entity [" + entity.getEntityName() + "]";
                                        Debug.logVerbose(message, module);
                                        if (messages != null) messages.add(message);
                                        createdConstraints = true;
                                        numIndicesCreated++;
                                    }
                                }
                            }
                        }
                        if (createdConstraints) {
                            String message = "Created foreign key index/indices for entity [" + entity.getEntityName() + "]";
                            Debug.logImportant(message, module);
                            if (messages != null) messages.add(message);
                        }
                    }

                    // show foreign key references that exist but are unknown
                    if (tableIndexList != null) {
                        for (String indexLeft: tableIndexList) {
                            String message = "Unknown Index " + indexLeft + " found in table " + entity.getTableName(datasourceInfo);
                            Debug.logImportant(message, module);
                            if (messages != null) messages.add(message);
                        }
                    }
                }
            }
            if (Debug.infoOn()) Debug.logInfo("Created " + numIndicesCreated + " indices", module);
        }

        if (datasourceInfo.checkIndicesOnStart) {
            int numIndicesCreated = 0;
            // TODO: check each key-map to make sure it exists in the index, if any differences warn and then remove the index and recreate it

            // get ALL column info, put into hashmap by table name
            Map<String, Set<String>> tableIndexListMap = this.getIndexInfo(indexTableNames, messages);

            // Debug.logVerbose("Ref Info Map: " + refTableInfoMap, module);

            if (tableIndexListMap == null) {
                // uh oh, something happened while getting info...
                if (Debug.verboseOn()) Debug.logVerbose("Ref Table Info Map is null", module);
            } else {
                for (ModelEntity entity: modelEntityList) {
                    String entityName = entity.getEntityName();
                    // if this is a view entity, do not check it...
                    if (entity instanceof ModelViewEntity) {
                        String entMessage = "NOT Checking View Entity " + entity.getEntityName();
                        Debug.logVerbose(entMessage, module);
                        if (messages != null) messages.add(entMessage);
                        continue;
                    }

                    // get existing index list for this table
                    Set<String> tableIndexList = tableIndexListMap.get(entity.getTableName(datasourceInfo));

                    // Debug.logVerbose("Got ind info for table " + entity.getTableName(datasourceInfo) + ": " + tableIndexList, module);

                    if (tableIndexList == null) {
                        // evidently no indexes in the database for this table, do the create all
                        this.createDeclaredIndices(entity, messages);
                    } else {
                        // go through each indice to see if an indice already exists
                        boolean createdIndexes = false;
                        Iterator<ModelIndex> indexes = entity.getIndexesIterator();
                        while (indexes.hasNext()) {
                            ModelIndex modelIndex = indexes.next();

                            String relIndexName = makeIndexName(modelIndex, datasourceInfo.constraintNameClipLength);
                            if (tableIndexList.contains(relIndexName)) {
                                tableIndexList.remove(relIndexName);
                            } else {
                                // if not, create one
                                String noIdxMessage = "No Index [" + relIndexName + "] found for entity [" + entityName + "]";
                                if (messages != null) messages.add(noIdxMessage);
                                if (Debug.infoOn()) Debug.logInfo(noIdxMessage, module);

                                if (addMissing) {
                                    String errMsg = createDeclaredIndex(entity, modelIndex);
                                    if (errMsg != null && errMsg.length() > 0) {
                                        String message = "Could not create index " + relIndexName + " for entity [" + entity.getEntityName() + "]: " + errMsg;
                                        Debug.logError(message, module);
                                        if (messages != null) messages.add(message);
                                    } else {
                                        String message = "Created index " + relIndexName + " for entity [" + entity.getEntityName() + "]";
                                        Debug.logVerbose(message, module);
                                        if (messages != null) messages.add(message);
                                        createdIndexes = true;
                                        numIndicesCreated++;
                                    }
                                }
                            }
                        }
                        if (createdIndexes) {
                            String message = "Created foreign key index/indices for entity [" + entity.getEntityName() + "]";
                            Debug.logImportant(message, module);
                            if (messages != null) messages.add(message);
                        }
                    }

                    // show Indexe key references that exist but are unknown
                    if (tableIndexList != null) {
                        for (String indexLeft: tableIndexList) {
                            String message = "Unknown Index " + indexLeft + " found in table " + entity.getTableName(datasourceInfo);
                            Debug.logImportant(message, module);
                            if (messages != null) messages.add(message);
                        }
                    }
                }
            }
            if (Debug.infoOn()) Debug.logInfo("Created " + numIndicesCreated + " indices", module);

        }


        timer.timerString("Finished Checking Entity Database");
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

     * @return Status.  Possible values: STATUS_CONTINUE, STATUS_ERROR, STATUS_CANCELED
     */
    protected int replicateOneRelated(GenericValue mainInstance,
        String relationTitle, String relatedEntityName, HashMap filterMap,
        boolean replicateAll, String replicatorClassName) {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1, "[replicateOneRelated] Start");
        }

        Debug.logVerbose("[replicateOneRelated] Start", module);

        Debug.logVerbose("[replicateOneRelated] relationTitle: " + relationTitle, module);
        Debug.logVerbose("[replicateOneRelated] relatedEntityName: " + relatedEntityName, module);
        Debug.logVerbose("[replicateOneRelated] replicatorClassName: " + replicatorClassName, module);

        // Instantiate related replicator class.
        EntityReplicator relatedReplicator = getEntityReplicator(replicatorClassName,
                getLocalDelegator(), getMasterDelegator(), relatedEntityName,
                getUserInfo());

        if (relatedReplicator == null) {
            return STATUS_ERROR;
        }

        String entityName = "*";

        if (mainInstance != null) {
            entityName = mainInstance.getEntityName();
        }

        if (TIMER) {
            timer.timerString(1,
                "[EntityReplicator.replicateOneRelated] Starting findOneRelated (" +
                entityName + "/" + relationTitle + relatedEntityName + ")");
        }

        List relatedGVL = findOneRelated(getMasterDelegator(), mainInstance,
                relationTitle, relatedEntityName, filterMap, replicateAll);

        if (relatedGVL == null) {
            return STATUS_ERROR;
        }

        if (TIMER) {
            timer.timerString(1,
                "[EntityReplicator.replicateOneRelated] Finished findOneRelated (" +
                entityName + "/" + relationTitle + relatedEntityName + ")");
        }

        Iterator relatedGVI = relatedGVL.iterator();

        while (relatedGVI.hasNext()) {
            GenericValue relatedGV = (GenericValue) relatedGVI.next();
            int status = relatedReplicator.replicateInstance(relatedGV);

            if (status != STATUS_CONTINUE) {
                return status;
            }
        }

        if (TIMER) {
            timer.timerString(1, "[replicateOneRelated] End");
        }

        return STATUS_CONTINUE;
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

     */
    protected List findOneRelated(GenericDelegator delegator,
        GenericValue mainInstance, String relationTitle,
        String relatedEntityName, HashMap filterMap, boolean findAll) {

        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(2, "[EntityReplicator.findOneRelated] Start");
        }

        String entityName = "*";

        if (mainInstance != null) {
            entityName = mainInstance.getEntityName();
        }

        if (delegator == null) {
            Debug.logError("[findOneRelated] Delegator is required.", module);

            return null;
        }

        if (userInfo == null) {
            Debug.logError("[findOneRelated] User info object is required.", module);

            return null;
        }

        GenericPK entityPK = null;

        String entityKeyString = null;
        List relatedGVL = null;

        if (findAll) {
            // Need to find all entity instances, not just the ones related to
            // the main entity instance.
            try {
                if (TIMER) {
                    timer.timerString(2,
                        "[EntityReplicator.findOneRelated] Start findByAnd");
                }

                relatedGVL = delegator.findByAnd(relatedEntityName, filterMap);

                if (TIMER) {
                    timer.timerString(2,
                        "[EntityReplicator.findOneRelated] Finished findByAnd");
                }

                return relatedGVL;
            } catch (GenericEntityException e) {
                Debug.logError("[findOneRelated] Error getting " +
                    relatedEntityName + " records by and: " +
                    e.getLocalizedMessage(), module);

                return null;
            }
        } else {
            // Need to find just the entity instances related to the main entity instance.
            if (mainInstance == null) {
                Debug.logError(
                    "[findOneRelated] Main instance is required if findAll is false.", module);

                return null;
            }

            entityPK = mainInstance.getPrimaryKey();
            entityKeyString = entityPK.toString();
            Debug.logVerbose("[findOneRelated] Retrieving all " +
                    relatedEntityName + " records related to " +
                    entityKeyString, module);

            try {
                if (TIMER) {
                    timer.timerString(2,
                        "[EntityReplicator.findOneRelated] Start getRelated");
                }

                relatedGVL = delegator.getRelated(relationTitle +
                        relatedEntityName, filterMap, null, mainInstance);

                if (TIMER) {
                    timer.timerString(2,
                        "[EntityReplicator.findOneRelated] Finished getRelated");
                }

                return relatedGVL;
            } catch (GenericEntityException e) {
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    }

    public UIScreenSectionEntity(GenericValue uiScreenSectionEntityGV,
        GenericDelegator delegator, UICache uiCache)
        throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(4,
                "[UIScreenSectionEntity.UIScreenSectionEntity] Start");
        }

        setGenericValue(uiScreenSectionEntityGV);

        setSectionId(uiScreenSectionEntityGV.getString("sectionId"));
        setEntityId(uiScreenSectionEntityGV.getString("entityId"));
        setIsUpdateable(uiScreenSectionEntityGV.getString("isUpdateable"));
        setIsOuterJoined(uiScreenSectionEntityGV.getString("isOuterJoined"));
        setHasSequenceKey(uiScreenSectionEntityGV.getString("hasSequenceKey"));
        setRelationTitle(uiScreenSectionEntityGV.getString("relationTitle"));
        setRelationByAndFields(uiScreenSectionEntityGV.getString(
                "relationByAndFields"));
        setRelationOrderByFields(uiScreenSectionEntityGV.getString(
                "relationOrderByFields"));
        setInsertOrder(uiScreenSectionEntityGV.getString("insertOrder"));
        setRetrieveOrder(uiScreenSectionEntityGV.getString("retrieveOrder"));
        setDeleteOrder(uiScreenSectionEntityGV.getString("deleteOrder"));
        setUpdateOrder(uiScreenSectionEntityGV.getString("updateOrder"));

        // Get the UIEntity object.
        if (TIMER) {
            timer.timerString(4,
                "[UIScreenSectionEntity.UIScreenSectionEntity] Looking for UIEntity in cache.");
        }


        UIEntity uiEntity = uiCache.getUiEntity(getEntityId());

        if (uiEntity == null) {
            if (TIMER) {
                timer.timerString(4,
                    "[UIScreenSectionEntity.UIScreenSectionEntity] UIEntity not found in cache. Creating a new one.");
            }


            GenericValue uiEntityGV = delegator.getRelatedOne("UiEntity",
                    uiScreenSectionEntityGV);
            uiEntity = new UIEntity(uiEntityGV, delegator, uiCache);
            uiCache.putUiEntity(getEntityId(), uiEntity);
        } else {
            if (TIMER) {
                timer.timerString(4,
                    "[UIScreenSectionEntity.UIScreenSectionEntity] Found UIEntity in cache.");
            }

        }

        setUiEntity(uiEntity);

        if (TIMER) {
            timer.timerString(4,
                "[UIScreenSectionEntity.UIScreenSectionEntity] Got UIEntity");
            timer.timerString(4,
                "[UIScreenSectionEntity.UIScreenSectionEntity] End");
        }
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    protected GenericValue genericValue = null;
    protected ArrayList uiAttributeList = new ArrayList();

    public UIEntity(GenericValue uiEntityGV, GenericDelegator delegator,
        UICache uiCache) throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(5, "[UIEntity.UIEntity] Start");
        }

        setGenericValue(uiEntityGV);

        //    setDelegator(delegator);
        setEntityId(uiEntityGV.getString("entityId"));
        setEntityName(uiEntityGV.getString("entityName"));
        setTableName(uiEntityGV.getString("tableName"));
        setDescription(uiEntityGV.getString("description"));
        setExtTableName(uiEntityGV.getString("extTableName"));

        if (TIMER) {
            timer.timerString(5,
                "[UIEntity.UIEntity] Finished setting UI entity attributes");
        }

        setModelEntity(delegator.getModelEntity(getEntityName()));
        setPrimaryKeyFieldNames(getModelEntity().getPkFieldNames());

        if (TIMER) {
            timer.timerString(5,
                "[UIEntity.UIEntity] Finished setting model entity");
        }

        // Get info about the UI Attributes.
        HashMap findMap = new HashMap();
        findMap.put("entityId", getEntityId());

        List uiAttributeL = delegator.findByAnd("UiAttribute", findMap, null);

        if (TIMER) {
            timer.timerString(5,
                "[UIEntity.UIEntity] Finished finding UI attributes");
        }

        Iterator uiAttributeI = uiAttributeL.iterator();

        while (uiAttributeI.hasNext()) {
            // Get the UIAttribute object for this attribute.
            GenericValue uiAttributeGV = (GenericValue) uiAttributeI.next();
            String attributeId = uiAttributeGV.getString("attributeId");

            if (TIMER) {
                timer.timerString(5,
                    "[UIEntity.UIEntity] Looking for UIAttribute in cache.");
            }

            UIAttribute uiAttribute = uiCache.getUiAttribute(attributeId);

            if (uiAttribute == null) {
                if (TIMER) {
                    timer.timerString(5,
                        "[UIEntity.UIEntity] UIAttribute not found in cache. Creating a new one.");
                }

                uiAttribute = new UIAttribute(uiAttributeGV, delegator, this);
                uiCache.putUiAttribute(attributeId, uiAttribute);
            } else {
                if (TIMER) {
                    timer.timerString(5,
                        "[UIEntity.UIEntity] Found UIAttribute in cache.");
                }
            }

            getUiAttributeList().add(uiAttribute);
        }

        if (TIMER) {
            timer.timerString(5, "[UIEntity.UIEntity] End");
        }

    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    List uiScreenSectionEntityList = new ArrayList();

    public UIScreenSection(UserInfo userInfo, String screenName,
        String sectionName, GenericDelegator delegator, UICache uiCache)
        throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1, "[UIScreenSection.UIScreenSection] Start");
        }

        Debug.logVerbose( "-->[UIScreenSection.UIScreenSection] screenName: " + screenName, module);
        Debug.logVerbose( "-->[UIScreenSection.UIScreenSection] sectionName: " + sectionName, module);

        if (userInfo == null) {
            throw new GenericEntityException(
                "UserInfo passed in was null for UIScreenSection.");
        } else {
            setUserInfo(userInfo);
        }

        if (delegator == null) {
            throw new GenericEntityException(
                "GenericDelegator passed in was null for UIScreenSection.");
        } else {
            setDelegator(delegator);
        }

        if (screenName == null) {
            throw new GenericEntityException(
                "ScreenName passed in was null for UIScreenSection.");
        }

        if (sectionName == null) {
            throw new GenericEntityException(
                "SectionName passed in was null for UIScreenSection.");
        }

        // Get the uiScreen object.
        if (TIMER) {
            timer.timerString(1,
                "[UIScreenSection.UIScreenSection] Looking for UIScreen in cache.");
        }

        UIScreen uiScreen = uiCache.getUiScreen(screenName);

        if (uiScreen == null) {
            if (TIMER) {
                timer.timerString(1,
                    "[UIScreenSection.UIScreenSection] UIScreen not found in cache. Creating a new one.");
            }

            uiScreen = new UIScreen(screenName, delegator);
            uiCache.putUiScreen(screenName, uiScreen);
        } else {
            if (TIMER) {
                timer.timerString(1,
                    "[UIScreenSection.UIScreenSection] Found UIScreen in cache.");
            }
        }

        setUiScreen(uiScreen);

        if (TIMER) {
            timer.timerString(1, "[UIScreenSection.UIScreenSection] Got screen");
        }

        // Get the uiScreenSection object.

        HashMap findHashMap = new HashMap();
        findHashMap.put("screenId", getUiScreen().getScreenId());
        findHashMap.put("sectionName", sectionName);

        List uiScreenSectionGVL = delegator.findByAnd("UiScreenSection",
                findHashMap, null);

        if (uiScreenSectionGVL.size() == 0) {
            throw new GenericEntityException("No screen section with name \"" +
                sectionName + "\" for screen \"" + screenName +
                "\" was found in database.");
        }

        if (uiScreenSectionGVL.size() > 1) {
            throw new GenericEntityException(
                "More than one screen section found with name \"" +
                sectionName + "\" for screen \"" + screenName + "\".");
        }

        Iterator uiScreenSectionGVI = uiScreenSectionGVL.iterator();
        GenericValue uiScreenSectionGV = (GenericValue) uiScreenSectionGVI.next();

        if (uiScreenSectionGV.get("layoutTypeId") == null) {
            throw new GenericEntityException(
                "Layout type not set for screen section \"" + sectionName +
                "\".");
        }

        setSectionId(uiScreenSectionGV.getString("sectionId"));
        setScreenId(uiScreenSectionGV.getString("screenId"));
        setSectionName(uiScreenSectionGV.getString("sectionName"));
        setSectionDescription(uiScreenSectionGV.getString("sectionDescription"));
        setLayoutTypeId(uiScreenSectionGV.getString("layoutTypeId"));
        setDisplayOrder(uiScreenSectionGV.getString("displayOrder"));
        setColumnCount(uiScreenSectionGV.getString("columnCount"));
        setRowCount(uiScreenSectionGV.getString("rowCount"));
        setButtonKeys(uiScreenSectionGV.getString("buttonKeys"));
        setTitleDef(uiScreenSectionGV.getString("titleDef"));
        setSortDef(uiScreenSectionGV.getString("sortDef"));
        setSearchAttributeId(uiScreenSectionGV.getString("searchAttributeId"));
        setButtonAction(uiScreenSectionGV.getString("buttonAction"));
        setButtonTarget(uiScreenSectionGV.getString("buttonTarget"));
        setDetailButtonAction(uiScreenSectionGV.getString("detailButtonAction"));
        setDetailButtonTarget(uiScreenSectionGV.getString("detailButtonTarget"));
        setSearchAction(uiScreenSectionGV.getString("searchAction"));
        setSearchTarget(uiScreenSectionGV.getString("searchTarget"));
        setNewButtonAction(uiScreenSectionGV.getString("newButtonAction"));
        setNewButtonTarget(uiScreenSectionGV.getString("newButtonTarget"));
        setEditButtonAction(uiScreenSectionGV.getString("editButtonAction"));
        setEditButtonTarget(uiScreenSectionGV.getString("editButtonTarget"));
        setHideButtons(uiScreenSectionGV.getString("hideButtons"));
        setSelectNameDef(uiScreenSectionGV.getString("selectNameDef"));
        setSendQueryParameterList(uiScreenSectionGV.getString("sendQueryParameterList"));
        setUseQueryParameterList(uiScreenSectionGV.getString("useQueryParameterList"));

        /* add after value added to screen settings
                        setRowsPerPage(uiScreenSectionGV.getString("rowsPerPage"));

        */
        rowsPerPage = 0;
        uiScreenSectionGVI = null;

        if (TIMER) {
            timer.timerString(1, "[UIScreenSection.UIScreenSection] Got section");
        }

        // if rowsPerPage = 0, then use the global prefernece ROWS_PER_PAGE.
        if (rowsPerPage <= 0) {
            Preference pref = Preference.getInstance(delegator);
            rowsPerPage = pref.getPreference(userInfo.getPartyId(),
                    userInfo.getAccountId(), PREFERENCE_ROWS_PER_PAGE, 20);
        }

        // Get the uiScreenSectionEntity entities.

        findHashMap = new HashMap();
        findHashMap.put("sectionId", getSectionId());

        ArrayList orderBy = new ArrayList();
        orderBy.add("retrieveOrder");

        List uiScreenSectionEntityGVL = delegator.findByAnd("UiScreenSectionEntity",
                findHashMap, orderBy);

        if ((uiScreenSectionEntityGVL == null) ||
                (uiScreenSectionEntityGVL.size() == 0)) {
            throw new GenericEntityException(
                "No screen section entities were found in database for screen section \"" +
                sectionName + "\" and screen \"" + screenName + "\".");
        }

        Iterator uiScreenSectionEntityGVI = uiScreenSectionEntityGVL.iterator();

        while (uiScreenSectionEntityGVI.hasNext()) {

            GenericValue uiScreenSectionEntityGV = (GenericValue) uiScreenSectionEntityGVI.next();
            String entityId = uiScreenSectionEntityGV.getString("entityId");

            if (TIMER) {
                timer.timerString(1,
                    "[UIScreenSection.UIScreenSection] Looking for a UIScreenSectionEntity in cache.");
            }

            UIScreenSectionEntity uiScreenSectionEntity = uiCache.getUiScreenSectionEntity(getSectionId(),
                    entityId);

            if (uiScreenSectionEntity == null) {
                if (TIMER) {
                    timer.timerString(1,
                        "[UIScreenSection.UIScreenSection] UIScreenSectionEntity not found in cache. Creating a new one.");
                }

                uiScreenSectionEntity = new UIScreenSectionEntity(uiScreenSectionEntityGV,
                        delegator, uiCache);
                uiCache.putUiScreenSectionEntity(getSectionId(), entityId,
                    uiScreenSectionEntity);
            } else {
                if (TIMER) {
                    timer.timerString(1,
                        "[UIScreenSection.UIScreenSection] Found UIScreenSectionEntity in cache.");
                }
            }

            uiScreenSectionEntityList.add(uiScreenSectionEntity);

            if (TIMER) {
                timer.timerString(1,
                    "[UIScreenSection.UIScreenSection] Got a UIScreenSectionEntity.");
            }

            if (uiScreenSectionEntity.getIsUpdateable()) {
                setIsUpdateable(true);
            }
        }

        uiScreenSectionEntityGVI = null; // Reset the iterator for next time.

        Debug.logVerbose("-->[UIScreenSection.UIScreenSection] Finished getting the UiScreenSectionEntity's for sectionId " + getSectionId(), module);
        Debug.logVerbose("-->[UIScreenSection.UIScreenSection] uiScreenSectionEntityList: " + uiScreenSectionEntityList.toString(), module);
    
        if (TIMER) {
            timer.timerString(1,
                "[UIScreenSection.UIScreenSection] Calling getDisplayFields");
        }

        setUiFieldList(getDisplayFields(uiCache));

        if (TIMER) {
            timer.timerString(1, "[UIScreenSection.UIScreenSection] End");
        }
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

     * @return
     *
     * @throws GenericEntityException
     */
    public List getDisplayFields(UICache uiCache) throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(2, "[UIScreenSection.getDisplayFields] Start");
        }

        ArrayList uiFields = new ArrayList();
        boolean gotFields = false;

        // Get the primary key names for the primary entity.
        UIScreenSectionEntity primaryUiScreenSectionEntity = (UIScreenSectionEntity) (getUiScreenSectionEntityList()
                                                                                          .get(0));
        UIEntity primaryUiEntity = primaryUiScreenSectionEntity.getUiEntity();
        String primaryEntityName = primaryUiEntity.getEntityName();
        ModelEntity primaryModelEntity = primaryUiScreenSectionEntity.getUiEntity()
                                                                     .getModelEntity();
        List primaryPrimaryKeyFieldNameList = primaryModelEntity.getPkFieldNames();

        boolean[] primaryKeyIncluded = new boolean[20];

        for (int keyFieldNbr = 0;
                keyFieldNbr < primaryPrimaryKeyFieldNameList.size();
                keyFieldNbr++) {
            primaryKeyIncluded[keyFieldNbr] = false;
        }

        for (int i = 0; i < 3; i++) {
            String partyId = getUserInfo().getPartyId();

            if (i == 1) {
                partyId = getUserInfo().getAccountId(); //search for the company settings the second time through the loop
            }

            if (i == 2) {
                partyId = "-1"; //search for default party the last time through the loop
            }

            HashMap findMap = new HashMap();
            findMap.put("sectionId", sectionId);
            findMap.put("partyId", partyId);

            ArrayList orderBy = new ArrayList();
            orderBy.add("displayOrder");

            List uiFieldInfoL = getDelegator().findByAnd("UiScreenSectionInfo",
                    findMap, orderBy);

            int numRows = 0;

            Iterator uiFieldInfoI = uiFieldInfoL.iterator();

            while (uiFieldInfoI.hasNext()) {
                numRows++;

                GenericValue uiScreenSectionInfoGV = (GenericValue) uiFieldInfoI.next();
                int displayOrder = (uiScreenSectionInfoGV.get("displayOrder") == null)
                    ? 0
                    : Integer.valueOf(uiScreenSectionInfoGV.getString(
                            "displayOrder")).intValue();

                if (displayOrder > 0) {
                    // Only fields with display order > 0 get displayed.
                    String attributeId = (uiScreenSectionInfoGV.getString(
                            "attributeId") == null) ? ""
                                                    : uiScreenSectionInfoGV.getString(
                            "attributeId");

                    if (TIMER) {
                        timer.timerString(2,
                            "[UIScreenSection.getDisplayFields] Processing field with attribute ID " +
                            attributeId);
                    }

                    if (TIMER) {
                        timer.timerString(1,
                            "[UIScreenSection.getDisplayFields] Looking for UIScreenSectionInfo in cache.");
                    }

                    UIFieldInfo uiFieldInfo = uiCache.getUiFieldInfo(sectionId,
                            partyId, attributeId);

                    if (uiFieldInfo == null) {
                        if (TIMER) {
                            timer.timerString(1,
                                "[UIScreenSection.getDisplayFields] UIScreenSectionInfo not found in cache. Creating a new one.");
                        }

                        uiFieldInfo = new UIFieldInfo(uiScreenSectionInfoGV,
                                getDelegator(), uiCache);
                        uiCache.putUiFieldInfo(sectionId, partyId, attributeId,
                            uiFieldInfo);
                    } else {
                        if (TIMER) {
                            timer.timerString(1,
                                "[UIScreenSection.getDisplayFields] Found UIScreenSectionInfo in cache.");
                        }
                    }

                    uiFields.add(uiFieldInfo);

                    String attributeName = uiFieldInfo.getUiAttribute()
                                                      .getAttributeName();

                    for (int keyFieldNbr = 0;
                            keyFieldNbr < primaryPrimaryKeyFieldNameList.size();
                            keyFieldNbr++) {
                        if (attributeName.equals(
                                    primaryPrimaryKeyFieldNameList.get(
                                        keyFieldNbr))) {
                            primaryKeyIncluded[keyFieldNbr] = true;
                        }
                    }
                }
            }

            if (numRows > 0) {
                break;
            }
        }

        // Make sure all the primary key fields of the primary entity were included.
        for (int keyFieldNbr = 0;
                keyFieldNbr < primaryPrimaryKeyFieldNameList.size();
                keyFieldNbr++) {
            if (!primaryKeyIncluded[keyFieldNbr]) {
                throw new GenericEntityException(
                    "[UIScreenSection.getDisplayFields]: All primary key fields of the primary entity must be included in the field list.");
            }
        }

        if (TIMER) {
            timer.timerString(2, "[UIScreenSection.getDisplayFields] End");
        }

        return uiFields;
    }
View Full Code Here

Examples of org.ofbiz.base.util.UtilTimer

    public String processEvents(String screenName, String sectionName,
        UserInfo userInfo, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, UICache uiCache,
        boolean isSubsection, int tabOffset) throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString("[GenericWebEventProcessor.processEvents] Start");
        }

        if ((screenName == null) || screenName.equals("")) {
            throw new GenericEntityException("Screen name is required.");
        }

        if ((sectionName == null) || sectionName.equals("")) {
            throw new GenericEntityException("Screen section name is required.");
        }

        UIWebScreenSection uiWebScreenSection = getUiWebScreenSection(userInfo,
                screenName, sectionName, delegator, uiCache);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Got web screen section");
        }

        // Get the additional parameters that are needed for this screen section.  These will be used
        // for filtering a related entity on a tab page, or in completing keys in a SELECT screen.
        evalUseQueryParameterList(uiWebScreenSection, request);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Evaluated \"use\" query parameter list");
        }

        Debug.logVerbose("Returned from evalUseQueryParameterList.", module);

        // Find out what needs to be done depending on the action passed in the request object.
        String action = "";

        if (request.getParameter("action") != null) {
            // Actions for Free Form sections:
            //   ACTION_SHOW          - Display the entity in non-edit mode
            //   ACTION_SHOW_UPDATE   - Display the entity so the user can edit it
            //   ACTION_SHOW_INSERT   - Show the form with empty cells so the user can enter a new entity
            //   ACTION_SHOW_QUERY    - Show the form in Query mode, and set next action to QUERY.
            //   ACTION_SHOW_QUERY_REPORT - Show the form in Query mode, and set next action to SHOW_REPORT.
            //   ACTION_SHOW_REPORT   - Show the form in Report mode, and set next action to SHOW_REPORT.
            //   ACTION_SHOW_SELECT   - Show the form in select mode, and set next action to UPDATE_SELECT.
            //   ACTION_SHOW_COPY     - Show the form with a copy of the specified entity from which a new
            //                entity will be created.  (Same as showCreate with values prefilled.)
            //   ACTION_UPDATE        - Save the entity into the database using the form values.
            //   ACTION_INSERT        - Insert a new entity into into the database using the form values
            //   ACTION_DELETE        - Delete the entity from the database.
            //   ACTION_BUTTON        - A button in the header was pushed to get here.  Look for a parameter with
            //                each possible button name until we know which button was pushed.
            // Actions for Tabular sections:
            //   ACTION_QUERY         - Search for values based on attibute values using a custom WHERE clause.
            //   ACTION_QUERY_UPDATE  - Search for values based on attibute values using a custom WHERE clause,
            //                and go into update mode.
            //   ACTION_QUERY_ALL     - Search for all values.
            //   ACTION_UPDATE        - Save the entit(ies) into the database using the form values.
            //   ACTION_UPDATE_SELECT - Add and remove entities in a many-to-many relationship table.
            action = request.getParameter("action");
        } else {
            // No action specified.
            action = uiWebScreenSection.ACTION_NONE;
        }

        if (!action.equals(uiWebScreenSection.ACTION_BUTTON) &&
                !action.equals(uiWebScreenSection.ACTION_COPY) &&
                !action.equals(uiWebScreenSection.ACTION_DELETE) &&
                !action.equals(uiWebScreenSection.ACTION_INSERT) &&
                !action.equals(uiWebScreenSection.ACTION_NONE) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY_ALL) &&
                !action.equals(uiWebScreenSection.ACTION_UPDATE) &&
                !action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_COPY) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_INSERT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_QUERY) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_REPORT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_SELECT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_UPDATE)) {
                Debug.logWarning("\"" + action + "\" is not a valid action.", module);

            throw new GenericEntityException(
                "[GenericWebEventProcessor.processEvents] \"" + action +
                "\" is not a valid action.");
        }

        Debug.logVerbose("Starting action is \"" + action + "\".", module);
        Debug.logVerbose(
                "About to convert button action to regular action if necessary.", module);

        action = UIWebUtility.convertButtonAction(action, request);

        Debug.logVerbose("Final action is \"" + action + "\".", module);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Determined action");
        }

        String queryId = "";

        if (request.getParameter("queryId") != null) {
            queryId = request.getParameter("queryId");
        } else if (request.getParameter("savedQueryName") != null) {
            // The calling link specified to use a named query if it exists.
            String savedQueryName = request.getParameter("savedQueryName");
            GenericValue queryGV = UIQuery.getUiQueryByName(delegator,
                    userInfo.getPartyId(), sectionName, screenName,
                    savedQueryName);

            if (queryGV == null) {
                // Named query was not found.  Don't use a query.
                queryId = "1"// Query = All
                Debug.logWarning("Named query not found for query name " +
                    savedQueryName + ", partyId " + userInfo.getPartyId() +
                    ", sectionName " + sectionName + ", and screenName " +
                    screenName + ".  queryId is now \"" + queryId + "\"", module);
            } else {
                // Named query was found.
                queryId = (queryGV.getString("queryId") == null) ? "NONE"
                                                                 : queryGV.getString(
                        "queryId");

                Debug.logVerbose("Named query was found. queryId is \"" +
                        queryId + "\"", module);
            }
        }

        DataMatrix dataMatrix = new DataMatrix(delegator,
                uiWebScreenSection.getEntityParamVector());

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Constructed data matrix");
        }

        // ---------------------------------------------------------------------------------
        // Process all events before generating the HTML to display the data on the screen.
        // ---------------------------------------------------------------------------------
        // --------
        // INSERT
        // --------
        if (action.equals(uiWebScreenSection.ACTION_INSERT)) {
            // Insert the new record(s) into the database.
            int status = this.processInsert(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix,
                    uiCache);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished insert");
            }

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while inserting the new information into the data base.";

            case STATUS_CANCEL:
                return "Insert canceled.";
            }

            // --------
            // UPDATE
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_UPDATE)) {
            // Update the existing record(s) in the database.
            int status = this.processUpdate(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix,
                    uiCache);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished update");
            }

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while updating the information in the data base.";

            case STATUS_CANCEL:
                return "Update canceled.";
            }

            // --------
            // UPDATE_SELECT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT)) {
            // Add and/or remove records in a many-to-many table.
            int status = this.processUpdateSelect(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEventsSelect] Finished update");
            }

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while updating the information in the data base.";

            case STATUS_CANCEL:
                return "Update canceled.";
            }

            // --------
            // DELETE
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_DELETE)) {
            // Delete the current record.
            int status = this.processDelete(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, uiCache);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while deleting the information.";

            case STATUS_CANCEL:
                return "Delete canceled.";
            }

            // Create an empty entity so the user can insert a new one.
            status = this.processCreate(userInfo, uiWebScreenSection, request,
                    response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty data form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished delete");
            }

            // --------
            // SHOW_INSERT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_INSERT)) {
            // Create an empty entity so the user can insert a new one.
            int status = this.processCreate(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty data form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished show_insert");
            }

            // --------
            // SHOW_QUERY or SHOW_QUERY_REPORT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_QUERY) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT)) {
            // Create an empty entity to be displayed for query mode.
            int status = this.processShowQuery(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty query form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished show_query");
            }

            // --------
            // SHOW_REPORT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_REPORT)) {
            // Load in the entered query criteria, and re-display them in query mode.
            int status = this.processShowReport(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while displaying the report.";

            case STATUS_CANCEL:
                return "Report canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished show_report");
            }

            // --------
            // NO ACTION
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_NONE)) {
            // No action was specified.  Allow a blank screen section to be displayed.
            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished no_action");
            }
        }

        // --------
        // RETRIEVE
        // --------
        if (action.equals(uiWebScreenSection.ACTION_SHOW) ||
        action.equals(uiWebScreenSection.ACTION_SHOW_UPDATE) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_COPY) ||
                action.equals(uiWebScreenSection.ACTION_QUERY) ||
                action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) ||
                action.equals(uiWebScreenSection.ACTION_QUERY_ALL) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_SELECT) ||
                action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT)) {
            // Need to retrieve data from the data base.
            // Note:  ACTION_SHOW_SELECT and ACTION_UPDATE_SELECT are the only two actions that have something happen
            // in the previous IF statement, and then get retrieved.  In all other actions, the data matrix is either
            // filled from the HTML, or does not need to be filled.
            // Determine the retreive method.
            int retrieveMethod = eventProcessor.RETRIEVE_METHOD_ALL;

            switch (uiWebScreenSection.getLayoutTypeId()) {
            case UIWebScreenSection.LAYOUT_TYPE_FREEFORM:

                // Free form section should be retrieved using the primary key.
                retrieveMethod = eventProcessor.RETRIEVE_METHOD_PK;

                break;

            case UIWebScreenSection.LAYOUT_TYPE_TABULAR:

                // Tabular section can be retrieved multiple ways depending on the action
                // requested by the button or link that triggered it.
                if (action.equals(uiWebScreenSection.ACTION_QUERY) ||
                        action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE)) {
                    retrieveMethod = eventProcessor.RETRIEVE_METHOD_CLAUSE;
                } else if (action.equals(uiWebScreenSection.ACTION_QUERY_ALL)) {
                    retrieveMethod = eventProcessor.RETRIEVE_METHOD_ALL;
                } else {
                    throw new GenericEntityException("Action \"" + action +
                        "\" is not valid for tabular layout type.");
                }

                break;

            case UIWebScreenSection.LAYOUT_TYPE_SELECT:

                // A select screen section is always retrieved as a query because it is always subordinate
                // to some other entity.
                retrieveMethod = eventProcessor.RETRIEVE_METHOD_CLAUSE;

                break;

            case UIWebScreenSection.LAYOUT_TYPE_CROSSTAB:
                throw new GenericEntityException(
                    "Crosstab layout type not implemented yet.");

            default:
                throw new GenericEntityException("Invalid layout type.");
            }

            // handle paging of result sets.
            int startRow = 0;
            int rowsPerPage = uiWebScreenSection.getRowsPerPage();

            if (request.getParameter("startRow") != null) {
                startRow = Integer.parseInt(request.getParameter("startRow"));
            }

            uiWebScreenSection.setFirstVisibleRow(startRow);
            eventProcessor.setRowOffset(startRow);

            eventProcessor.setFetchSize(rowsPerPage);

            // Retrieve the data for the screen section.
            Debug.logVerbose(
                    "About to call GenericWebEventProcessor.processRetrieve.", module);

            StringBuffer queryIdBuffer = new StringBuffer(queryId);
            int status = this.processRetrieve(userInfo, uiWebScreenSection,
                    retrieveMethod, request, response, delegator,
                    eventProcessor, dataMatrix, queryIdBuffer, action);
            queryId = queryIdBuffer.toString();

      if ( eventProcessor.getHasMoreData() )
        uiWebScreenSection.setTotalRows(eventProcessor.getTotalRows() + 1);
      else
            uiWebScreenSection.setTotalRows(eventProcessor.getTotalRows());

            Debug.logVerbose("queryId after call to processRetrieve: " +
                    queryId, module);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while retrieving the data from the data base.";

            case STATUS_CANCEL:
                return "Retrieve canceled.";
            }

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished retrieve");
            }
        }

        // --------
        // SHOW_COPY
        // --------
        if (action.equals(uiWebScreenSection.ACTION_SHOW_COPY)) {
            // Displaying a copy of the retrieved record on the screen.
            int status = this.processShowCopy(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished showCopy");
            }

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while updating the copied record before displaying it.";

            case STATUS_CANCEL:
                return "Copy canceled.";
            }
        }

        // Get values of extra parameters to send to other screen sections when buttons on this screen
        // section are clicked.
        evalSendQueryParameterList(uiWebScreenSection, request, dataMatrix);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Evaluated \"send\" query parameter list");
        }

        // ---------------------------------------------------------------------------------
        // Generate the HTML to display the data on the screen, and return it to the calling method.
        // ---------------------------------------------------------------------------------
        Debug.logVerbose("Data matrix before display: " +
                dataMatrix.getCurrentBuffer().getContents().toString(), module);


        String displayHtml = uiWebScreenSection.display(dataMatrix, action,
                queryId, isSubsection, tabOffset);

        if (TIMER) {
            timer.timerString("[GenericWebEventProcessor.processEvents] End");
        }

        logUiHistory(action, request, dataMatrix, delegator, userInfo,
            uiWebScreenSection);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.