Package com.dotmarketing.common.db

Examples of com.dotmarketing.common.db.DotConnect


      FixAssetsProcessStatus.startProgress();
      FixAssetsProcessStatus.setDescription("task 30: DeleteOrphanedAssets");
      HibernateUtil.startTransaction();
      int total = 0;
      try {
         DotConnect dc = new DotConnect();
           dc.setSQL(identifiersToDelete);
           List<Map<String, String>> identifiersToDeleteResult = dc.loadResults();
       
           total = total + identifiersToDeleteResult.size();
         FixAssetsProcessStatus.setTotal(total);
   
           if ((identifiersToDeleteResult != null) && (0 < identifiersToDeleteResult.size())) {
      
         modifiedData = identifiersToDeleteResult;
       
         List<Map<String, String>> inodesToDeleteResult;
         List<Map<String, String>> assetsToDeleteResult;
         Map<String, String> identifierToDelete;
         boolean assetDeleted;
       
         for (int i = 0; i < identifiersToDeleteResult.size(); ++i) {
          identifierToDelete = identifiersToDeleteResult.get(i);
          assetDeleted = false;
          dc.setSQL(inodesToDelete);
          dc.addParam(identifierToDelete.get("id"));
          dc.addParam(identifierToDelete.get("id"));
          dc.addParam(identifierToDelete.get("id"));
          inodesToDeleteResult = dc.loadResults();
         
          if ((inodesToDeleteResult != null) && (0 < inodesToDeleteResult.size())) {
            modifiedData.addAll(inodesToDeleteResult);
           
            if (inodesToDeleteResult.get(0).get("type").equals("htmlpage")) {
              Logger.debug(this, "Deleting orphan HTMLPage with Identifier='" + identifierToDelete.get("id") + "'");
             
              dc.setSQL(htmlPagesToDelete);
              dc.addParam(identifierToDelete.get("id"));
              assetsToDeleteResult = dc.loadResults();
             
              if ((assetsToDeleteResult != null) && (0 < assetsToDeleteResult.size())) {
                modifiedData.addAll(assetsToDeleteResult);
               
                dc.setSQL(deleteHTMLPages);
                dc.addParam(identifierToDelete.get("id"));
                dc.loadResult();
               
                assetDeleted = true;
              }
            } else if (inodesToDeleteResult.get(0).get("type").equals("links")) {
              Logger.debug(this, "Deleting orphan Link with Identifier='" + identifierToDelete.get("id") + "'");
             
              dc.setSQL(linksToDelete);
              dc.addParam(identifierToDelete.get("id"));
              assetsToDeleteResult = dc.loadResults();
             
              if ((assetsToDeleteResult != null) && (0 < assetsToDeleteResult.size())) {
                modifiedData.addAll(assetsToDeleteResult);
               
                dc.setSQL(deleteLinks);
                dc.addParam(identifierToDelete.get("id"));
                dc.loadResult();
               
                assetDeleted = true;
              }
            } else if (inodesToDeleteResult.get(0).get("type").equals("file_asset")) {
              Logger.debug(this, "Deleting orphan File Asset with Identifier='" + identifierToDelete.get("id") + "'");
             
              dc.setSQL(fileAssetsToDelete);
              dc.addParam(identifierToDelete.get("id"));
              assetsToDeleteResult = dc.loadResults();
             
              if ((assetsToDeleteResult != null) && (0 < assetsToDeleteResult.size())) {
                modifiedData.addAll(assetsToDeleteResult);
               
                dc.setSQL(deleteFileAssets);
                dc.addParam(identifierToDelete.get("id"));
                dc.loadResult();
               
                assetDeleted = true;
              }
            }
           
            if (assetDeleted) {
              dc.setSQL(deleteTrees);
              dc.addParam(identifierToDelete.get("id"));
              dc.addParam(identifierToDelete.get("id"));
              dc.addParam(identifierToDelete.get("id"));
              dc.addParam(identifierToDelete.get("id"));
              dc.addParam(identifierToDelete.get("id"));
              dc.addParam(identifierToDelete.get("id"));
              dc.loadResult();
             
              dc.setSQL(deleteInodes);
              dc.addParam(identifierToDelete.get("id"));
              dc.addParam(identifierToDelete.get("id"));
              dc.addParam(identifierToDelete.get("id"));
              dc.loadResult();
            }
          }
         
          if (assetDeleted) {
            dc.setSQL(deleteIdentifier);
            dc.addParam(identifierToDelete.get("id"));
            dc.loadResult();
           
            Logger.debug(this, "Delete completed");
          }
        }
         }
View Full Code Here


    }else if( c.equals(Folder.class)){
      throw new DotStateException("You should use the FolderAPI to get folder information");
    }else if(c.equals(Inode.class)){
      Logger.debug(InodeFactory.class, "You should not send Inode.class to getInode.  Send the extending class instead (inode:" + x + ")" );
      //Thread.dumpStack();
      DotConnect dc = new DotConnect();
      dc.setSQL("select type from inode where inode = ?");
      dc.addParam(x);
      try {
        if(dc.loadResults().size()>0){
          c = InodeUtils.getClassByDBType(dc.getString("type"));
        }
        else{
          Logger.debug(InodeFactory.class,  x + " is not an Inode " );
          return new Inode();
        }
View Full Code Here

        if (!FixAssetsProcessStatus.getRunning()) {
            try {
                FixAssetsProcessStatus.startProgress();
                FixAssetsProcessStatus.setDescription("70 Fix versionInfo");
                int total=0;
                DotConnect dc=new DotConnect();
               
                String[] versionables=new String[] {
                        "file_asset","htmlpage",
                        "template","containers","links"};
                for(String table : versionables) {
                    String vitable=UtilMethods.getVersionInfoTableName(table);
                    String sql = " select distinct id from "+table+" join identifier on (id=identifier) " +
                             " left outer join " + vitable +
                             " on("+table+".identifier="+vitable+".identifier) " +
                             " where working_inode is null";
                    dc.setSQL(sql);
                    List<Map<String, Object>> results = dc.loadObjectResults();
                    for(Map<String, Object> rr : results) {
                        String id=rr.get("id").toString();
                        sql="select inode from "+table+" where identifier=? order by mod_date desc";
                        dc.setSQL(sql);
                        dc.addParam(id);
                        List<Map<String, Object>> versions = dc.loadObjectResults();
                        String inode=versions.get(0).get("inode").toString();
                       
                        HibernateUtil hu=new HibernateUtil(UtilMethods.getVersionableClass(table));
                        Versionable workingVersion=(Versionable) hu.load(inode);
                        APILocator.getVersionableAPI().setWorking(workingVersion);
                       
                        total++;
                    }
                }
               
                // contentlets are different because of language_id
                String sql="select distinct id,language_id from contentlet join identifier on(id=identifier) " +
                       "   left outer join contentlet_version_info " +
                       "   on (contentlet.identifier=contentlet_version_info.identifier " +
                       "   and contentlet.language_id=contentlet_version_info.lang) " +
                       " where working_inode is null";
                dc.setSQL(sql);
                List<Map<String, Object>> results = dc.loadObjectResults();
                for(Map<String, Object> rr : results) {
                    String id=rr.get("id").toString();
                    Integer langId=Integer.parseInt(rr.get("language_id").toString());
                    sql="select inode from contentlet where identifier=? and language_id=? order by mod_date desc";
                    dc.setSQL(sql);
                    dc.addParam(id);
                    dc.addParam(langId);
                    List<Map<String, Object>> versions = dc.loadObjectResults();
                    String inode=versions.get(0).get("inode").toString();
                    APILocator.getVersionableAPI().setWorking(
                       APILocator.getContentletAPI().find(inode, APILocator.getUserAPI().getSystemUser(), false)
                    );
                    total++;
View Full Code Here

    }
   

        // workaround for dbs where we can't have more than one constraint
        // or triggers
        DotConnect db = new DotConnect();
        db.setSQL("delete from tree where child = ? or parent =?");
        db.addParam(inode.getInode());
        db.addParam(inode.getInode());
        db.getResult();
 
        // workaround for dbs where we can't have more than one constraint
        // or triggers
        db.setSQL("delete from multi_tree where child = ? or parent1 =? or parent2 = ?");
        db.addParam(inode.getInode());
        db.addParam(inode.getInode());
        db.addParam(inode.getInode());
        db.getResult();
                   
      HibernateUtil.delete(o);
      db.setSQL("delete from inode where inode = ?");
      db.addParam(inode.getInode());
      db.getResult();
  }
View Full Code Here

      throw new DotStateException("Identifiers are no longer Inodes!");
    }
    try {

      String tableName = ((Inode) c.newInstance()).getType();
      DotConnect db = new DotConnect();
      db
      .setSQL("select count(*) as test from inode, tree where inode.inode = tree.child and tree.parent = ?  and inode.type = '"
          + tableName + "' ");
      db.addParam(i.getInode());
      // db.addParam(tableName);
      return db.getInt("test");
    } catch (Exception e) {
      Logger.warn(InodeFactory.class, "countChildrenOfClass failed:" + e, e);
      throw new DotRuntimeException(e.toString());
      // return 0;
    }
View Full Code Here

       
        if( arrayParams.length() > 0 ) {
          params = arrayParams.toString().substring(0, arrayParams.length() - 1);
        }
 
        DotConnect db = new DotConnect();
        db
        .setSQL("select count(*) as test, inode.type from inode, tree where inode.inode = tree.child and tree.parent = ?  and inode.type IN (" + params + ") group by inode.type");
        db.addParam(i.getInode());
       
        for(String type: types) {
          db.addParam(type);
        }

        ArrayList<Map<String, Object>> results = db.getResults();
        int length = results.size();
        for(n = 0; n < length; n++)
        {
          Map<String, Object> hash = (Map<String, Object>) results.get(n);
          String type = (String) hash.get("type");
View Full Code Here

  }
 
  //http://jira.dotmarketing.net/browse/DOTCMS-3232
    //To Check whether given inode exists in DB or not
  public static boolean isInode(String inode){
    DotConnect dc = new DotConnect();
    String InodeQuery = "Select count(*) as count from inode where inode = ?";
    dc.setSQL(InodeQuery);
    dc.addParam(inode);
    ArrayList<Map<String, String>> results = new ArrayList<Map<String, String>>();
    try {
      results = dc.getResults();
    } catch (DotDataException e) {
      Logger.error(InodeFactory.class,"isInode method failed:"+ e, e);
    }
    int count = Parameter.getInt(results.get(0).get("count"),0);
    if(count > 0){
View Full Code Here

      FixAssetsProcessStatus.setDescription("task 20: DeleteOrphanedIdentifiers");
      HibernateUtil.startTransaction();
      int total=0
      int error=0;
        try {
        DotConnect dc = new DotConnect();
        dc.setSQL(treesToDelete);
        modifiedData = dc.loadResults();
        total = total + dc.getResults().size();
        dc.setSQL(identifiersToDelete);
        modifiedData.addAll(dc.loadResults());
        total = total + dc.getResults().size();
        FixAssetsProcessStatus.setTotal(total);
        getModifiedData();
        if(total > 0){
          try{
          HibernateUtil.startTransaction();
          dc.executeStatement(deleteTreesToDelete);
          dc.executeStatement(deleteIdentifiersToDelete);
          FixAssetsProcessStatus.setError(total);
          /*if(DbConnectionFactory.getDBType().equals(DbConnectionFactory.MYSQL)){
            deleteInodesInMySQL(dc);
          }else{
              dc.executeStatement(deleteIdentifiersToDelete);
View Full Code Here

    if (!FixAssetsProcessStatus.getRunning()) {
      FixAssetsProcessStatus.startProgress();
      FixAssetsProcessStatus.setDescription("task 9: check for contentlets  that points to inexistent inodes and deleted them");     
      HibernateUtil.startTransaction();
      try {
        DotConnect db = new DotConnect();

        int total=0;
        String query = "select * from contentlet c where c.inode not in (select inode from inode where type='contentlet')";
        Logger.debug(CMSMaintenanceFactory.class,
            "Running query for Contentlets: " + query);
        db.setSQL(query);
        List<Map<String, String>> contentletIds = db.getResults();
       
        modifiedData=contentletIds;
        getModifiedData();
        Logger.debug(CMSMaintenanceFactory.class, "Found "
            + contentletIds.size() + " Contentlets");
        total += contentletIds.size();

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

        // Check the working and live versions of contentlets
        String identifierInode;
     


        String inode;

        Logger.info(CMSMaintenanceFactory.class,"deleting " + contentletIds.size()+" contentlets that point to inexistent inodes ");
        for (Map<String, String> identifier : contentletIds) {
          identifierInode = identifier.get("inode");

          Logger.debug(CMSMaintenanceFactory.class,"identifier inode " + identifierInode);

            inode = identifier.get("inode");
            Logger.debug(CMSMaintenanceFactory.class,"Non Working Contentlet inode : " + inode);
            Logger.debug(CMSMaintenanceFactory.class,"Running query: " + fixContentletQuery);
            db.setSQL(fixContentletQuery);
            db.addParam(inode);
            db.getResult();

            FixAssetsProcessStatus.addAError();
            counter++;
          }
       
View Full Code Here

  }
   


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

    String query = "select c.inode from contentlet c where c.inode not in (select inode from inode where type='contentlet') ";
   
    db.setSQL(query);
    List<HashMap<String, String>> contentletIds =null;
    try {
      contentletIds = db.getResults();
    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
    }
    Logger.debug(CMSMaintenanceFactory.class, "Found "
        + contentletIds.size() + " Contentlets");
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.