1 20 21 package com.methodhead.sitecontext; 22 23 import com.methodhead.aikp.AutoIntKeyPersistable; 24 import com.methodhead.persistable.Key; 25 import org.apache.commons.beanutils.DynaClass; 26 import java.util.List ; 27 import java.util.Iterator ; 28 29 34 public class SiteContextAikp 35 extends 36 AutoIntKeyPersistable { 37 38 40 public SiteContextAikp( 41 DynaClass dynaClass ) { 42 43 super( dynaClass ); 44 } 45 46 48 50 52 54 58 public SiteContext getSiteContext() { 59 if ( siteContext_ == null ) 60 throw new RuntimeException ( "Site context has not been set." ); 61 62 return siteContext_; 63 } 64 65 69 public void setSiteContext( 70 SiteContext siteContext ) { 71 72 if ( siteContext == null ) 73 throw new RuntimeException ( "Trying to set a null site context." ); 74 75 siteContext_ = siteContext; 76 77 setInt( "sitecontext_id", siteContext.getInt( "id" ) ); 78 } 79 80 83 public void saveNew() { 84 setInt( "sitecontext_id", getSiteContext().getInt( "id" ) ); 85 super.saveNew(); 86 } 87 88 91 public void save() { 92 setInt( "sitecontext_id", getSiteContext().getInt( "id" ) ); 93 super.save(); 94 } 95 96 99 public void load( 100 Key key ) { 101 102 super.load( 103 key.getWhereClause() + " AND sitecontext_id=" + 104 getSiteContext().getInt( "id" ) ); 105 } 106 107 110 public void load( 111 String whereClause ) { 112 113 super.load( 114 whereClause + " AND sitecontext_id=" + 115 getSiteContext().getInt( "id" ) ); 116 } 117 118 121 public List loadAll( 122 String whereClause, 123 String orderByClause ) { 124 125 if ( whereClause == null ) 129 whereClause = "sitecontext_id=" + getSiteContext().getInt( "id" ); 130 else 131 whereClause += " AND sitecontext_id=" + getSiteContext().getInt( "id" ); 132 133 List list = loadAll( getDynaClass(), whereClause, orderByClause ); 137 138 for ( Iterator iter = list.iterator(); iter.hasNext(); ) { 139 SiteContextAikp aikp = ( SiteContextAikp )iter.next(); 140 aikp.setSiteContext( getSiteContext() ); 141 } 142 143 return list; 144 } 145 146 148 private SiteContext siteContext_ = null; 149 } 150 | Popular Tags |