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

org.simpleflatmapper.map.mapper.AbstractColumnNameDiscriminatorMapperFactory Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.map.mapper;

import org.simpleflatmapper.map.FieldKey;
import org.simpleflatmapper.map.property.OptionalProperty;
import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.util.Consumer;

import java.lang.reflect.Type;

public class AbstractColumnNameDiscriminatorMapperFactory<
        K extends FieldKey,
        MF extends AbstractColumnNameDiscriminatorMapperFactory, S> extends AbstractMapperFactory {
    private final ColumnNameGetterFactory columnNameGetterFactory;
    public AbstractColumnNameDiscriminatorMapperFactory(AbstractMapperFactory config, ColumnNameGetterFactory columnNameGetterFactory) {
        super(config);
        this.columnNameGetterFactory = columnNameGetterFactory;
    }

    public AbstractColumnNameDiscriminatorMapperFactory(AbstractColumnDefinitionProvider columnDefinitions, ColumnDefinition identity, ColumnNameGetterFactory columnNameGetterFactory) {
        super(columnDefinitions, identity);
        this.columnNameGetterFactory = columnNameGetterFactory;
    }
    public  MF discriminator(Class commonType, String discriminatorColumn, Consumer> consumer) {
        return discriminator((Type)commonType, discriminatorColumn, consumer);
    }
    
    public  MF discriminator(Type commonType, String discriminatorColumn, Consumer> consumer) {
        return discriminator(commonType, discriminatorColumn, Object.class, consumer);
    }
    
    public  MF discriminator(Class commonType, String discriminatorColumn, Class discriminatorType, Consumer> consumer) {
        return discriminator((Type)commonType, discriminatorColumn, discriminatorType, consumer);
    }
    
    public  MF discriminator(Type commonType, String discriminatorColumn, Class discriminatorType, Consumer> consumer) {
        addColumnProperty(discriminatorColumn, OptionalProperty.INSTANCE);
        Getter getter = columnNameGetterFactory.getGetter(discriminatorColumn, discriminatorType);
        return discriminator(commonType, getter, consumer);
    }

    public interface ColumnNameGetterFactory {
         Getter getGetter(String discriminatorColumn, Class discriminatorType);
    }
    
}