1、删除无用demo代码

2、添加主数据模块项目
This commit is contained in:
2025-10-15 10:05:49 +08:00
parent b850a3779c
commit fd6e2d8ce6
89 changed files with 1312 additions and 2364 deletions

View File

@ -0,0 +1,166 @@
package com.pictc.jdbc;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URL;
import java.sql.Array;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.CallableStatement;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLXML;
import java.sql.Struct;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.format.DateTimeParseException;
import com.pictc.utils.StringUtils;
public class CallUtils {
@SuppressWarnings("unchecked")
public static <T> T getObject(CallableStatement res,int columnIndex,Class<T> type) throws SQLException {
if (type.equals(String.class)) {
return (T) res.getString(columnIndex);
} else if (type.equals(BigDecimal.class)) {
return (T) res.getBigDecimal(columnIndex);
} else if (type.equals(BigInteger.class)) {
return (T) getBigInteger(res, columnIndex);
} else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
return (T) Boolean.valueOf(res.getBoolean(columnIndex));
} else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
return (T) Integer.valueOf(res.getInt(columnIndex));
} else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
return (T) Long.valueOf(res.getLong(columnIndex));
} else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
return (T) Float.valueOf(res.getFloat(columnIndex));
} else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
return (T) Double.valueOf(res.getDouble(columnIndex));
} else if (type.equals(byte[].class)) {
return (T) res.getBytes(columnIndex);
} else if (type.equals(Date.class)) {
return (T) res.getDate(columnIndex);
} else if (type.equals(Time.class)) {
return (T) res.getTime(columnIndex);
} else if (type.equals(Timestamp.class)) {
return (T) res.getTimestamp(columnIndex);
} else if (type.equals(java.sql.Clob.class)) {
return (T) res.getClob(columnIndex);
} else if (type.equals(java.sql.Blob.class)) {
return (T) res.getBlob(columnIndex);
} else if (type.equals(Array.class)) {
return (T) res.getArray(columnIndex);
} else if (type.equals(Ref.class)) {
return (T) res.getRef(columnIndex);
} else if (type.equals(URL.class)) {
return (T) res.getURL(columnIndex);
} else if (type.equals(Struct.class)) {
throw new SQLFeatureNotSupportedException();
} else if (type.equals(RowId.class)) {
return (T) res.getRowId(columnIndex);
} else if (type.equals(NClob.class)) {
return (T) res.getNClob(columnIndex);
} else if (type.equals(SQLXML.class)) {
return (T) res.getSQLXML(columnIndex);
} else if (type.equals(LocalDate.class)) {
return (T) getLocalDate(res,columnIndex);
} else if (type.equals(LocalDateTime.class)) {
return (T) getLocalDateTime(res,columnIndex);
} else if (type.equals(LocalTime.class)) {
return (T) getLocalTime(res,columnIndex);
} else if (type.equals(OffsetDateTime.class)) {
try {
String odt = res.getString(columnIndex);
return odt == null ? null : (T) OffsetDateTime.parse(odt);
} catch (DateTimeParseException e) {
// Let it continue and try by object deserialization.
}
} else if (type.equals(OffsetTime.class)) {
try {
String ot = res.getString(columnIndex);
return ot == null ? null : (T) OffsetTime.parse(ot);
} catch (DateTimeParseException e) {}
}else if(type.isEnum()) {
try {
String _vl = res.getString(columnIndex);
if(!StringUtils.isEmpty(_vl)) {
Method method=Enum.class.getMethod("valueOf", String.class);
return (T) method.invoke(null,_vl);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return (T) res.getObject(columnIndex);
}
private static LocalDate getLocalDate(CallableStatement res,int columnIndex) throws SQLException {
Date date = res.getDate(columnIndex);
if(date!=null) {
return date.toLocalDate();
}
return null;
}
private static LocalDateTime getLocalDateTime(CallableStatement res,int columnIndex) throws SQLException {
Timestamp date = res.getTimestamp(columnIndex);
if(date!=null) {
return date.toLocalDateTime();
}
return null;
}
private static LocalTime getLocalTime(CallableStatement res,int columnIndex) throws SQLException {
Time date = res.getTime(columnIndex);
if(date!=null) {
return date.toLocalTime();
}
return null;
}
private static BigInteger getBigInteger(CallableStatement res,int columnIndex) throws SQLException {
String stringVal = res.getString(columnIndex);
if (stringVal == null) {
return null;
}
try {
return new BigInteger(stringVal);
} catch (NumberFormatException nfe) {
throw new RuntimeException("CallableStatement.Bad_format_for_BigInteger");
}
}
}

View File

@ -140,18 +140,34 @@ public static final int DEF_STEP = 1000;
}
}
}
private void setOutParams() throws SQLException {
if(params!=null) {
for (int i = 0; i < params.size(); i++) {
JdbcParam parameter = params.get(i);
int index = i+1;
if(parameter.isOut()) {
parameter.setVal(CallUtils.getObject(ctmt, index,parameter.getJavaType()));
continue;
}
}
}
}
public int executeUpdate() throws SQLException {
executeParams();
size = this._executeUpdate();
setOutParams();
return size;
}
public boolean execute() throws SQLException {
executeParams();
return this._execute();
boolean res = this._execute();
setOutParams();
return res;
}
public int executeBatch() throws SQLException {

View File

@ -162,6 +162,23 @@ public class JdbcTools {
}
}
/**
* 执行存储过程返回基础数据类型
* */
public static void call(String sql,List<JdbcParam> params){
JdbcContext context = null;
try {
context = new JdbcContext(true);
context.initCall(sql);
context.setParams(params);
context.execute();
} catch (SQLException e) {
throw context.createException(e);
}finally {
context.end();
}
}
/**
* 执行存储过程返回基础数据类型
* */

View File

@ -33,7 +33,7 @@ public class JdbcParam implements Serializable{
@Override
public String toString() {
return val+"("+JdbcType.valueOf(jdbc).name()+")";
return (out?"OUT ":"IN ")+val+"("+JdbcType.valueOf(jdbc).name()+")";
}
public static JdbcParam ofOut(int jdbc,Class<?> javaType) {
@ -160,6 +160,111 @@ public class JdbcParam implements Serializable{
.setJavaType(LocalDateTime.class)
.setVal(val);
}
/**
* 获取String类型值
*/
public String getStringValue() {
return val == null ? null : String.class.cast(val);
}
/**
* 获取Integer类型值
*/
public Integer getIntValue() {
return val == null ? null : Integer.class.cast(val);
}
/**
* 获取Long类型值
*/
public Long getLongValue() {
return val == null ? null : Long.class.cast(val);
}
/**
* 获取Boolean类型值
*/
public Boolean getBooleanValue() {
return val == null ? null : Boolean.class.cast(val);
}
/**
* 获取Float类型值
*/
public Float getFloatValue() {
return val == null ? null : Float.class.cast(val);
}
/**
* 获取Double类型值
*/
public Double getDoubleValue() {
return val == null ? null : Double.class.cast(val);
}
/**
* 获取Byte类型值
*/
public Byte getByteValue() {
return val == null ? null : Byte.class.cast(val);
}
/**
* 获取Short类型值
*/
public Short getShortValue() {
return val == null ? null : Short.class.cast(val);
}
/**
* 获取Date类型值
*/
public Date getDateValue() {
return val == null ? null : Date.class.cast(val);
}
/**
* 获取Timestamp类型值
*/
public Timestamp getTimestampValue() {
return val == null ? null : Timestamp.class.cast(val);
}
/**
* 获取BigDecimal类型值
*/
public BigDecimal getBigDecimalValue() {
return val == null ? null : BigDecimal.class.cast(val);
}
/**
* 获取BigInteger类型值
*/
public BigInteger getBigIntegerValue() {
return val == null ? null : BigInteger.class.cast(val);
}
/**
* 获取LocalDate类型值
*/
public LocalDate getLocalDateValue() {
return val == null ? null : LocalDate.class.cast(val);
}
/**
* 获取LocalTime类型值
*/
public LocalTime getLocalTimeValue() {
return val == null ? null : LocalTime.class.cast(val);
}
/**
* 获取LocalDateTime类型值
*/
public LocalDateTime getLocalDateTimeValue() {
return val == null ? null : LocalDateTime.class.cast(val);
}
}