Skip to content

Commit

Permalink
BasicHelperNG / BasicWrapperNG with no serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Mar 8, 2024
1 parent c57acf0 commit 049cb68
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.fugerit.java.core.db.daogen;

public class BasicHelperNG {

public void throwUnsupported( String message ) {
BasicHelper.throwUnsupported( message );
}

}
Original file line number Diff line number Diff line change
@@ -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<T> implements Wrapper<T> {

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 );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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" ) );
}
} );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ModelUser> 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 ));
} );
}

}

0 comments on commit 049cb68

Please sign in to comment.