Package com.dotmarketing.common.db

Examples of com.dotmarketing.common.db.DotConnect


    if (!FixAssetsProcessStatus.getRunning()) {
      FixAssetsProcessStatus.startProgress();
      FixAssetsProcessStatus.setDescription("task 4: check the working and live versions of file assets for inconsistencies");     
      HibernateUtil.startTransaction();
      try {
        DotConnect db = new DotConnect();

        String query = "select distinct ident.* " + "from identifier ident, "
            + "inode i, " + "file_asset c "
            + "where ident.id = c.identifier and "
            + "ident.id not in (select ident.id "
            + "from identifier id, " + "inode i, "
            + "file_asset c, " + "fileasset_version_info fvi "
            + "where c.identifier = ident.id and "
            + "i.inode = c.inode and " + "fvi.working_inode = c.inode) and "
            + "i.type = 'file_asset' and " + "i.inode = c.inode";
        Logger.debug(CMSMaintenanceFactory.class,
            "Running query for file assets: " + query);
        db.setSQL(query);
        List<HashMap<String, String>> fileAssetIds = db.getResults();
        Logger.debug(CMSMaintenanceFactory.class, "Found "
            + fileAssetIds.size() + " File Assets");
        int total = fileAssetIds.size();
       
        Logger.info(CMSMaintenanceFactory.class,
            "Total number of assets: " + total);
        FixAssetsProcessStatus.setTotal(total);

        // Check the working and live versions of contentlets
        String identifierInode;
        List<HashMap<String, String>> versions;
        HashMap<String, String> version;
        //String versionWorking;
        String DbConnFalseBoolean = DbConnectionFactory.getDBFalse()
            .trim().toLowerCase();

        char DbConnFalseBooleanChar;
        if (DbConnFalseBoolean.charAt(0) == '\'')
          DbConnFalseBooleanChar = DbConnFalseBoolean.charAt(1);
        else
          DbConnFalseBooleanChar = DbConnFalseBoolean.charAt(0);

        String inode;

        // Check the working and live versions of file assets
        Logger.info(CMSMaintenanceFactory.class,
            "Verifying working and live versions for "
                + fileAssetIds.size() + " file_assets");
        for (HashMap<String, String> identifier : fileAssetIds) {
          identifierInode = identifier.get("id");

          Logger.debug(CMSMaintenanceFactory.class,
              "identifier inode " + identifierInode);
          Logger.debug(CMSMaintenanceFactory.class, "Running query: "
              + fix2FileAssetQuery);

          db.setSQL(fix2FileAssetQuery);
          db.addParam(identifierInode);
          versions = db.getResults();
          modifiedData.addAll(versions);

          if (0 < versions.size()) {
            version = versions.get(0);
            //versionWorking = version.get("working").trim().toLowerCase();

            inode = version.get("inode");
            Logger.debug(CMSMaintenanceFactory.class,
                "Non Working File inode : " + inode);
            Logger.debug(CMSMaintenanceFactory.class,
                "Running query: " + fix3FileAssetQuery);
            db.setSQL(fix3FileAssetQuery);           
            db.addParam(inode);
            db.addParam(identifierInode);
            db.getResult();

            FixAssetsProcessStatus.addAError();
            counter++;

          }
View Full Code Here


  }
 

  public boolean shouldRun() {

    DotConnect db = new DotConnect();

    String query = "select distinct ident.* " + "from identifier ident, "
        + "inode i, " + "file_asset c "
        + "where ident.id = c.identifier and "
        + "ident.id not in (select ident.id " + "from identifier ident, "
        + "inode i, " + "file_asset c, " + "fileasset_version_info fvi "
        + "where c.identifier = ident.id and "
        + "i.inode = c.inode and " + "fvi.working_inode = c.inode) and "
        + "i.type = 'file_asset' and " + "i.inode = c.inode";

    db.setSQL(query);
    List<HashMap<String, String>> fileAssetIds =null;
    try {
      fileAssetIds = db.getResults();
    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
    }
    int total = fileAssetIds.size();
    if (total > 0)
View Full Code Here

      FixAssetsProcessStatus.startProgress();
      FixAssetsProcessStatus.setDescription("task 50: FixInodesWithoutContentlets");
      HibernateUtil.startTransaction();
      int counter=0;
      try {
        DotConnect dc = new DotConnect();
        dc.setSQL(selectInodeContentletWithoutContent);
        List<Map<String, String>> inodes = dc.getResults();
        dc.setSQL(selectIdentifierContentletWithoutContent);
        List<Map<String, String>> identifiers = dc.getResults()
        List<Map<String, String>> result;
        String inodeS="";
        String identifierS=""


        for (Map<String, String> inode: inodes) {
          inodeS = inode.get("inode");
          //identifierS = inode.get("identifier");
          try {             
            /*dc = new DotConnect();
            dc.setSQL(cleanInodeContentletWithoutContentTree);
            dc.addParam(identifierS);
            dc.addParam(inodeS);
            result = dc.getResults();*/
           
            dc = new DotConnect();
            dc.setSQL(cleanInodeContentletWithoutContent);
            dc.addParam(inodeS);
            result = dc.getResults();

            /*dc = new DotConnect();
            dc.setSQL(cleanInodeIdentifierContentletWithoutContent);
            dc.addParam(identifierS);
            result = dc.getResults();*/

            counter=counter++;
          } catch (Exception e) {
            Logger.error(FixTask00050FixInodesWithoutContentlets.class,e.getMessage(),e);
          }         
        } 
        for (Map<String, String> ident: identifiers) {
          identifierS = ident.get("id");
          try{
            dc = new DotConnect();
            dc.setSQL(cleanInodeContentletWithoutContentPermissionReference);
            dc.addParam(identifierS);
            result = dc.getResults();
         
            dc = new DotConnect();
            dc.setSQL(cleanInodeContentletWithoutContentPermission);
            dc.addParam(identifierS);
            result = dc.getResults();
         
            dc = new DotConnect();
            dc.setSQL(cleanIdentifierInodeContentletWithoutContent);
            dc.addParam(identifierS);
            result = dc.getResults();
          } catch (Exception e) {
            Logger.error(FixTask00050FixInodesWithoutContentlets.class,e.getMessage(),e);
          }   
         
        }
View Full Code Here

  /**
   * Validated if exist inodes without content
   */
  public boolean shouldRun() {
    int total = 0;
    DotConnect dc = new DotConnect();
    dc.setSQL(selectInodeContentletWithoutContent);
    List<HashMap<String, String>> result =null ;
    try {
      result = dc.getResults();
    } catch (DotDataException e) {
      Logger.error(this,e.getMessage(), e);
    }
    total = total + result.size();

View Full Code Here

        if (!FixAssetsProcessStatus.getRunning()) {
            try {
                FixAssetsProcessStatus.startProgress();
                FixAssetsProcessStatus.setDescription("60 Fix asset_type");
                int total=0;
                DotConnect dc=new DotConnect();
               
                // contentlets
                dc.setSQL("select identifier.* from contentlet join identifier on (identifier=id) where asset_type<>'contentlet'");
                List<Map<String,String>> results = dc.getResults();
                total+=results.size();
                for(Map<String,String> rr : results) {
                    try {
                        dc.setSQL("update identifier set asset_type='contentlet' where id=?");
                        dc.addParam(rr.get("id"));
                        dc.loadResult();
                        modifiedData.add(rr);
                        total++;
                    } catch(Exception ex) {
                        Logger.warn(this, "error fixing asset_type on id="+rr.get("id"));
                    }
                    modifiedData.add(rr);
                }
               
                // files
                dc.setSQL("select identifier.* from file_asset join identifier on (identifier=id) where asset_type<>'file_asset'");
                results = dc.getResults();
                total+=results.size();
                for(Map<String,String> rr : results) {
                    try {
                        dc.setSQL("update identifier set asset_type='file_asset' where id=?");
                        dc.addParam(rr.get("id"));
                        dc.loadResult();
                        modifiedData.add(rr);
                        total++;
                    } catch(Exception ex) {
                        Logger.warn(this, "error fixing asset_type on id="+rr.get("id"));
                    }
                }
               
                // containers
                dc.setSQL("select identifier.* from containers join identifier on (identifier=id) where asset_type<>'containers'");
                results = dc.getResults();
                total+=results.size();
                for(Map<String,String> rr : results) {
                    try {
                        dc.setSQL("update identifier set asset_type='containers' where id=?");
                        dc.addParam(rr.get("id"));
                        dc.loadResult();
                        modifiedData.add(rr);
                        total++;
                    } catch(Exception ex) {
                        Logger.warn(this, "error fixing asset_type on id="+rr.get("id"));
                    }
                    modifiedData.add(rr);
                }
               
                // templates
                dc.setSQL("select identifier.* from template join identifier on (identifier=id) where asset_type<>'template'");
                results = dc.getResults();
                total+=results.size();
                for(Map<String,String> rr : results) {
                    try {
                        dc.setSQL("update identifier set asset_type='template' where id=?");
                        dc.addParam(rr.get("id"));
                        dc.loadResult();
                        modifiedData.add(rr);
                        total++;
                    } catch(Exception ex) {
                        Logger.warn(this, "error fixing asset_type on id="+rr.get("id"));
                    }
                }
               
                // links
                dc.setSQL("select identifier.* from links join identifier on (identifier=id) where asset_type<>'links'");
                results = dc.getResults();
                total+=results.size();
                for(Map<String,String> rr : results) {
                    try {
                        dc.setSQL("update identifier set asset_type='links' where id=?");
                        dc.addParam(rr.get("id"));
                        dc.loadResult();
                        modifiedData.add(rr);
                        total++;
                    } catch(Exception ex) {
                        Logger.warn(this, "error fixing asset_type on id="+rr.get("id"));
                    }
                }
               
                // htmlpage
                dc.setSQL("select identifier.* from htmlpage join identifier on (identifier=id) where asset_type<>'htmlpage'");
                results = dc.getResults();
                total+=results.size();
                for(Map<String,String> rr : results) {
                    try {
                        dc.setSQL("update identifier set asset_type='htmlpage' where id=?");
                        dc.addParam(rr.get("id"));
                        dc.loadResult();
                        modifiedData.add(rr);
                        total++;
                    } catch(Exception ex) {
                        Logger.warn(this, "error fixing asset_type on id="+rr.get("id"));
                    }
                }
               
                // folder
                dc.setSQL("select identifier.* from folder join identifier on (identifier=id) where asset_type<>'folder'");
                results = dc.getResults();
                for(Map<String,String> rr : results) {
                    try {
                        dc.setSQL("update identifier set asset_type='folder' where id=?");
                        dc.addParam(rr.get("id"));
                        dc.loadResult();
                        modifiedData.add(rr);
                        total++;
                    } catch(Exception ex) {
                        Logger.warn(this, "error fixing asset_type on id="+rr.get("id"));
                    }
View Full Code Here

    if (!FixAssetsProcessStatus.getRunning()) {
      FixAssetsProcessStatus.startProgress();
      FixAssetsProcessStatus.setDescription("task 5: check the working and live versions of html pages for inconsistencies");     
      HibernateUtil.startTransaction();
      try {
        DotConnect db = new DotConnect();

        String query = "select distinct ident.* " + "from identifier ident, "
            + "inode i, " + "htmlpage c "
            + "where ident.id = c.identifier and "
            + "ident.id not in (select ident.id "
            + "from identifier ident, " + "inode i, " + "htmlpage c, " + "htmlpage_version_info hvi "
            + "where c.identifier = ident.id and "
            + "i.inode = c.inode and " + "hvi.working_inode = c.inode) and " 
            + "i.type = 'htmlpage' and " + "i.inode = c.inode";

        Logger.debug(CMSMaintenanceFactory.class,
            "Running query for html pages: " + query);
        db.setSQL(query);
        List<HashMap<String, String>> htmlpageIds = db.getResults();
       
        Logger.debug(CMSMaintenanceFactory.class, "Found "
            + htmlpageIds.size() + " Html pages");
        int total = htmlpageIds.size();

        Logger.info(CMSMaintenanceFactory.class,
            "Total number of assets: " + total);
        FixAssetsProcessStatus.setTotal(total);

        String identifierInode;
        List<HashMap<String, String>> versions;
        HashMap<String, String> version;
        //String versionWorking;
        String DbConnFalseBoolean = DbConnectionFactory.getDBFalse()
            .trim().toLowerCase();

        char DbConnFalseBooleanChar;
        if (DbConnFalseBoolean.charAt(0) == '\'')
          DbConnFalseBooleanChar = DbConnFalseBoolean.charAt(1);
        else
          DbConnFalseBooleanChar = DbConnFalseBoolean.charAt(0);

        String inode;

        // Check the working and live versions of html pages
        Logger.info(CMSMaintenanceFactory.class,
            "Verifying working and live versions for "
                + htmlpageIds.size() + " htmlpages");
        for (HashMap<String, String> identifier : htmlpageIds) {
          identifierInode = identifier.get("id");

          Logger.debug(CMSMaintenanceFactory.class,
              "identifier inode " + identifierInode);
          Logger.debug(CMSMaintenanceFactory.class, "Running query: "
              + fix2HtmlPageQuery);

          db.setSQL(fix2HtmlPageQuery);
          db.addParam(identifierInode);
          versions = db.getResults();
          modifiedData.addAll(versions);
         
          if (0 < versions.size()) {
            version = versions.get(0);
            //versionWorking = version.get("working").trim().toLowerCase();

            // Logger.info("Step 5 versionWorking: " +
            // versionWorking);

            inode = version.get("inode");
            Logger.debug(CMSMaintenanceFactory.class,
                "Non Working HTML page inode : " + inode);
            Logger.debug(CMSMaintenanceFactory.class,
                "Running query: " + fix3HtmlPageQuery);
            db.setSQL(fix3HtmlPageQuery);           
            db.addParam(inode);
            db.addParam(identifierInode);
            db.getResult();

            FixAssetsProcessStatus.addAError();
            counter++;
          }

View Full Code Here

    return modifiedData;
  }


  public boolean shouldRun() {
    DotConnect db = new DotConnect();

    String query = "select distinct ident.* " + "from identifier ident, "
        + "inode i, " + "htmlpage c "
        + "where ident.id = c.identifier and "
        + "ident.id not in (select ident.id " + "from identifier ident, "
        + "inode i, " + "htmlpage c, " + "htmlpage_version_info hvi "
        + "where c.identifier = ident.id and "
        + "i.inode = c.inode and " + "hvi.working_inode = c.inode) and "
        + "i.type = 'htmlpage' and " + "i.inode = c.inode";
    db.setSQL(query);
    List<HashMap<String, String>> htmlpageIds =null;
    try {
      htmlpageIds = db.getResults();
    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
    }
    int total = htmlpageIds.size();
    if (total > 0)
View Full Code Here

  /* (non-Javadoc)
   * @see com.dotmarketing.plugin.business.PluginFactory#delete(com.dotmarketing.plugin.model.Plugin)
   */
  @Override
  protected void delete(Plugin plugin) throws DotDataException {
    DotConnect dc = new DotConnect();
    dc.setSQL("delete from plugin_property where plugin_id = ?");
    dc.addParam(plugin.getId());
    dc.getResult();
    dc.setSQL("delete from plugin where id = ?");
    dc.addParam(plugin.getId());
    dc.getResult();
    cache.removePlugin(plugin.getId());
    cache.clearPropertyCache();
  }
View Full Code Here

    cache.clearPropertyCache();
  }
 
  @Override
  protected void deletePluginProperties(String pluginId) throws DotDataException {
    DotConnect dc = new DotConnect();
    dc.setSQL("delete from plugin_property where plugin_id = ?");
    dc.addParam(pluginId);
    dc.getResult();
    cache.clearPropertyCache();
  }
View Full Code Here

      dc.executeStatement(trigger);
    }
  }
 
  private void addTriggerToFolder() throws SQLException {
    DotConnect dc = new DotConnect();
    String trigger = "";
    if(DbConnectionFactory.isPostgres()){
      trigger = "CREATE OR REPLACE FUNCTION folder_identifier_check() RETURNS trigger AS '\n" +
              "DECLARE\n" +
                  "versionsCount integer;\n" +
              "BEGIN\n" +
                  "IF (tg_op = ''DELETE'') THEN\n" +
                    "select count(*) into versionsCount from folder where identifier = OLD.identifier;\n"  +
                    "IF (versionsCount = 0)THEN\n"
                      "DELETE from identifier where id = OLD.identifier;\n" +
                    "ELSE\n" +
                      "RETURN OLD;\n" +
                    "END IF;\n" +
                  "END IF;\n" +
                "RETURN NULL;\n" +
                "END\n" +
                "' LANGUAGE plpgsql;\n" +
                "CREATE TRIGGER folder_identifier_check_trigger AFTER DELETE\n" +
                "ON folder FOR EACH ROW\n" +
                "EXECUTE PROCEDURE folder_identifier_check();\n";
    }else if(DbConnectionFactory.isMsSql()){
      trigger = "CREATE Trigger folder_identifier_check\n" +
              "ON folder\n" +
              "FOR DELETE AS\n" +
              "DECLARE @totalCount int\n" +
              "DECLARE @identifier varchar(36)\n" +  
              "DECLARE folder_cur_Deleted cursor LOCAL FAST_FORWARD for\n" +
                "Select identifier\n" +
                "from deleted\n" +
                "for Read Only\n" +
                "open folder_cur_Deleted\n" +  
                "fetch next from folder_cur_Deleted into @identifier\n" +
                "while @@FETCH_STATUS <> -1\n" +
                "BEGIN\n" +
                  "select @totalCount = count(*) from folder where identifier = @identifier\n" +
                  "IF (@totalCount = 0)\n" +     
                  "BEGIN\n" +      
                    "DELETE from identifier where id = @identifier\n" +          
                  "END\n" +
                  "fetch next from folder_cur_Deleted into @identifier\n" +
                "END;\n";
    }else if(DbConnectionFactory.isOracle()){
      String oracleTrigger = "CREATE OR REPLACE PACKAGE folder_pkg as\n" +
                      "type array is table of folder%rowtype index by binary_integer;\n" +
                      "oldvals array;\n" +
                      "empty array;\n" +
                      "END;\n" +
                      "/\n" +
                      "CREATE OR REPLACE trigger folder_identifier_bd\n" +
                      "BEFORE DELETE ON folder\n" +
                      "BEGIN\n" +
                        "folder_pkg.oldvals := folder_pkg.empty;\n" +
                        "END;\n" +
                        "/\n" +
                        "CREATE OR REPLACE TRIGGER folder_identifier_bdfer\n" +
                        "BEFORE DELETE ON folder\n" +
                        "FOR EACH ROW\n" +
                        "BEGIN\n" +
                          "folder_pkg.oldvals(folder_pkg.oldvals.count+1).identifier := :old.identifier;\n"
                        "END;\n" +
                        "/\n" +
                        "CREATE OR REPLACE TRIGGER  folder_identifier_trigger\n" +
                        "AFTER DELETE ON folder\n" +
                        "DECLARE\n" +
                          "versionsCount integer;\n" +
                        "BEGIN\n" +
                          "for i in 1 .. folder_pkg.oldvals.count LOOP\n" +
                            "select count(*) into versionsCount from folder where identifier = folder_pkg.oldvals(i).identifier;\n" +
                            "IF (versionsCount = 0)THEN\n"
                              "DELETE from identifier where id = folder_pkg.oldvals(i).identifier;\n" +     
                            "END IF;\n" +
                          "END LOOP;\n" +
                          "END;\n" +
                      "/\n";
      List<String> triggers = SQLUtil.tokenize(oracleTrigger);
      for(String t:triggers){
        dc.executeStatement(t);
      }

    }else
      String checkVersions = "DROP PROCEDURE IF EXISTS checkVersions;\n" +
                      "CREATE PROCEDURE checkVersions(IN ident varchar(36),IN tableName VARCHAR(20),OUT versionsCount INT)\n" +
                      "BEGIN\n" +
                      "SET versionsCount := 0;\n" +
                          "IF(tableName = 'htmlpage') THEN\n" +
                          "select count(inode) into versionsCount from htmlpage where identifier = ident;\n" +
                          "END IF;\n" +
                          "IF(tableName = 'file_asset') THEN\n" +
                          "select count(inode) into versionsCount from file_asset where identifier = ident;\n" +
                          "END IF;\n" +
                          "IF(tableName = 'links') THEN\n" +
                            "select count(inode) into versionsCount from links where identifier = ident;\n" +
                          "END IF;\n" +
                          "IF(tableName = 'containers') THEN\n" +
                            "select count(inode) into versionsCount from containers where identifier = ident;\n" +
                          "END IF;\n" +
                          "IF(tableName = 'template') THEN\n" +
                            "select count(inode) into versionsCount from template where identifier = ident;\n" +
                          "END IF;\n" +
                          "IF(tableName = 'contentlet') THEN\n" +
                            "select count(inode) into versionsCount from contentlet where identifier = ident;\n" +
                          "END IF;\n" +
                          "IF(tableName = 'folder') THEN\n" +
                            "select count(inode) into versionsCount from folder where identifier = ident;\n" +
                          "END IF;\n" +
                      "END\n" +
                      "#" ;
      String folderTrigger = "DROP TRIGGER IF EXISTS folder_identifier_check;\n" +
                   "CREATE TRIGGER folder_identifier_check BEFORE DELETE\n" +
                   "on folder\n" +
                   "FOR EACH ROW\n" +
                   "BEGIN\n" +
                   "DECLARE tableName VARCHAR(20);\n" +
                   "DECLARE count INT;\n" +
                   "SET tableName = 'folder';\n" +
                   "CALL checkVersions(OLD.identifier,tableName,count);\n" +
                   "IF(count = 0)THEN\n" +
                   "delete from identifier where id = OLD.identifier;\n" +
                   "END IF;\n" +
                   "END\n" +
                   "#";
     
      List<String> triggers = SQLUtil.tokenize(checkVersions + folderTrigger);
      for(String t:triggers){
        dc.executeStatement(t);
      }
    }
    if(UtilMethods.isSet(trigger)){
      dc.executeStatement(trigger);
    }
  }
View Full Code Here

TOP

Related Classes of com.dotmarketing.common.db.DotConnect

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.