Skip to content

Relax generic constraints on built-in functions #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,22 @@ static StringConstant stringConstant(String constant) {
}

// functions
static <T extends Number> Add<T> add(BindableColumn<T> firstColumn, BasicColumn secondColumn,
static <T> Add<T> add(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
return Add.of(firstColumn, secondColumn, subsequentColumns);
}

static <T extends Number> Divide<T> divide(BindableColumn<T> firstColumn, BasicColumn secondColumn,
static <T> Divide<T> divide(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
return Divide.of(firstColumn, secondColumn, subsequentColumns);
}

static <T extends Number> Multiply<T> multiply(BindableColumn<T> firstColumn, BasicColumn secondColumn,
static <T> Multiply<T> multiply(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
return Multiply.of(firstColumn, secondColumn, subsequentColumns);
}

static <T extends Number> Subtract<T> subtract(BindableColumn<T> firstColumn, BasicColumn secondColumn,
static <T> Subtract<T> subtract(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
return Subtract.of(firstColumn, secondColumn, subsequentColumns);
}
Expand All @@ -384,15 +384,15 @@ static <T> OperatorFunction<T> applyOperator(String operator, BindableColumn<T>
return OperatorFunction.of(operator, firstColumn, secondColumn, subsequentColumns);
}

static Lower lower(BindableColumn<String> column) {
static <T> Lower<T> lower(BindableColumn<T> column) {
return Lower.of(column);
}

static Substring substring(BindableColumn<String> column, int offset, int length) {
static <T> Substring<T> substring(BindableColumn<T> column, int offset, int length) {
return Substring.of(column, offset, length);
}

static Upper upper(BindableColumn<String> column) {
static <T> Upper<T> upper(BindableColumn<T> column) {
return Upper.of(column);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/mybatis/dynamic/sql/select/function/Add.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.BindableColumn;

public class Add<T extends Number> extends OperatorFunction<T> {
public class Add<T> extends OperatorFunction<T> {

private Add(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
Expand All @@ -33,12 +33,12 @@ protected Add<T> copy() {
return new Add<>(column, secondColumn, subsequentColumns);
}

public static <T extends Number> Add<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
public static <T> Add<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
return of(firstColumn, secondColumn, Arrays.asList(subsequentColumns));
}

public static <T extends Number> Add<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
public static <T> Add<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
return new Add<>(firstColumn, secondColumn, subsequentColumns);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.BindableColumn;

public class Divide<T extends Number> extends OperatorFunction<T> {
public class Divide<T> extends OperatorFunction<T> {

private Divide(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
Expand All @@ -33,12 +33,12 @@ protected Divide<T> copy() {
return new Divide<>(column, secondColumn, subsequentColumns);
}

public static <T extends Number> Divide<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
public static <T> Divide<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
return of(firstColumn, secondColumn, Arrays.asList(subsequentColumns));
}

public static <T extends Number> Divide<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
public static <T> Divide<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
return new Divide<>(firstColumn, secondColumn, subsequentColumns);
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/mybatis/dynamic/sql/select/function/Lower.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,9 +18,9 @@
import org.mybatis.dynamic.sql.BindableColumn;
import org.mybatis.dynamic.sql.render.TableAliasCalculator;

public class Lower extends AbstractUniTypeFunction<String, Lower> {
public class Lower<T> extends AbstractUniTypeFunction<T, Lower<T>> {

private Lower(BindableColumn<String> column) {
private Lower(BindableColumn<T> column) {
super(column);
}

Expand All @@ -32,11 +32,11 @@ public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
}

@Override
protected Lower copy() {
return new Lower(column);
protected Lower<T> copy() {
return new Lower<>(column);
}

public static Lower of(BindableColumn<String> column) {
return new Lower(column);
public static <T> Lower<T> of(BindableColumn<T> column) {
return new Lower<>(column);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.BindableColumn;

public class Multiply<T extends Number> extends OperatorFunction<T> {
public class Multiply<T> extends OperatorFunction<T> {

private Multiply(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
Expand All @@ -33,12 +33,12 @@ protected Multiply<T> copy() {
return new Multiply<>(column, secondColumn, subsequentColumns);
}

public static <T extends Number> Multiply<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
public static <T> Multiply<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
return of(firstColumn, secondColumn, Arrays.asList(subsequentColumns));
}

public static <T extends Number> Multiply<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
public static <T> Multiply<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
return new Multiply<>(firstColumn, secondColumn, subsequentColumns);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,12 +18,12 @@
import org.mybatis.dynamic.sql.BindableColumn;
import org.mybatis.dynamic.sql.render.TableAliasCalculator;

public class Substring extends AbstractUniTypeFunction<String, Substring> {
public class Substring<T> extends AbstractUniTypeFunction<T, Substring<T>> {

private final int offset;
private final int length;

private Substring(BindableColumn<String> column, int offset, int length) {
private Substring(BindableColumn<T> column, int offset, int length) {
super(column);
this.offset = offset;
this.length = length;
Expand All @@ -41,11 +41,11 @@ public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
}

@Override
protected Substring copy() {
return new Substring(column, offset, length);
protected Substring<T> copy() {
return new Substring<>(column, offset, length);
}

public static Substring of(BindableColumn<String> column, int offset, int length) {
return new Substring(column, offset, length);
public static <T> Substring<T> of(BindableColumn<T> column, int offset, int length) {
return new Substring<>(column, offset, length);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.BindableColumn;

public class Subtract<T extends Number> extends OperatorFunction<T> {
public class Subtract<T> extends OperatorFunction<T> {

private Subtract(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
Expand All @@ -33,13 +33,13 @@ protected Subtract<T> copy() {
return new Subtract<>(column, secondColumn, subsequentColumns);
}

public static <T extends Number> Subtract<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
public static <T> Subtract<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
BasicColumn... subsequentColumns) {
return of(firstColumn, secondColumn, Arrays.asList(subsequentColumns));
}

public static <T extends Number> Subtract<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
public static <T> Subtract<T> of(BindableColumn<T> firstColumn, BasicColumn secondColumn,
List<BasicColumn> subsequentColumns) {
return new Subtract<>(firstColumn, secondColumn, subsequentColumns);
}
}
14 changes: 7 additions & 7 deletions src/main/java/org/mybatis/dynamic/sql/select/function/Upper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,9 +18,9 @@
import org.mybatis.dynamic.sql.BindableColumn;
import org.mybatis.dynamic.sql.render.TableAliasCalculator;

public class Upper extends AbstractUniTypeFunction<String, Upper> {
public class Upper<T> extends AbstractUniTypeFunction<T, Upper<T>> {

private Upper(BindableColumn<String> column) {
private Upper(BindableColumn<T> column) {
super(column);
}

Expand All @@ -32,11 +32,11 @@ public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
}

@Override
protected Upper copy() {
return new Upper(column);
protected Upper<T> copy() {
return new Upper<>(column);
}

public static Upper of(BindableColumn<String> column) {
return new Upper(column);
public static <T> Upper<T> of(BindableColumn<T> column) {
return new Upper<>(column);
}
}