Skip to content

Feature/type dictionary import export #128

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 3 commits into from
Jul 10, 2024
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 @@ -205,7 +205,7 @@ private BinaryPersistenceFoundation<?> hostConnectionFoundation()
hostFoundation.setTypeMismatchValidator(Persistence.typeMismatchValidatorFailing());

final PersistenceTypeDictionaryManager typeDictionaryManager = PersistenceTypeDictionaryManager.Transient(
hostFoundation.getTypeDictionaryCreator());
hostFoundation.getTypeDictionaryProvider());

final PersistenceTypeDictionaryView typeDictionaryView = this.provideTypeDictionary();
typeDictionaryView.allTypeDefinitions().forEach(d -> typeDictionaryManager.registerTypeDefinition(d.value()));
Expand Down Expand Up @@ -252,7 +252,7 @@ public BinaryPersistenceFoundation<?> provideClientPersistenceFoundation(
clientFoundation.setTypeIdProvider (protocol.idStrategy().createTypeIdProvider());

final PersistenceTypeDictionaryManager typeDictionaryManager = PersistenceTypeDictionaryManager.Transient(
clientFoundation.getTypeDictionaryCreator());
clientFoundation.getTypeDictionaryProvider());

final PersistenceTypeDictionaryView typeDictionaryView = protocol.typeDictionary();
typeDictionaryView.allTypeDefinitions().forEach(d -> typeDictionaryManager.registerTypeDefinition(d.value()));
Expand Down Expand Up @@ -376,7 +376,7 @@ public PersistenceTypeDictionary provideTypeDictionaryInternal()

initFoundation.setTypeDictionaryManager(
PersistenceTypeDictionaryManager.Transient(
initFoundation.getTypeDictionaryCreator()
initFoundation.getTypeDictionaryProvider()
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public default PersistenceTypeDictionaryView provideTypeDictionary()

initFoundation.setTypeDictionaryManager(
PersistenceTypeDictionaryManager.Transient(
initFoundation.getTypeDictionaryCreator()
initFoundation.getTypeDictionaryProvider()
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import static org.eclipse.serializer.util.X.notNull;

import org.eclipse.serializer.util.X;
import org.eclipse.serializer.persistence.exceptions.PersistenceException;
import org.eclipse.serializer.util.X;

public interface PersistenceTypeDictionaryManager extends PersistenceTypeDictionaryProvider
{
Expand Down Expand Up @@ -326,11 +326,11 @@ public final synchronized boolean registerRuntimeTypeDefinitions(


public static PersistenceTypeDictionaryManager Transient(
final PersistenceTypeDictionaryCreator typeDictionaryCreator
final PersistenceTypeDictionaryProvider typeDictionaryProvider
)
{
return new PersistenceTypeDictionaryManager.Transient(
notNull(typeDictionaryCreator)
notNull(typeDictionaryProvider)
);
}

Expand All @@ -340,18 +340,18 @@ public final class Transient extends PersistenceTypeDictionaryManager.Abstract<P
// instance fields //
////////////////////

private final PersistenceTypeDictionaryCreator typeDictionaryCreator;
private final PersistenceTypeDictionaryProvider typeDictionaryProvider;



///////////////////////////////////////////////////////////////////////////
// constructors //
/////////////////

Transient(final PersistenceTypeDictionaryCreator typeDictionaryCreator)
Transient(final PersistenceTypeDictionaryProvider typeDictionaryProvider)
{
super();
this.typeDictionaryCreator = typeDictionaryCreator;
this.typeDictionaryProvider = typeDictionaryProvider;
}


Expand All @@ -363,7 +363,7 @@ public final class Transient extends PersistenceTypeDictionaryManager.Abstract<P
@Override
protected PersistenceTypeDictionary internalProvideTypeDictionary()
{
return this.typeDictionaryCreator.createTypeDictionary();
return this.typeDictionaryProvider.provideTypeDictionary();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,14 @@ public final boolean registerType(final long tid, final Class<?> type) throws Pe
@Override
public final synchronized PersistenceTypeHandlerManager<D> initialize()
{
logger.info("Initializing type handler manager");

if(this.initialized)
{
// XDebug.debugln("already initialized");
logger.debug("type handler manager already initialized");
return this;
}

logger.info("Initializing type handler manager");

synchronized(this.typeHandlerRegistry)
{
this.synchInternalInitialize();
Expand Down
14 changes: 14 additions & 0 deletions serializer/src/main/java/org/eclipse/serializer/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public interface Serializer<M> extends AutoCloseable
* @return the deserialized object graph
*/
public <T> T deserialize(M medium);

/**
* Export the current type dictionary as String.
*
* @return type dictionary as String.
*/
public String exportTypeDictionay();

public static Serializer<byte[]> Bytes()
{
Expand Down Expand Up @@ -231,6 +238,13 @@ public synchronized void close()
}
}

@Override
public String exportTypeDictionay()
{
return this.foundation.getTypeDictionaryAssembler()
.assemble(this.persistenceManager.typeDictionary());
}

private void lazyInit()
{
if(this.persistenceManager == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.serializer.persistence.types.PersistenceRootsProvider;
import org.eclipse.serializer.persistence.types.PersistenceStorer;
import org.eclipse.serializer.persistence.types.PersistenceStorer.CreationObserver;
import org.eclipse.serializer.persistence.types.PersistenceTypeDictionaryLoader;
import org.eclipse.serializer.persistence.types.PersistenceTypeDictionaryManager;
import org.eclipse.serializer.persistence.types.PersistenceTypeHandlerManager;
import org.eclipse.serializer.persistence.types.PersistenceTypeIdProvider;
Expand All @@ -50,6 +51,8 @@ public interface SerializerFoundation<F extends SerializerFoundation<?>> extends

public F setSerializerTypeInfoStrategyCreator(SerializerTypeInfoStrategyCreator serializerTypeInfoStrategyCreator);

public F setInitialTypeDictionary(String typeDictionaryString);

public XEnum<Class<?>> getEntityTypes();

public F setEntityTypes(XEnum<Class<?>> entityTypes);
Expand All @@ -66,6 +69,14 @@ public static SerializerFoundation<?> New()
return new SerializerFoundation.Default<>();
}

public static SerializerFoundation<?> New(String typeDictionaryString)
{
SerializerFoundation<?> foundation = new SerializerFoundation.Default<>();
foundation.setInitialTypeDictionary(typeDictionaryString);

return foundation;
}


public static class Default<F extends SerializerFoundation.Default<?>>
extends BinaryPersistenceFoundation.Default<F>
Expand Down Expand Up @@ -96,6 +107,15 @@ public F setSerializerTypeInfoStrategyCreator(final SerializerTypeInfoStrategyCr
return this.$();
}

@Override
public F setInitialTypeDictionary(String typeDictionaryString)
{
this.setTypeDictionaryLoader(()->typeDictionaryString);
this.ensureTypeDictionaryProvider();

return this.$();
}

@Override
public XEnum<Class<?>> getEntityTypes()
{
Expand Down Expand Up @@ -269,12 +289,17 @@ protected PersistenceTypeDictionaryManager ensureTypeDictionaryManager()
{
final PersistenceTypeDictionaryManager newTypeDictionaryManager =
PersistenceTypeDictionaryManager.Transient(
this.getTypeDictionaryCreator()
this.getTypeDictionaryProvider()
)
;
return newTypeDictionaryManager;
}

@Override
protected PersistenceTypeDictionaryLoader ensureTypeDictionaryLoader() {
return () -> null;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ public synchronized void close()
}
}

@Override
public String exportTypeDictionay()
{
return this.foundation.getTypeDictionaryAssembler()
.assemble(this.persistenceManager.typeDictionary());
}

private void initialize()
{
if(this.persistenceManager == null)
Expand Down
Loading