Dialect.java 3.3 KB
Newer Older
M
MaxKey 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
 * 
 * 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.dromara.mybatis.jpa.dialect;


import java.sql.PreparedStatement;
import java.util.HashMap;

M
MaxKey 已提交
24
import org.dromara.mybatis.jpa.entity.JpaPage;
M
MaxKey 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * DB Access Dialect,inspiration from hibernate
 * 
 * @author Crystal.Sea
 * Create 2017-7-24
 *
 */
public abstract class Dialect {

	private static final Logger _logger 			= 	LoggerFactory.getLogger(Dialect.class);

	public static final String DEFAULT_BATCH_SIZE	= 	"20";
	public static final String NO_BATCH 			= 	"0";
	public static final String DEFAULT_DIALECT 		= 	"mysql";

	protected static HashMap<String,String> dialectMap;
	
	static {
		
		dialectMap=new HashMap<String,String>();
M
MaxKey 已提交
48 49 50 51 52 53 54
		dialectMap.put("db2", 			"org.dromara.mybatis.jpa.dialect.DB2Dialect");
		dialectMap.put("derby", 		"org.dromara.mybatis.jpa.dialect.DerbyDialect");
		dialectMap.put("mysql", 		"org.dromara.mybatis.jpa.dialect.MySQLDialect");
		dialectMap.put("oracle", 		"org.dromara.mybatis.jpa.dialect.OracleDialect");
		dialectMap.put("postgresql", 	"org.dromara.mybatis.jpa.dialect.PostgreSQLDialect");
		dialectMap.put("highgo", 		"org.dromara.mybatis.jpa.dialect.HighgoDialect");
		dialectMap.put("sqlserver", 	"org.dromara.mybatis.jpa.dialect.SQLServerDialect");
M
MaxKey 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
		
		
		_logger.trace("Dialect Mapper : \n"+dialectMap);
	}
	
	// constructors and factory methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	protected Dialect() {

	}

	@Override
    public String toString() {
		return getClass().getName();
	}

	/**
	 * Given a limit and an offset, apply the limit clause to the query.
	 *
	 * @param query The query to which to apply the limit.
	 * @param offset The offset of the limit
	 * @param limit The limit of the limit ;)
	 * @return The modified query statement with the limit applied.
	 */

M
MaxKey 已提交
80
	public String getLimitString(String query, JpaPage page) {
M
MaxKey 已提交
81 82 83 84 85 86
		throw new UnsupportedOperationException( "Paged queries not supported by " + getClass().getName());
	}
	
	
	
	
M
MaxKey 已提交
87
	public String getPreparedStatementLimitString(String query, JpaPage page) {
M
MaxKey 已提交
88 89 90 91
		throw new UnsupportedOperationException( "Paged queries not supported by " + getClass().getName());
	}
	
	
M
MaxKey 已提交
92
	public void setLimitParamters(PreparedStatement preparedStatement,int parameterSize,JpaPage pagination) {
M
MaxKey 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
		throw new UnsupportedOperationException( "Paged queries not supported by " + getClass().getName());
	}
	
	
	public boolean supportsLimit() {
		return false;
	}

	/**
	 * @return the dialectMap
	 */
	public static HashMap<String, String> getDialectMap() {
		return dialectMap;
	}
	
	public static String getDialect(String dialect) {
		String dialectString =dialectMap.get(dialect);
		if(dialectString == null) {
			dialectString =dialectMap.get(DEFAULT_DIALECT);
		}
		return dialectString;
	}
	
	
}