agave-tags/tags-core/src/main/java/org/iplantc/service/tags/dao/TagDao.java
/**
	 * Finds a {@link Tag} for the given owner by name. In the event of a namespace 
	 * conflict where the owner created a tag with the name of a tag that was
	 * also shared with them, their personal tag is always returned.
	 *  
	 * @param name the name of the tag to search
	 * @param owner the owner of the tag
	 * @return a {@link Tag} matching the given {@code name} with the given {@code owner} or null if no match
	 * @throws TagException if unable to query
	 */
Finds a  Tag for the given owner by name. In the event of a namespace
conflict where the owner created a tag with the name of a tag that was
also shared with them, their personal tag is always returned.

@param name the name of the tag to search
@param owner the owner of the tag
@return a  Tag matching the given  name with the given  owner or null if no match
@throws TagException if unable to query
Finds a Tag for the given owner by name . In the event of a namespace conflict where the owner created a tag with the name of a tag that was also shared with them their personal tag is always returned . @param name the name of the tag to search @param owner the owner of the tag @return a Tag matching the given name with the given owner or null if no match @throws TagException if unable to query
@SuppressWarnings("unchecked")
	public Tag findByNameAndOwner(String name, String owner) 
	throws TagException 
	{
		try
		{	
			HibernateUtil.beginTransaction();
			Session session = HibernateUtil.getSession();
			session.clear();
			String hql = "from Tag t where t.name = :name and " +
					"		( " +
					"			t.owner = :owner OR \n" +
                    "	        t.id in ( \n" + 
                    "               SELECT tp.entityId FROM TagPermission tp \n" +
                    "               WHERE tp.username = :owner AND tp.permission <> :none \n" +
                    "           ) \n" +
                    "       )";
			List<Tag> tags = (List<Tag>)session.createQuery(hql)
					.setString("name",name)
					.setString("owner", owner)
					.setString("none", PermissionType.NONE.name())
					.list();
			session.flush();
			if (tags.size() > 0) {
				for (Tag tag: tags) {
					if (StringUtils.equals(tag.getOwner(), owner)) {
						return tag;
					}
				}
			}
			return null;
		}
		catch (HibernateException ex)
		{
			try
			{
				if (HibernateUtil.getSession().isOpen()) {
					HibernateUtil.rollbackTransaction();
				}
			}
			catch (Exception ignored) {}
			throw new TagException(ex);
		}
		finally {
			try { HibernateUtil.commitTransaction(); } catch (Exception ignored) {}
		}
	}
@ SuppressWarnings ( "unchecked" ) public Tag findByNameAndOwner ( String name , String owner ) throws TagException { try { HibernateUtil . beginTransaction ( ) ; Session session = HibernateUtil . getSession ( ) ; session . clear ( ) ; String hql = "from Tag t where t.name = :name and " + "		( " + "			t.owner = :owner OR \n" + "	        t.id in ( \n" + "               SELECT tp.entityId FROM TagPermission tp \n" + "               WHERE tp.username = :owner AND tp.permission <> :none \n" + "           ) \n" + "       )" ; List < Tag > tags = ( List < Tag > ) session . createQuery ( hql ) . setString ( "name" , name ) . setString ( "owner" , owner ) . setString ( "none" , PermissionType . NONE . name ( ) ) . list ( ) ; session . flush ( ) ; if ( tags . size ( ) > 0 ) { for ( Tag tag : tags ) { if ( StringUtils . equals ( tag . getOwner ( ) , owner ) ) { return tag ; } } } return null ; } catch ( HibernateException ex ) { try { if ( HibernateUtil . getSession ( ) . isOpen ( ) ) { HibernateUtil . rollbackTransaction ( ) ; } } catch ( Exception ignored ) { } throw new TagException ( ex ) ; } finally { try { HibernateUtil . commitTransaction ( ) ; } catch ( Exception ignored ) { } } }
Finds a {@link Tag} for the given owner by name.
Finds a { @link Tag } for the given owner by name .