[jOOQ/jOOQ#9325] Add Name.empty() to check if a name consists only of the empty string

This commit is contained in:
Lukas Eder 2019-10-03 11:19:12 +02:00
parent b2a90be054
commit a4e92c30fd
4 changed files with 26 additions and 2 deletions

View File

@ -138,6 +138,15 @@ public interface Name extends QueryPart {
*/
String last();
/**
* Whether this is the empty name.
* <p>
* An unnamed object will have an <code>""</code> empty string as its name.
* If a table has no explicit schema, it will be located in the default
* schema whose name is <code>""</code>.
*/
boolean empty();
/**
* Whether this is a qualified name.
* <p>

View File

@ -59,8 +59,8 @@ abstract class AbstractName extends AbstractQueryPart implements Name {
/**
* Generated UID
*/
private static final long serialVersionUID = 8562325639223483938L;
static final Name NO_NAME = DSL.name("");
private static final long serialVersionUID = 8562325639223483938L;
static final UnqualifiedName NO_NAME = new UnqualifiedName("");
@Override
public final Name append(String name) {

View File

@ -178,6 +178,15 @@ final class QualifiedName extends AbstractName {
return qualifiedName.length > 0 ? qualifiedName[qualifiedName.length - 1].last() : null;
}
@Override
public final boolean empty() {
for (UnqualifiedName n : qualifiedName)
if (!n.empty())
return false;
return true;
}
@Override
public final boolean qualified() {
return qualifiedName.length > 1;

View File

@ -45,6 +45,7 @@ import org.jooq.Context;
import org.jooq.Name;
import org.jooq.conf.RenderQuotedNames;
import org.jooq.conf.SettingsTools;
import org.jooq.tools.StringUtils;
/**
* The default implementation for an unqualified SQL identifier.
@ -95,6 +96,11 @@ final class UnqualifiedName extends AbstractName {
return name;
}
@Override
public final boolean empty() {
return StringUtils.isEmpty(name);
}
@Override
public final boolean qualified() {
return false;