All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yx.db.mapper.SqlHolder Maven / Gradle / Ivy

There is a newer version: 4.0.2
Show newest version
/**
 * Copyright (C) 2016 - 2030 youtongluan.
 *
 * 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.yx.db.mapper;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;

import javax.xml.parsers.DocumentBuilder;

import org.yx.conf.AppInfo;
import org.yx.conf.LocalMultiResourceLoaderSupplier;
import org.yx.conf.MultiResourceLoader;
import org.yx.exception.SumkException;

public class SqlHolder {
	private static Map SQLS = new HashMap<>();

	public static void setSQLS(Map sqls) {
		SQLS = sqls;
	}

	private static Supplier documentBuilderFactory = new SqlXmlBuilderFactory();

	private static Supplier resourceLoader = new LocalMultiResourceLoaderSupplier(
			AppInfo.get("sumk.db.sql.path", AppInfo.CLASSPATH_URL_PREFIX + "sql"));

	public static Supplier resourceLoader() {
		return resourceLoader;
	}

	public static void resourceLoader(Supplier resourceLoader) {
		SqlHolder.resourceLoader = Objects.requireNonNull(resourceLoader);
	}

	public static Supplier documentBuilderFactory() {
		return documentBuilderFactory;
	}

	public static void documentBuilderFactory(Supplier documentBuilderFactory) {
		SqlHolder.documentBuilderFactory = Objects.requireNonNull(documentBuilderFactory);
	}

	public static SqlParser findSql(String name) {
		SqlParser sql = SQLS.get(name);
		if (sql == null) {
			SumkException.throwException(64342451, "sql [" + name + "] can not found ");
		}
		return sql;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy