1 21 package com.db4o.cs; 22 23 import com.db4o.*; 24 import com.db4o.cs.messages.*; 25 import com.db4o.foundation.*; 26 27 final class TransactionClient extends Transaction { 28 29 private final YapClient i_client; 30 31 private Tree i_yapObjectsToGc; 32 33 TransactionClient(YapClient a_stream, Transaction a_parent) { 34 super(a_stream, a_parent); 35 i_client = a_stream; 36 } 37 38 public void commit() { 39 commitTransactionListeners(); 40 clearAll(); 41 i_client.writeMsg(Msg.COMMIT); 42 43 } 44 45 protected void clearAll() { 46 removeYapObjectReferences(); 47 super.clearAll(); 48 } 49 50 private void removeYapObjectReferences() { 51 if(i_yapObjectsToGc != null){ 52 i_yapObjectsToGc.traverse(new Visitor4() { 53 public void visit(Object a_object) { 54 YapObject yo = (YapObject)((TreeIntObject) a_object)._object; 55 stream().removeReference(yo); 56 } 57 }); 58 } 59 i_yapObjectsToGc = null; 60 } 61 62 public boolean delete(YapObject ref, int id, int cascade) { 63 if (! super.delete(ref, id, cascade)){ 64 return false; 65 } 66 i_client.writeMsg(Msg.TA_DELETE.getWriterForInts(this, new int[] {id, cascade})); 67 return true; 68 } 69 70 public boolean isDeleted(int a_id) { 71 72 76 78 i_client.writeMsg(Msg.TA_IS_DELETED.getWriterForInt(this, a_id)); 79 int res = i_client.expectedByteResponse(Msg.TA_IS_DELETED).readInt(); 80 return res == 1; 81 } 82 83 public Object [] objectAndYapObjectBySignature(final long a_uuid, final byte[] a_signature) { 84 int messageLength = YapConst.LONG_LENGTH + YapConst.INT_LENGTH + a_signature.length; 85 MsgD message = Msg.OBJECT_BY_UUID.getWriterForLength(this, messageLength); 86 message.writeLong(a_uuid); 87 message.writeBytes(a_signature); 88 i_client.writeMsg(message); 89 message = (MsgD)i_client.expectedResponse(Msg.OBJECT_BY_UUID); 90 int id = message.readInt(); 91 if(id > 0){ 92 return stream().getObjectAndYapObjectByID(this, id); 93 } 94 return new Object [2]; 95 } 96 97 98 public void processDeletes() { 99 if (i_delete != null) { 100 i_delete.traverse(new Visitor4() { 101 public void visit(Object a_object) { 102 DeleteInfo info = (DeleteInfo) a_object; 103 if (info._reference != null) { 104 i_yapObjectsToGc = Tree.add(i_yapObjectsToGc, new TreeIntObject(info._key, info._reference)); 105 } 106 } 107 }); 108 } 109 i_delete = null; 110 i_writtenUpdateDeletedMembers = null; 111 i_client.writeMsg(Msg.PROCESS_DELETES); 112 } 113 114 public void rollback() { 115 i_yapObjectsToGc = null; 116 rollBackTransactionListeners(); 117 clearAll(); 118 } 119 120 public void writeUpdateDeleteMembers(int a_id, YapClass a_yc, int a_type, 121 int a_cascade) { 122 i_client.writeMsg(Msg.WRITE_UPDATE_DELETE_MEMBERS.getWriterForInts(this, 123 new int[]{ 124 a_id, 125 a_yc.getID(), 126 a_type, 127 a_cascade 128 })); 129 } 130 131 public void setPointer(int a_id, int a_address, int a_length) { 132 } 133 } | Popular Tags |