001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.db.dialect;
017
018import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
019import io.jboot.db.model.Column;
020import io.jboot.db.model.SqlBuilder;
021import io.jboot.db.model.Join;
022
023import java.util.List;
024
025
026public class JbootMysqlDialect extends MysqlDialect implements JbootDialect {
027
028    @Override
029    public String forFindByColumns(String alias, List<Join> joins, String table, String loadColumns, List<Column> columns, String orderBy, Object limit) {
030        StringBuilder sqlBuilder = SqlBuilder.forFindByColumns(alias, joins, table, loadColumns, columns, orderBy, '`');
031
032        if (limit != null) {
033            sqlBuilder.append(" LIMIT " + limit);
034        }
035
036        return sqlBuilder.toString();
037    }
038
039    @Override
040    public String forFindCountByColumns(String alias, List<Join> joins, String table, String loadColumns, List<Column> columns) {
041        return SqlBuilder.forFindCountByColumns(alias, joins, table, loadColumns, columns, '`');
042    }
043
044    @Override
045    public String forDeleteByColumns(String alias, List<Join> joins, String table, List<Column> columns) {
046        return SqlBuilder.forDeleteByColumns(alias, joins, table, columns, '`');
047    }
048
049
050    @Override
051    public String forPaginateSelect(String loadColumns) {
052        return "SELECT " + loadColumns;
053    }
054
055
056    @Override
057    public String forPaginateFrom(String alias, List<Join> joins, String table, List<Column> columns, String orderBy) {
058        return SqlBuilder.forPaginateFrom(alias, joins, table, columns, orderBy, '`');
059    }
060
061    @Override
062    public String forPaginateTotalRow(String select, String sqlExceptSelect, Object ext) {
063        String distinctSql = SqlBuilder.forPaginateDistinctTotalRow(select, sqlExceptSelect, ext);
064        return distinctSql != null ? distinctSql : super.forPaginateTotalRow(select, sqlExceptSelect, ext);
065    }
066
067}