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

org.sfm.jooq.SfmRecordMapperProvider 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: 1.10.3
Show newest version
package org.sfm.jooq;

import org.jooq.*;
import org.sfm.map.Mapper;
import org.sfm.map.impl.MapperCache;
import org.sfm.map.impl.TargetColumnsMapperKey;

public class SfmRecordMapperProvider implements RecordMapperProvider {

	private final MapperCache> mapperCache = new MapperCache>();

	
	@Override
	public  RecordMapper provide(RecordType recordType, Class type) {
		
		TargetColumnsMapperKey key = getMapperKey(recordType, type);
		
		@SuppressWarnings("unchecked")
		Mapper mapper = (Mapper) mapperCache.get(key);
		
		if (mapper == null) {
			JooqMapperBuilder mapperBuilder = new JooqMapperBuilder(type);
			
			int i = 0;
			for(Field field : recordType.fields()) {
				mapperBuilder.addField(new JooqFieldKey(field, i++));
			}
			
			mapper = mapperBuilder.mapper();
			mapperCache.add(key, mapper);
		}
		
		return new RecordMapperWrapper(mapper);
	}

	
	private  TargetColumnsMapperKey getMapperKey(RecordType recordType, Class type) {
		String[] columns = new String[recordType.size()];
		int i = 0;
		for(Field field : recordType.fields()) {
			columns[i++] = field.getName();
		}
		
		return new TargetColumnsMapperKey(type, columns);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy