Commit f3a8f93f authored by 李丛阳's avatar 李丛阳

oracle branch init

parent 8b6bffa1
......@@ -148,13 +148,18 @@
<!--mysql的连接-->
<!--mysql 连接-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<!--oracle的连接-->
<dependency>
<groupId>cn.easyproject</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2.0</version>
</dependency>
<!--alibaba fastjson-->
<dependency>
......@@ -311,6 +316,12 @@
</dependency>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.3.3</version>
</dependency>
</dependencies>
......@@ -355,6 +366,74 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals><goal>proguard</goal></goals>
</execution>
</executions>
<configuration>
<proguardVersion>5.3.3</proguardVersion>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}.jar</outjar>
<obfuscate>true</obfuscate>
<options>
<option>-dontshrink</option>
<option>-dontoptimize</option>
<!-- This option will replace all strings in reflections method invocations with new class names.
For example, invokes Class.forName('className')-->
<option>-adaptclassstrings</option>
<!-- This option will save all original annotations and etc. Otherwise all we be removed from files.-->
<option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option>
<!-- This option will save all original names in interfaces (without obfuscate).-->
<option>-keepnames interface **</option>
<!-- This option will save all original methods parameters in files defined in -keep sections,
otherwise all parameter names will be obfuscate.-->
<option>-keepparameternames</option>
<option>-keeppackagenames</option>
<!-- This option will save all original class files (without obfuscate) but obfuscate all in domain package.-->
<option>-keep class org.rcisoft.EducationApplication{ *; }</option>
<option>-keep class org.rcisoftc.config.** { *; }</option>
<!-- This option will save all original defined annotations in all class in all packages.-->
<option>-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Value *;
@org.springframework.stereotype.Service *;
@org.springframework.stereotype.Component *;
@org.springframework.scheduling.annotation.Scheduled *;
}
</option>
<!--<option>-ignorewarnings</option>-->
</options>
<libs>
<!-- Include main JAVA library required.-->
<lib>${java.home}/lib/rt.jar</lib>
<!-- Include crypto JAVA library if necessary.-->
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
</plugin>
<!-- 不混淆job包下的所有类名,且类中的方法也不混淆
<option>-keep class com.chinatelecom.gz.wy.zhukun.shiro_spring.job.** { &lt;methods&gt;; }</option>
&lt;!&ndash; 不混淆filter包下的所有类名,这里主要是对Shiro的路踢人过滤器混淆,对类的属性和方法进行了混淆&ndash;&gt;
<option>-keep class com.chinatelecom.gz.wy.zhukun.shiro_spring.filter.** </option>
&lt;!&ndash; 不混淆凭证包下的所有类名,但对类中的属性、方法进行混淆,原因是Spring配置中用到了这个类名&ndash;&gt;
<option>-keep class com.chinatelecom.gz.wy.zhukun.shiro_spring.credntials.** </option>
&lt;!&ndash; 混淆目的同上,这个是拦截器的包,包中有防止重复提交的拦截器&ndash;&gt;
<option>-keep class com.chinatelecom.gz.wy.zhukun.shiro_spring.interceptor.** </option>
&lt;!&ndash; 混淆目的同上,这个是域包,包中有用户登录域&ndash;&gt;
<option>-keep class com.chinatelecom.gz.wy.zhukun.shiro_spring.realm.** </option>
&lt;!&ndash; 不混淆model包中的所有类以及类的属性及方法,实体包,混淆了会导致ORM框架及前端无法识别&ndash;&gt;
<option>-keep class com.chinatelecom.gz.wy.zhukun.shiro_spring.model.** {*;}</option>
&lt;!&ndash; 以下两个包因为大部分是Spring管理的Bean,不对包类的类名进行混淆,但对类中的属性和方法混淆&ndash;&gt;
<option>-keep class com.chinatelecom.gz.wy.zhukun.shiro_spring.service.** </option>
<option>-keep class com.chinatelecom.gz.wy.zhukun.shiro_spring.dao.**</option>-->
</plugins>
</build>
......
......@@ -78,6 +78,8 @@ public class CodeSchema implements Serializable {
public String getUrl() {
if(DbModel.MYSQL.getType().equals(getDb()))
return "jdbc:mysql://" + getIp() + ":" + getPort() + "/" + getDbName();
if(DbModel.ORACLE.getType().equals(getDb()))
return "jdbc:oracle:thin:@" + getIp() + ":" + getPort() + ":" + getDbName();
return url;
}
......@@ -120,6 +122,8 @@ public class CodeSchema implements Serializable {
public String getDriverClass() {
if(DbModel.MYSQL.getType().equals(getDb()))
return "com.mysql.jdbc.Driver";
else if(DbModel.ORACLE.getType().equals(getDb()))
return "oracle.jdbc.driver.OracleDriver";
return driverClass;
}
......
......@@ -53,7 +53,7 @@ public class DbColumnModel implements Serializable{
* @param rs
* @throws SQLException
*/
public void copyColumnFromSqlResult(ResultSet rs) throws SQLException{
public void copyColumnFromSqlResult(ResultSet rs,CodeSchema codeSchema) throws SQLException{
try {
String colName = rs.getString("COLUMN_NAME");//列名
String typeName = rs.getString("TYPE_NAME");//类型名称
......@@ -62,8 +62,11 @@ public class DbColumnModel implements Serializable{
int dataType = rs.getInt("DATA_TYPE");//类型
int scale = rs.getInt("DECIMAL_DIGITS");// 小数的位数
String remarks = rs.getString("REMARKS");//注释
String defaultValue = rs.getString("COLUMN_DEF");//默认值
String defaultValue = null;
if(DbModel.MYSQL.getType().equals(codeSchema.getDb()))
defaultValue = rs.getString("COLUMN_DEF");//默认值
else if (DbModel.ORACLE.getType().equals(codeSchema.getDb()))
defaultValue = null;
this.setColName(colName);
this.setTypeName(typeName);
this.setPrecision(precision);
......@@ -92,6 +95,9 @@ public class DbColumnModel implements Serializable{
case "varchar":
javaType = "String";
break;
case "varchar2":
javaType = "String";
break;
case "char":
javaType = "Char";
break;
......
......@@ -3,13 +3,10 @@ package org.rcisoft.code.service.impl;
import freemarker.template.Configuration;
import freemarker.template.Template;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.code.model.CodeSchema;
import org.rcisoft.code.model.CodeTable;
import org.rcisoft.code.model.*;
import org.rcisoft.code.service.CodeService;
import org.rcisoft.common.component.FamilyDbUtils;
import org.rcisoft.common.component.Global;
import org.rcisoft.code.model.DbColumnModel;
import org.rcisoft.code.model.DbTableModel;
import org.rcisoft.core.service.BaseService;
import org.rcisoft.core.util.DateUtil;
import org.rcisoft.core.util.ZipCompress;
......@@ -51,13 +48,15 @@ public class CodeServiceImpl extends BaseService implements CodeService {
public List<CodeTable> getCodeTablesBySchema(CodeSchema schema){
List<CodeTable> tables = new ArrayList<>();
Connection conn = familyDbUtils.getConnection(schema);;
if(null == conn)
return null;
ResultSet rs = null;
DatabaseMetaData dbmd = null;
CodeTable ct = null;
try {
dbmd = (DatabaseMetaData) conn.getMetaData();
rs=(ResultSet) dbmd.getTables(null, schema.getDbName(), "%", null);
rs = FamilyDbUtils.getResultSetByDbmd(dbmd,schema,FamilyDbUtils.RESULT_TYPE_TABLE,null);
while(rs.next()){
ct = new CodeTable();
ct.setTableName(rs.getString("TABLE_NAME"));
......@@ -81,6 +80,7 @@ public class CodeServiceImpl extends BaseService implements CodeService {
String[] tables = codeSchema.getTables().split(",");
Connection conn = familyDbUtils.getConnection(codeSchema);;
ResultSet rs = null;
ResultSet resultSet = null;
DatabaseMetaData dbmd = null;
CodeTable ct = null;
DbTableModel tableModel = null;
......@@ -89,7 +89,8 @@ public class CodeServiceImpl extends BaseService implements CodeService {
Map tableRemarks = new HashMap<>();
try {
dbmd = (DatabaseMetaData) conn.getMetaData();
ResultSet resultSet = dbmd.getTables(null, "%", "%", new String[] { "TABLE" });
//ResultSet resultSet = dbmd.getTables(null, "%", "%", new String[] { "TABLE" });
resultSet = FamilyDbUtils.getResultSetByDbmd(dbmd,codeSchema,FamilyDbUtils.RESULT_TYPE_TABLE,null);
while (resultSet.next()) {
tableRemarks.put(resultSet.getString("TABLE_NAME"),resultSet.getString("REMARKS"));
}
......@@ -98,9 +99,10 @@ public class CodeServiceImpl extends BaseService implements CodeService {
tableModel = new DbTableModel();
models = new ArrayList<DbColumnModel>();
tableModel.setTableName(table.toLowerCase());
tableModel.setTableRemark(tableRemarks.get(table).toString());
if(null != tableRemarks.get(table))
tableModel.setTableRemark(tableRemarks.get(table).toString());
//column
rs = (ResultSet) dbmd.getColumns(null, codeSchema.getDbName(), table.toLowerCase(), null);
rs = FamilyDbUtils.getResultSetByDbmd(dbmd,codeSchema,FamilyDbUtils.RESULT_TYPE_COLUMN,table);
dbmd.getPrimaryKeys(null, null, tables[0].toLowerCase());
boolean flag = false;
while (rs.next()) {
......@@ -108,10 +110,10 @@ public class CodeServiceImpl extends BaseService implements CodeService {
/* 根据 CREATE_BY 判断是否存在7个字段 */
if("CREATE_BY".equals(rs.getString("COLUMN_NAME").toUpperCase()))
flag = true;
model.copyColumnFromSqlResult(rs);
model.copyColumnFromSqlResult(rs,codeSchema);
models.add(model);
}
rs = (ResultSet) dbmd.getPrimaryKeys(null, codeSchema.getDbName(), table.toLowerCase());
rs = FamilyDbUtils.getResultSetByDbmd(dbmd,codeSchema,FamilyDbUtils.RESULT_TYPE_PK,table);
while (rs.next()) {
String column = rs.getString("COLUMN_NAME");
for(DbColumnModel cm : models){
......
......@@ -10,11 +10,11 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.TransactionFactory;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.rcisoft.code.model.CodeSchema;
import org.rcisoft.code.model.DbModel;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
/**
* Created by lcy on 17/6/30.
......@@ -24,6 +24,14 @@ import java.sql.DriverManager;
public class FamilyDbUtils implements Serializable {
public static final String RESULT_TYPE_TABLE = "table";
public static final String RESULT_TYPE_COLUMN = "column";
public static final String RESULT_TYPE_PK = "pk";
public static final String RESULT_TYPE_TABLE_LIST = "tableList";
private static final long serialVersionUID = 1985679477781607104L;
/**
......@@ -75,4 +83,48 @@ public class FamilyDbUtils implements Serializable {
return con;
}
/**
* 获取 resultset
* @param dbmd
* @param codeSchema
* @param resultType
* @return
*/
public static ResultSet getResultSetByDbmd(DatabaseMetaData dbmd , CodeSchema codeSchema , String resultType ,String table) throws SQLException {
ResultSet resultSet = null ;
//表
if(RESULT_TYPE_TABLE.equals(resultType)) {
//mysql
if (DbModel.MYSQL.getType().equals(codeSchema.getDb()))
resultSet = dbmd.getTables(null, codeSchema.getDbName(), "%", null);
//oracle
else if (DbModel.ORACLE.getType().equals(codeSchema.getDb()))
resultSet = dbmd.getTables(null, codeSchema.getUsername().toUpperCase(), "%", null);
}
else if(RESULT_TYPE_TABLE_LIST.equals(resultType)) {
resultSet = dbmd.getTables(null, "%", "%", new String[] { "TABLE" });
}
//列
else if(RESULT_TYPE_COLUMN.equals(resultType)) {
//mysql
if (DbModel.MYSQL.getType().equals(codeSchema.getDb()))
resultSet = dbmd.getColumns(null, codeSchema.getDbName(), table.toLowerCase(), null);
//oracle
else if (DbModel.ORACLE.getType().equals(codeSchema.getDb()))
resultSet = dbmd.getColumns(null, codeSchema.getUsername().toUpperCase(), table.toLowerCase(), null);
}
//主键
else if(RESULT_TYPE_PK.equals(resultType)) {
//mysql
if (DbModel.MYSQL.getType().equals(codeSchema.getDb()))
resultSet = (ResultSet) dbmd.getPrimaryKeys(null, codeSchema.getDbName(), table.toLowerCase());
//oracle
else if (DbModel.ORACLE.getType().equals(codeSchema.getDb()))
resultSet = (ResultSet) dbmd.getPrimaryKeys(null, codeSchema.getUsername().toUpperCase(), table.toLowerCase());
}
return resultSet;
}
}
......@@ -40,9 +40,7 @@ public class Global implements Serializable{
@Value("${global.code.admin}")
private String adminCode;
/*client Code*/
@Value("${global.code.client}")
private String clientCode;
/**
* 基本存储路径
......
......@@ -12,7 +12,7 @@ import javax.servlet.annotation.WebServlet;
@WebServlet(urlPatterns = "/druid/*",
initParams={
//@WebInitParam(name="allow",value="192.168.16.110,127.0.0.1"),// IP白名单 (没有配置或者为空,则允许所有访问)
@WebInitParam(name="deny",value="192.168.16.111"),// IP黑名单 (存在共同时,deny优先于allow)
//@WebInitParam(name="deny",value="192.168.16.111"),// IP黑名单 (存在共同时,deny优先于allow)
@WebInitParam(name="loginUsername",value="cy"),// 用户名
@WebInitParam(name="loginPassword",value="pass"),// 密码
@WebInitParam(name="resetEnable",value="false")// 禁用HTML页面上的“Reset All”功能
......
......@@ -11,8 +11,8 @@ server:
# org.springframework.web: DEBUG
druid:
url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username: root
url: jdbc:oracle:thin:@103.249.252.109:10521:cydb
username: cy_first
password: cy
initial-size: 1
min-idle: 1
......
......@@ -56,7 +56,7 @@
<logger name="org.springframework.aop.aspectj" level="ERROR"/>
<springProfile name="dev">
<root level="debug">
<root level="info">
<appender-ref ref="consoleLog" />
<appender-ref ref="fileInfoLog" />
<appender-ref ref="fileErrorLog" />
......
......@@ -3,23 +3,26 @@
<title>代码生成</title>
</head>
<body>
ip:<input type="text" id="ip" /><br></br>
db:<select id="db">
<option value="1">mysql</option>
<option value="2">oracle</option>
<option value="3">sqlserver</option>
</select><br></br>
port:<input type="text" id="port" /><br></br>
dbName:<input type="text" id="dbName" /><br></br>
username:<input type="text" id="username" /><br></br>
password:<input type="text" id="password" /><br></br>
<button onclick="connect()">连接</button>
<hr/>
<div id="tableDiv">
basepackage:<input type="text" id="basepackage" /><br></br>
author:<input type="text" id="author" /><br></br>
<div align="center">
ip:<input type="text" id="ip" /><br></br>
db:<select id="db">
<option value="1">mysql</option>
<option value="2">sqlserver</option>
<option value="3">oracle</option>
</select><br></br>
port:<input type="text" id="port" /><br></br>
dbName:<input type="text" id="dbName" /><br></br>
username:<input type="text" id="username" /><br></br>
password:<input type="text" id="password" /><br></br>
<button onclick="connect()">连接</button>
<hr/>
<div id="tableDiv">
basepackage:<input type="text" id="basepackage" /><br></br>
author:<input type="text" id="author" /><br></br>
</div>
<button onclick="generate()">生成</button>
</div>
<button onclick="generate()">生成</button>
<script src="../static/jquery-1.7.2.min.js"></script>
<script src="../static/connect.js"></script>
</body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment