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

com.jk.db.dynamic.dataaccess.DynamicDataAccessFactory Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2002-2016 Jalal Kiswani.
 *
 * 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 com.jk.db.dynamic.dataaccess;

import com.jk.db.dataaccess.mysql.MysqlAbstractDao;
import com.jk.db.dataaccess.oracle.OracleAbstractDao;
import com.jk.db.dataaccess.plain.JKAbstractPlainDataAccess;
import com.jk.db.dataaccess.plain.JKPlainDataAccess;
import com.jk.db.datasource.JKDataSource;
import com.jk.db.datasource.JKDataSourceFactory;
import com.jk.db.dynamic.analyzer.DataBaseAnalayzer;
import com.jk.db.dynamic.analyzer.DefaultDatabaseAnalayzer;
import com.jk.db.dynamic.meta.AbstractEntityMetaFactory;
import com.jk.db.dynamic.mysql.MySqlDatabaseAnalayzer;
import com.jk.db.dynamic.oracle.OracleDatabaseAnalayzer;
import com.jk.db.dynamic.oracle.OracleDynamicDao;
import com.jk.db.util.JdbcUtil;
import com.jk.metadata.db.meta.EntityMeta;

/**
 * A factory for creating DynamicDao objects.
 */
public class DynamicDataAccessFactory {

	/**
	 * Creates a new DynamicDao object.
	 *
	 * @param tableMetaName
	 *            the table meta name
	 * @return the dynamic dao
	 */
	public static DynamicDataAccess createDynamicDao(final String tableMetaName) {
		return createDynamicDao(AbstractEntityMetaFactory.getInstance().getEntityMeta(tableMetaName));
	}

	/**
	 * Creates a new DynamicDao object.
	 *
	 * @param tableMeta
	 *            the table meta
	 * @return the dynamic dao
	 */
	// ///////////////////////////////////////////////////////////////////////////////////////
	public static DynamicDataAccess createDynamicDao(final EntityMeta tableMeta) {
		final JKDataSource dataSource = JKDataSourceFactory.getDefaultDataSource();
		switch (dataSource.getDatabaseType()) {
		case ORACLE:
			return new OracleDynamicDao(tableMeta);
		default:
			return new DynamicDataAccess(tableMeta);
		}
	}

	/**
	 * Gets the database analayzer.
	 *
	 * @return the database analayzer
	 */
	public static DataBaseAnalayzer getDatabaseAnalayzer() {
		final JKDataSource dataSource = JKDataSourceFactory.getDefaultDataSource();
		return getDatabaseAnalayzer(dataSource);
	}

	/**
	 * Gets the database analayzer.
	 *
	 * @param dataSource
	 *            the data source
	 * @return the database analayzer
	 */
	public static DataBaseAnalayzer getDatabaseAnalayzer(JKDataSource dataSource) {
		switch (dataSource.getDatabaseType()) {
		case ORACLE:
			return new OracleDatabaseAnalayzer(dataSource);
		case MYSQL:
			return new MySqlDatabaseAnalayzer(dataSource);
		default:
			return new DefaultDatabaseAnalayzer(dataSource);
		}

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy