/** * Add a {@link Field} to the map using its current name as the key * * @param column the Field to add * @return the value of any previous mapping with the specified key, or null if there was no mapping */ public Field<?> put(Field<?> column) { if (column == null) { throw new IllegalArgumentException("Cannot use null column in ProjectionMap"); } return map.put(column.getName(), column); }
/** * Add a {@link Field} to the map. If the name of the Field being added does not match the name, it will be aliased * to that name before being added to the map. * * @param name the key to use * @param column the Field to add * @return the value of any previous mapping with the specified key, or null if there was no mapping */ public Field<?> put(String name, Field<?> column) { if (column == null) { throw new IllegalArgumentException("Cannot use null column in ProjectionMap"); } if (SqlUtils.isEmpty(name)) { throw new IllegalArgumentException("Cannot use empty string as a key"); } if (!SqlUtils.equals(name, column.getName())) { column = column.as(name); } return map.put(name, column); }
/** * Clone the given {@link Field} with this object's name as its qualifier. This is useful for selecting * from views, subqueries, or aliased tables. * * @param field the field to clone * @return a clone of the given field with this object as its qualifier */ @SuppressWarnings("unchecked") public <F extends Field<?>> F qualifyField(F field) { if (field instanceof Property<?>) { return (F) ((Property<?>) field).asSelectionFromTable(this, null); } else { return (F) Field.field(field.getName(), getName()); } }
public void testInvalidProjectionIgnored() { ContentProviderQueryBuilder builder = getBuilder(); final String IGNORE = "foo"; String[] projection = {IGNORE, COL_GIVEN_NAME, COL_SURNAME, COL_LUCKY_NUMBER}; Query query = builder.setDataSource(TestModel.TABLE).build(projection, null, null, null); List<Field<?>> fields = query.getFields(); assertEquals(3, fields.size()); for (int i = 0; i < fields.size(); i++) { if (IGNORE.equals(fields.get(i).getName())) { fail("Invalid projection not ignored!"); } } }
public void testPutAliasesColumnIfNameDiffers() { final String key = "given_name"; ProjectionMap map = new ProjectionMap(); map.put(key, TestModel.FIRST_NAME); Field<?> field = map.get(key); assertEquals(key, field.getName()); }
/** * Add a {@link Field} to the map using its current name as the key * * @param column the Field to add * @return the value of any previous mapping with the specified key, or null if there was no mapping */ public Field<?> put(Field<?> column) { if (column == null) { throw new IllegalArgumentException("Cannot use null column in ProjectionMap"); } return map.put(column.getName(), column); }
/** * Add a {@link Field} to the map. If the name of the Field being added does not match the name, it will be aliased * to that name before being added to the map. * * @param name the key to use * @param column the Field to add * @return the value of any previous mapping with the specified key, or null if there was no mapping */ public Field<?> put(String name, Field<?> column) { if (column == null) { throw new IllegalArgumentException("Cannot use null column in ProjectionMap"); } if (SqlUtils.isEmpty(name)) { throw new IllegalArgumentException("Cannot use empty string as a key"); } if (!SqlUtils.equals(name, column.getName())) { column = column.as(name); } return map.put(name, column); }
/** * Clone the given {@link Field} with this object's name as its qualifier. This is useful for selecting * from views, subqueries, or aliased tables. * * @param field the field to clone * @return a clone of the given field with this object as its qualifier */ @SuppressWarnings("unchecked") public <F extends Field<?>> F qualifyField(F field) { if (field instanceof Property<?>) { return (F) ((Property<?>) field).asSelectionFromTable(this, null); } else { return (F) Field.field(field.getName(), getName()); } }