[jOOQ/jOOQ#12425] Move ROWID to API generator
This commit is contained in:
parent
bf03f64549
commit
8446afcaff
@ -344,33 +344,6 @@ public interface Table<R extends Record> extends TableLike<R>, RecordQualifier<R
|
||||
@Support
|
||||
QualifiedAsterisk asterisk();
|
||||
|
||||
/**
|
||||
* Get a <code>table.rowid</code> reference from this table.
|
||||
* <p>
|
||||
* A rowid value describes the physical location of a row on the disk, which
|
||||
* can be used as a replacement for a primary key in some situations -
|
||||
* especially within a query, e.g. to self-join a table:
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* -- Emulating this MySQL statement...
|
||||
* DELETE FROM x ORDER BY x.y LIMIT 1
|
||||
*
|
||||
* -- ... in other databases
|
||||
* DELETE FROM x
|
||||
* WHERE x.rowid IN (
|
||||
* SELECT x.rowid FROM x ORDER BY x.a LIMIT 1
|
||||
* )
|
||||
* </pre></code>
|
||||
* <p>
|
||||
* It is <em>not</em> recommended to use <code>rowid</code> values in client
|
||||
* applications as actual row identifiers as the database system may move a
|
||||
* row to a different physical location at any time, thus changing the rowid
|
||||
* value. In general, use primary keys, instead.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, POSTGRES, SQLITE })
|
||||
Field<RowId> rowid();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: Aliasing clauses
|
||||
// -------------------------------------------------------------------------
|
||||
@ -2452,6 +2425,39 @@ public interface Table<R extends Record> extends TableLike<R>, RecordQualifier<R
|
||||
@Support
|
||||
Condition notEqual(Table<R> arg2);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Table functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The <code>ROWID</code> operator.
|
||||
* <p>
|
||||
* Get a <code>table.rowid</code> reference from this table.
|
||||
* <p>
|
||||
* A rowid value describes the physical location of a row on the disk, which
|
||||
* can be used as a replacement for a primary key in some situations -
|
||||
* especially within a query, e.g. to self-join a table:
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* -- Emulating this MySQL statement...
|
||||
* DELETE FROM x ORDER BY x.y LIMIT 1
|
||||
*
|
||||
* -- ... in other databases
|
||||
* DELETE FROM x
|
||||
* WHERE x.rowid IN (
|
||||
* SELECT x.rowid FROM x ORDER BY x.a LIMIT 1
|
||||
* )
|
||||
* </pre></code>
|
||||
* <p>
|
||||
* It is <em>not</em> recommended to use <code>rowid</code> values in client
|
||||
* applications as actual row identifiers as the database system may move a
|
||||
* row to a different physical location at any time, thus changing the rowid
|
||||
* value. In general, use primary keys, instead.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, POSTGRES, SQLITE })
|
||||
Field<RowId> rowid();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -174,11 +174,6 @@ abstract class AbstractTable<R extends Record> extends AbstractNamed implements
|
||||
return new QualifiedAsteriskImpl(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<RowId> rowid() {
|
||||
return new RowIdField(this);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: TableLike API
|
||||
// ------------------------------------------------------------------------
|
||||
@ -782,6 +777,15 @@ abstract class AbstractTable<R extends Record> extends AbstractNamed implements
|
||||
return ne(arg2);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Table functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final Field<RowId> rowid() {
|
||||
return new QualifiedRowid(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -74,7 +74,7 @@ extends
|
||||
Condition condition
|
||||
) {
|
||||
super(
|
||||
N_CONDITION_AS_FIELD,
|
||||
N_FIELD,
|
||||
allNotNull(BOOLEAN)
|
||||
);
|
||||
|
||||
|
||||
@ -19612,7 +19612,7 @@ public class DSL {
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>XMLSERIALIZE_DOCUMENT</code> function.
|
||||
* The <code>XMLSERIALIZE</code> function.
|
||||
*
|
||||
* @param value is wrapped as {@link #val(Object)}.
|
||||
*/
|
||||
@ -19623,7 +19623,7 @@ public class DSL {
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>XMLSERIALIZE_DOCUMENT</code> function.
|
||||
* The <code>XMLSERIALIZE</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ POSTGRES })
|
||||
@ -19887,7 +19887,7 @@ public class DSL {
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>REGR_AVG_X</code> function.
|
||||
* The <code>REGR_AVGX</code> function.
|
||||
* <p>
|
||||
* Calculate the average of the independent values (x). This standard SQL function may
|
||||
* be supported natively, or emulated using {@link #sum(Field)} and {@link #count(Field)}.
|
||||
@ -19901,7 +19901,7 @@ public class DSL {
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>REGR_AVG_Y</code> function.
|
||||
* The <code>REGR_AVGY</code> function.
|
||||
* <p>
|
||||
* Calculate the average of the dependent values (y). This standard SQL function may
|
||||
* be supported natively, or emulated using {@link #sum(Field)} and {@link #count(Field)}.
|
||||
|
||||
@ -75,7 +75,7 @@ extends
|
||||
Field<? extends Number> radians
|
||||
) {
|
||||
super(
|
||||
N_DEGREES,
|
||||
N_DEG,
|
||||
allNotNull(NUMERIC, radians)
|
||||
);
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@ extends
|
||||
|
||||
Euler() {
|
||||
super(
|
||||
N_EULER,
|
||||
N_E,
|
||||
allNotNull(NUMERIC)
|
||||
);
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ extends
|
||||
Field<? extends Number> value
|
||||
) {
|
||||
super(
|
||||
N_LOG,
|
||||
N_LN,
|
||||
allNotNull(NUMERIC, value)
|
||||
);
|
||||
|
||||
@ -89,7 +89,7 @@ extends
|
||||
Field<? extends Number> base
|
||||
) {
|
||||
super(
|
||||
N_LOG,
|
||||
N_LN,
|
||||
allNotNull(NUMERIC, value, base)
|
||||
);
|
||||
|
||||
|
||||
@ -119,7 +119,6 @@ final class Names {
|
||||
static final Name N_CHR = unquotedName("chr");
|
||||
static final Name N_COALESCE = unquotedName("coalesce");
|
||||
static final Name N_COLLECT = unquotedName("collect");
|
||||
static final Name N_CONDITION_AS_FIELD = unquotedName("condition_as_field");
|
||||
static final Name N_CONCAT = unquotedName("concat");
|
||||
static final Name N_CONNECT_BY_IS_CYCLE = unquotedName("connect_by_iscycle");
|
||||
static final Name N_CONNECT_BY_IS_LEAF = unquotedName("connect_by_isleaf");
|
||||
@ -162,6 +161,7 @@ final class Names {
|
||||
static final Name N_DB_NAME = unquotedName("db_name");
|
||||
static final Name N_DECODE = unquotedName("decode");
|
||||
static final Name N_DEFAULT = unquotedName("default");
|
||||
static final Name N_DEG = unquotedName("deg");
|
||||
static final Name N_DEGREES = unquotedName("degrees");
|
||||
static final Name N_DELETING = unquotedName("deleting");
|
||||
static final Name N_DENSE_RANK = unquotedName("dense_rank");
|
||||
@ -263,7 +263,6 @@ final class Names {
|
||||
static final Name N_NEWID = unquotedName("newid");
|
||||
static final Name N_NEXTVAL = unquotedName("nextval");
|
||||
static final Name N_NOT = unquotedName("not");
|
||||
static final Name N_NOT_FIELD = unquotedName("not_field");
|
||||
static final Name N_NOW = unquotedName("now");
|
||||
static final Name N_NTILE = unquotedName("ntile");
|
||||
static final Name N_NULLIF = unquotedName("nullif");
|
||||
@ -287,6 +286,7 @@ final class Names {
|
||||
static final Name N_PRINTF = unquotedName("printf");
|
||||
static final Name N_PRIOR = unquotedName("prior");
|
||||
static final Name N_PRODUCT = unquotedName("product");
|
||||
static final Name N_RAD = unquotedName("rad");
|
||||
static final Name N_RADIANS = unquotedName("radians");
|
||||
static final Name N_RAND = unquotedName("rand");
|
||||
static final Name N_RANDOM = unquotedName("random");
|
||||
@ -319,6 +319,7 @@ final class Names {
|
||||
static final Name N_ROUND = unquotedName("round");
|
||||
static final Name N_ROUND_DOWN = unquotedName("round_down");
|
||||
static final Name N_ROW = unquotedName("row");
|
||||
static final Name N_ROWID = unquotedName("rowid");
|
||||
static final Name N_ROWNUM = unquotedName("rownum");
|
||||
static final Name N_ROWSFROM = unquotedName("rowsfrom");
|
||||
static final Name N_ROW_NUMBER = unquotedName("row_number");
|
||||
|
||||
@ -74,7 +74,7 @@ extends
|
||||
Field<Boolean> arg1
|
||||
) {
|
||||
super(
|
||||
N_NOT_FIELD,
|
||||
N_NOT,
|
||||
allNotNull(BOOLEAN, arg1)
|
||||
);
|
||||
|
||||
|
||||
140
jOOQ/src/main/java/org/jooq/impl/QualifiedRowid.java
Normal file
140
jOOQ/src/main/java/org/jooq/impl/QualifiedRowid.java
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.*;
|
||||
import static org.jooq.impl.Internal.*;
|
||||
import static org.jooq.impl.Keywords.*;
|
||||
import static org.jooq.impl.Names.*;
|
||||
import static org.jooq.impl.SQLDataType.*;
|
||||
import static org.jooq.impl.Tools.*;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.*;
|
||||
import static org.jooq.impl.Tools.DataExtendedKey.*;
|
||||
import static org.jooq.impl.Tools.DataKey.*;
|
||||
import static org.jooq.SQLDialect.*;
|
||||
|
||||
import org.jooq.*;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.conf.*;
|
||||
import org.jooq.impl.*;
|
||||
import org.jooq.tools.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ROWID</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
final class QualifiedRowid
|
||||
extends
|
||||
AbstractField<RowId>
|
||||
{
|
||||
|
||||
final Table<?> arg1;
|
||||
|
||||
QualifiedRowid(
|
||||
Table<?> arg1
|
||||
) {
|
||||
super(
|
||||
N_ROWID,
|
||||
allNotNull(ROWID)
|
||||
);
|
||||
|
||||
this.arg1 = arg1;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case H2:
|
||||
ctx.visit(arg1.getQualifiedName().append(unquotedName("_rowid_")));
|
||||
break;
|
||||
|
||||
case POSTGRES:
|
||||
ctx.visit(arg1.getQualifiedName().append(unquotedName("ctid")));
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
ctx.visit(arg1.getQualifiedName().append(unquotedName("rowid")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof QualifiedRowid) {
|
||||
return
|
||||
StringUtils.equals(arg1, ((QualifiedRowid) that).arg1)
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,7 @@ extends
|
||||
Field<? extends Number> degrees
|
||||
) {
|
||||
super(
|
||||
N_RADIANS,
|
||||
N_RAD,
|
||||
allNotNull(NUMERIC, degrees)
|
||||
);
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ import java.math.BigDecimal;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>REGR AVG X</code> statement.
|
||||
* The <code>REGR AVGX</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
final class RegrAvgx
|
||||
|
||||
@ -61,7 +61,7 @@ import java.math.BigDecimal;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>REGR AVG Y</code> statement.
|
||||
* The <code>REGR AVGY</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
final class RegrAvgy
|
||||
|
||||
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.unquotedName;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.RowId;
|
||||
import org.jooq.Table;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class RowIdField extends AbstractField<RowId> {
|
||||
private final Table<?> table;
|
||||
|
||||
RowIdField(Table<?> table) {
|
||||
super(table.getQualifiedName().append(unquotedName("rowid")), SQLDataType.ROWID);
|
||||
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
case H2:
|
||||
ctx.visit(table.getQualifiedName().append(unquotedName("_rowid_")));
|
||||
break;
|
||||
|
||||
case POSTGRES:
|
||||
ctx.visit(table.getQualifiedName().append(unquotedName("ctid")));
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
ctx.visit(getQualifiedName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,7 +60,7 @@ import java.util.stream.*;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>XMLSERIALIZE DOCUMENT</code> statement.
|
||||
* The <code>XMLSERIALIZE</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class Xmlserialize<T>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user