⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typeconvertor.java

📁 生成与Oracle相关的Ibatis相关配置文件及Java源码
💻 JAVA
字号:
/*
 * Copyright (c) 2008 胜利油田胜利软件有限责任公司. All rights reserved.
 */
package com.victorysoft.code.base;

import java.util.HashMap;
import java.util.Map;

import com.victorysoft.code.bean.ColInfo;

/**
 * 
 * @author 于景洋
 * @newtime Oct 21, 2008,9:22:01 AM
 * @version 1.0
 * @see
 * @since JDK 1.5.0
 */
public class TypeConvertor {
	private static final String $TYPECONVERTOR = "$TYPECONVERTOR";
	private static CodeTemplete bct = null;
	private static Map<String, String> beanTypeMap = null;
	private static Map<String, String> javaTypeMap = null;
	private static Map<String, String> jdbcTypeMap = null;
	static {
		bct = new CodeTemplete(TypeConvertor.class, "type.txt");
		beanTypeMap = new HashMap<String, String>();
		javaTypeMap = new HashMap<String, String>();
		jdbcTypeMap = new HashMap<String, String>();
		String str = bct.getTemplete($TYPECONVERTOR);
		String[] strs = str.split("\n");
		for (int i = 0; i < strs.length; i++) {
			String[] s = strs[i].trim().substring(1).split("-");
			beanTypeMap.put(s[0].trim(), s[1].trim());
			javaTypeMap.put(s[0].trim(), s[2].trim());
			jdbcTypeMap.put(s[0].trim(), s[3].trim());
		}
	}

	public static String getBeanType(ColInfo col) {
		return beanTypeMap.get(getBaseType(col));
	}

	public static String getJavaType(ColInfo col) {
		return javaTypeMap.get(getBaseType(col));
	}

	public static String getJdbcType(ColInfo col) {
		return jdbcTypeMap.get(getBaseType(col));
	}

	private static String getBaseType(ColInfo col) {
		String type = col.getType();
		int length = col.getLength();
		String scale = col.getScale();
		if ("CHAR".equals(type)) {
			if (length == 1) {
				return "CHAR(1)";
			} else {
				return "CHAR(*)";
			}
		} else if ("NUMBER".equals(type)) {
			if (parseScale(scale) == 0) {
				return "NUMBER(*,0)";
			} else {
				return "NUMBER(*,*)";
			}
		} else {
			return type;
		}
	}

	private static int parseScale(String scale) {
		if (scale == null || scale.length() == 0) {
			return 22;// 22为Oracle中NUMBER类型的长度
		} else {
			return Integer.parseInt(scale);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -