Skip to content

Commit 914dccd

Browse files
authored
[JOOQ]: Added support for YDB functions and types (#135)
1 parent 0c2df1e commit 914dccd

File tree

110 files changed

+6721
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+6721
-239
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.jooq.impl;
2+
3+
import org.jooq.DataType;
4+
import org.jooq.Field;
5+
import org.jooq.Name;
6+
7+
public abstract class AbstractYdbAggregateFunction<T> extends AbstractAggregateFunction<T> {
8+
protected AbstractYdbAggregateFunction(String name, DataType<T> type, Field<?>... arguments) {
9+
super(name, type, arguments);
10+
}
11+
12+
protected AbstractYdbAggregateFunction(Name name, DataType<T> type, Field<?>... arguments) {
13+
super(name, type, arguments);
14+
}
15+
16+
protected AbstractYdbAggregateFunction(boolean distinct, String name, DataType<T> type, Field<?>... arguments) {
17+
super(distinct, name, type, arguments);
18+
}
19+
20+
protected AbstractYdbAggregateFunction(boolean distinct, Name name, DataType<T> type, Field<?>... arguments) {
21+
super(distinct, name, type, arguments);
22+
}
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.jooq.impl;
2+
3+
public abstract class AbstractYdbCondition extends AbstractCondition {
4+
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.jooq.impl;
2+
3+
import org.jooq.Binding;
4+
import org.jooq.Comment;
5+
import org.jooq.Context;
6+
import org.jooq.DataType;
7+
import org.jooq.Name;
8+
9+
public abstract class AbstractYdbFunction<T> extends AbstractField<T> {
10+
protected AbstractYdbFunction(Name name, DataType<T> type) {
11+
super(name, type);
12+
}
13+
14+
protected AbstractYdbFunction(Name name, DataType<T> type, Comment comment, Binding<?, T> binding) {
15+
super(name, type, comment, binding);
16+
}
17+
18+
@Override
19+
protected boolean parenthesised(Context<?> ctx) {
20+
return true;
21+
}
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.jooq.impl;
2+
3+
import org.jooq.Binding;
4+
import org.jooq.DataType;
5+
import tech.ydb.jooq.YDB;
6+
7+
import static org.jooq.impl.DSL.name;
8+
9+
@SuppressWarnings({"UnstableApiUsage", "unchecked"})
10+
public final class DataTypesUtils {
11+
12+
private DataTypesUtils() {
13+
throw new UnsupportedOperationException();
14+
}
15+
16+
public static <T> DataType<T> newDataType(DataType<T> sqlDataType, String typeName) {
17+
return new DefaultDataType<>(YDB.DIALECT, sqlDataType, typeName);
18+
}
19+
20+
@SuppressWarnings("rawtypes")
21+
public static <T> DataType<T> newDataType(DataType sqlDataType, String typeName, Binding<?, T> binding) {
22+
return new DefaultDataType<>(
23+
YDB.DIALECT,
24+
sqlDataType,
25+
sqlDataType.getType(),
26+
binding,
27+
name(typeName),
28+
typeName,
29+
typeName,
30+
sqlDataType.precisionDefined() ? sqlDataType.precision() : null,
31+
sqlDataType.scaleDefined() ? sqlDataType.scale() : null,
32+
sqlDataType.lengthDefined() ? sqlDataType.length() : null,
33+
sqlDataType.nullability(),
34+
sqlDataType.defaultValue()
35+
);
36+
}
37+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.jooq.impl;
2+
3+
import org.jooq.*;
4+
import tech.ydb.jooq.YDB;
5+
6+
public final class YdbTools {
7+
8+
private YdbTools() {
9+
throw new UnsupportedOperationException();
10+
}
11+
12+
@SuppressWarnings("unchecked")
13+
public static <T> Field<T>[] combineTyped(Field<T> field, Field<T>... fields) {
14+
if (fields == null) {
15+
return new Field[]{field};
16+
} else {
17+
Field<T>[] result = new Field[fields.length + 1];
18+
result[0] = field;
19+
System.arraycopy(fields, 0, result, 1, fields.length);
20+
21+
return result;
22+
}
23+
}
24+
25+
@SuppressWarnings("unchecked")
26+
public static Field<?>[] combine(Field<?> field, Field<?>... fields) {
27+
return combineTyped((Field<Object>) field, (Field<Object>[]) fields);
28+
}
29+
30+
@SuppressWarnings("unchecked")
31+
public static <T> Field<T>[] fieldsArray(T[] values) {
32+
Field<T>[] result = new Field[values.length];
33+
34+
for (int i = 0; i < values.length; i++) {
35+
result[i] = YDB.val(values[i]);
36+
}
37+
38+
return result;
39+
}
40+
}

jooq-dialect/src/main/java/tech/ydb/jooq/YDB.java

Lines changed: 388 additions & 65 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)