1 19 20 package org.apache.cayenne.access; 21 22 import org.apache.cayenne.DataChannel; 23 import org.apache.cayenne.ObjectContext; 24 import org.apache.cayenne.QueryResponse; 25 import org.apache.cayenne.cache.QueryCache; 26 import org.apache.cayenne.event.EventManager; 27 import org.apache.cayenne.graph.GraphDiff; 28 import org.apache.cayenne.intercept.DataChannelCallbackInterceptor; 29 import org.apache.cayenne.map.EntityResolver; 30 import org.apache.cayenne.query.Query; 31 32 39 public class ClientServerChannel implements DataChannel { 40 41 protected DataContext serverContext; 42 protected boolean lifecycleCallbacksEnabled; 43 44 public ClientServerChannel(DataDomain domain) { 45 this(domain.createDataContext()); 46 } 47 48 ClientServerChannel(DataContext serverContext) { 49 this.serverContext = serverContext; 50 } 51 52 56 public ClientServerChannel(DataDomain domain, boolean lifecycleEventsEnabled) { 57 this(domain); 58 } 59 60 65 public boolean isLifecycleEventsEnabled() { 66 return false; 67 } 68 69 74 public void setLifecycleEventsEnabled(boolean lifecycleEventsEnabled) { 75 76 } 77 78 public QueryResponse onQuery(ObjectContext context, Query query) { 79 return new ClientServerChannelQueryAction(this, query).execute(); 80 } 81 82 QueryCache getQueryCache() { 83 return serverContext.getQueryCache(); 84 } 85 86 DataChannel getParentChannel() { 87 return serverContext; 88 } 89 90 public EntityResolver getEntityResolver() { 91 return serverContext.getEntityResolver(); 92 } 93 94 public EventManager getEventManager() { 95 return serverContext != null ? serverContext.getEventManager() : null; 96 } 97 98 public GraphDiff onSync( 99 ObjectContext originatingContext, 100 GraphDiff changes, 101 int syncType) { 102 103 return getParentChannel().onSync(null, changes, syncType); 104 } 105 106 109 public boolean isLifecycleCallbacksEnabled() { 110 return lifecycleCallbacksEnabled; 111 } 112 113 120 public void setLifecycleCallbacksEnabled(boolean lifecycleCallbacksEnabled) { 121 if (lifecycleCallbacksEnabled != this.lifecycleCallbacksEnabled) { 122 this.lifecycleCallbacksEnabled = lifecycleCallbacksEnabled; 123 124 if (lifecycleCallbacksEnabled) { 125 enableCallbacks(); 126 } 127 else { 128 disableCallbacks(); 129 } 130 } 131 } 132 133 void enableCallbacks() { 134 DataChannelCallbackInterceptor interceptor = new DataChannelCallbackInterceptor(); 135 136 interceptor.setContextCallbacksEnabled(true); 138 interceptor.setChannel(serverContext.getParentDataDomain()); 139 140 serverContext.setChannel(interceptor); 141 } 142 143 void disableCallbacks() { 144 serverContext.setChannel(serverContext.getParentDataDomain()); 145 } 146 } 147 | Popular Tags |