<commit_before>package com.uikoo9.gcode.util;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Map;
import java.util.Vector;

import javax.swing.table.DefaultTableModel;

/**
 * 代码生成-业务代码
 * @author qiaowenbin
 */
public class QGenCodeUtil {
	
	public static final String dbPath = "/com/uikoo9/gcode/db.properties";
	
	/**
	 * 填充表格-获取数据库表信息
	 */
	public static void fillTable(DefaultTableModel model){
		Connection con = null;
		
		try {
			try {
				con = QDbUtil.getCon(dbPath);
				ResultSet rs = con.getMetaData().getTables(null,null,"",null);
				while(rs.next()){
					Vector<String> v = new Vector<String>();
					v.add(0, "");
					v.add(1, rs.getString("TABLE_NAME"));
					
					model.addRow(v);
				}
			} finally {
				QDbUtil.closeCon(con);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 生成一个表对应的代码
	 * @param tableName
	 * @param destBasePath
	 * @return
	 */
	public static String genCodeFromTable(String tableName, String destBasePath){
		StringBuilder res = new StringBuilder();
		
		String tmpBasePath = QUtil.getJarPath() + File.separator + "com" + File.separator + "uikoo9";
		try {
			Connection con = null;
			try {
				con = QDbUtil.getCon(dbPath);
				res.append(generateJfinalCode(tableName, destBasePath, tmpBasePath));
			} finally {
				QDbUtil.closeCon(con);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return res.toString();
	}
	
	/**
	 * 生成一个表具体的代码for jfinal
	 * @param tableName
	 * @param destBasePath
	 * @param tmpBasePath
	 * @return
	 */
	public static String generateJfinalCode(String tableName, String destBasePath, String tmpBasePath){
		StringBuilder sb = new StringBuilder();
		
		String folderName = tableName.split("_")[1];
		String ftlName = tableName.replace("_", "-").substring(2);
		String className = QStringUtil.getClassNameFromTableName(tableName);
		
		Map<String, Object> map = QDbUtil.getTableInfoMap(dbPath, tableName);
		String tmpPath 	= tmpBasePath + File.separator + "gcode" + File.separator + "tmp";
		String destFTLPath = 
				destBasePath + File.separator + 
				"WebRoot" + File.separator + 
				"WEB-INF" + File.separator + 
				"view" + File.separator + 
				"manage" + File.separator + 
				folderName;
		String destSRCPath = 
				destBasePath + File.separator + 
				"src" + File.separator + 
				"com" + File.separator + 
				"uikoo9" + File.separator + 
				"manage" + File.separator + 
				folderName + File.separator;
		
		boolean indexFtl 	= QUtil.generateCodeByVelocity(map, destFTLPath, 				ftlName + "-index.html", 		tmpPath, "ftl-index.vm");
		boolean inputFtl 	= QUtil.generateCodeByVelocity(map, destFTLPath, 				ftlName + "-input.html", 		tmpPath, "ftl-input.vm");
		boolean model 		= QUtil.generateCodeByVelocity(map, destSRCPath + "model",		className + "Model.java", 		tmpPath, "Model.vm");
		boolean controller 	= QUtil.generateCodeByVelocity(map, destSRCPath + "controller",	className + "Controller.java",	tmpPath, "Controller.vm");
		
		sb.append("generate jfinal code begin...\r\n");
		sb.append("jfinal index.html生成" + (indexFtl ? "成功" : "失败") + "!\r\n");
		sb.append("jfinal input.html生成" + (inputFtl ? "成功" : "失败") + "!\r\n");
		sb.append("jfinal model生成" 	+ (model ? "成功" : "失败") + "!\r\n");
		sb.append("jfinal controller生成"+ (controller ? "成功" : "失败") + "!\r\n");
		sb.append("generate jfinal code end...\r\n");
		
		return sb.toString();
	}
	
}<commit_msg>search页单独出来<commit_after>package com.uikoo9.gcode.util;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Map;
import java.util.Vector;

import javax.swing.table.DefaultTableModel;

/**
 * 代码生成-业务代码
 * @author qiaowenbin
 */
public class QGenCodeUtil {
	
	public static final String dbPath = "/com/uikoo9/gcode/db.properties";
	
	/**
	 * 填充表格-获取数据库表信息
	 */
	public static void fillTable(DefaultTableModel model){
		Connection con = null;
		
		try {
			try {
				con = QDbUtil.getCon(dbPath);
				ResultSet rs = con.getMetaData().getTables(null,null,"",null);
				while(rs.next()){
					Vector<String> v = new Vector<String>();
					v.add(0, "");
					v.add(1, rs.getString("TABLE_NAME"));
					
					model.addRow(v);
				}
			} finally {
				QDbUtil.closeCon(con);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 生成一个表对应的代码
	 * @param tableName
	 * @param destBasePath
	 * @return
	 */
	public static String genCodeFromTable(String tableName, String destBasePath){
		StringBuilder res = new StringBuilder();
		
		String tmpBasePath = QUtil.getJarPath() + File.separator + "com" + File.separator + "uikoo9";
		try {
			Connection con = null;
			try {
				con = QDbUtil.getCon(dbPath);
				res.append(generateJfinalCode(tableName, destBasePath, tmpBasePath));
			} finally {
				QDbUtil.closeCon(con);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return res.toString();
	}
	
	/**
	 * 生成一个表具体的代码for jfinal
	 * @param tableName
	 * @param destBasePath
	 * @param tmpBasePath
	 * @return
	 */
	public static String generateJfinalCode(String tableName, String destBasePath, String tmpBasePath){
		StringBuilder sb = new StringBuilder();
		
		String folderName = tableName.split("_")[1];
		String ftlName = tableName.replace("_", "-").substring(2);
		String className = QStringUtil.getClassNameFromTableName(tableName);
		
		Map<String, Object> map = QDbUtil.getTableInfoMap(dbPath, tableName);
		String tmpPath 	= tmpBasePath + File.separator + "gcode" + File.separator + "tmp";
		String destFTLPath = 
				destBasePath + File.separator + 
				"WebRoot" + File.separator + 
				"WEB-INF" + File.separator + 
				"view" + File.separator + 
				"manage" + File.separator + 
				folderName;
		String destSRCPath = 
				destBasePath + File.separator + 
				"src" + File.separator + 
				"com" + File.separator + 
				"uikoo9" + File.separator + 
				"manage" + File.separator + 
				folderName + File.separator;
		
		boolean indexFtl 	= QUtil.generateCodeByVelocity(map, destFTLPath, 				ftlName + "-index.html", 		tmpPath, "ftl-index.vm");
		boolean inputFtl 	= QUtil.generateCodeByVelocity(map, destFTLPath, 				ftlName + "-input.html", 		tmpPath, "ftl-input.vm");
		boolean searchFtl 	= QUtil.generateCodeByVelocity(map, destFTLPath, 				ftlName + "-search.html", 		tmpPath, "ftl-search.vm");
		boolean model 		= QUtil.generateCodeByVelocity(map, destSRCPath + "model",		className + "Model.java", 		tmpPath, "Model.vm");
		boolean controller 	= QUtil.generateCodeByVelocity(map, destSRCPath + "controller",	className + "Controller.java",	tmpPath, "Controller.vm");
		
		sb.append("generate jfinal code begin...\r\n");
		sb.append("jfinal index.html生成" + (indexFtl ? "成功" : "失败") + "!\r\n");
		sb.append("jfinal input.html生成" + (inputFtl ? "成功" : "失败") + "!\r\n");
		sb.append("jfinal search.html生成" + (searchFtl ? "成功" : "失败") + "!\r\n");
		sb.append("jfinal model生成" 	+ (model ? "成功" : "失败") + "!\r\n");
		sb.append("jfinal controller生成"+ (controller ? "成功" : "失败") + "!\r\n");
		sb.append("generate jfinal code end...\r\n");
		
		return sb.toString();
	}
	
}
{'fraction_non_alphanumeric': 0.15141242937853108, 'fraction_numerical': 0.0022598870056497176, 'mean_word_length': 3.513065646908859, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2968932', 'n_tokens_mistral': 2919, 'n_tokens_neox': 2564, 'n_words': 490}