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