Package com.dotmarketing.common.db

Examples of com.dotmarketing.common.db.DotConnect


              conn = DbConnectionFactory.getConnection();
            }
            info=cache.get();
            if(info==null) {
                info=new IndiciesInfo();
                DotConnect dc = new DotConnect();
                dc.setSQL("SELECT index_name,index_type FROM indicies");
                List<Map<String,Object>> results=dc.loadResults(conn);
                for(Map<String,Object> rr : results) {
                    String name=(String)rr.get("index_name");
                    String type=(String)rr.get("index_type");
                    if(type.equalsIgnoreCase(IndexTypes.WORKING.toString()))
                        info.working=name;
View Full Code Here


    public void point(IndiciesInfo info) throws DotDataException {
        point(DbConnectionFactory.getConnection(),info);
    }
   
    public void point(Connection conn,IndiciesInfo info) throws DotDataException {
        DotConnect dc = new DotConnect();
       
        // first we delete them all
        dc.setSQL("DELETE FROM indicies");
        dc.loadResult(conn);
       
        final String insertSQL="INSERT INTO indicies VALUES(?,?)";
       
        if(info.working!=null) {
            dc.setSQL(insertSQL);
            dc.addParam(info.working);
            dc.addParam(IndexTypes.WORKING.toString().toLowerCase());
            dc.loadResult(conn);
        }
       
        if(info.live!=null) {
            dc.setSQL(insertSQL);
            dc.addParam(info.live);
            dc.addParam(IndexTypes.LIVE.toString().toLowerCase());
            dc.loadResult(conn);
        }
       
        if(info.reindex_live!=null) {
            dc.setSQL(insertSQL);
            dc.addParam(info.reindex_live);
            dc.addParam(IndexTypes.REINDEX_LIVE.toString().toLowerCase());
            dc.loadResult(conn);
        }
       
        if(info.reindex_working!=null) {
            dc.setSQL(insertSQL);
            dc.addParam(info.reindex_working);
            dc.addParam(IndexTypes.REINDEX_WORKING.toString().toLowerCase());
            dc.loadResult(conn);
        }
       
        if(info.site_search!=null) {
            dc.setSQL(insertSQL);
            dc.addParam(info.site_search);
            dc.addParam(IndexTypes.SITE_SEARCH.toString().toLowerCase());
            dc.loadResult(conn);
        }
       
        cache.clearCache();
       
        HibernateUtil.addCommitListener(new Runnable() {
View Full Code Here

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

        //Tree Query (Child)
        String query =  fix2TreeQuery;
        Logger.debug(CMSMaintenanceFactory.class, "Running query for tree: " + query);
        db.setSQL(query);
        List<Map<String, String>> treeChildren = db.getResults();
        Logger.debug(CMSMaintenanceFactory.class, "Found " + treeChildren.size() + " Tree");
        int total = treeChildren.size();
       
        //Tree Query (Child)
        query =  fix3TreeQuery;
        Logger.debug(CMSMaintenanceFactory.class,"Running query for tree: " + query);
        db.setSQL(query);
        List<HashMap<String, String>> treeParents = db.getResults();
        Logger.debug(CMSMaintenanceFactory.class,"Found " + treeParents.size() + " Tree");
        total += treeParents.size();       
       
        Logger.info(CMSMaintenanceFactory.class,"Total number of assets: " + total);
        FixAssetsProcessStatus.setTotal(total);
       
        long inodeInode;
        long parentIdentifierInode;

       
        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 tree entries that doesn't have a child o parent in the inode table
        treeChildren.addAll(treeParents);
        modifiedData=treeChildren;
        getModifiedData();
        Logger.info(CMSMaintenanceFactory.class,"Fixing " + treeChildren.size()+ " tree entries");
        for (Map<String, String> tree : treeChildren)
        {           
            Logger.debug(CMSMaintenanceFactory.class,"Running query: "+ fix4TreeQuery);         
            try
            {
              db.setSQL(fix4TreeQuery);
              db.addParam(tree.get("child"));
              db.addParam(tree.get("parent"));
              db.addParam(tree.get("relation_type"));
              db.getResults();
            }
            catch(Exception ex)
            {
              FixAssetsProcessStatus.addAError();
              counter++;
View Full Code Here

    return modifiedData;
  }


  public boolean shouldRun() {
    DotConnect db = new DotConnect();
   
    //final String fix2TreeQuery = "select child,parent,relation_type from tree left join inode on tree.child  = inode.inode where inode.inode is null";
    //final String fix3TreeQuery = "select child,parent,relation_type from tree left join inode on tree.parent = inode.inode where inode.inode is null";
    final String fix2TreeQuery = "select child,parent,relation_type from tree left join inode on tree.child  = inode.inode left join identifier " +
                   "on tree.child = identifier.id where inode.inode is null and identifier.id is null ";
   
    final String fix3TreeQuery = "select child,parent,relation_type from tree left join inode on tree.parent = inode.inode left join identifier " +
                   "on tree.parent = identifier.id where inode.inode is null and identifier.id is null";



    //Tree Query (Child)
    String query =  fix2TreeQuery;
    Logger.debug(CMSMaintenanceFactory.class, "Running query for tree: " + query);
    db.setSQL(query);
    List<HashMap<String, String>> treeChildren =null ;
    try {
      treeChildren = db.getResults();
    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
    }
    Logger.debug(CMSMaintenanceFactory.class, "Found " + treeChildren.size() + " Tree");
    int total = treeChildren.size();
   
    //Tree Query (Child)
    query =  fix3TreeQuery;
    Logger.debug(CMSMaintenanceFactory.class,"Running query for tree: " + query);
    db.setSQL(query);
    List<HashMap<String, String>> treeParents =null ;
    try {
      treeParents = db.getResults();
    } catch (DotDataException e) {
      Logger.error(this,e.getMessage(), e);
    }
    Logger.debug(CMSMaintenanceFactory.class,"Found " + treeParents.size() + " Tree");
    total += treeParents.size();       
View Full Code Here

      FixAssetsProcessStatus.startProgress();
      FixAssetsProcessStatus.setDescription("task 40: CheckFileAssetsMimeType");
      HibernateUtil.startTransaction();
      int total = 0;
       try {
           DotConnect dc = new DotConnect();
           dc.setSQL(filesWithInvalidMimeType);
           List<Map<String, String>> filesWithInvalidMimeTypeResult = dc.loadResults();
       
           total = total + filesWithInvalidMimeTypeResult.size();
           FixAssetsProcessStatus.setTotal(total);
   
           if ((filesWithInvalidMimeTypeResult != null) && (0 < filesWithInvalidMimeTypeResult.size())) {
     
             Map<String, String> fileWithInvalidMimeType;
             String mimeType;
             for (int i = 0; i < filesWithInvalidMimeTypeResult.size(); ++i) {
           fileWithInvalidMimeType = filesWithInvalidMimeTypeResult.get(i);
           mimeType = Config.CONTEXT.getMimeType(fileWithInvalidMimeType.get("file_name"));
         
           if (!UtilMethods.isSet(mimeType)) {
            mimeType = com.dotmarketing.portlets.files.model.File.UNKNOWN_MIME_TYPE;
           }
         
           modifiedData.add(fileWithInvalidMimeType);
         
          dc.setSQL(updateFileWithInvalidMimeType);
          dc.addParam(mimeType);
          dc.addParam(fileWithInvalidMimeType.get("inode"));
          dc.loadResult();
        }
       
        if (DbConnectionFactory.isPostgres()) {
          dc.setSQL(addFileAssetMimeTypeNotNullPostgres);
          dc.loadResult();
        } else if (DbConnectionFactory.isMySql()) {
          dc.setSQL(addFileAssetMimeTypeNotNullMySQL);
          dc.loadResult();
        } else if (DbConnectionFactory.isOracle()) {
          dc.setSQL(addFileAssetMimeTypeNotNullOracle);
          dc.loadResult();
        } else if (DbConnectionFactory.isMsSql()) {
          dc.setSQL(addFileAssetMimeTypeNotNullMSSQL);
          dc.loadResult();
        }
      }
        FixAudit Audit = new FixAudit();
      Audit.setTableName("file_asset");
      Audit.setDatetime(new Date());
View Full Code Here

   
    List<Tag> tags = new ArrayList<Tag>();
   
    try {
      if(userIds!=null && !userIds.isEmpty()){
        DotConnect dc = new DotConnect();
        dc.setSQL("select tagname, user_id from tag where user_id is not null");
       
        //Gets all the tags from DB that are not null.
        List<Map<String, Object>> results = (ArrayList<Map<String, Object>>)dc.loadResults();
       
        //Checks each of the tag to see if match any of the users in the list.
        for (int i = 0; i < results.size(); i++) {
          Map<String, Object> hash = (Map<String, Object>) results.get(i);
         
View Full Code Here

    Inode inode3 = (Inode) o3;

    try {


      DotConnect db = new DotConnect();
      db.setSQL("delete from multi_tree where parent1 =? and parent2 = ? and child = ? ");
      db.addParam(inode1.getInode());
      db.addParam(inode2.getInode());
      db.addParam(inode3.getInode());
      db.getResult();
    }
    catch (Exception e) {
      throw new DotRuntimeException(e.getMessage());
    }
View Full Code Here

    Inode inode2 = (Inode) o2;
    Inode inode3 = (Inode) o3;

    try {

      DotConnect db = new DotConnect();
      db.setSQL("select count(*) mycount from multi_tree where parent1 =? and parent2 = ? and child = ? ");
      db.addParam(inode1.getInode());
      db.addParam(inode2.getInode());
      db.addParam(inode3.getInode());
     
      int count = db.getInt("mycount");
     
      return (count > 0);
    }
    catch (Exception e) {
      throw new DotRuntimeException(e.getMessage());
View Full Code Here

  @SuppressWarnings({ "unchecked", "deprecation" })
  public List<Map<String, Object>> executeFix() throws DotDataException,
      DotRuntimeException {
    List<Map<String, Object>> returnValue = new ArrayList<Map<String, Object>>();
    Logger.info(FixTask00021CheckOrphanedAssets.class,"Beginning CheckOrphanedAssets");
    DotConnect dc = new DotConnect();
    /*Host host = null;
    String hostId = "";
    Folder folder = null;
    FolderAPI folderAPI = APILocator.getFolderAPI();*/
    //String identifier = null;
    if (!FixAssetsProcessStatus.getRunning()) {
      FixAssetsProcessStatus.startProgress();
      FixAssetsProcessStatus.setDescription("task 21: CheckOrphanedAssets");
      HibernateUtil.startTransaction();
      int total=0;     
         try {
        User user = APILocator.getUserAPI().getSystemUser();
        /*String query = "SELECT * FROM inode WHERE (type='file_asset' or type='htmlpage') " +
                    "and inode NOT IN (SELECT child FROM tree WHERE parent in (SELECT inode from folder))";*/
          String hostQuery = "select distinct host_inode from identifier";
          dc.setSQL(hostQuery);
          List<HashMap<String, String>> hosts = dc.getResults();
          for(HashMap<String, String> host1 : hosts){
           String hostInode = host1.get("host_inode");
           if(UtilMethods.isSet(hostInode)){
             String query = " SELECT * FROM identifier WHERE (asset_type='file_asset' or asset_type='htmlpage') " +
                         " and host_inode = ? " +
                         " and id NOT IN (SELECT identifier FROM folder where host_inode = ?) ";

             dc.setSQL(query);
             dc.addParam(hostInode);
             dc.addParam(hostInode);
             List<HashMap<String, String>> assetIds = dc.getResults();
             total = total + assetIds.size();
             FixAssetsProcessStatus.setTotal(total);
             for(HashMap<String, String> asset:assetIds){
               String identifier = asset.get("id");
               if(APILocator.getIdentifierAPI().isIdentifier(identifier)){
View Full Code Here

    }
  }

  @SuppressWarnings({ "unchecked", "deprecation" })
  public boolean shouldRun() {
    DotConnect dc = new DotConnect();
    /*String query = "SELECT * FROM inode WHERE (type='file_asset' or type='htmlpage') " +
               "and inode NOT IN (SELECT child FROM tree WHERE parent in (SELECT inode from folder))";*/
    int total = 0;
    String hostQuery = " select distinct host_inode from identifier ";
    dc.setSQL(hostQuery);
    List<HashMap<String, String>> hosts =null;
    try {
      hosts = dc.getResults();
      for(HashMap<String, String> host : hosts){
        String hostInode = host.get("host_inode");
        if(UtilMethods.isSet(hostInode)){
          String query = " SELECT * FROM identifier WHERE (asset_type='file_asset' or asset_type='htmlpage') " +
                      " and host_inode = ? " +
                      " and id NOT IN (SELECT identifier FROM folder where host_inode = ?) ";

          dc.setSQL(query);
          dc.addParam(hostInode);
          dc.addParam(hostInode);
          List<HashMap<String, String>> assetIds ;
          assetIds = dc.getResults();
          total = total + assetIds.size();
        }
      }
    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
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.