Domain Mapper SubClass

 

SubClass Extension methods

public CollectionBean getSetMembers(String authorizeLoginName, String id);

public DataBean move(String authorizeLoginName, String id, String idParentOld, String idParentNew ) 
throws OOCTXException

Example SubClass Code

public class MapperSet extends MapperOOC implements IMapperSet {



//  **********  Abstract Methods for Sub-Classes **********
//  **********  Replace Set references with types appropriate for mapper  **********


//	**********  Core methods  

	protected EJBLocalObject doCreate( String id ) 
		throws OOCTXException {
			
		SetLocal ejb;		
		
		try  {
			
			SetLocalHome localHome = (SetLocalHome)getLocalHome();
			ejb = (SetLocal)localHome.create( id );
			
			if ( ejb == null )  {		
						
				System.out.println( "Error in MapperSet.doCreate: create object failed"  );
				return null;		
						
			}
			
		} catch (CreateException e) {
									
			System.out.println( "Error in MapperSet.doCreate: " + e.getMessage() );
			throw new OOCTXException();
			
		}  
		
		return ejb;
		
	}
	

//	**********  Support methods  
		
	protected DataBean getReturnBean()  {
		
		SetBean bean =  new SetBean();
		return bean;
		
	}

	protected EJBLocalHome getLocalHome()  {	
			
		SetLocalHome localHome = null;		
		InitialContext context;		
		
		try {			
			
			context = new InitialContext();			
			localHome = (SetLocalHome)context.lookup( "java:comp/env/SetLocalHome" );		
		
		} catch (NamingException e) {
			
			System.out.println( "Naming Error in MapperSet.getLocalHome.JNDI lookup: " + e.getMessage() + " **************" );
			return null;
			
		}			
			
		return localHome;
		
	}

	//  **********  DataBean <==> EJB/CMR  methods

	protected void mapBeanToEJB ( DataBean dataBean, EJBLocalObject ejbGeneric, boolean setDateCreated )  {
				
	// Includes only CMP fields, not CMR fields
	
		SetBean bean = (SetBean)dataBean;
		SetLocal ejb = (SetLocal)ejbGeneric;

		try {
			
			//ejb.setSetID		( bean.getSetID() );  	Primary Key
	
			//  DataBean fields
			ejb.setName		( bean.getName() );						
			ejb.setOwner		( bean.getOwner() );
			if ( setDateCreated ) 
			ejb.setDateCreated	( ooc.util.Time.getTimestamp() );
			ejb.setDateModified	( ooc.util.Time.getTimestamp() );
			
			//  SetBean fields
			ejb.setObjectType	( bean.getObjectType() );
			ejb.setObjectID		( bean.getObjectID() );	
						
		} catch (Exception e) {
			
			System.out.println( "Error in SetMapper.mapBeanToEJBSet: " + e.getMessage() );

		}
		
	}
		
//  **********  Extension Methods **********


	public CollectionBean getSetMembers(
		String authorizeLoginName, 
		String id) {

		//  define CollectionBean for return
		CollectionBean collectionBean;;
		
		try  {
				
			// find Set			
			SetLocal ejb = (SetLocal)doFind( id );
			
			if ( ejb == null )  {		
						
				System.out.println( "Error in MapperSet.getSetMembers: find Set failed"  );
				return null;	
							
			}
							
			// get Children Sets			
			Collection children = ejb.getChildren();

			// build return CollectionBean
			collectionBean = buildCollectionBean( children );
			
		} catch (Exception e) {	
					
			System.out.println( "Error in MapperSet.getSetMembers: " + e.getMessage() );
			return null;
			
		} 
	
		return collectionBean;
		
	}
	

	public DataBean move(
		String authorizeLoginName,
		String id, 
		String idParentOld,
		String idParentNew ) 
		throws OOCTXException {
			
		SetLocal ejb = null;
		SetLocal ejbParentOld = null;
		SetLocal ejbParentNew = null;
		
		//get new bean for return
		DataBean returnBean = getReturnBean();

		try {
			
			// find object			
			ejb = (SetLocal)doFind( id );
			
			if ( ejb == null )  {		
						
				System.out.println( "Error in MapperSet.move: find object failed"  );
				return null;	
							
			}
								
			// test null move			
			if ( idParentOld.equals(idParentNew) ) {
				return null;
			}  
			
			//  update parent			
			ejbParentNew = (SetLocal)doFind( idParentNew );
			ejb.setParent( ejbParentNew );
			
			// Prepare return data			
			mapEJBToBean( ejb, returnBean );
			mapCMRToBean( ejb, returnBean );
			
		} catch (Exception e) {
			
			System.out.println( "Error in MapperSet.move: " + e.getMessage() );
			throw new OOCTXException();
			
		}			
	
		return (DataBean)returnBean;

	}		


}


previous  contents  next