|
| 1 | +/* |
| 2 | + * Copyright 2016-2020 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package examples.animal.data; |
| 17 | + |
| 18 | +import org.mybatis.dynamic.sql.BindableColumn; |
| 19 | +import org.mybatis.dynamic.sql.render.TableAliasCalculator; |
| 20 | +import org.mybatis.dynamic.sql.select.function.AbstractTypeConvertingFunction; |
| 21 | + |
| 22 | +import java.sql.JDBCType; |
| 23 | +import java.util.Optional; |
| 24 | + |
| 25 | +public class Length extends AbstractTypeConvertingFunction<Object, Integer, Length> { |
| 26 | + private Length(BindableColumn<Object> column) { |
| 27 | + super(column); |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public Optional<JDBCType> jdbcType() { |
| 32 | + return Optional.of(JDBCType.INTEGER); |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public Optional<String> typeHandler() { |
| 37 | + return Optional.empty(); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) { |
| 42 | + return "length(" //$NON-NLS-1$ |
| 43 | + + column.renderWithTableAlias(tableAliasCalculator) |
| 44 | + + ")"; //$NON-NLS-1$ |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + protected Length copy() { |
| 49 | + return new Length(column); |
| 50 | + } |
| 51 | + |
| 52 | + public static Length length(BindableColumn<?> column) { |
| 53 | + @SuppressWarnings("unchecked") |
| 54 | + BindableColumn<Object> c = (BindableColumn<Object>) column; |
| 55 | + return new Length(c); |
| 56 | + } |
| 57 | +} |
| 58 | + |
0 commit comments