org.jooq.RecordMapper Java Examples

The following examples show how to use org.jooq.RecordMapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Issue550Test.java    From SimpleFlatMapper with MIT License 6 votes vote down vote up
@Test
public void test550() throws SQLException {

    SfmRecordMapperProvider recordMapperProvider = 
            SfmRecordMapperProviderFactory
                    .newInstance()
                    .addAlias("DATA", "blob")
                    .newProvider();

    RecordType<Record> rt = mock(RecordType.class);


    Field[] fields = new Field[] {
            createField("id", Long.class),
            createField("data", Blob.class),
    };

    when(rt.size()).thenReturn(fields.length);
    when(rt.fields()).thenReturn(fields);

    RecordMapper<Record, Foo> mapper = recordMapperProvider.provide(rt, Foo.class);

    assertNotNull(mapper);
}
 
Example #2
Source File: Dao.java    From StubbornJava with MIT License 5 votes vote down vote up
public Dao(Table table,
           RecordMapper<Rec, T> mapper,
           RecordUnmapper<T, Rec> unmapper) {
    super();
    this.table = table;
    this.mapper = mapper;
    this.unmapper = unmapper;
}
 
Example #3
Source File: Dao.java    From StubbornJava with MIT License 5 votes vote down vote up
public Dao(Table table,
           RecordMapper<Rec, T> mapper,
           RecordUnmapper<T, Rec> unmapper) {
    super();
    this.table = table;
    this.mapper = mapper;
    this.unmapper = unmapper;
}
 
Example #4
Source File: SfmRecordMapperProvider.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
@Override
public <R extends org.jooq.Record, E> RecordMapper<R, E> provide(RecordType<R> recordType, Class<? extends E> type) {

	SourceMapper<org.jooq.Record, E> mapper;
	MappingContextFactory<? super org.jooq.Record> mappingContextFactory;

	TargetColumnsMapperKey key = getMapperKey(recordType, type);

	MapperAndContext mc = mapperCache.get(key);
	
			
	if (mc == null) {
		MapperConfig<JooqFieldKey, org.jooq.Record> mapperConfig = mapperConfigFactory.apply(type);

		JooqMapperBuilder<E> mapperBuilder =
				new JooqMapperBuilder<E>(
						reflectionService.<E>getClassMeta(type),
						new JooqMappingContextFactoryBuilder<org.jooq.Record>(!mapperConfig.unorderedJoin()),
						mapperConfig);

		int i = 0;
		for(Field<?> field : recordType.fields()) {
			mapperBuilder.addField(new JooqFieldKey(field, i++));
		}

		mapper = mapperBuilder.mapper();
		mappingContextFactory = mapperBuilder.contextFactory();
		
		mapperCache.putIfAbsent(key, new MapperAndContext(mapper, mappingContextFactory));
	} else {
		mapper = (SourceMapper<org.jooq.Record, E>) mc.mapper;
		mappingContextFactory = mc.mappingContextFactory;
	}
	
	return new JooqRecordMapperWrapper<R, E>(mapper, mappingContextFactory);
}
 
Example #5
Source File: Issue318Test.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testLocalDateTimeFromTimestamp() throws SQLException {

    SfmRecordMapperProvider recordMapperProvider = new SfmRecordMapperProvider();

    RecordType<Record> rt = mock(RecordType.class);


    Field[] fields = new Field[] {
        createField("t", Timestamp.class),
        createField("id", String.class)
        };

    when(rt.size()).thenReturn(fields.length);
    when(rt.fields()).thenReturn(fields);

    RecordMapper<Record, Issue318> mapper = recordMapperProvider.provide(rt, Issue318.class);

    assertNotNull(mapper);
}
 
Example #6
Source File: Issue629Test.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@Test
public void test629() throws SQLException {

    SfmRecordMapperProvider recordMapperProvider = 
            SfmRecordMapperProviderFactory
                    .newInstance()
                    .addAliasForType(Bar.class, "barId", "id")
                    .addAliasForType(Zoom.class, "zoomId", "id")
                    .newProvider();

    RecordType<Record> rt = mock(RecordType.class);

    Field[] fields = new Field[] {
            createField("id", Long.class),
    };

    when(rt.size()).thenReturn(fields.length);
    when(rt.fields()).thenReturn(fields);

    RecordMapper<Record, Foo> fooMapper = recordMapperProvider.provide(rt, Foo.class);
    assertNotNull(fooMapper);

    fields = new Field[] {
            createField("barId", Long.class),
    };

    reset(rt);
    when(rt.size()).thenReturn(fields.length);
    when(rt.fields()).thenReturn(fields);

    RecordMapper<Record, Bar> barMapper = recordMapperProvider.provide(rt,  Bar.class);
    assertNotNull(fooMapper);


    fields = new Field[] {
            createField("zoomId", Long.class),
    };

    reset(rt);
    when(rt.size()).thenReturn(fields.length);
    when(rt.fields()).thenReturn(fields);

    RecordMapper<Record, Zoom> zoomMapper = recordMapperProvider.provide(rt, Zoom.class);
    assertNotNull(fooMapper);
}
 
Example #7
Source File: Issue537Test.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@Test
public void testMonetaryAmount() throws SQLException, NoSuchMethodException {

    SfmRecordMapperProvider recordMapperProvider = SfmRecordMapperProviderFactory.newInstance().newProvider();

    RecordType<Record> rt = mock(RecordType.class);


    Field[] fields = new Field[] {
        createField("currencyAndAmount_number", Double.class),
        createField("currencyAndAmount_currency", String.class)
    };

    when(rt.size()).thenReturn(fields.length);
    when(rt.fields()).thenReturn(fields);

    RecordMapper<Record, Issue537> mapper = recordMapperProvider.provide(rt, Issue537.class);

    assertNotNull(mapper);
    
}
 
Example #8
Source File: Issue486Test.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@Test
public void testIssue() {

    SfmRecordMapperProvider recordMapperProvider = new SfmRecordMapperProvider();

    RecordType<Record> rt = mock(RecordType.class);


    Field[] fields = new Field[] {
            createField("t", Timestamp.class),
            createField("id", String.class)
    };

    when(rt.size()).thenReturn(fields.length);
    when(rt.fields()).thenReturn(fields);

    RecordMapper<Record, Issue486Test.Issue486> mapper = recordMapperProvider.provide(rt, Issue486Test.Issue486.class);

    assertNotNull(mapper);


}