package mit.roles ;

public class Qualifier
implements roles.Qualifier
{
	private static String QUALIFIER_ID = "QUALIFIER_ID" ;
	private static String QUALIFIER_CODE = "QUALIFIER_CODE" ;
	private static String QUALIFIER_DESCRIPTION = "QUALIFIER_NAME" ;
	private static String QUALIFIER_TYPE = "QUALIFIER_TYPE" ;
	private static String HAS_CHILD = "HAS_CHILD" ;

	private mit.roles.RolesFactory rolesFactory = null ;
	public mit.roles.RolesFactory getRolesFactory() { return rolesFactory ; }
	protected void setRolesFactory( mit.roles.RolesFactory rFactory )
		{ rolesFactory = rFactory ; }

	private java.util.Properties properties = null ;
	public java.util.Properties getProperties() { return this.properties ; }
	private void setProperties( java.util.Properties properties )
		{ this.properties = properties ; }

	public Object getId()
	{
		if( null != this.properties )
		{
			return this.properties.get( QUALIFIER_ID ) ;
		}
		return null ;
	}
	public void setId( Object id )
	{
		if( null == this.properties )
		{
			this.properties = new java.util.Properties() ;
		}
		this.properties.put( QUALIFIER_ID , id ) ;
	}

	public String getCode()
	{
		if( null != this.properties )
		{
			return ( String ) this.properties.get( QUALIFIER_CODE ) ;
		}
		return null ;
	}
	public void setCode( String code )
	{
		if( null == this.properties )
		{
			this.properties = new java.util.Properties() ;
		}
		this.properties.put( QUALIFIER_CODE , code ) ;
	}

	public String getDescription()
	{
		if( null != this.properties )
		{
			return ( String ) this.properties.get( QUALIFIER_DESCRIPTION ) ;
		}
		return null ;
	}
	protected void setDescription( String description )
	{
		if( null == this.properties )
		{
			this.properties = new java.util.Properties() ;
		}
		this.properties.put( QUALIFIER_DESCRIPTION , description ) ;
	}

	public roles.QualifierType getQualifierType()
	{
		if( null != this.properties )
		{
			return ( roles.QualifierType ) this.properties.get( QUALIFIER_TYPE ) ;
		}
		return null ;
	}
	public void setQualifierType( roles.QualifierType qualifierType )
	{
		if( null == this.properties )
		{
			this.properties = new java.util.Properties() ;
		}
		this.properties.put( QUALIFIER_TYPE , qualifierType ) ;
	}

	public Boolean getHasChild()
	{
		if( null != this.properties )
		{
			return ( Boolean ) this.properties.get( HAS_CHILD ) ;
		}
		return null ;
	}
	protected void setHasChild( Boolean hasChild )
	{
		if( null == this.properties )
		{
			this.properties = new java.util.Properties() ;
		}
		this.properties.put( HAS_CHILD , hasChild ) ;
	}

	private Boolean foundInRoles = new Boolean( false ) ;
	public Boolean isFoundInRoles()
		throws Exception
	{
		if( ! this.foundInRoles.booleanValue() )
		{
			this.foundInRoles
				= new Boolean( isIdInRoles() || isCodeAndTypeInRoles() ) ;
		}
		return this.foundInRoles ;
	}

	public void refresh()
		throws Exception
	{
		if( ! isIdInRoles() )
		{
			isCodeAndTypeInRoles() ;
		}
	}

	public Qualifier
		( mit.roles.RolesFactory rolesFactory
		, java.util.Properties properties
		)
	{
		setRolesFactory( rolesFactory ) ;
		setProperties( properties ) ;
	}

	public Qualifier
		( mit.roles.RolesFactory rolesFactory
		, String code
		, String description
		, roles.QualifierType qualifierType
		)
	{
		setRolesFactory( rolesFactory ) ;
		setCode( code ) ;
		setDescription( description ) ;
		setQualifierType( qualifierType ) ;
	}

	public Qualifier
		( mit.roles.RolesFactory rolesFactory
		, Object id
		, String code
		, String description
		, roles.QualifierType qualifierType
		)
	{
		setRolesFactory( rolesFactory ) ;
		setId( id ) ;
		setCode( code ) ;
		setDescription( description ) ;
		setQualifierType( qualifierType ) ;
	}

	protected Qualifier
		( mit.roles.RolesFactory rolesFactory
		, Object id
		, String code
		, String description
		, roles.QualifierType qualifierType
		, Boolean hasChild
		)
	{
		setRolesFactory( rolesFactory ) ;
		setId( id ) ;
		setCode( code ) ;
		setDescription( description ) ;
		setQualifierType( qualifierType ) ;
		setHasChild( hasChild ) ;
	}

	public void delete()
		throws Exception
	{
		if( ( null != getRolesFactory() )
		&&  ( null != getRolesFactory().getConnection() )
		&&
			(  ( null != getId() )
			|| ( ( null != getQualifierType() ) && ( null != getCode() ) )
			)
		)
		{
			sql.Connection connection = getRolesFactory().getConnection() ;

			Object[] args = new Object[ 3 ] ;
			args[ 0 ] = getQualifierType().getType() ;
			args[ 1 ] = getCode() ;
			args[ 2 ]
				= (
					( null != getRolesFactory().getForUser() )
					? ( ( mit.roles.Person ) getRolesFactory().getForUser() ).getKerberosName()
					: null
				) ;
			int[] columnTypes = new int[ 3 ] ;
			columnTypes[ 0 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 1 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 2 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			int[] dataTypes = new int[ 3 ] ;
			dataTypes[ 0 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 1 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 2 ] = java.sql.Types.VARCHAR ;
			connection.callProcedure
				( "AUTH_SP_DELETE_QUAL"
				, args
				, columnTypes
				, dataTypes
				) ;
			setRolesFactory( null ) ;
			setId( null ) ;
			setCode( null ) ;
			setDescription( null ) ;
			setQualifierType( null ) ;
			setHasChild( null ) ;
			return ;
		}
		throw new roles.RolesException( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	public void update
		( String newQualifierCode
		, String newDescription
		)
		throws Exception
	{
		if( ( null != getRolesFactory() )
		&&  ( null != getRolesFactory().getConnection() )
		&&  ( null != getId() )
		)
		{
			sql.Connection connection = getRolesFactory().getConnection() ;
			Object[] args = new Object[ 4 ] ;
			args[ 0 ] = getQualifierType().getType() ;
			args[ 1 ] = getCode() ;
			args[ 3 ]
				= (
					( null != getRolesFactory().getForUser() )
					? ( ( mit.roles.Person ) getRolesFactory().getForUser() ).getKerberosName()
					: null
				) ;
			int[] columnTypes = new int[ 4 ] ;
			columnTypes[ 0 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 1 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 2 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 3 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			int[] dataTypes = new int[ 4 ] ;
			dataTypes[ 0 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 1 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 2 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 3 ] = java.sql.Types.VARCHAR ;
			if( null != newDescription )
			{
				args[ 2 ] = newDescription ;
				connection.callProcedure
					( "AUTH_SP_UPDATE_QUALNAME"
					, args
					, columnTypes
					, dataTypes
					) ;
				setDescription( newDescription ) ;
			}
			if( null != newQualifierCode )
			{
				args[ 2 ] = newQualifierCode ;
				connection.callProcedure
					( "AUTH_SP_UPDATE_QUALCODE"
					, args
					, columnTypes
					, dataTypes
					) ;
				setCode( newQualifierCode ) ;
			}
			return ;
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	public void addLink
		( roles.Qualifier parent
		)
		throws Exception
	{
		if( ( null != getRolesFactory() )
		&&  ( null != getRolesFactory().getConnection() )
		&&  ( null != getId() )
		&&  ( null != parent )
		)
		{
			sql.Connection connection = getRolesFactory().getConnection() ;
			Object[] args = new Object[ 5 ] ;
			args[ 0 ] = getQualifierType().getType() ;
			args[ 1 ] = getCode() ;
			args[ 2 ] = ( ( mit.roles.Qualifier ) parent ).getId() ;
			args[ 3 ] = null ;
			args[ 4 ]
				= (
					( null != getRolesFactory().getForUser() )
					? ( ( mit.roles.Person ) getRolesFactory().getForUser() ).getKerberosName()
					: null
				) ;
			int[] columnTypes = new int[ 5 ] ;
			columnTypes[ 0 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 1 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 2 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 3 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 4 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			int[] dataTypes = new int[ 5 ] ;
			dataTypes[ 0 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 1 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 2 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 3 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 4 ] = java.sql.Types.VARCHAR ;
			connection.callProcedure
				( "AUTH_SP_UPDATE_QUALPAR"
				, args
				, columnTypes
				, dataTypes
				) ;
			return ;
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	public void deleteLink()
		throws Exception
	{
		if( ( null != getRolesFactory() )
		&&  ( null != getRolesFactory().getConnection() )
		&&  ( null != getId() )
		)
		{
			sql.Connection connection = getRolesFactory().getConnection() ;
			Object[] args = new Object[ 5 ] ;
			args[ 0 ] = getQualifierType().getType() ;
			args[ 1 ] = getCode() ;
			args[ 2 ] = null ;
			args[ 3 ] = null ;
			args[ 4 ]
				= (
					( null != getRolesFactory().getForUser() )
					? ( ( mit.roles.Person ) getRolesFactory().getForUser() ) .getKerberosName()
					: null
				) ;
			int[] columnTypes = new int[ 5 ] ;
			columnTypes[ 0 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 1 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 2 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 3 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 4 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			int[] dataTypes = new int[ 5 ] ;
			dataTypes[ 0 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 1 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 2 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 3 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 4 ] = java.sql.Types.VARCHAR ;
			connection.callProcedure
				( "AUTH_SP_UPDATE_QUALPAR"
				, args
				, columnTypes
				, dataTypes
				) ;
			return ;
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	public void moveLink
		( roles.Qualifier oldParent
		, roles.Qualifier newParent
		)
		throws Exception
	{
		if( ( null != getRolesFactory() )
		&&  ( null != getRolesFactory().getConnection() )
		&&  ( null != getId() )
		&&  ( null != oldParent )
		&&  ( null != newParent )
		)
		{
			sql.Connection connection = getRolesFactory().getConnection() ;
			Object[] args = new Object[ 5 ] ;
			args[ 0 ] = getQualifierType().getType() ;
			args[ 1 ] = getCode() ;
			args[ 2 ] = ( ( mit.roles.Qualifier ) oldParent ).getId() ;
			args[ 3 ] = ( ( mit.roles.Qualifier ) newParent ).getId() ;
			args[ 4 ]
				= (
					( null != getRolesFactory().getForUser() )
					? ( ( mit.roles.Person ) getRolesFactory().getForUser() ).getKerberosName()
					: null
				) ;
			int[] columnTypes = new int[ 5 ] ;
			columnTypes[ 0 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 1 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 2 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 3 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 4 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			int[] dataTypes = new int[ 5 ] ;
			dataTypes[ 0 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 1 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 2 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 3 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 4 ] = java.sql.Types.VARCHAR ;
			connection.callProcedure
				( "AUTH_SP_UPDATE_QUALPAR"
				, args
				, columnTypes
				, dataTypes
				) ;
			return ;
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	public static roles.Qualifier create
		( mit.roles.RolesFactory rolesFactory
		, roles.QualifierType qualifierType
		, String qualifierCode
		, String qualifierDescription
		, roles.Qualifier parent
		)
		throws Exception
	{
		if( ( null != rolesFactory )
		&&  ( null != rolesFactory.getConnection() )
		&&  ( null != qualifierType )
		&&  ( null != qualifierCode )
		&&  ( null != qualifierDescription )
		&&  ( null != parent )
		)
		{
			sql.Connection connection = rolesFactory.getConnection() ;
			Object[] args = new Object[ 5 ] ;
			args[ 0 ] = ( ( mit.roles.QualifierType ) qualifierType ).getType() ;
			args[ 1 ] = qualifierCode ;
			args[ 2 ]
				= (
					( ( null != parent ) && ( null != parent.getCode() ) )
					? parent.getCode()
					: null
				) ;
			args[ 3 ] = qualifierDescription ;
			args[ 4 ]
				= (
					( null != rolesFactory.getForUser() )
					? ( ( mit.roles.Person ) rolesFactory.getForUser() ).getKerberosName()
					: null
				) ;
			int[] columnTypes = new int[ 5 ] ;
			columnTypes[ 0 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 1 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 2 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 3 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			columnTypes[ 4 ] = java.sql.DatabaseMetaData.procedureColumnIn ;
			int[] dataTypes = new int[ 5 ] ;
			dataTypes[ 0 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 1 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 2 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 3 ] = java.sql.Types.VARCHAR ;
			dataTypes[ 4 ] = java.sql.Types.VARCHAR ;
			connection.callProcedure
				( "ROLESAPI_CREATE_QUALIFIER"
				, args
				, columnTypes
				, dataTypes
				) ;
			mit.roles.Qualifier qualifier
				= getQualifier
					( rolesFactory
					, qualifierCode
					, qualifierType
					) ;
			if( null != qualifier )
			{
				return ( roles.Qualifier ) qualifier ;
			}
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	private static String getQualifierCode
		( mit.roles.RolesFactory rolesFactory
		, String qualifierId
		)
		throws Exception
	{
		if( ( null != rolesFactory )
		&&  ( null != rolesFactory.getConnection() )
		&&  ( null != qualifierId )
		)
		{
			sql.Connection connection = rolesFactory.getConnection() ;
			sql.Table table
				= connection.executeQuery
					( new String
						( "select qualifier_code "
						+ "from qualifier "
						+ "where qualifier_id = "
						+ qualifierId
						+ " ;"
						)
					) ;
			if( null != table )
			{
				sql.Rows rows = table.getRows() ;
				if( rows.hasMoreRows() )
				{
					Object[] row = rows.nextRow() ;
					String qualifierCode
						= ( String ) row[ rows.getColumn( QUALIFIER_CODE ) ] ;
					return qualifierCode ;
				}
			}
			throw new roles.RolesException
				( roles.RolesException.QUALIFIERNOTFOUNDINROLES ) ;
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	public static mit.roles.Qualifier getRootQualifier
		( mit.roles.RolesFactory rolesFactory
		, roles.QualifierType qualifierType
		)
		throws Exception
	{
		if( ( null != rolesFactory )
		&&  ( null != rolesFactory.getConnection() )
		)
		{
			sql.Connection connection = rolesFactory.getConnection() ;
			sql.Table table
				= connection.executeQuery
					( new String
						( "select "
						+ "q.qualifier_id, q.qualifier_code, q.qualifier_name "
						+ "q.qualifier_type, q.has_child "
						+ "from qualifier q "
						+ "where "
						+ "qualifier_type = " + ( ( mit.roles.QualifierType ) qualifierType ).getType()
						+ " and q.qualifier_level = 1 "
						+ " ;"
						)
					) ;
			if( null != table )
			{
				sql.Rows rows = table.getRows() ;
				if( rows.hasMoreRows() )
				{
					Object[] row = rows.nextRow() ;
					mit.roles.Qualifier rootQualifier = new mit.roles.Qualifier
						( rolesFactory
						, ( Number ) row[ rows.getColumn( QUALIFIER_ID ) ]
						, ( String ) row[ rows.getColumn( QUALIFIER_CODE ) ]
						, ( String ) row[ rows.getColumn( QUALIFIER_DESCRIPTION ) ]
						, new mit.roles.QualifierType
							( rolesFactory
							, ( String ) row[ rows.getColumn( QUALIFIER_TYPE ) ]
							, null
							)
						, new Boolean
							( ( ( String ) row[ rows.getColumn( HAS_CHILD )	] ).equals( "Y" )
							)
						) ;
					return rootQualifier ;
				}
			}
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	private static mit.roles.Qualifier getQualifier
		( mit.roles.RolesFactory rolesFactory
		, String qualifierCode
		, roles.QualifierType qualifierType
		)
		throws Exception
	{
		if( ( null != rolesFactory )
		&&  ( null != rolesFactory.getConnection() )
		&&  ( null != qualifierType )
		&&  ( null != qualifierCode )
		)
		{
			sql.Connection connection = rolesFactory.getConnection() ;
			sql.Table table
				= connection.executeQuery
					( new String
						( "select "
						+ "q.qualifier_id, q.qualifier_code, q.qualifier_name "
						+ "q.qualifier_type, q.has_child "
						+ "from qualifier q "
						+ "where "
						+ " q.qualifier_type = " + ( ( mit.roles.QualifierType ) qualifierType ).getType()
						+ " and q.qualifier_code = " + qualifierCode
						+ " ;"
						)
					) ;
			if( null != table )
			{
				sql.Rows rows = table.getRows() ;
				if( rows.hasMoreRows() )
				{
					Object[] row = rows.nextRow() ;
					mit.roles.Qualifier rootQualifier = new mit.roles.Qualifier
						( rolesFactory
						, ( Number ) row[ rows.getColumn( QUALIFIER_ID ) ]
						, ( String ) row[ rows.getColumn( QUALIFIER_CODE ) ]
						, ( String ) row[ rows.getColumn( QUALIFIER_DESCRIPTION ) ]
						, new mit.roles.QualifierType
							( rolesFactory
							, ( String ) row[ rows.getColumn( QUALIFIER_TYPE ) ]
							, null
							)
						, new Boolean
							( ( ( String ) row[ rows.getColumn( HAS_CHILD ) ] ).equals( "Y" )
							)
						) ;
					return rootQualifier ;
				}
			}
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	private static mit.roles.Qualifier getQualifier
		( mit.roles.RolesFactory rolesFactory
		, Number qualifierId
		)
		throws Exception
	{
		if( ( null != rolesFactory )
		&&  ( null != rolesFactory.getConnection() )
		&&  ( null != qualifierId )
		)
		{
			sql.Connection connection = rolesFactory.getConnection() ;
			sql.Table table
				= connection.executeQuery
					( new String
						( "select "
						+ "q.qualifier_id, q.qualifier_code, q.qualifier_name "
						+ "q.qualifier_type, q.has_child "
						+ "from qualifier q "
						+ "where "
						+ " q.qualifier_id = " + qualifierId
						+ " ;"
						)
					) ;
			if( null != table )
			{
				sql.Rows rows = table.getRows() ;
				if( rows.hasMoreRows() )
				{
					Object[] row = rows.nextRow() ;
					mit.roles.Qualifier rootQualifier = new mit.roles.Qualifier
						( rolesFactory
						, ( Number ) row[ rows.getColumn( QUALIFIER_ID ) ]
						, ( String ) row[ rows.getColumn( QUALIFIER_CODE ) ]
						, ( String ) row[ rows.getColumn( QUALIFIER_DESCRIPTION ) ]
						, new mit.roles.QualifierType
							( rolesFactory
							, ( String ) row[ rows.getColumn( QUALIFIER_TYPE ) ]
							, null
							)
						, new Boolean
							( ( ( String ) row[ rows.getColumn( HAS_CHILD ) ] ).equals( "Y" )
							)
						) ;
					return rootQualifier ;
				}
			}
		}
		throw new roles.RolesException
			( roles.RolesException.INVALIDQUALIFIER ) ;
	}

	private boolean isIdInRoles()
		throws Exception
	{
		if( ( null != getId() )
		&&  ( null != getRolesFactory() )
		&&  ( null != getRolesFactory().getConnection() )
		)
		{
			sql.Connection connection = getRolesFactory().getConnection() ;
			sql.Table table
				= connection.executeQuery
					( new String
						( "select qualifier_code, qualifier_name, "
						+ "qualifier_type, has_child "
						+ "from qualifier "
						+ "where qualifier_id = "
						+ getId()
						+ " ;"
						)
					) ;
			if( null != table )
			{
				sql.Rows rows = table.getRows() ;
				if( rows.hasMoreRows() )
				{
					Object[] row = rows.nextRow() ;
					setCode( ( String ) row[ rows.getColumn( QUALIFIER_CODE ) ] ) ;
					setDescription( ( String ) row[ rows.getColumn( QUALIFIER_DESCRIPTION ) ] ) ;
					String type = ( String ) row[ rows.getColumn( QUALIFIER_TYPE ) ] ;
					setQualifierType( new mit.roles.QualifierType( rolesFactory , type , null ) ) ;
					setHasChild( new Boolean( "Y".equals( ( String ) row[ rows.getColumn( HAS_CHILD ) ] ) ) ) ;
					return true ;
				}
			}
		}
		return false ;
	}

	private boolean isCodeAndTypeInRoles()
		throws Exception
	{
		if( ( null != getCode() )
		&&  ( null != getQualifierType() )
		&&  ( null != getQualifierType().getType() )
		&&  ( null != getRolesFactory() )
		&&  ( null != getRolesFactory().getConnection() )
		)
		{
			sql.Connection connection = getRolesFactory().getConnection() ;
			sql.Table table
				= connection.executeQuery
					( new String
						( "select qualifier_id , qualifier_name, "
						+ "has_child, "
						+ "from qualifier "
						+ "where qualifier_code = "
						+ getCode()
						+ " and qualifier_type = "
						+ getQualifierType().getType()
						+ " ;"
						)
					) ;
			if( null != table )
			{
				sql.Rows rows = table.getRows() ;
				if( rows.hasMoreRows() )
				{
					Object[] row = rows.nextRow() ;
					setId( row[ rows.getColumn( QUALIFIER_ID ) ] ) ;
					setDescription( ( String ) row[ rows.getColumn( QUALIFIER_DESCRIPTION ) ] ) ;
					setHasChild( new Boolean( "Y".equals( ( String ) row[ rows.getColumn( HAS_CHILD ) ] ) ) ) ;
					return true ;
				}
			}
		}
		return false ;
	}


}