Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*****************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
****************************************************************/
package org.apache.cayenne.remote;
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.DataChannel;
import org.apache.cayenne.DataChannelSyncCallbackAction;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.Persistent;
import org.apache.cayenne.QueryResponse;
import org.apache.cayenne.event.EventBridge;
import org.apache.cayenne.event.EventManager;
import org.apache.cayenne.event.EventSubject;
import org.apache.cayenne.graph.CompoundDiff;
import org.apache.cayenne.graph.GraphDiff;
import org.apache.cayenne.graph.GraphDiffCompressor;
import org.apache.cayenne.graph.GraphEvent;
import org.apache.cayenne.map.EntityResolver;
import org.apache.cayenne.query.EntityResultSegment;
import org.apache.cayenne.query.Query;
import org.apache.cayenne.query.QueryMetadata;
import org.apache.cayenne.util.DeepMergeOperation;
import org.apache.cayenne.util.ToStringBuilder;
import java.util.List;
import java.util.ListIterator;
/**
* A {@link org.apache.cayenne.DataChannel} implementation that accesses a remote server
* via a ClientConnection.
*
* @since 1.2
*/
public class ClientChannel implements DataChannel {
protected ClientConnection connection;
protected EventManager eventManager;
protected EntityResolver entityResolver;
protected boolean channelEventsEnabled;
protected GraphDiffCompressor diffCompressor;
EventBridge remoteChannelListener;
/**
* @param remoteEventsOptional if true, failure to start an EventBridge will not
* result in an exception.
* @since 3.0
*/
public ClientChannel(ClientConnection connection, boolean channelEventsEnabled,
EventManager eventManager, boolean remoteEventsOptional)
throws CayenneRuntimeException {
this.connection = connection;
this.diffCompressor = new GraphDiffCompressor();
this.eventManager = eventManager;
this.channelEventsEnabled = eventManager != null && channelEventsEnabled;
if (!remoteEventsOptional) {
setupRemoteChannelListener();
} else {
try {
setupRemoteChannelListener();
} catch (CayenneRuntimeException ignored) {}
}
}
/**
* @since 3.1
*/
public ClientConnection getConnection() {
return connection;
}
/**
* @since 3.1
*/
public boolean isChannelEventsEnabled() {
return channelEventsEnabled;
}
public EventManager getEventManager() {
return eventManager;
}
@SuppressWarnings("unchecked")
public QueryResponse onQuery(ObjectContext context, Query query) {
QueryResponse response = send( new QueryMessage(query), QueryResponse.class);
// if needed, register objects in provided context, rewriting the response
// (assuming all lists are mutable)
if (context != null) {
EntityResolver resolver = context.getEntityResolver();
QueryMetadata info = query.getMetaData(resolver);
if (!info.isFetchingDataRows()) {
response.reset();
while (response.next()) {
if (response.isList()) {
List objects = response.currentList();
if (!objects.isEmpty()) {
DeepMergeOperation merger = new DeepMergeOperation(context);
List