Package com.dotmarketing.db

Examples of com.dotmarketing.db.HibernateUtil


   * @return a list of tags filtered by tag name or host name
   */
  public java.util.List<Tag> getFilteredTags(String tagName, String hostFilter, boolean globalTagsFilter, String sort, int start, int count) {
        try {

          HibernateUtil dh = new HibernateUtil(Tag.class);
          List list = new java.util.ArrayList();

        Host host = null;
        try {
          host = APILocator.getHostAPI().find(hostFilter, APILocator.getUserAPI().getSystemUser(), true);
        }catch (Exception e){
          Logger.warn(Tag.class, "Unable to get host according to search criteria - hostId = "+ hostFilter);
        }
      if (UtilMethods.isSet(host)){

        String sortStr = "";
        if (UtilMethods.isSet(sort)) {
                String sortDirection = sort.startsWith("-")?"desc":"asc";
            sort = sort.startsWith("-")?sort.substring(1,sort.length()):sort;

            if(sort.equalsIgnoreCase("hostname")) sort = "host_id";

            sortStr = " order by " + sort + " " + sortDirection;
        } else {
          sortStr = "order by tagname";
        }

        //if tag name and host name are set as filters
        //search by name, global tags and current host.
        if(UtilMethods.isSet(tagName) && globalTagsFilter){
            dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where lower(tagname) like ? and (host_id = ? or host_id = ?) " + sortStr);
                  dh.setParam("%" + tagName.toLowerCase()  + "%");
                  try {
              dh.setParam(host.getMap().get("tagStorage").toString());
            } catch(NullPointerException e) {
              dh.setParam(Host.SYSTEM_HOST);
            }
                  dh.setParam(Host.SYSTEM_HOST);
        }
        //if global host is not set as unique filter but tag name is set, search in current host
        else if (UtilMethods.isSet(tagName) && !globalTagsFilter){
            dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where lower(tagname) like ? and (host_id = ?) " + sortStr);
            dh.setParam("%" + tagName.toLowerCase() + "%");
            try {
              dh.setParam(host.getMap().get("tagStorage").toString());
            } catch(NullPointerException e) {
              dh.setParam(Host.SYSTEM_HOST);
            }
        }else if(!UtilMethods.isSet(tagName) && globalTagsFilter){
               //check if tag name is not set and if should display global tags
               //it will check all global tags and current host tags.
          dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where "+
                  "(host_id = ? or host_id = ? ) " + sortStr);

          try {
              dh.setParam(host.getMap().get("tagStorage").toString());
            } catch(NullPointerException e) {
              dh.setParam(Host.SYSTEM_HOST);
            }
                dh.setParam(Host.SYSTEM_HOST);
        } else {
          //check all current host tags.
          String sql =  "from tag in class com.dotmarketing.tag.model.Tag ";
         
          Object tagStorage = host.getMap().get("tagStorage");
         
          if(UtilMethods.isSet(tagStorage)){
            sql = sql + "where ( host_id = ? ) " + sortStr;
            dh.setQuery(sql);
            dh.setParam(tagStorage.toString());
          }else{
            dh.setQuery(sql);
          }
        }

        dh.setFirstResult(start);

        list = dh.list();

            return list;
      }
        } catch (Exception e) {
            Logger.warn(Tag.class, "getFilteredTags failed:" + e, e);
View Full Code Here


     * @param tagId tagId of the object tagged
     * @return list of all the TagInode where the tags are associated to the object
     */
  public static List<TagInode> getTagInodeByTagId(String tagId) {
        try {
            HibernateUtil dh = new HibernateUtil(TagInode.class);
            dh.setQuery("from tag_inode in class com.dotmarketing.tag.model.TagInode where tag_id = ?");
            dh.setParam(tagId);

            List list = dh.list();
          return list;

        } catch (Exception e) {
            Logger.warn(Tag.class, "getTagInodeByTagId failed:" + e, e);
        }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public static java.util.List<MultiTree> getMultiTree(String parentInode) {
    try {
      HibernateUtil dh = new HibernateUtil(MultiTree.class);
      dh.setQuery("from multi_tree in class com.dotmarketing.beans.MultiTree where parent1 = ? or parent2 = ? ");
      dh.setParam(parentInode);
      dh.setParam(parentInode);

      return dh.list();
           
    } catch (Exception e) {
            Logger.error(MultiTreeFactory.class, "getMultiTree failed:" + e, e);
      throw new DotRuntimeException(e.toString());
    }
View Full Code Here

   * @return tag
   * @throws DotHibernateException
   */
  public static Tag getTagByTagId(String tagId) throws DotHibernateException {

        HibernateUtil dh = new HibernateUtil(Tag.class);

      dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where tag_id = ?");
        dh.setParam(tagId);

        Tag tag = (Tag) dh.load();

        return tag;
  }
View Full Code Here

    //return new java.util.ArrayList();
  }
  @SuppressWarnings("unchecked")
  public static java.util.List<MultiTree> getMultiTree(HTMLPage htmlPage, Container container) {
    try {
      HibernateUtil dh = new HibernateUtil(MultiTree.class);
      dh.setQuery("from multi_tree in class com.dotmarketing.beans.MultiTree where parent1 = ? and parent2 = ? ");
      dh.setParam(htmlPage.getIdentifier());
      dh.setParam(container.getIdentifier());

      return dh.list();
           
    } catch (Exception e) {
            Logger.error(MultiTreeFactory.class, "getMultiTree failed:" + e, e);
      throw new DotRuntimeException(e.toString());
    }
View Full Code Here

  public static void updateTagReferences (String hostIdentifier, String oldTagStorageId, String newTagStorageId) {
    try {
            if(!oldTagStorageId.equals(Host.SYSTEM_HOST) && !oldTagStorageId.equals(newTagStorageId)) {
              //copy or update tags if the tag storage id has changed when editing the host
              //or if the previous tag storage was global
          HibernateUtil dh = new HibernateUtil(Tag.class);
          dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where host_id = ?");
          dh.setParam(oldTagStorageId);
                List<Tag> list = (List<Tag>)dh.list();
              for (Tag tag: list){
                  try{
                  if(hostIdentifier.equals(newTagStorageId) && !newTagStorageId.equals(Host.SYSTEM_HOST)){
                        //copy old tag to host with new tag storage
                        tag = saveTag(tag.getTagName(), "", hostIdentifier);
View Full Code Here

   * @return tag
   * @throws DotHibernateException
   */
  public static Tag getTagByTagIdAndHostId(String tagId, String hostId) throws DotHibernateException {

        HibernateUtil dh = new HibernateUtil(Tag.class);

      dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where tag_id = ? and host_id = ?");
        dh.setParam(tagId);
        dh.setParam(hostId);

        Tag tag = (Tag) dh.load();

        return tag;
  }
View Full Code Here

   * Jun 26, 2013 - 12:34:29 PM
   */
  @SuppressWarnings("unchecked")
  public static java.util.List<MultiTree> getContainerMultiTree(String containerIdentifier) {
    try {
      HibernateUtil dh = new HibernateUtil(MultiTree.class);
      dh.setQuery("from multi_tree in class com.dotmarketing.beans.MultiTree where parent1 = ? or parent2 = ? or child = ?");
      dh.setParam(containerIdentifier);
      dh.setParam(containerIdentifier);
      dh.setParam(containerIdentifier);

      return dh.list();
           
    } catch (Exception e) {
            Logger.error(MultiTreeFactory.class, "getContainerMultiTree failed:" + e, e);
      throw new DotRuntimeException(e.toString());
    }
View Full Code Here

        }
        catch (Exception e) {
          Logger.error(this, "Unable to load current host.");
        }*/

      HibernateUtil dh = new HibernateUtil(Tag.class);
      dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where lower(tagname) like ? and (host_id like ? OR host_id like ?)");
          dh.setParam("%" + name.toLowerCase() + "%");
          /*
          if(UtilMethods.isSet(selectedHostId)){
            //if structure has a host field, search in selected host
            dh.setParam(selectedHostId);
          } else {
            //search in tag storage for current host
            dh.setParam(hostId);
          }*/
          //search global
          dh.setParam(selectedHostId);
          dh.setParam(Host.SYSTEM_HOST);
            List<Tag> list = dh.list();
          return list;
    }
    catch (Exception e) {}
    return new ArrayList<Tag>();
  }
View Full Code Here

    //return new java.util.ArrayList();
  }
  @SuppressWarnings("unchecked")
  public static java.util.List<MultiTree> getMultiTreeByChild(String contentIdentifier) {
    try {
      HibernateUtil dh = new HibernateUtil(MultiTree.class);
      dh.setQuery("from multi_tree in class com.dotmarketing.beans.MultiTree where child = ? ");
      dh.setParam(contentIdentifier);

      return dh.list();
           
    } catch (Exception e) {
            Logger.error(MultiTreeFactory.class, "getMultiTreeByChild failed:" + e, e);
      throw new DotRuntimeException(e.toString());
    }
View Full Code Here

TOP

Related Classes of com.dotmarketing.db.HibernateUtil

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.