diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bf37824..78441582 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- BasicHelperNG / BasicWrapperNG with no serialization + ## [8.5.1] - 2024-03-08 ### Added diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/daogen/BasicHelperNG.java b/fj-core/src/main/java/org/fugerit/java/core/db/daogen/BasicHelperNG.java new file mode 100644 index 00000000..c74355bc --- /dev/null +++ b/fj-core/src/main/java/org/fugerit/java/core/db/daogen/BasicHelperNG.java @@ -0,0 +1,9 @@ +package org.fugerit.java.core.db.daogen; + +public class BasicHelperNG { + + public void throwUnsupported( String message ) { + BasicHelper.throwUnsupported( message ); + } + +} diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/daogen/BasicWrapperNG.java b/fj-core/src/main/java/org/fugerit/java/core/db/daogen/BasicWrapperNG.java new file mode 100644 index 00000000..89a3a7fc --- /dev/null +++ b/fj-core/src/main/java/org/fugerit/java/core/db/daogen/BasicWrapperNG.java @@ -0,0 +1,39 @@ +package org.fugerit.java.core.db.daogen; + +import org.fugerit.java.core.lang.helpers.Wrapper; +import org.fugerit.java.core.lang.helpers.WrapperHelper; + +public class BasicWrapperNG implements Wrapper { + + public static void throwUnsupported( String message ) { + BasicHelper.throwUnsupported( message ); + } + + private T wrapped; + + @Override + public T unwrapModel() { + return wrapped; + } + + @Override + public void wrapModel(T wrapped) { + this.wrapped = wrapped; + } + + public BasicWrapperNG(T wrapped) { + super(); + this.wrapped = wrapped; + } + + @Override + public String toString() { + return this.getClass().getSimpleName()+"[wraps:"+unwrapModel().toString()+"]"; + } + + @Override + public T unwrap() { + return WrapperHelper.unwrap( this.wrapped ); + } + +} diff --git a/fj-core/src/main/java/org/fugerit/java/core/io/ObjectIO.java b/fj-core/src/main/java/org/fugerit/java/core/io/ObjectIO.java index c997d9fe..73bd27c0 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/io/ObjectIO.java +++ b/fj-core/src/main/java/org/fugerit/java/core/io/ObjectIO.java @@ -18,7 +18,7 @@ public static Object fullSerializationTest( Object value ) throws IOException { public static Object deserialize( byte[] data ) throws IOException { Object res = null; try ( ObjectInputStream ois = new ObjectInputStream( new ByteArrayInputStream( data ) ) ) { - res = HelperIOException.get( () -> ois.readObject() ); + res = HelperIOException.get( ois::readObject ); log.info( "deserializeTest, read object : {}", res ); } return res; diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/daogen/TestBasicDataFacade.java b/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/daogen/TestBasicDataFacade.java index cb769d77..83b94227 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/daogen/TestBasicDataFacade.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/daogen/TestBasicDataFacade.java @@ -1,18 +1,13 @@ package test.org.fugerit.java.core.db.dao.daogen; +import java.io.NotSerializableException; import java.io.Serializable; import java.math.BigDecimal; import org.fugerit.java.core.db.dao.DAOException; import org.fugerit.java.core.db.dao.DAORuntimeException; import org.fugerit.java.core.db.dao.FieldList; -import org.fugerit.java.core.db.daogen.BasicDaoResult; -import org.fugerit.java.core.db.daogen.BasicDataFacade; -import org.fugerit.java.core.db.daogen.BasicWrapper; -import org.fugerit.java.core.db.daogen.CloseableDAOContextSC; -import org.fugerit.java.core.db.daogen.DataEntityInfo; -import org.fugerit.java.core.db.daogen.DataEntityUtils; -import org.fugerit.java.core.db.daogen.QueryHelper; +import org.fugerit.java.core.db.daogen.*; import org.fugerit.java.core.function.SafeFunction; import org.junit.Assert; import org.junit.Test; @@ -85,13 +80,16 @@ public void testBasicDataFacade2() { log.info( "test 1 : {}", userWrapper.unwrap() ); log.info( "test 2 : {}", userWrapper.unwrapModel() ); log.info( "test 3 : {}", HELPER.fullSerializationTest( userWrapper ) ); + log.info( "test 4 : {}", userWrapper ); userWrapper.wrapModel( userTest ); Assert.assertThrows( UnsupportedOperationException.class , () -> BasicWrapper.throwUnsupported( "message" ) ); + userWrapper.wrapModel( userTest ); // test DataEntityUtils DataEntityUtils.unwrap( facade ); Assert.assertThrows( DAOException.class , () -> DataEntityUtils.unwrap( userTest ) ); QueryHelper helper = new QueryHelper( TABLE_NAME , new FieldList() ); DataEntityUtils.addToQuery( facade , helper ); + Assert.assertThrows( UnsupportedOperationException.class, () -> new BasicHelperNG().throwUnsupported( "test 1" ) ); } } ); } diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/daogen/TestBasicWrapperNG.java b/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/daogen/TestBasicWrapperNG.java new file mode 100644 index 00000000..ceb39aef --- /dev/null +++ b/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/daogen/TestBasicWrapperNG.java @@ -0,0 +1,32 @@ +package test.org.fugerit.java.core.db.dao.daogen; + +import lombok.extern.slf4j.Slf4j; +import org.fugerit.java.core.db.daogen.BasicWrapperNG; +import org.fugerit.java.core.function.SafeFunction; +import org.junit.Assert; +import org.junit.Test; +import test.org.fugerit.java.BasicTest; +import test.org.fugerit.java.core.db.dao.ModelUser; + +import java.io.NotSerializableException; + +@Slf4j +public class TestBasicWrapperNG { + + private static final BasicTest HELPER = new BasicTest(); + + @Test + public void testBasicDataFacade2() { + SafeFunction.apply( () -> { + ModelUser userTest = new ModelUser(); + // wrapper ng + BasicWrapperNG userWrapperNG = new BasicWrapperNG<>( userTest ); + log.info( "test 1 : {}", userWrapperNG.unwrap() ); + log.info( "test 2 : {}", userWrapperNG.unwrapModel() ); + log.info( "test 3 : {}", userWrapperNG ); + Assert.assertThrows( UnsupportedOperationException.class, () -> BasicWrapperNG.throwUnsupported( "test 1" ) ); + Assert.assertThrows(NotSerializableException.class, () -> HELPER.fullSerializationTest( userWrapperNG )); + } ); + } + +}