Package org.ofbiz.entity.jdbc

Examples of org.ofbiz.entity.jdbc.DatabaseUtil$CreateTableCallable


        Boolean fixSizes = (Boolean) context.get("fixColSizes");
        if (fixSizes == null) fixSizes = Boolean.FALSE;
        List messages = new ArrayList();

        String helperName = delegator.getGroupHelperName(groupName);
        DatabaseUtil dbUtil = new DatabaseUtil(helperName);
        Map modelEntities = delegator.getModelEntityMapByGroup(groupName);
        Set modelEntityNames = new TreeSet(modelEntities.keySet());

        Iterator modelEntityNameIter = null;

        // step 1 - remove FK indices
        Debug.logImportant("Removing all foreign key indices", module);
        modelEntityNameIter = modelEntityNames.iterator();
        while (modelEntityNameIter.hasNext()) {
            String modelEntityName = (String) modelEntityNameIter.next();
            ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName);
            dbUtil.deleteForeignKeyIndices(modelEntity, messages);
        }
        modelEntityNameIter = null;

        // step 2 - remove FKs
        Debug.logImportant("Removing all foreign keys", module);
        modelEntityNameIter = modelEntityNames.iterator();
        while (modelEntityNameIter.hasNext()) {
            String modelEntityName = (String) modelEntityNameIter.next();
            ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName);
            dbUtil.deleteForeignKeys(modelEntity, modelEntities, messages);
        }
        modelEntityNameIter = null;

        // step 3 - remove PKs
        Debug.logImportant("Removing all primary keys", module);
        modelEntityNameIter = modelEntityNames.iterator();
        while (modelEntityNameIter.hasNext()) {
            String modelEntityName = (String) modelEntityNameIter.next();
            ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName);
            dbUtil.deletePrimaryKey(modelEntity, messages);
        }
        modelEntityNameIter = null;

        // step 4 - remove declared indices
        Debug.logImportant("Removing all declared indices", module);
        modelEntityNameIter = modelEntityNames.iterator();
        while (modelEntityNameIter.hasNext()) {
            String modelEntityName = (String) modelEntityNameIter.next();
            ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName);
            dbUtil.deleteDeclaredIndices(modelEntity, messages);
        }
        modelEntityNameIter = null;

        // step 5 - repair field sizes
        if (fixSizes.booleanValue()) {
            Debug.logImportant("Updating column field size changes", module);
            List fieldsWrongSize = new LinkedList();
            dbUtil.checkDb(modelEntities, fieldsWrongSize, messages, true, true, true, true);
            if (fieldsWrongSize.size() > 0) {
                dbUtil.repairColumnSizeChanges(modelEntities, fieldsWrongSize, messages);
            } else {
                String thisMsg = "No field sizes to update";
                messages.add(thisMsg);
                Debug.logImportant(thisMsg, module);
            }
        }

        // step 6 - create PKs
        Debug.logImportant("Creating all primary keys", module);
        modelEntityNameIter = modelEntityNames.iterator();
        while (modelEntityNameIter.hasNext()) {
            String modelEntityName = (String) modelEntityNameIter.next();
            ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName);
            dbUtil.createPrimaryKey(modelEntity, messages);
        }
        modelEntityNameIter = null;

        // step 7 - create FK indices
        Debug.logImportant("Creating all foreign key indices", module);
        modelEntityNameIter = modelEntityNames.iterator();
        while (modelEntityNameIter.hasNext()) {
            String modelEntityName = (String) modelEntityNameIter.next();
            ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName);
            dbUtil.createForeignKeyIndices(modelEntity, messages);
        }
        modelEntityNameIter = null;

        // step 8 - create FKs
        Debug.logImportant("Creating all foreign keys", module);
        modelEntityNameIter = modelEntityNames.iterator();
        while (modelEntityNameIter.hasNext()) {
            String modelEntityName = (String) modelEntityNameIter.next();
            ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName);
            dbUtil.createForeignKeys(modelEntity, modelEntities, messages);
        }
        modelEntityNameIter = null;

        // step 8 - create FKs
        Debug.logImportant("Creating all declared indices", module);
        modelEntityNameIter = modelEntityNames.iterator();
        while (modelEntityNameIter.hasNext()) {
            String modelEntityName = (String) modelEntityNameIter.next();
            ModelEntity modelEntity = (ModelEntity) modelEntities.get(modelEntityName);
            dbUtil.createDeclaredIndices(modelEntity, messages);
        }
        modelEntityNameIter = null;

        // step 8 - checkdb
        Debug.logImportant("Running DB check with add missing enabled", module);
        dbUtil.checkDb(modelEntities, messages, true);
       
        Map result = ServiceUtil.returnSuccess();
        result.put("messages", messages);
        return result;
    }
View Full Code Here


    }

    /* ====================================================================== */

    public void checkDb(Map modelEntities, List messages, boolean addMissing) {
        DatabaseUtil dbUtil = new DatabaseUtil(this.helperName);
        dbUtil.checkDb(modelEntities, messages, addMissing);
    }
View Full Code Here

        dbUtil.checkDb(modelEntities, messages, addMissing);
    }

    /** Creates a list of ModelEntity objects based on meta data from the database */
    public List induceModelFromDb(Collection messages) {
        DatabaseUtil dbUtil = new DatabaseUtil(this.helperName);
        return dbUtil.induceModelFromDb(messages);
    }
View Full Code Here

TOP

Related Classes of org.ofbiz.entity.jdbc.DatabaseUtil$CreateTableCallable

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