[#5623] Add Name.first() and Name.last()
This commit is contained in:
parent
649525512a
commit
d0c636d20a
@ -71,6 +71,16 @@ import org.jooq.conf.Settings;
|
||||
*/
|
||||
public interface Name extends QueryPart {
|
||||
|
||||
/**
|
||||
* Get the first segment of the qualified name (usually a {@link Catalog} or {@link Schema} name).
|
||||
*/
|
||||
String first();
|
||||
|
||||
/**
|
||||
* Get the last segment of the qualified name (usually a {@link Table}, {@link Field}, or {@link Parameter} name).
|
||||
*/
|
||||
String last();
|
||||
|
||||
/**
|
||||
* The qualified name of this SQL identifier.
|
||||
*/
|
||||
|
||||
@ -90,7 +90,7 @@ final class NameImpl extends AbstractQueryPart implements Name {
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx.literal(qualifiedName[qualifiedName.length - 1]);
|
||||
ctx.literal(last());
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,6 +99,24 @@ final class NameImpl extends AbstractQueryPart implements Name {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String first() {
|
||||
for (int i = 0; i < qualifiedName.length; i++)
|
||||
if (qualifiedName[i] != null)
|
||||
return qualifiedName[i];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String last() {
|
||||
for (int i = qualifiedName.length - 1; i >= 0; i--)
|
||||
if (qualifiedName[i] != null)
|
||||
return qualifiedName[i];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String[] getName() {
|
||||
return qualifiedName;
|
||||
@ -120,7 +138,7 @@ final class NameImpl extends AbstractQueryPart implements Name {
|
||||
if (qualifiedName.length != 1)
|
||||
throw new IllegalStateException("Cannot create a DerivedColumnList from a qualified name : " + Arrays.asList(qualifiedName));
|
||||
|
||||
return new DerivedColumnListImpl(qualifiedName[0], fieldNames);
|
||||
return new DerivedColumnListImpl(first(), fieldNames);
|
||||
}
|
||||
|
||||
|
||||
@ -132,7 +150,7 @@ final class NameImpl extends AbstractQueryPart implements Name {
|
||||
|
||||
@Override
|
||||
public final DerivedColumnListImpl fields(BiFunction<? super Field<?>, ? super Integer, ? extends String> fieldNameFunction) {
|
||||
return new DerivedColumnListImpl(qualifiedName[0], fieldNameFunction);
|
||||
return new DerivedColumnListImpl(first(), fieldNameFunction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user