[#3843] Deprecate DSL.fieldByName(), DSL.tableByName(),

DSL.schemaByName(), DSL.sequenceByName()
This commit is contained in:
lukaseder 2014-12-04 19:19:43 +01:00
parent 494924a1ab
commit d2cd24fb4d
18 changed files with 101 additions and 69 deletions

View File

@ -48,8 +48,9 @@ import static org.jooq.Clause.ALTER_TABLE_DROP;
import static org.jooq.Clause.ALTER_TABLE_TABLE;
import static org.jooq.SQLDialect.FIREBIRD;
// ...
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.queryPart;
import org.jooq.AlterTableAlterStep;
@ -103,7 +104,7 @@ class AlterTableImpl extends AbstractQuery implements
@Override
public final AlterTableImpl add(String field, DataType<?> type) {
return add((Field) fieldByName(type, field), type);
return add((Field) field(name(field), type), type);
}
@Override
@ -115,7 +116,7 @@ class AlterTableImpl extends AbstractQuery implements
@Override
public final AlterTableImpl alter(String field) {
return alter(fieldByName(field));
return alter(field(name(field)));
}
@Override
@ -143,7 +144,7 @@ class AlterTableImpl extends AbstractQuery implements
@Override
public final AlterTableImpl drop(String field) {
return drop(fieldByName(field));
return drop(field(name(field)));
}
@Override

View File

@ -40,7 +40,7 @@
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.name;
import java.util.ArrayList;
import java.util.List;
@ -130,7 +130,7 @@ class ArrayTable extends AbstractTable<Record> {
try {
UDTRecord<?> record = (UDTRecord<?>) arrayType.newInstance();
for (Field<?> f : record.fields()) {
result.add(fieldByName(f.getDataType(), alias, f.getName()));
result.add(DSL.field(name(alias, f.getName()), f.getDataType()));
}
}
catch (Exception e) {
@ -140,7 +140,7 @@ class ArrayTable extends AbstractTable<Record> {
// Simple array types have a synthetic field called "COLUMN_VALUE"
else {
result.add(fieldByName(DSL.getDataType(arrayType), alias, "COLUMN_VALUE"));
result.add(DSL.field(name(alias, "COLUMN_VALUE"), DSL.getDataType(arrayType)));
}
return new Fields<Record>(result);

View File

@ -41,7 +41,7 @@
package org.jooq.impl;
import static org.jooq.impl.DSL.falseCondition;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.using;
@ -86,7 +86,7 @@ class ArrayTableSimulation extends AbstractTable<Record> {
this.array = array;
this.alias = alias;
this.fieldAlias = fieldAlias == null ? "COLUMN_VALUE" : fieldAlias;
this.field = new Fields<Record>(fieldByName(DSL.getDataType(array.getClass().getComponentType()), alias, this.fieldAlias));
this.field = new Fields<Record>(DSL.field(name(alias, this.fieldAlias), DSL.getDataType(array.getClass().getComponentType())));
}
@Override

View File

@ -40,8 +40,6 @@
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.fieldByName;
import java.util.List;
import org.jooq.CommonTableExpression;
@ -122,14 +120,16 @@ class CommonTableExpressionImpl<R extends Record> extends AbstractTable<R> imple
Field<?>[] f = new Field[s.size()];
for (int i = 0; i < f.length; i++) {
f[i] = fieldByName(
s.get(i).getDataType(),
name.name,
f[i] = DSL.field(
DSL.name(
name.name,
// If the CTE has no explicit column names, inherit those of the subquery
name.fieldNames.length > 0
? name.fieldNames[i]
: s.get(i).getName());
// If the CTE has no explicit column names, inherit those of the subquery
name.fieldNames.length > 0
? name.fieldNames[i]
: s.get(i).getName()),
s.get(i).getDataType()
);
}
Fields<R> result = new Fields<R>(f);

View File

@ -41,9 +41,9 @@
package org.jooq.impl;
import static org.jooq.Clause.CREATE_INDEX;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.tableByName;
import static org.jooq.impl.DSL.table;
import org.jooq.Clause;
import org.jooq.Configuration;
@ -96,9 +96,9 @@ class CreateIndexImpl extends AbstractQuery implements
Field<?>[] f = new Field[fieldNames.length];
for (int i = 0; i < f.length; i++)
f[i] = fieldByName(fieldNames[i]);
f[i] = field(name(fieldNames[i]));
return on(tableByName(tableName), f);
return on(table(name(tableName)), f);
}
// ------------------------------------------------------------------------

View File

@ -48,7 +48,8 @@ import static org.jooq.Clause.CREATE_TABLE_NAME;
// ...
// ...
// ...
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.Utils.DATA_SELECT_INTO_TABLE;
import java.util.ArrayList;
@ -112,7 +113,7 @@ class CreateTableImpl<R extends Record> extends AbstractQuery implements
@Override
public final CreateTableColumnStep column(String field, DataType<?> type) {
columnFields.add(fieldByName(type, field));
columnFields.add(field(name(field), type));
columnTypes.add(type);
return this;
}

View File

@ -5054,7 +5054,9 @@ public class DSL {
*
* @param name The schema's reference name.
* @return A schema referenced by <code>name</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #schema(Name)} instead
*/
@Deprecated
@Support
public static Schema schemaByName(String name) {
return new SchemaImpl(name);
@ -5102,7 +5104,9 @@ public class DSL {
* @param qualifiedName The various parts making up your sequence's
* reference name.
* @return A sequence referenced by <code>sequenceName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #sequence(Name)} instead
*/
@Deprecated
@Support
public static Sequence<BigInteger> sequenceByName(String... qualifiedName) {
return sequenceByName(BigInteger.class, qualifiedName);
@ -5129,7 +5133,9 @@ public class DSL {
* reference name.
* @param type The type of the returned field
* @return A sequence referenced by <code>sequenceName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #sequence(Name, Class)} instead
*/
@Deprecated
@Support
public static <T extends Number> Sequence<T> sequenceByName(Class<T> type, String... qualifiedName) {
return sequenceByName(getDataType(type), qualifiedName);
@ -5156,7 +5162,9 @@ public class DSL {
* reference name.
* @param type The type of the returned field
* @return A sequence referenced by <code>sequenceName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #sequence(Name, DataType)} instead
*/
@Deprecated
@Support
public static <T extends Number> Sequence<T> sequenceByName(DataType<T> type, String... qualifiedName) {
if (qualifiedName == null)
@ -5266,7 +5274,9 @@ public class DSL {
* @param qualifiedName The various parts making up your table's reference
* name.
* @return A table referenced by <code>tableName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #table(Name)} instead
*/
@Deprecated
@Support
public static Table<Record> tableByName(String... qualifiedName) {
return table(name(qualifiedName));
@ -5323,7 +5333,9 @@ public class DSL {
* @param qualifiedName The various parts making up your field's reference
* name.
* @return A field referenced by <code>fieldName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #field(Name)} instead
*/
@Deprecated
@Support
public static Field<Object> fieldByName(String... qualifiedName) {
return fieldByName(Object.class, qualifiedName);
@ -5359,7 +5371,9 @@ public class DSL {
* name.
* @param type The type of the returned field
* @return A field referenced by <code>fieldName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #sequence(Name, Class)} instead
*/
@Deprecated
@Support
public static <T> Field<T> fieldByName(Class<T> type, String... qualifiedName) {
return fieldByName(getDataType(type), qualifiedName);
@ -5395,7 +5409,9 @@ public class DSL {
* name.
* @param type The type of the returned field
* @return A field referenced by <code>fieldName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #sequence(Name, DataType)} instead
*/
@Deprecated
@Support
public static <T> Field<T> fieldByName(DataType<T> type, String... qualifiedName) {
return field(name(qualifiedName), type);
@ -5491,7 +5507,7 @@ public class DSL {
*/
@Support
public static <T> Field<T> field(Name name, DataType<T> type) {
return new QualifiedField<T>(type, name);
return new QualifiedField<T>(name, type);
}
// -------------------------------------------------------------------------

View File

@ -44,10 +44,10 @@ import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.conf.ParamType.NAMED;
import static org.jooq.conf.ParamType.NAMED_OR_INLINED;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.queryPart;
import static org.jooq.impl.DSL.sequenceByName;
import static org.jooq.impl.DSL.tableByName;
import static org.jooq.impl.DSL.sequence;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.DSL.template;
import static org.jooq.impl.DSL.trueCondition;
import static org.jooq.impl.Utils.list;
@ -812,7 +812,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
List<Field<?>> fields = new ArrayList<Field<?>>();
for (String name : data.get(0)) {
fields.add(fieldByName(String.class, name));
fields.add(field(name(name), String.class));
}
Result<Record> result = new ResultImpl<Record>(configuration(), fields);
@ -1624,7 +1624,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public CreateViewAsStep<Record> createView(String viewName, String... fieldNames) {
return createView(tableByName(viewName), Utils.fieldsByName(viewName, fieldNames));
return createView(table(name(viewName)), Utils.fieldsByName(viewName, fieldNames));
}
@Override
@ -1634,7 +1634,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public CreateTableAsStep<Record> createTable(String tableName) {
return createTable(tableByName(tableName));
return createTable(table(name(tableName)));
}
@Override
@ -1654,7 +1654,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public CreateSequenceFinalStep createSequence(String sequence) {
return createSequence(sequenceByName(sequence));
return createSequence(sequence(name(sequence)));
}
@Override
@ -1664,7 +1664,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public AlterSequenceRestartStep<BigInteger> alterSequence(String sequence) {
return alterSequence(sequenceByName(sequence));
return alterSequence(sequence(name(sequence)));
}
@Override
@ -1674,7 +1674,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public AlterTableStep alterTable(String table) {
return alterTable(tableByName(table));
return alterTable(table(name(table)));
}
@Override
@ -1684,7 +1684,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public DropViewFinalStep dropView(String table) {
return dropView(tableByName(table));
return dropView(table(name(table)));
}
@Override
@ -1694,7 +1694,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public DropViewFinalStep dropViewIfExists(String table) {
return dropViewIfExists(tableByName(table));
return dropViewIfExists(table(name(table)));
}
@Override
@ -1704,7 +1704,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public DropTableStep dropTable(String table) {
return dropTable(tableByName(table));
return dropTable(table(name(table)));
}
@Override
@ -1714,7 +1714,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public DropTableStep dropTableIfExists(String table) {
return dropTableIfExists(tableByName(table));
return dropTableIfExists(table(name(table)));
}
@Override
@ -1734,7 +1734,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public DropSequenceFinalStep dropSequence(String sequence) {
return dropSequence(sequenceByName(sequence));
return dropSequence(sequence(name(sequence)));
}
@Override
@ -1744,7 +1744,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public DropSequenceFinalStep dropSequenceIfExists(String sequence) {
return dropSequenceIfExists(sequenceByName(sequence));
return dropSequenceIfExists(sequence(name(sequence)));
}
@Override
@ -1808,7 +1808,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public BigInteger nextval(String sequence) {
return nextval(sequenceByName(sequence));
return nextval(sequence(name(sequence)));
}
@Override
@ -1819,7 +1819,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public BigInteger currval(String sequence) {
return currval(sequenceByName(sequence));
return currval(sequence(name(sequence)));
}
@Override

View File

@ -117,6 +117,6 @@ class GenerateSeries extends AbstractTable<Record1<Integer>> {
@Override
final Fields<Record1<Integer>> fields0() {
return new Fields<Record1<Integer>>(DSL.fieldByName(Integer.class, "generate_series"));
return new Fields<Record1<Integer>>(DSL.field(name("generate_series"), Integer.class));
}
}

View File

@ -42,7 +42,8 @@ package org.jooq.impl;
import static java.lang.Boolean.TRUE;
import static org.jooq.Clause.SELECT;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.Utils.DATA_LOCALLY_SCOPED_DATA_MAP;
import static org.jooq.impl.Utils.DATA_OVERRIDE_ALIASES_IN_ORDER_BY;
import static org.jooq.impl.Utils.DATA_UNALIAS_ALIASES_IN_ORDER_BY;

View File

@ -41,6 +41,7 @@
package org.jooq.impl;
import static org.jooq.conf.RenderNameStyle.AS_IS;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.nullSafe;
import org.jooq.Context;
@ -83,7 +84,7 @@ class Prior<T> extends AbstractField<T> {
xx xxxxx xxx xxxxxx xxxxxxx xx xxxxx xxxxxxxxx
xxxxxxxx x x xxxxxx xxxxxxxxxx xxxxxxxxxxx
x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx
x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx
x xxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx

View File

@ -61,7 +61,7 @@ class QualifiedField<T> extends AbstractField<T> {
private final Name name;
QualifiedField(DataType<T> type, Name name) {
QualifiedField(Name name, DataType<T> type) {
super(name.getName()[name.getName().length - 1], type);
this.name = name;

View File

@ -44,7 +44,8 @@ package org.jooq.impl;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.jooq.impl.DSL.insertInto;
import static org.jooq.impl.DSL.tableByName;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.Utils.indexOrFail;
import static org.jooq.tools.StringUtils.abbreviate;
import static org.jooq.tools.StringUtils.leftPad;
@ -813,7 +814,7 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
table = ((TableRecord<?>) records.get(0)).getTable();
if (table == null)
table = tableByName("UNKNOWN_TABLE");
table = table(name("UNKNOWN_TABLE"));
formatInsert(writer, table, fields());
}

View File

@ -55,7 +55,8 @@ import static org.jooq.SQLDialect.MYSQL;
// ...
import static org.jooq.SQLDialect.POSTGRES;
import static org.jooq.impl.DSL.exists;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.notExists;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.select;
@ -163,7 +164,7 @@ class RowSubqueryCondition extends AbstractCondition {
Field<?>[] fields = new Field[names.size()];
for (int i = 0; i < fields.length; i++) {
fields[i] = fieldByName(table, names.get(i));
fields[i] = field(name(table, names.get(i)));
}
Condition condition;

View File

@ -54,8 +54,8 @@ import static org.jooq.conf.SettingsTools.reflectionCaching;
import static org.jooq.conf.SettingsTools.updatablePrimaryKeys;
import static org.jooq.impl.DSL.concat;
import static org.jooq.impl.DSL.escape;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.getDataType;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.nullSafe;
import static org.jooq.impl.DSL.val;
import static org.jooq.impl.DefaultExecuteContext.localConnection;
@ -669,7 +669,7 @@ final class Utils {
String[] names = fieldNames(length);
for (int i = 0; i < length; i++)
result[i] = fieldByName(names[i]);
result[i] = DSL.field(name(names[i]));
return result;
}
@ -692,9 +692,9 @@ final class Utils {
for (int i = 0; i < fieldNames.length; i++)
if (tableName == null)
result[i] = fieldByName(fieldNames[i]);
result[i] = DSL.field(name(fieldNames[i]));
else
result[i] = fieldByName(tableName, fieldNames[i]);
result[i] = DSL.field(name(tableName, fieldNames[i]));
return result;
}
@ -727,6 +727,14 @@ final class Utils {
}
}
/**
* @deprecated - This method is probably called by mistake (ambiguous static import).
*/
@Deprecated
static final Field<Object> field(Name name) {
return DSL.field(name);
}
/**
* Be sure that a given object is a field.
*
@ -945,7 +953,7 @@ final class Utils {
QueryPartList<Field<?>> result = new QueryPartList<Field<?>>();
for (Field<?> field : fields)
result.add(fieldByName(field.getName()));
result.add(DSL.field(name(field.getName())));
return result;
}

View File

@ -41,7 +41,8 @@
package org.jooq.tools.jdbc;
import static java.lang.reflect.Array.newInstance;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.name;
import java.sql.Array;
import java.sql.ResultSet;
@ -136,16 +137,16 @@ public class MockArray<T> implements Array {
private ResultSet getResultSet0(T[] a) {
DSLContext create = DSL.using(dialect);
Field<Long> index = fieldByName(Long.class, "INDEX");
Field<T> value = (Field<T>) fieldByName(type.getComponentType(), "VALUE");
Field<Long> index = field(name("INDEX"), Long.class);
Field<T> value = (Field<T>) field(name("VALUE"), type.getComponentType());
Result<Record2<Long, T>> result = create.newResult(index, value);
for (int i = 0; i < a.length; i++) {
Record2<Long, T> record = create.newRecord(index, value);
record.setValue(index, i + 1L);
record.setValue(value, a[i]);
result.add(record);
}

View File

@ -44,11 +44,11 @@ package org.jooq.test;
import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.impl.DSL.condition;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.param;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.tableByName;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.DSL.val;
import static org.jooq.test.data.Table1.FIELD_ID1;
import static org.jooq.test.data.Table1.TABLE1;
@ -725,8 +725,8 @@ public class BasicTest extends AbstractTest {
@Test
public void testQueryPartByName() throws Exception {
Field<Object> field = fieldByName("A", "b", "';`");
Table<Record> table = tableByName("A", "b", "';`");
Field<Object> field = field(name("A", "b", "';`"));
Table<Record> table = table(name("A", "b", "';`"));
assertEquals("`A`.`b`.`';```", r_ref().render(field));
assertEquals("`A`.`b`.`';```", r_refI().render(field));
@ -737,13 +737,13 @@ public class BasicTest extends AbstractTest {
@Test
public void testQueryPartByNameAndConditions() throws Exception {
List<String> v1 = Arrays.asList("1", "2");
Condition c1 = fieldByName(String.class, "A", "b").in(v1);
Condition c1 = field(name("A", "b"), String.class).in(v1);
assertEquals("`A`.`b` in (?, ?)", r_ref().render(c1));
assertEquals("`A`.`b` in ('1', '2')", r_refI().render(c1));
Set<String> v2 = new TreeSet<String>(Arrays.asList("1", "2"));
Condition c2 = fieldByName(String.class, "A", "b").in(v2);
Condition c2 = field(name("A", "b"), String.class).in(v2);
assertEquals("`A`.`b` in (?, ?)", r_ref().render(c2));
assertEquals("`A`.`b` in ('1', '2')", r_refI().render(c2));

View File

@ -41,7 +41,8 @@
package org.jooq.test;
import static org.jooq.impl.DSL.fieldByName;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.val;
import static org.junit.Assert.assertTrue;
@ -73,7 +74,7 @@ public class DataTypeTest extends AbstractTest {
Field integer = Table1.FIELD_ID1;
Field string = Table1.FIELD_NAME1;
Field object = fieldByName("ANY");
Field object = field(name("ANY"));
// Check if a correct type was coerced correctly
// ---------------------------------------------
@ -165,7 +166,7 @@ public class DataTypeTest extends AbstractTest {
Field integer = Table1.FIELD_ID1;
Field string = Table1.FIELD_NAME1;
Field object = fieldByName("ANY");
Field object = field(name("ANY"));
// Check if a correct type was coerced correctly
// ---------------------------------------------