新增Sql构造器工厂,解耦Sql构造器实现与使用者关系

master
星期八 5 years ago
parent fc1a46feed
commit 5e3972670d
  1. 12
      src/main/java/com/lq/code/util/sql/factory/DbBuilerFactory.java
  2. 29
      src/main/java/com/lq/code/util/sql/factory/impl/DefaultDbBuilerFactory.java

@ -0,0 +1,12 @@
package com.lq.code.util.sql.factory;
import com.lq.code.util.sql.AbstractDbBuiler;
/**
* Sql 工厂
* @author qi
*/
public interface DbBuilerFactory {
AbstractDbBuiler getSqlBuilder(String dbType);
}

@ -0,0 +1,29 @@
package com.lq.code.util.sql.factory.impl;
import com.lq.code.util.sql.AbstractDbBuiler;
import com.lq.code.util.sql.MysqlBuilder;
import com.lq.code.util.sql.OracleBuiler;
import com.lq.code.util.sql.SqlConstant;
import com.lq.code.util.sql.factory.DbBuilerFactory;
/**
* @author qi
* dbBuilfer 生产工厂模式默认实现
*/
public class DefaultDbBuilerFactory implements DbBuilerFactory {
@Override
public AbstractDbBuiler getSqlBuilder(String dbType) {
AbstractDbBuiler abstractDbBuiler = null;
switch (dbType){
case SqlConstant
.DB_TYPE_MYSQL:
abstractDbBuiler = new MysqlBuilder();
break;
case SqlConstant.DB_TYPE_ORACLE:
abstractDbBuiler = new OracleBuiler();
break;
}
return abstractDbBuiler;
}
}
Loading…
Cancel
Save