Package io.keikai.doc.collab.utils
Class Transaction
- java.lang.Object
-
- io.keikai.doc.collab.utils.Transaction
-
public class Transaction extends java.lang.ObjectA transaction is created for every change on the Yjs model. It is possible to bundle changes on the Yjs model in a single transaction to minimize the number on messages sent and the number of observer calls. If possible the user of this library should bundle as many changes as possible. Here is an example to illustrate the advantages of bundling:
-
-
Constructor Summary
Constructors Constructor Description Transaction(Doc doc, java.lang.Object origin, boolean local)Constructor for the Transaction class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddChangedTypeToTransaction(Transaction transaction, AbstractType type, java.lang.String parentSub)Adds a changed type to the transaction.java.util.Map<java.lang.Integer,java.lang.Integer>getAfterState()java.util.Map<java.lang.Integer,java.lang.Integer>getBeforeState()java.util.Map<AbstractType,java.util.Set<java.lang.String>>getChanged()java.util.Map<AbstractType,java.util.List<YEvent>>getChangedParentTypes()DeleteSetgetDeleteSet()DocgetDoc()java.util.List<AbstractStruct>getMergeStructs()java.util.Map<java.lang.Object,java.lang.Object>getMeta()java.lang.ObjectgetOrigin()java.util.Set<Doc>getSubdocsAdded()java.util.Set<Doc>getSubdocsLoaded()java.util.Set<Doc>getSubdocsRemoved()booleanisLocal()booleanisNeedFormattingCleanup()static IDnextID(Transaction transaction)Returns the next ID for the transaction.voidsetAfterState(java.util.Map<java.lang.Integer,java.lang.Integer> afterState)voidsetLocal(boolean local)voidsetNeedFormattingCleanup(boolean needFormattingCleanup)static voidtransact(Doc doc, java.lang.Runnable f)Implements the functionality of `y.transact(()=>{..})`.static voidtransact(Doc doc, java.lang.Runnable f, java.lang.Object origin)Implements the functionality of `y.transact(()=>{..})`.static voidtransact(Doc doc, java.lang.Runnable f, java.lang.Object origin, boolean local)Implements the functionality of `y.transact(()=>{..})`.static voidtransact(Doc doc, java.util.function.Consumer<Transaction> f)Implements the functionality of `y.transact(()=>{..})`.static voidtransact(Doc doc, java.util.function.Consumer<Transaction> f, java.lang.Object origin)Implements the functionality of `y.transact(()=>{..})`.static voidtransact(Doc doc, java.util.function.Consumer<Transaction> f, java.lang.Object origin, boolean local)Implements the functionality of `y.transact(()=>{..})`.static <T> Ttransact(Doc doc, java.util.function.Function<Transaction,T> f)Implements the functionality of `y.transact(()=>{..})`.static <T> Ttransact(Doc doc, java.util.function.Function<Transaction,T> f, java.lang.Object origin)Implements the functionality of `y.transact(()=>{..})`.static <T> Ttransact(Doc doc, java.util.function.Function<Transaction,T> f, java.lang.Object origin, boolean local)Implements the functionality of `y.transact(()=>{..})`.static voidtryGc(DeleteSet ds, StructStore store, java.util.function.Function<Item,java.lang.Boolean> gcFilter)Attempts to garbage collect the delete set.static booleanwriteUpdateMessageFromTransaction(UpdateEncoder encoder, Transaction transaction)Writes an update message from the transaction to the encoder.
-
-
-
Constructor Detail
-
Transaction
public Transaction(Doc doc, java.lang.Object origin, boolean local)
Constructor for the Transaction class.- Parameters:
doc- The Yjs document instance.origin- The origin of the transaction.local- Whether this change originates from this doc.
-
-
Method Detail
-
getDoc
public Doc getDoc()
-
getBeforeState
public java.util.Map<java.lang.Integer,java.lang.Integer> getBeforeState()
-
getAfterState
public java.util.Map<java.lang.Integer,java.lang.Integer> getAfterState()
-
setAfterState
public void setAfterState(java.util.Map<java.lang.Integer,java.lang.Integer> afterState)
-
getChanged
public java.util.Map<AbstractType,java.util.Set<java.lang.String>> getChanged()
-
getChangedParentTypes
public java.util.Map<AbstractType,java.util.List<YEvent>> getChangedParentTypes()
-
getDeleteSet
public DeleteSet getDeleteSet()
-
getOrigin
public java.lang.Object getOrigin()
-
getMeta
public java.util.Map<java.lang.Object,java.lang.Object> getMeta()
-
getMergeStructs
public java.util.List<AbstractStruct> getMergeStructs()
-
isLocal
public boolean isLocal()
-
setLocal
public void setLocal(boolean local)
-
getSubdocsAdded
public java.util.Set<Doc> getSubdocsAdded()
-
getSubdocsRemoved
public java.util.Set<Doc> getSubdocsRemoved()
-
getSubdocsLoaded
public java.util.Set<Doc> getSubdocsLoaded()
-
isNeedFormattingCleanup
public boolean isNeedFormattingCleanup()
-
setNeedFormattingCleanup
public void setNeedFormattingCleanup(boolean needFormattingCleanup)
-
writeUpdateMessageFromTransaction
public static boolean writeUpdateMessageFromTransaction(UpdateEncoder encoder, Transaction transaction)
Writes an update message from the transaction to the encoder.- Parameters:
encoder- The encoder (either UpdateEncoderV1 or UpdateEncoderV2).transaction- The transaction object.- Returns:
- Whether data was written.
-
nextID
public static ID nextID(Transaction transaction)
Returns the next ID for the transaction.- Parameters:
transaction- The transaction object.- Returns:
- The next ID.
-
addChangedTypeToTransaction
public static void addChangedTypeToTransaction(Transaction transaction, AbstractType type, java.lang.String parentSub)
Adds a changed type to the transaction.- Parameters:
transaction- The transaction object.type- The type of the object that changed.parentSub- The parent sub key.
-
tryGc
public static void tryGc(DeleteSet ds, StructStore store, java.util.function.Function<Item,java.lang.Boolean> gcFilter)
Attempts to garbage collect the delete set.- Parameters:
ds- The delete set.store- The struct store.gcFilter- The garbage collection filter function.
-
transact
public static void transact(Doc doc, java.lang.Runnable f)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Runnable function to execute within the transaction.
-
transact
public static void transact(Doc doc, java.util.function.Consumer<Transaction> f)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The function to execute within the transaction.
-
transact
public static <T> T transact(Doc doc, java.util.function.Function<Transaction,T> f)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The function to execute within the transaction.- Returns:
- The result of the function.
-
transact
public static void transact(Doc doc, java.lang.Runnable f, java.lang.Object origin)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Runnable function to execute within the transaction.origin- The origin of the transaction.
-
transact
public static void transact(Doc doc, java.util.function.Consumer<Transaction> f, java.lang.Object origin)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The function to execute within the transaction.origin- The origin of the transaction.
-
transact
public static <T> T transact(Doc doc, java.util.function.Function<Transaction,T> f, java.lang.Object origin)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The function to execute within the transaction.origin- The origin of the transaction.- Returns:
- The result of the function.
-
transact
public static void transact(Doc doc, java.lang.Runnable f, java.lang.Object origin, boolean local)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Runnable to execute within the transaction.origin- The origin of the transaction.local- Whether the transaction is local.
-
transact
public static void transact(Doc doc, java.util.function.Consumer<Transaction> f, java.lang.Object origin, boolean local)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Consumer to execute within the transaction.origin- The origin of the transaction.local- Whether the transaction is local.
-
transact
public static <T> T transact(Doc doc, java.util.function.Function<Transaction,T> f, java.lang.Object origin, boolean local)
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Function to execute within the transaction.origin- The origin of the transaction.local- Whether the transaction is local.- Returns:
- The result of the function.
-
-