This is an automated email from the ASF dual-hosted git repository. ahuber pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push: new ca91795034 ISIS-3199: purge ObjectSerializer ca91795034 is described below commit ca91795034495f38b1f578b1f0d110bb36843a42 Author: Andi Huber <ahu...@apache.org> AuthorDate: Mon Sep 5 17:17:35 2022 +0200 ISIS-3199: purge ObjectSerializer --- .../metamodel/objectmanager/ObjectManager.java | 2 - .../objectmanager/ObjectManagerDefault.java | 3 - .../memento/ObjectMementoForScalar.java | 13 --- .../objectmanager/memento/_Recreatable.java | 7 +- .../memento/_RecreatableSerializable.java | 54 --------- .../objectmanager/serialize/ObjectSerializer.java | 129 --------------------- .../ObjectSerializer_builtinHandlers.java | 113 ------------------ 7 files changed, 1 insertion(+), 320 deletions(-) diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/ObjectManager.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/ObjectManager.java index d0ef9e9764..2e6e9b5f35 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/ObjectManager.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/ObjectManager.java @@ -32,7 +32,6 @@ import org.apache.isis.core.metamodel.context.HasMetaModelContext; import org.apache.isis.core.metamodel.object.ManagedObject; import org.apache.isis.core.metamodel.object.ProtoObject; import org.apache.isis.core.metamodel.objectmanager.memento.ObjectMemento; -import org.apache.isis.core.metamodel.objectmanager.serialize.ObjectSerializer; import org.apache.isis.core.metamodel.spec.ObjectSpecification; import lombok.NonNull; @@ -53,7 +52,6 @@ public interface ObjectManager extends HasMetaModelContext { ObjectLoader getObjectLoader(); ObjectBulkLoader getObjectBulkLoader(); ObjectBookmarker getObjectBookmarker(); - ObjectSerializer getObjectSerializer(); // -- OBJECT MEMENTOS diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/ObjectManagerDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/ObjectManagerDefault.java index 118c857364..6bbe36550e 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/ObjectManagerDefault.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/ObjectManagerDefault.java @@ -37,7 +37,6 @@ import org.apache.isis.core.metamodel.objectmanager.memento.ObjectMemento; import org.apache.isis.core.metamodel.objectmanager.memento.ObjectMementoCollection; import org.apache.isis.core.metamodel.objectmanager.memento.ObjectMementoForEmpty; import org.apache.isis.core.metamodel.objectmanager.memento.ObjectMementoForScalar; -import org.apache.isis.core.metamodel.objectmanager.serialize.ObjectSerializer; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -60,7 +59,6 @@ public class ObjectManagerDefault implements ObjectManager { @Getter(onMethod_ = {@Override}) private ObjectBulkLoader objectBulkLoader; @Getter(onMethod_ = {@Override}) private ObjectCreator objectCreator; @Getter(onMethod_ = {@Override}) private ObjectBookmarker objectBookmarker; - @Getter(onMethod_ = {@Override}) private ObjectSerializer objectSerializer; @PostConstruct public void init() { @@ -68,7 +66,6 @@ public class ObjectManagerDefault implements ObjectManager { objectLoader = ObjectLoader.createDefault(metaModelContext); objectBulkLoader = ObjectBulkLoader.createDefault(metaModelContext); objectBookmarker = ObjectBookmarker.createDefault(); - objectSerializer = ObjectSerializer.createDefault(metaModelContext); } @Override diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/ObjectMementoForScalar.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/ObjectMementoForScalar.java index 8967684dc3..2607dff32d 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/ObjectMementoForScalar.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/ObjectMementoForScalar.java @@ -117,19 +117,6 @@ implements HasLogicalType, Serializable, ObjectMemento { return; } - if(spec.isSerializable()) { - val serializer = spec.getMetaModelContext().getObjectManager().getObjectSerializer(); - - final int hashCode = adapter.getPojo().hashCode(); - - serializedPayload = serializer.serialize(adapter); - recreateStrategy = _Recreatable.RecreateStrategy.SERIALIZABLE; - // pseudo bookmark - bookmark = Bookmark.forLogicalTypeNameAndIdentifier( - getLogicalTypeName(), "" + hashCode); - return; - } - throw _Exceptions.illegalArgument("Don't know how to create an ObjectMemento for a type " + "with ObjectSpecification %s. " + "All other strategies failed. Type is neither " diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/_Recreatable.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/_Recreatable.java index 50dd84f829..ef8ecffcbe 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/_Recreatable.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/_Recreatable.java @@ -39,12 +39,7 @@ interface _Recreatable { * The {@link ManagedObject} that this is for, is already known by its * (persistent) {@link Oid}. */ - LOOKUP(new _RecreatableLookup()), - /** - * If all other strategies fail, as last resort we use plain java serialization, provided - * that the type in question is serializable - */ - SERIALIZABLE(new _RecreatableSerializable()); + LOOKUP(new _RecreatableLookup()); private final _Recreatable delegate; diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/_RecreatableSerializable.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/_RecreatableSerializable.java deleted file mode 100644 index bbc3023b8a..0000000000 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/memento/_RecreatableSerializable.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.isis.core.metamodel.objectmanager.memento; - -import java.util.Objects; - -import org.apache.isis.core.metamodel.context.MetaModelContext; -import org.apache.isis.core.metamodel.object.ManagedObject; -import org.apache.isis.core.metamodel.spec.ObjectSpecification; - -class _RecreatableSerializable implements _Recreatable{ - - @Override - public ManagedObject recreateObject( - final ObjectMementoForScalar memento, - final MetaModelContext mmc) { - ObjectSpecification spec = mmc.getSpecificationLoader() - .specForLogicalTypeElseFail(memento.logicalType); - return mmc.getObjectManager().getObjectSerializer() - .deserialize(spec, memento.serializedPayload); - } - - @Override - public boolean equals( - final ObjectMementoForScalar memento, - final ObjectMementoForScalar otherMemento) { - return otherMemento.recreateStrategy == RecreateStrategy.SERIALIZABLE - && Objects.equals(memento.logicalType, otherMemento.logicalType) - && Objects.equals(memento.serializedPayload, otherMemento.serializedPayload); - } - - @Override - public int hashCode(final ObjectMementoForScalar memento) { - // thats where we stored the hash of the originating pojo - return memento.bookmark.getIdentifier().hashCode(); - } - -} diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/serialize/ObjectSerializer.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/serialize/ObjectSerializer.java deleted file mode 100644 index a653343697..0000000000 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/serialize/ObjectSerializer.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.isis.core.metamodel.objectmanager.serialize; - -import org.springframework.lang.Nullable; - -import org.apache.isis.commons.handler.ChainOfResponsibility; -import org.apache.isis.commons.internal.collections._Lists; -import org.apache.isis.core.metamodel.context.MetaModelContext; -import org.apache.isis.core.metamodel.object.ManagedObject; -import org.apache.isis.core.metamodel.spec.ObjectSpecification; - -import lombok.NonNull; -import lombok.Value; -import lombok.val; - -public interface ObjectSerializer { - - /** - * Does both, serialize or deserialize, depending on the request's type. - * @apiNote Rather use the more convenient specialized variants - * {@link #serialize(ManagedObject)} and {@link #deserialize(ObjectSpecification, byte[])} - * @param request - */ - BiForm serializeObject(BiForm request); - - default ManagedObject deserialize(final ObjectSpecification spec, final byte[] serializedObjectBytes) { - val request = BiForm.deSerializationRequest(SerializedObject.of(spec, serializedObjectBytes)); - val response = serializeObject(request); - return response.getObject(); - } - - default byte[] serialize(final ManagedObject object) { - val request = BiForm.serializationRequest(object); - val response = serializeObject(request); - return response.getSerializedObject().getSerializedObjectBytes(); - } - - @Value(staticConstructor = "of") - static class SerializedObject { - @NonNull private ObjectSpecification specification; - @NonNull private byte[] serializedObjectBytes; - } - - // -- BOTH, REQUEST AND RESPONSE OBJECT FOR THE HANDLER - - @Value(staticConstructor = "of") - static class BiForm { - @Nullable private ManagedObject object; - @Nullable private SerializedObject serializedObject; - public boolean isSerialized() { return serializedObject!=null; } - public boolean isDeserialized() { return object!=null; } - public static BiForm serializationRequest(final ManagedObject object) { - return of(object, null); - } - public static BiForm deSerializationRequest(final SerializedObject serializedObject) { - return of(null, serializedObject); - } - public static BiForm serializationResponse(final SerializedObject serializedObject) { - return of(null, serializedObject); - } - public static BiForm deSerializationResponse(final ManagedObject object) { - return of(object, null); - } - public ObjectSpecification getSpecification() { - return isDeserialized() - ? object.getSpecification() - : serializedObject.getSpecification(); - } - } - - // -- HANDLER - - static interface Handler - extends ChainOfResponsibility.Handler<BiForm, BiForm> { - - @Override - default boolean isHandling(final BiForm request) { - val spec = request.getSpecification(); - return isHandling(spec); - } - - @Override - default BiForm handle(final BiForm request) { - val spec = request.getSpecification(); // can only be a scalar - if(request.isSerialized()) { - val serializedObjectBytes = request.getSerializedObject().getSerializedObjectBytes(); - return BiForm.deSerializationResponse( - ManagedObject.adaptScalar(spec, deserialize(spec, serializedObjectBytes))); - } else { - val serializedObjectBytes = serialize(request.getObject()); - return BiForm.serializationResponse(SerializedObject.of(spec, serializedObjectBytes)); - } - } - - boolean isHandling(ObjectSpecification spec); - Object deserialize(ObjectSpecification spec, byte[] serializedObjectBytes); - byte[] serialize(ManagedObject object); - } - - // -- FACTORY - - public static ObjectSerializer createDefault(final MetaModelContext metaModelContext) { - return request -> - ChainOfResponsibility.named( - "ObjectSerializer", - _Lists.of( - new ObjectSerializer_builtinHandlers.SerializeSerializable(), - new ObjectSerializer_builtinHandlers.SerializeOther())) - .handle(request); - } - -} diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/serialize/ObjectSerializer_builtinHandlers.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/serialize/ObjectSerializer_builtinHandlers.java deleted file mode 100644 index f370b9b2eb..0000000000 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/objectmanager/serialize/ObjectSerializer_builtinHandlers.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.isis.core.metamodel.objectmanager.serialize; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -import org.apache.isis.commons.internal.base._Bytes; -import org.apache.isis.commons.internal.base._Casts; -import org.apache.isis.commons.internal.exceptions._Exceptions; -import org.apache.isis.core.metamodel.context.MetaModelContext; -import org.apache.isis.core.metamodel.object.ManagedObject; -import org.apache.isis.core.metamodel.spec.ObjectSpecification; - -import lombok.Data; -import lombok.SneakyThrows; -import lombok.val; - -/** - * - * @since 2.0 - * - */ -final class ObjectSerializer_builtinHandlers { - - @Data - public static class SerializeSerializable implements ObjectSerializer.Handler { - - private MetaModelContext metaModelContext; - - @Override - public boolean isHandling(ObjectSpecification spec) { - return spec.isSerializable(); - } - - @SneakyThrows - @Override - public byte[] serialize(ManagedObject object) { - val bos = new ByteArrayOutputStream(16*1024); // 16k initial buffer size - try(val oos = new ObjectOutputStream(bos)){ - oos.writeObject(object.getPojo()); - oos.flush(); - return _Bytes.compress(bos.toByteArray()); - } - } - - @SneakyThrows - @Override - public Object deserialize(ObjectSpecification spec, byte[] serializedObjectBytes) { - val pojoType = spec.getCorrespondingClass(); - return unmarshall(pojoType, serializedObjectBytes); - } - - private <T> T unmarshall(Class<T> type, byte[] input) throws IOException, ClassNotFoundException { - try(val bis = new ByteArrayInputStream(_Bytes.decompress(input))){ - try(val ois = new ObjectInputStream(bis)) { - return _Casts.uncheckedCast(ois.readObject()); - } - } - } - - } - - @Data - public static class SerializeOther implements ObjectSerializer.Handler { - - private MetaModelContext metaModelContext; - - @Override - public boolean isHandling(ObjectSpecification spec) { - return true; // the last handler in the chain - } - - @Override - public byte[] serialize(ManagedObject object) { - throw _Exceptions.illegalArgument( - "None of the registered ObjectSerializers knows how to serialize this object. " - + "(when serializing pojo as held by ManagedObject %s)", - object); - } - - @Override - public Object deserialize(ObjectSpecification spec, byte[] serializedObjectBytes) { - throw _Exceptions.illegalArgument( - "None of the registered ObjectSerializers knows how to de-serialize " - + "an object having ObjectSpecification %s", - spec); - } - - } - - - -}