Package net.datacrow.core.modules

Examples of net.datacrow.core.modules.DcModule


            // Delete children. Ignore any abstract module (parent and/or children)
            if (    dco.getModule().getChild() != null &&
                   !dco.getModule().isAbstract() &&
                   !dco.getModule().getChild().isAbstract()) {
               
                DcModule childModule = dco.getModule().getChild();
                stmt.execute("DELETE FROM " + childModule.getTableName() + " WHERE " +
                             childModule.getField(childModule.getParentReferenceFieldIndex()).getDatabaseFieldName() + " = '" + dco.getID() + "'");
            }
           
            // Remove any references to the to be deleted item.
            if (dco.getModule().hasDependingModules()) {
                for (DcModule m : DcModules.getReferencingModules(dco.getModule().getIndex())) {
                    if (m.isAbstract()) continue;
                   
                    if (m.getType() == DcModule._TYPE_MAPPING_MODULE) {
                        stmt.execute("DELETE FROM " + m.getTableName() + " WHERE " +
                                m.getField(DcMapping._B_REFERENCED_ID).getDatabaseFieldName() + " = '" + dco.getID() + "'");
                    } else {
                        for (DcField field : m.getFields()) {
                            if (!field.isUiOnly() && field.getReferenceIdx() == dco.getModule().getIndex()) {
                                stmt.execute("UPDATE " + m.getTableName() + " SET " +  field.getDatabaseFieldName() + " = NULL WHERE " +
                                             field.getDatabaseFieldName() + " = '" + dco.getID() + "'");
                            }
                        }
                    }
                }
            }
           
            File file;
            boolean deleted;
            for (DcField field : dco.getFields()) {
               
                if (field.getValueType() == DcRepository.ValueTypes._PICTURE) {
                    file = new File(DataCrow.imageDir, dco.getID() + "_" + field.getDatabaseFieldName() + ".jpg");
                    if (file.exists()) {
                        deleted = file.delete();
                        logger.debug("Delete file " + file + " [success = " + deleted + "]");
                    }
                   
                    file = new File(DataCrow.imageDir, dco.getID() + "_" + field.getDatabaseFieldName() + "_small.jpg");
                    if (file.exists()) {
                        deleted = file.delete();
                        logger.debug("Delete file " + file + " [success = " + deleted + "]");
                    }
                }
               
                if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
                  DcModule m = DcModules.get(DcModules.getMappingModIdx(field.getModule(), field.getReferenceIdx(), field.getIndex()));
                    stmt.execute("DELETE FROM " + m.getTableName() + " WHERE " + m.getField(DcMapping._A_PARENT_ID).getDatabaseFieldName() + " = '" + dco.getID() + "'");
                }  
            }
           
            stmt.execute("DELETE FROM " + DcModules.get(DcModules._PICTURE).getTableName() + " WHERE " +
                         DcModules.get(DcModules._PICTURE).getField(Picture._A_OBJECTID).getDatabaseFieldName() + " = '" + dco.getID() + "'");
View Full Code Here


    private void save() {
        panelDefinitionsParent.save();
        if (panelDefinitionsChild != null)
            panelDefinitionsChild.save();
       
        DcModule module = DcModules.getCurrent();
        module.getSettings().set(DcRepository.ModuleSettings.stShowPicturesInSeparateTabs,
                                 Boolean.valueOf(cbShowPicturesInTabs.isSelected()));
        module.getSearchView().refreshQuickView();

    }
View Full Code Here

       
        cbShowPicturesInTabs.setSelected(DcModules.getCurrent().getSettings().getBoolean(DcRepository.ModuleSettings.stShowPicturesInSeparateTabs));
       
        tp.addTab(DcResources.getText("lblGroupGeneral"), IconLibrary._icoSettings16, panelGeneral);
       
        DcModule module = DcModules.get(DcSettings.getInt(DcRepository.Settings.stModule));
        panelDefinitionsParent = new DefinitionPanel(module);
        tp.addTab(DcResources.getText("lblXFields", module.getLabel()), IconLibrary._icoSettings16, panelDefinitionsParent);

        if (module.getChild() != null) {
            panelDefinitionsChild = new DefinitionPanel(module.getChild());
            tp.addTab(DcResources.getText("lblXFields", module.getChild().getLabel()), IconLibrary._icoSettings16, panelDefinitionsChild);
        }
       
        DcColorSelector cs = ComponentFactory.getColorSelector(DcRepository.Settings.stQuickViewBackgroundColor);
        cs.setValue(DcSettings.getColor(DcRepository.Settings.stQuickViewBackgroundColor));
        tp.addTab(DcResources.getText("lblBackgroundColor"), IconLibrary._icoColor16, cs);       
View Full Code Here

        buttonRun.setActionCommand("renumber");
       
        DcLongTextField explanation = ComponentFactory.getLongTextField();
        ComponentFactory.setUneditable(explanation);
       
        DcModule module = DcModules.getCurrent();
       
        explanation.setText(DcResources.getText("lblRenumberExplanation", module.getObjectNamePlural()));
       
        JLabel labelOrderBy = ComponentFactory.getLabel(DcResources.getText("lblSortOn"));
        comboOrderBy1.addItem("");
        comboOrderBy2.addItem("");
        comboOrderBy3.addItem("");
       
        for (DcFieldDefinition definition : module.getFieldDefinitions().getDefinitions()) {
            DcField field = module.getField(definition.getIndex());
            if (field.isSearchable() && !field.isUiOnly()) {
                comboOrderBy1.addItem(field);
                comboOrderBy2.addItem(field);
                comboOrderBy3.addItem(field);
            }
View Full Code Here

        return success;
    }
   
    private boolean cleanupReferences() {
      MappingModule mm;
      DcModule pm;
      DcModule cm;
      String sql;
      ResultSet rs;
      int count;
      for (DcModule module : DcModules.getAllModules()) {
       
        if (module.getType() == DcModule._TYPE_MAPPING_MODULE) {
          try {
            mm = (MappingModule) module;
            pm = DcModules.get(mm.getParentModIdx());
            cm = DcModules.get(mm.getReferencedModIdx());
           
            sql = "select count(*) as INVALIDENTRIES from " + mm.getTableName() + " where objectid not in " +
            "(select id from " + pm.getTableName() + ") or referencedid not in " +
            "(select id from " + cm.getTableName() + ")";
           
            rs = DatabaseManager.executeSQL(sql);
            rs.next();
            count = rs.getInt(1);
            rs.close();
           
            if (count > 0) {
              logger.info("Cleaning " + mm.getTableName() + " of " + count + " ghost record(s).");
             
              sql = "delete from " + mm.getTableName() + " where objectid not in " +
                "(select id from " + pm.getTableName() + ") or referencedid not in " +
                "(select id from " + cm.getTableName() + ")";
           
              rs = DatabaseManager.executeSQL(sql);
             
              if (rs != null) rs.close();
            }
View Full Code Here

        String id;
       
        Connection conn = DatabaseManager.getAdminConnection();
        PreparedStatement ps = null;
       
        DcModule module = DcModules.get(DcModules._AUTHOR);

        String fieldFn = module.getField(DcAssociate._E_FIRSTNAME).getDatabaseFieldName();
        String fieldLn = module.getField(DcAssociate._F_LASTTNAME).getDatabaseFieldName();
        String fieldN  = module.getField(DcAssociate._A_NAME).getDatabaseFieldName();
        String fieldC  = module.getField(DcAssociate._G_IS_COMPANY).getDatabaseFieldName();

        try {
            sql = "update " + module.getTableName() + " set " + fieldC + " = false where " + fieldC + " = true";
            DatabaseManager.executeSQL(sql);
        } catch (SQLException se) {
            logger.error("Could not mark " + module.getObjectNamePlural() + " as non-companies for module " + module, se);
        }         
        try {
            sql = "select " + fieldFn + ", " + fieldLn + ", ID from " + module.getTableName() + " where " + fieldC + " is null or " + fieldC + " = false";
            ResultSet rs = DatabaseManager.executeSQL(sql);
            while (rs.next()) {
                firstname = rs.getString(1);
                lastname = rs.getString(2);
                id = rs.getString(3);
               
                firstname = firstname == null ? "" : firstname.trim();
                lastname = lastname == null ? "" : lastname.trim();
                if (lastname.startsWith("(") && firstname.indexOf(" ") > -1) {
                    String tmp = lastname;
                    lastname = firstname.substring(firstname.indexOf(" ") + 1);
                    firstname = firstname.substring(0, firstname.indexOf(" ")) + " " + tmp;
                }
               
                name = firstname.length() > 0 && lastname.length() > 0 ? lastname + ", " + firstname :
                       firstname.length() == 0 ? lastname : firstname;
               
                sql = "update " + module.getTableName() + " set " +
                       fieldN + " = ? , " +
                       fieldFn + " = ?, " +
                       fieldLn + " = ? " +
                       "where ID = ?";
               
View Full Code Here

                    continue;
                 
                  fldPersist = module.getPersistentField(fld.getIndex());
                 
                    try {
                        DcModule mm = DcModules.get(DcModules.getMappingModIdx(fld.getModule(), fld.getReferenceIdx(), fld.getIndex()));

                        sql =
                          " select objectid, referencedid from " + mm.getTableName() +
                          " inner join " + DcModules.get(fld.getReferenceIdx()).getTableName() +
                          " on " + DcModules.get(fld.getReferenceIdx()).getTableName() + ".ID = " +  mm.getTableName() + ".referencedID " +
                          " order by objectid, name";
                       
                        rs = DatabaseManager.executeSQL(sql);
                       
                        String prevID = null;
View Full Code Here

            DcObject dco = module.getItem();
            for (DcField fld : module.getFields()) {
                logger.info("Creating persistant field for module: " + module.getTableName() + ": " + fld);
                if (fld.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
                    try {
                        DcModule mm = DcModules.get(DcModules.getMappingModIdx(fld.getModule(), fld.getReferenceIdx(), fld.getIndex()));

                        sql = "select distinct objectid from " + mm.getTableName();
                        rs = DatabaseManager.executeSQL(sql);
                       
                        while (rs.next()) {
                            ID = rs.getString(1);
                            sql = "select top 1 referencedid from " + mm.getTableName() + " where objectid = '" + ID + "'";
                            rs2 = DatabaseManager.executeSQL(sql);
                            if (rs2.next()) {
                                dco.clearValues();
                               
                                referenceID = rs2.getString(1);
View Full Code Here

            for (XmlField field : module.getFields()) {
               
                field.setModule(module.getIndex());
               
                if (field.getModuleReference() !=  0 && field.getModuleReference() != module.getIndex()) {
                    DcModule m = DcModules.get(field.getModuleReference()) == null ?
                                 DcModules.get(field.getModuleReference() + module.getIndex()) :
                                 DcModules.get(field.getModuleReference());
                   
                    if (m != null && m.getXmlModule() != null)
                        new ModuleJar(m.getXmlModule()).save();
                else {
                    field.setModuleReference(module.getIndex());
                }
            }
           
View Full Code Here

    @Override
    public List<DcObject> run() {
        Connection conn = null;
        Statement stmt = null;

        DcModule module = getModule();
        String columns = "";
        for (DcField field : module.getFields()) {
            if (!field.isUiOnly()) {
                if (columns.length() > 0)
                    columns += ", ";

                columns += field.getDatabaseFieldName() + " " + field.getDataBaseFieldType();
                if (field.getIndex() == DcObject._ID) {
                    columns += " PRIMARY KEY";
                }
            }
        }
       
        String sql = "CREATE MEMORY TABLE " + module.getTableName() + "\r\n(" + columns + ");";
       
        try {
            conn = DatabaseManager.getConnection();
            stmt = conn.createStatement();
            stmt.execute(sql);
        } catch (SQLException se) {
            if (isLog())
                logger.error(se, se);
        }
       
        if (module.getIndex() == DcModules._PICTURE) {
            try {
                stmt.execute("CREATE UNIQUE INDEX " + module.getTableName() + "_IDX ON " + module.getTableName() + " (" +
                        module.getField(Picture._A_OBJECTID).getDatabaseFieldName() + ", " +
                        module.getField(Picture._B_FIELD).getDatabaseFieldName() + ")");
            } catch (SQLException se) {
                if (isLog())
                    logger.error(se, se);
            }
        } else if (module.getType() == DcModule._TYPE_MAPPING_MODULE) {
            try {
                stmt.execute("CREATE UNIQUE INDEX " + module.getTableName() + "_IDX ON " + module.getTableName() + " (" +
                        module.getField(DcMapping._A_PARENT_ID).getDatabaseFieldName() + ", " +
                        module.getField(DcMapping._B_REFERENCED_ID).getDatabaseFieldName() + ")");
            } catch (SQLException se) {
                if (isLog())
                    logger.error(se, se);
            }
        } else if (module.getType() == DcModule._TYPE_EXTERNALREFERENCE_MODULE) {
            try {
                stmt.execute("CREATE UNIQUE INDEX " + module.getTableName() + "_IDX ON " + module.getTableName() + " (" +
                        module.getField(ExternalReference._EXTERNAL_ID).getDatabaseFieldName() + ", " +
                        module.getField(ExternalReference._EXTERNAL_ID_TYPE).getDatabaseFieldName() + ")");
            } catch (SQLException se) {
                if (isLog())
                    logger.error(se, se);
            }
        }
View Full Code Here

TOP

Related Classes of net.datacrow.core.modules.DcModule

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.