mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#395 - No functional change - cleanup unused BeanDelta
This commit is contained in:
@@ -23,8 +23,6 @@ public class BinaryMessage {
|
||||
public static final int TYPE_MSGCONTROL = 0;
|
||||
public static final int TYPE_BEANIUD = 1;
|
||||
public static final int TYPE_TABLEIUD = 2;
|
||||
public static final int TYPE_BEANDELTA = 3;
|
||||
public static final int TYPE_BEANPATHUPDATE = 4;
|
||||
|
||||
public static final int TYPE_MSGACK = 8;
|
||||
public static final int TYPE_MSGRESEND = 9;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.cluster;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable.TableIUD;
|
||||
import com.avaje.ebeaninternal.server.transaction.BeanDelta;
|
||||
import com.avaje.ebeaninternal.server.transaction.BeanPersistIds;
|
||||
import com.avaje.ebeaninternal.server.transaction.RemoteTransactionEvent;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A Packet holding TransactionEvent data.
|
||||
* <p>
|
||||
@@ -57,10 +56,6 @@ public class PacketTransactionEvent extends Packet {
|
||||
event.addTableIUD(TableIUD.readBinaryMessage(dataInput));
|
||||
break;
|
||||
|
||||
case BinaryMessage.TYPE_BEANDELTA:
|
||||
event.addBeanDelta(BeanDelta.readBinaryMessage(server, dataInput));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Invalid Transaction msgType "+msgType);
|
||||
}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessage;
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessageList;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BeanDelta {
|
||||
|
||||
private final List<BeanDeltaProperty> properties;
|
||||
|
||||
private final BeanDescriptor<?> beanDescriptor;
|
||||
|
||||
private final Object id;
|
||||
|
||||
public BeanDelta(BeanDescriptor<?> beanDescriptor, Object id) {
|
||||
this.beanDescriptor = beanDescriptor;
|
||||
this.id = id;
|
||||
this.properties = new ArrayList<BeanDeltaProperty>();
|
||||
}
|
||||
|
||||
public BeanDescriptor<?> getBeanDescriptor() {
|
||||
return beanDescriptor;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "BeanDelta[" + beanDescriptor.getName() + ":" + properties + "]";
|
||||
}
|
||||
|
||||
public Object getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void add(BeanProperty beanProperty, Object value) {
|
||||
this.properties.add(new BeanDeltaProperty(beanProperty, value));
|
||||
}
|
||||
|
||||
public void add(BeanDeltaProperty propertyDelta) {
|
||||
this.properties.add(propertyDelta);
|
||||
}
|
||||
|
||||
public void apply(EntityBean bean) {
|
||||
|
||||
for (int i = 0; i < properties.size(); i++) {
|
||||
properties.get(i).apply(bean);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and return a BeanDelta from the binary input.
|
||||
*/
|
||||
public static BeanDelta readBinaryMessage(SpiEbeanServer server, DataInput dataInput) throws IOException {
|
||||
|
||||
String descriptorId = dataInput.readUTF();
|
||||
BeanDescriptor<?> desc = server.getBeanDescriptorById(descriptorId);
|
||||
Object id = desc.getIdBinder().readData(dataInput);
|
||||
BeanDelta bp = new BeanDelta(desc, id);
|
||||
|
||||
int count = dataInput.readInt();
|
||||
for (int i = 0; i < count; i++) {
|
||||
String propName = dataInput.readUTF();
|
||||
BeanProperty beanProperty = desc.getBeanProperty(propName);
|
||||
Object value = beanProperty.getScalarType().readData(dataInput);
|
||||
bp.add(beanProperty, value);
|
||||
}
|
||||
return bp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this bean delta in binary message format.
|
||||
*/
|
||||
public void writeBinaryMessage(BinaryMessageList msgList) throws IOException {
|
||||
|
||||
BinaryMessage m = new BinaryMessage(50);
|
||||
|
||||
DataOutputStream os = m.getOs();
|
||||
os.writeInt(BinaryMessage.TYPE_BEANDELTA);
|
||||
os.writeUTF(beanDescriptor.getDescriptorId());
|
||||
|
||||
beanDescriptor.getIdBinder().writeData(os, id);
|
||||
os.writeInt(properties.size());
|
||||
|
||||
for (int i = 0; i < properties.size(); i++) {
|
||||
properties.get(i).writeBinaryMessage(m);
|
||||
}
|
||||
|
||||
os.flush();
|
||||
msgList.add(m);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessageList;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BeanDeltaList {
|
||||
|
||||
private final BeanDescriptor<?> beanDescriptor;
|
||||
|
||||
private final List<BeanDelta> deltaBeans = new ArrayList<BeanDelta>();
|
||||
|
||||
public BeanDeltaList(BeanDescriptor<?> beanDescriptor) {
|
||||
this.beanDescriptor = beanDescriptor;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return deltaBeans.toString();
|
||||
}
|
||||
|
||||
public BeanDescriptor<?> getBeanDescriptor() {
|
||||
return beanDescriptor;
|
||||
}
|
||||
|
||||
public void add(BeanDelta b) {
|
||||
deltaBeans.add(b);
|
||||
}
|
||||
|
||||
public List<BeanDelta> getDeltaBeans() {
|
||||
return deltaBeans;
|
||||
}
|
||||
|
||||
public void writeBinaryMessage(BinaryMessageList msgList) throws IOException {
|
||||
for (int i = 0; i < deltaBeans.size(); i++) {
|
||||
deltaBeans.get(i).writeBinaryMessage(msgList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BeanDeltaMap {
|
||||
|
||||
private final Map<String, BeanDeltaList> deltaMap = new HashMap<String, BeanDeltaList>();
|
||||
|
||||
public BeanDeltaMap() {
|
||||
}
|
||||
|
||||
public BeanDeltaMap(List<BeanDelta> deltaBeans) {
|
||||
if (deltaBeans != null) {
|
||||
for (int i = 0; i < deltaBeans.size(); i++) {
|
||||
BeanDelta deltaBean = deltaBeans.get(i);
|
||||
addBeanDelta(deltaBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return deltaMap.values().toString();
|
||||
}
|
||||
|
||||
public void addBeanDelta(BeanDelta beanDelta) {
|
||||
BeanDescriptor<?> d = beanDelta.getBeanDescriptor();
|
||||
BeanDeltaList list = getDeltaBeanList(d);
|
||||
list.add(beanDelta);
|
||||
}
|
||||
|
||||
public Collection<BeanDeltaList> deltaLists() {
|
||||
return deltaMap.values();
|
||||
}
|
||||
|
||||
private BeanDeltaList getDeltaBeanList(BeanDescriptor<?> d) {
|
||||
BeanDeltaList deltaList = deltaMap.get(d.getFullName());
|
||||
if (deltaList == null) {
|
||||
deltaList = new BeanDeltaList(d);
|
||||
deltaMap.put(d.getFullName(), deltaList);
|
||||
}
|
||||
return deltaList;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessage;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BeanDeltaProperty {
|
||||
|
||||
private final BeanProperty beanProperty;
|
||||
|
||||
private final Object value;
|
||||
|
||||
public BeanDeltaProperty(BeanProperty beanProperty, Object value) {
|
||||
this.beanProperty = beanProperty;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return beanProperty.getName() + ":" + value;
|
||||
}
|
||||
|
||||
public void apply(EntityBean bean) {
|
||||
beanProperty.setValue(bean, value);
|
||||
}
|
||||
|
||||
public void writeBinaryMessage(BinaryMessage m) throws IOException {
|
||||
|
||||
DataOutputStream os = m.getOs();
|
||||
os.writeUTF(beanProperty.getName());
|
||||
beanProperty.getScalarType().writeData(os, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
* Wraps the information representing a Inserted Updated or Deleted Bean.
|
||||
* <p>
|
||||
* This information is broadcast across the cluster so that remote BeanListeners
|
||||
* are notified of the inserts updates and deletes that occured.
|
||||
* are notified of the inserts updates and deletes that occurred.
|
||||
* </p>
|
||||
* <p>
|
||||
* You control it the data is broadcast and what data is broadcast by the
|
||||
|
||||
@@ -14,10 +14,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
|
||||
private List<TableIUD> tableList;
|
||||
|
||||
private List<BeanDeltaList> beanDeltaLists;
|
||||
|
||||
private BeanDeltaMap beanDeltaMap;
|
||||
|
||||
private DeleteByIdMap deleteByIdMap;
|
||||
|
||||
private String serverName;
|
||||
@@ -38,9 +34,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (beanDeltaMap != null) {
|
||||
sb.append(beanDeltaMap);
|
||||
}
|
||||
sb.append(beanPersistList);
|
||||
if (tableList != null) {
|
||||
sb.append(tableList);
|
||||
@@ -67,12 +60,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
beanPersistList.get(i).writeBinaryMessage(msgList);
|
||||
}
|
||||
}
|
||||
|
||||
if (beanDeltaLists != null) {
|
||||
for (int i = 0; i < beanDeltaLists.size(); i++) {
|
||||
beanDeltaLists.get(i).writeBinaryMessage(msgList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
@@ -90,20 +77,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
tableList.add(tableIud);
|
||||
}
|
||||
|
||||
public void addBeanDeltaList(BeanDeltaList deltaList) {
|
||||
if (beanDeltaLists == null) {
|
||||
beanDeltaLists = new ArrayList<BeanDeltaList>();
|
||||
}
|
||||
beanDeltaLists.add(deltaList);
|
||||
}
|
||||
|
||||
public void addBeanDelta(BeanDelta beanDelta) {
|
||||
if (beanDeltaMap == null) {
|
||||
beanDeltaMap = new BeanDeltaMap();
|
||||
}
|
||||
beanDeltaMap.addBeanDelta(beanDelta);
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
@@ -132,10 +105,4 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
return beanPersistList;
|
||||
}
|
||||
|
||||
public List<BeanDeltaList> getBeanDeltaLists() {
|
||||
if (beanDeltaMap != null) {
|
||||
beanDeltaLists.addAll(beanDeltaMap.deltaLists());
|
||||
}
|
||||
return beanDeltaLists;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user