All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.jooq.converter.JooqConverterFactoryProducer Maven / Gradle / Ivy

package org.simpleflatmapper.jooq.converter;

import org.jooq.tools.json.JSONObject;
import org.jooq.tools.json.JSONParser;
import org.jooq.types.UByte;
import org.jooq.types.UInteger;
import org.jooq.types.ULong;
import org.jooq.types.UShort;
import org.simpleflatmapper.converter.AbstractContextualConverterFactoryProducer;
import org.simpleflatmapper.converter.Context;
import org.simpleflatmapper.converter.ContextualConverter;
import org.simpleflatmapper.converter.ContextualConverterFactory;
import org.simpleflatmapper.util.Consumer;

import java.math.BigInteger;

public class JooqConverterFactoryProducer extends AbstractContextualConverterFactoryProducer {
    @Override
    public void produce(Consumer> consumer) {
        this.constantConverter(consumer, byte.class, UByte.class, new ContextualConverter() {
            @Override
            public UByte convert(Byte in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return UByte.valueOf(in);
            }
        });
        this.constantConverter(consumer, short.class, UByte.class, new ContextualConverter() {
            @Override
            public UByte convert(Short in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return UByte.valueOf(in);
            }
        });
        this.constantConverter(consumer, int.class, UByte.class, new ContextualConverter() {
            @Override
            public UByte convert(Integer in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return UByte.valueOf(in);
            }
        });
        this.constantConverter(consumer, long.class, UByte.class, new ContextualConverter() {
            @Override
            public UByte convert(Long in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return UByte.valueOf(in);
            }
        });

        this.constantConverter(consumer, short.class, UShort.class, new ContextualConverter() {
            @Override
            public UShort convert(Short in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return UShort.valueOf(in);
            }
        });
        this.constantConverter(consumer, int.class, UShort.class, new ContextualConverter() {
            @Override
            public UShort convert(Integer in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return UShort.valueOf(in);
            }
        });

        this.constantConverter(consumer, int.class, UInteger.class, new ContextualConverter() {
            @Override
            public UInteger convert(Integer in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return UInteger.valueOf(in);
            }
        });
        this.constantConverter(consumer, long.class, UInteger.class, new ContextualConverter() {
            @Override
            public UInteger convert(Long in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return UInteger.valueOf(in);
            }
        });

        this.constantConverter(consumer, long.class, ULong.class, new ContextualConverter() {
            @Override
            public ULong convert(Long in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return ULong.valueOf(in);
            }
        });
        this.constantConverter(consumer, BigInteger.class, ULong.class, new ContextualConverter() {
            @Override
            public ULong convert(BigInteger in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                return ULong.valueOf(in);
            }
        });
        this.constantConverter(consumer, String.class, JSONObject.class, new ContextualConverter() {
            @Override
            public JSONObject convert(String in, Context context) throws Exception {
                if (in == null) {
                    return null;
                }
                JSONParser parser = new JSONParser();
                return (JSONObject)parser.parse(in);
            }
        });
        
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy