Skip to content

Feature/store new object with #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.eclipse.serializer.persistence.types.PersistenceCommitListener;
import org.eclipse.serializer.persistence.types.PersistenceEagerStoringFieldEvaluator;
import org.eclipse.serializer.persistence.types.PersistenceLocalObjectIdRegistry;
import org.eclipse.serializer.persistence.types.PersistenceObjectRegistrationListener;
import org.eclipse.serializer.persistence.types.PersistenceObjectIdRequestor;
import org.eclipse.serializer.persistence.types.PersistenceObjectManager;
import org.eclipse.serializer.persistence.types.PersistenceObjectRegistrationListener;
import org.eclipse.serializer.persistence.types.PersistenceStoreHandler;
import org.eclipse.serializer.persistence.types.PersistenceStorer;
import org.eclipse.serializer.persistence.types.PersistenceTarget;
Expand Down Expand Up @@ -472,7 +472,7 @@ private void processItems()
// process and collect required instances in item chain (graph recursion transformed to iteration)
for(Item item = this.tail; item != null; item = item.next)
{
// locks internally. May not lock the whole loop or other storers can't lookup concurrently.
// locks internally. May not lock the whole loop or other storers can't look up concurrently.
this.storeItem(item);
}
}
Expand Down Expand Up @@ -806,6 +806,61 @@ public final void synchRebuildStoreItems(final int newLength)
this.hashSlots = newSlots;
this.hashRange = newRange;
}



@Override
public long store(Object instance, long objectId)
{
return this.internalStore(instance, objectId);
}

protected final long internalStore(final Object root, long objectId)
{
logger.debug(
"Store request: {}({}) with ID {}",
LazyArg(() -> systemString(root)),
LazyArgInContext(STORER_CONTEXT, root),
objectId
);

/* (03.12.2019 TM)NOTE:
* Special case logic to handle explicitly passed instances:
* - if already handled by this storer, don't handle again.
* Apart from that:
* - register to be handled in any case, even if already registered in the object registry.
* - handle all registered graph objects recursively (but transformed to an iteration).
* Note that this is NOT the same as apply, which does NOT store if the instance is already registry-known.
*/
long rootOid;
if(Swizzling.isFoundId(rootOid = this.lookupOid(root)))
{
return rootOid;
}

// initial registration. After that, storing adds via recursion the graph and processing items iteratively.
//rootOid = this.registerGuaranteed(notNull(root));

this.registerGuaranteed(objectId, root, null);

// repeatedly calling #store to add an instance to the item chain is fine, but processing may only happen once.
if(!this.isProcessingItems)
{
try
{
this.isProcessingItems = true;
this.processItems();
}
finally
{
this.isProcessingItems = false;
}
}

return rootOid;
}



}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public long store(final Object instance)
{
return this.actual.store(instance);
}

@Override
public long store(Object instance, long objectId)
{
return this.actual.store(instance, objectId);
}

@Override
public PersistenceStorer reinitialize(final long initialCapacity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public long store(final Object instance)
{
throw new PersistenceExceptionStorerDeactivated();
}

@Override
public long store(Object instance, long objectId)
{
throw new PersistenceExceptionStorerDeactivated();
}

@Override
public long[] storeAll(final Object... instances)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.eclipse.serializer.persistence.types;

import org.eclipse.serializer.persistence.exceptions.PersistenceExceptionConsistencyObject;

/*-
* #%L
* Eclipse Serializer Persistence
Expand Down Expand Up @@ -142,37 +144,6 @@ public default boolean isEmpty()
*/
public long maximumCapacity();

// /**
// * Returns whether this {@link Storer} instance has been initialized.
// * <p>
// * What being initialized means exactely depends on the implementation. The general contract means to bring the
// * instance's internal data into a state with which the instance can be used to perform its actual tasks.
// *
// * @return whether this {@link Storer} instance has been initialized.
// */
// public boolean isInitialized();
//
// /**
// * Ensures the storer instance is initialized, i.e. ready to perform storing.
// * This method is idempotent.
// * For a forced (re)initialization, see {@link #reinitialize()}.
// *
// * @return this.
// */
// public Storer initialize();
//
// /**
// * Ensures the storer instance is initialized, i.e. ready to perform storing.
// * If the storer instance needs to be initialized as a consequence of this call, the passed {@code initialCapacity}
// * is considered as an estimate for the number of unique instances to be handled until the next commit.
// * This method is idempotent, meaning if this instance is already initialized, the passed value might not have
// * any effect.
// * For a forced (re)initialization, see {@link #reinitialize(long)}.
// *
// * @return this.
// */
// public Storer initialize(long initialCapacity);

/**
* Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary.
*
Expand Down Expand Up @@ -200,10 +171,21 @@ public default boolean isEmpty()
public Storer ensureCapacity(long desiredCapacity);



public void registerCommitListener(PersistenceCommitListener listener);



public void registerRegistrationListener(PersistenceObjectRegistrationListener listener);

/**
* Stores the passed instance with the provided id and all referenced instances of persistable references recursively,
* but stores the passed instance and referenced instances only if they are newly encountered (e.g. don't have an id associated with
* them in the object registry, yet and are therefore required to be handled).
* <br><br>
* If the provided instance is allready persisted with an other id an {@link PersistenceExceptionConsistencyObject} exception is trown.
*
* @param instance the root instance of the subgraph of required instances to be stored.
* @param objectId the storage object id which shall be assigned to the passed instance.
* @return the object id representing the passed instance.
*/
public long store(Object instance, long objectId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,15 @@ public final long store(final Object root)
{
return this.storeGraph(root);
}

/**
* Not implemented!
*/
@Override
public long store(Object instance, long objectId)
{
throw new NotImplementedYetError();
}

@Override
public final long[] storeAll(final Object... instances)
Expand Down