@Override public JdbcColumnKey newKey(String name, int i) { return new JdbcColumnKey(name, i); } };
@Override public JdbcColumnKey newKey(String name, int i) { return new JdbcColumnKey(name, i); } };
/** * add a new mapping to the specified property with the specified index, the specified type. * * @param column the property name * @param index the property index * @param sqlType the property type, @see java.sql.Types * @param columnDefinition the property definition * @return the current builder */ public JdbcMapperBuilder<T> addMapping(final String column, final int index, final int sqlType, FieldMapperColumnDefinition<JdbcColumnKey> columnDefinition) { return addMapping(new JdbcColumnKey(column, index, sqlType), columnDefinition); }
/** * add a new mapping to the specified property with the specified index, the specified type. * * @param column the property name * @param index the property index * @param sqlType the property type, @see java.sql.Types * @param columnDefinition the property definition * @return the current builder */ public JdbcMapperBuilder<T> addMapping(final String column, final int index, final int sqlType, FieldMapperColumnDefinition<JdbcColumnKey> columnDefinition) { return addMapping(new JdbcColumnKey(column, index, sqlType), columnDefinition); }
/** * add a new mapping to the specified property with the specified index, the specified type. * * @param column the property name * @param index the property index * @param sqlType the property type, @see java.sql.Types * @param properties the property properties * @return the current builder */ public JdbcMapperBuilder<T> addMapping(final String column, final int index, final int sqlType, Object... properties) { return addMapping(new JdbcColumnKey(column, index, sqlType), properties); }
@Override protected JdbcColumnKey newKey(String name, int i) { return new JdbcColumnKey(name, i); } }
/** * add a new mapping to the specified property with the specified index, the specified type. * * @param column the property name * @param index the property index * @param sqlType the property type, @see java.sql.Types * @param properties the property properties * @return the current builder */ public JdbcMapperBuilder<T> addMapping(final String column, final int index, final int sqlType, Object... properties) { return addMapping(new JdbcColumnKey(column, index, sqlType), properties); }
public static JdbcColumnKey of(ResultSetMetaData metaData, int columnIndex) throws SQLException { return new JdbcColumnKey(metaData.getColumnLabel(columnIndex), columnIndex, metaData.getColumnType(columnIndex), metaData.getColumnClassName(columnIndex)); }
@Test public void testEquals() throws Exception { assertEquals(new JdbcColumnKey("col", 1, Types.ARRAY), new JdbcColumnKey("col", 1, Types.ARRAY)); assertNotEquals(new JdbcColumnKey("col", 1, Types.ARRAY), new JdbcColumnKey("col", 1, Types.VARCHAR)); assertNotEquals(new JdbcColumnKey("col", 1, Types.ARRAY), new JdbcColumnKey("col", 2, Types.ARRAY)); assertNotEquals(new JdbcColumnKey("col", 1, Types.ARRAY), new JdbcColumnKey("col1", 1, Types.ARRAY)); }
@Override protected JdbcColumnKey newKey(String column, int i, FieldMapperColumnDefinition<JdbcColumnKey> columnDefinition) { JdbcColumnKey key = new JdbcColumnKey(column, i); SqlTypeColumnProperty typeColumnProperty = columnDefinition.lookFor(SqlTypeColumnProperty.class); if (typeColumnProperty == null) { ColumnDefinition<JdbcColumnKey, ?> globalDef = mapperConfig.columnDefinitions().getColumnDefinition(key); typeColumnProperty = globalDef.lookFor(SqlTypeColumnProperty.class); } if (typeColumnProperty != null) { return new JdbcColumnKey(key.getName(), key.getIndex(), typeColumnProperty.getSqlType(), key); } return key; }
@Override protected JdbcColumnKey newKey(String column, int i, FieldMapperColumnDefinition<JdbcColumnKey> columnDefinition) { JdbcColumnKey key = new JdbcColumnKey(column, i); SqlTypeColumnProperty typeColumnProperty = columnDefinition.lookFor(SqlTypeColumnProperty.class); if (typeColumnProperty == null) { ColumnDefinition<JdbcColumnKey, ?> globalDef = mapperConfig.columnDefinitions().getColumnDefinition(key); typeColumnProperty = globalDef.lookFor(SqlTypeColumnProperty.class); } if (typeColumnProperty != null) { return new JdbcColumnKey(key.getName(), key.getIndex(), typeColumnProperty.getSqlType(), key); } return key; }
@Override public ContextualConverter<? super Array, ? extends List> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) { Type elementType = TypeHelper.getComponentTypeOfListOrArray(targetedTypes.getTo()); Getter<? super ResultSet, ?> getter = ResultSetGetterFactory.INSTANCE.newGetter(elementType, new JdbcColumnKey("elt", 2), params); return new SqlArrayToListConverter<Object>( getter); } });
@Override public ContextualConverter<? super Array, ? extends List> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) { Type elementType = TypeHelper.getComponentTypeOfListOrArray(targetedTypes.getTo()); Getter<? super ResultSet, ?> getter = ResultSetGetterFactory.INSTANCE.newGetter(elementType, new JdbcColumnKey("elt", 2), params); return new SqlArrayToListConverter<Object>( getter); } });
@SuppressWarnings("unchecked") private <T, P> PropertyMapping<T, P, JdbcColumnKey> newPropertyMapping(Getter getter, Class<P> clazz, int sqltype, Object... properties) { PropertyMeta<T, P> propertyMeta = mock(PropertyMeta.class); when(propertyMeta.getGetter()).thenReturn(getter); when(propertyMeta.getPropertyType()).thenReturn(clazz); return new PropertyMapping<T, P, JdbcColumnKey>( propertyMeta, new JdbcColumnKey("col", index++, sqltype), FieldMapperColumnDefinition.<JdbcColumnKey>of(properties)); }
@Test public void testHashCode() throws Exception { assertEquals(new JdbcColumnKey("col", 1, Types.ARRAY).hashCode(), new JdbcColumnKey("col", 1, Types.ARRAY).hashCode()); assertNotEquals(new JdbcColumnKey("col", 1, Types.ARRAY).hashCode(), new JdbcColumnKey("col", 1, Types.VARCHAR).hashCode()); assertNotEquals(new JdbcColumnKey("col", 1, Types.ARRAY).hashCode(), new JdbcColumnKey("col", 2, Types.ARRAY).hashCode()); assertNotEquals(new JdbcColumnKey("col", 1, Types.ARRAY).hashCode(), new JdbcColumnKey("col1", 1, Types.ARRAY).hashCode()); }
@Override public ContextualConverter<? super Array, ? extends Object> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) { Type elementType = TypeHelper.getComponentTypeOfListOrArray(targetedTypes.getTo()); Getter<? super ResultSet, ?> getter = ResultSetGetterFactory.INSTANCE.newGetter(elementType, new JdbcColumnKey("elt", 2), params); return new SqlArrayToJavaArrayConverter<Object>(TypeHelper.<Object>toClass(elementType), getter); }
@Test public void testToString() throws Exception { assertEquals("ColumnKey [columnName=col, columnIndex=1, sqlType=2003]", new JdbcColumnKey("col", 1, Types.ARRAY).toString()); } }
@Test public void testPrimitiveField() { ClassMeta<DbObject> classMeta = ReflectionService.newInstance(false).getClassMeta(DbObject.class); PropertyMeta<DbObject, Long> id = classMeta.newPropertyFinder().<Long>findProperty(new DefaultPropertyNameMatcher("id", 0, false, false), new Object[0], (TypeAffinity)null, ConstantPredicate.<PropertyMeta<?, ?>>truePredicate()); FieldMapperColumnDefinition<JdbcColumnKey> identity = FieldMapperColumnDefinition.identity(); PropertyMapping<DbObject, Long, JdbcColumnKey> propertyMapping = new PropertyMapping<DbObject, Long, JdbcColumnKey>(id, new JdbcColumnKey("id", 1), identity); FieldMapper<ResultSet, DbObject> fieldMapper = factory.newFieldMapper( propertyMapping, null, RethrowMapperBuilderErrorHandler.INSTANCE); assertTrue(fieldMapper instanceof LongConstantSourceFieldMapper); PropertyMapping<DbObject, Long, JdbcColumnKey> propertyMapping1 = new PropertyMapping<DbObject, Long, JdbcColumnKey>(id, new JdbcColumnKey("id", 0), identity); fieldMapper = factory.newFieldMapper(propertyMapping1, null, RethrowMapperBuilderErrorHandler.INSTANCE); assertTrue(fieldMapper instanceof LongConstantSourceFieldMapper); } }
@Test public void testAlias() throws Exception { assertNotNull(new JdbcColumnKey("col", 1, Types.ARRAY).alias("h").getParent()); }
@Test public void test544() { final String VALUES_VAL = "values_val"; final String VALUES = "values"; JdbcColumnKey valuesKeys = new JdbcColumnKey(VALUES, 1, Types.VARCHAR); JdbcMapperFactory .newInstance() .addAlias(VALUES, VALUES_VAL) .newBuilder(C544.class) .addMapping(valuesKeys) .mapper(); }