Skip to content
Closed
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
10 changes: 10 additions & 0 deletions src/main/java/org/mybatis/dynamic/mysql/MySQLBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.mybatis.dynamic.mysql;

import org.mybatis.dynamic.sql.BindableColumn;
import org.mybatis.dynamic.mysql.select.function.Ascii;

public interface MySQLBuilder {
static Ascii ascii(BindableColumn<String> column) {
return Ascii.of(column);
}
}
43 changes: 43 additions & 0 deletions src/main/java/org/mybatis/dynamic/mysql/select/function/Ascii.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2016-2018 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.
* 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.
*/
package org.mybatis.dynamic.mysql.select.function;

import org.mybatis.dynamic.sql.BindableColumn;
import org.mybatis.dynamic.sql.render.TableAliasCalculator;
import org.mybatis.dynamic.sql.select.function.AbstractFunction;

public class Ascii extends AbstractFunction<String, Ascii> {

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

@Override
public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
return "ASCII(" //$NON-NLS-1$
+ column.renderWithTableAlias(tableAliasCalculator)
+ ")"; //$NON-NLS-1$
}

@Override
protected Ascii copy() {
return new Ascii(column);
}

public static Ascii of(BindableColumn<String> column) {
return new Ascii(column);
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/mybatis/dynamic/sqlserver/SQLServerBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.mybatis.dynamic.sqlserver;

import org.mybatis.dynamic.sql.BindableColumn;
import org.mybatis.dynamic.sqlserver.select.function.Ascii;

public interface SQLServerBuilder {
static Ascii ascii(BindableColumn<String> column) {
return Ascii.of(column);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2016-2018 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.
* 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.
*/
package org.mybatis.dynamic.sqlserver.select.function;

import org.mybatis.dynamic.sql.BindableColumn;
import org.mybatis.dynamic.sql.render.TableAliasCalculator;
import org.mybatis.dynamic.sql.select.function.AbstractFunction;

public class Ascii extends AbstractFunction<String, Ascii> {

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

@Override
public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
return "ASCII(" //$NON-NLS-1$
+ column.renderWithTableAlias(tableAliasCalculator)
+ ")"; //$NON-NLS-1$
}

@Override
protected Ascii copy() {
return new Ascii(column);
}

public static Ascii of(BindableColumn<String> column) {
return new Ascii(column);
}
}
43 changes: 43 additions & 0 deletions src/test/java/org/mybatis/dynamic/mysql/select/FunctionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.mybatis.dynamic.mysql.select;

import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
import static org.mybatis.dynamic.sql.SqlBuilder.select;
import static org.mybatis.dynamic.mysql.MySQLBuilder.ascii;

import java.sql.JDBCType;
import java.util.Date;

import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mybatis.dynamic.sql.SqlColumn;
import org.mybatis.dynamic.sql.SqlTable;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;

@RunWith(JUnitPlatform.class)
public class FunctionsTest {

public static final SqlTable table = SqlTable.of("foo");
public static final SqlColumn<Date> column1 = table.column("column1", JDBCType.DATE);
public static final SqlColumn<Integer> column2 = table.column("column2", JDBCType.INTEGER);
public static final SqlColumn<String> column3 = table.column("column3", JDBCType.VARCHAR);

@Test
public void testAscii() {
SelectStatementProvider selectStatement = select(ascii(column3).as("A_COLUMN3"))
.from(table, "a")
.where(ascii(column3), isEqualTo("A"))
.build()
.render(RenderingStrategy.MYBATIS3);

SoftAssertions.assertSoftly(softly -> {
String expectedFullStatement = "select ASCII(a.column3) as A_COLUMN3 "
+ "from foo a "
+ "where ASCII(a.column3) = #{parameters.p1,jdbcType=VARCHAR}";

softly.assertThat(selectStatement.getSelectStatement()).isEqualTo(expectedFullStatement);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.mybatis.dynamic.sqlserver.select;

import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
import static org.mybatis.dynamic.sql.SqlBuilder.select;
import static org.mybatis.dynamic.sqlserver.SQLServerBuilder.ascii;

import java.sql.JDBCType;
import java.util.Date;

import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mybatis.dynamic.sql.SqlColumn;
import org.mybatis.dynamic.sql.SqlTable;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;

@RunWith(JUnitPlatform.class)
public class FunctionsTest {

public static final SqlTable table = SqlTable.of("foo");
public static final SqlColumn<Date> column1 = table.column("column1", JDBCType.DATE);
public static final SqlColumn<Integer> column2 = table.column("column2", JDBCType.INTEGER);
public static final SqlColumn<String> column3 = table.column("column3", JDBCType.VARCHAR);

@Test
public void testAscii() {
SelectStatementProvider selectStatement = select(ascii(column3).as("A_COLUMN3"))
.from(table, "a")
.where(ascii(column3), isEqualTo("A"))
.build()
.render(RenderingStrategy.MYBATIS3);

SoftAssertions.assertSoftly(softly -> {
String expectedFullStatement = "select ASCII(a.column3) as A_COLUMN3 "
+ "from foo a "
+ "where ASCII(a.column3) = #{parameters.p1,jdbcType=VARCHAR}";

softly.assertThat(selectStatement.getSelectStatement()).isEqualTo(expectedFullStatement);
});
}
}