001/* 002 * Copyright (c) 2022-2025, Mybatis-Flex (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 com.mybatisflex.core.dialect; 017 018import com.mybatisflex.core.query.QueryWrapper; 019import com.mybatisflex.core.row.Row; 020import com.mybatisflex.core.table.TableInfo; 021import com.mybatisflex.core.table.TableManager; 022 023import java.util.Collection; 024import java.util.List; 025 026/** 027 * @author michael 028 */ 029public interface IDialect { 030 031 String wrap(String keyword); 032 033 String wrapColumnAlias(String keyword); 034 035 default String getRealTable(String table, OperateType operateType) { 036 return TableManager.getRealTable(table, operateType); 037 } 038 039 default String getRealSchema(String schema, String table, OperateType operateType) { 040 return TableManager.getRealSchema(schema, table, operateType); 041 } 042 043 String forHint(String hintString); 044 045 String forInsertRow(String schema, String tableName, Row row); 046 047 String forInsertBatchWithFirstRowColumns(String schema, String tableName, List<Row> rows); 048 049 String forDeleteById(String schema, String tableName, String[] primaryKeys); 050 051 String forDeleteBatchByIds(String schema, String tableName, String[] primaryKeys, Object[] ids); 052 053 String forDeleteByQuery(QueryWrapper queryWrapper); 054 055 String forUpdateById(String schema, String tableName, Row row); 056 057 String forUpdateByQuery(QueryWrapper queryWrapper, Row data); 058 059 String forUpdateBatchById(String schema, String tableName, List<Row> rows); 060 061 String forSelectOneById(String schema, String tableName, String[] primaryKeys, Object[] primaryValues); 062 063 String forSelectByQuery(QueryWrapper queryWrapper); 064 065 String buildSelectSql(QueryWrapper queryWrapper); 066 067 String buildNoSelectSql(QueryWrapper queryWrapper); 068 069 String buildDeleteSql(QueryWrapper queryWrapper); 070 071 String buildWhereConditionSql(QueryWrapper queryWrapper); 072 073 074 //////for entity ///// 075 String forInsertEntity(TableInfo tableInfo, Object entity, boolean ignoreNulls); 076 077 String forInsertEntityWithPk(TableInfo tableInfo, Object entity, boolean ignoreNulls); 078 079 String forInsertEntityBatch(TableInfo tableInfo, Collection<?> entities); 080 081 String forDeleteEntityById(TableInfo tableInfo); 082 083 String forDeleteEntityBatchByIds(TableInfo tableInfo, Object[] primaryValues); 084 085 String forDeleteEntityBatchByQuery(TableInfo tableInfo, QueryWrapper queryWrapper); 086 087 String forUpdateEntity(TableInfo tableInfo, Object entity, boolean ignoreNulls); 088 089 String forUpdateEntityByQuery(TableInfo tableInfo, Object entity, boolean ignoreNulls, QueryWrapper queryWrapper); 090 091 String forSelectOneEntityById(TableInfo tableInfo); 092 093 String forSelectEntityListByIds(TableInfo tableInfo, Object[] primaryValues); 094 095 /** 096 * 权限处理 097 * 098 * @param queryWrapper queryWrapper 099 * @param operateType 操作类型 100 */ 101 default void prepareAuth(QueryWrapper queryWrapper, OperateType operateType) { 102 } 103 104 /** 105 * 权限处理 106 * 107 * @param schema schema 108 * @param tableName 表名 109 * @param sql sql 110 * @param operateType 操作类型 111 */ 112 default void prepareAuth(String schema, String tableName, StringBuilder sql, OperateType operateType) { 113 } 114 115 /** 116 * 权限处理 117 * 118 * @param tableInfo tableInfo 119 * @param sql sql 120 * @param operateType 操作类型 121 */ 122 default void prepareAuth(TableInfo tableInfo, StringBuilder sql, OperateType operateType) { 123 } 124}