diff --git a/src/com/wentch/redkale/convert/Factory.java b/src/com/wentch/redkale/convert/Factory.java index 41da5a10b..1a5734515 100644 --- a/src/com/wentch/redkale/convert/Factory.java +++ b/src/com/wentch/redkale/convert/Factory.java @@ -5,35 +5,8 @@ */ package com.wentch.redkale.convert; -import com.wentch.redkale.convert.ext.StringArraySimpledCoder; -import com.wentch.redkale.convert.ext.DoubleArraySimpledCoder; -import com.wentch.redkale.convert.ext.LongSimpledCoder; -import com.wentch.redkale.convert.ext.ByteArraySimpledCoder; -import com.wentch.redkale.convert.ext.IntArraySimpledCoder; -import com.wentch.redkale.convert.ext.DoubleSimpledCoder; -import com.wentch.redkale.convert.ext.TwoLongSimpledCoder; -import com.wentch.redkale.convert.ext.CharSimpledCoder; -import com.wentch.redkale.convert.ext.IntSimpledCoder; -import com.wentch.redkale.convert.ext.InetAddressSimpledCoder; -import com.wentch.redkale.convert.ext.LongArraySimpledCoder; -import com.wentch.redkale.convert.ext.DateSimpledCoder; -import com.wentch.redkale.convert.ext.BoolSimpledCoder; -import com.wentch.redkale.convert.ext.CharArraySimpledCoder; -import com.wentch.redkale.convert.ext.EnumSimpledCoder; -import com.wentch.redkale.convert.ext.BigIntegerSimpledCoder; -import com.wentch.redkale.convert.ext.ByteSimpledCoder; -import com.wentch.redkale.convert.ext.StringSimpledCoder; -import com.wentch.redkale.convert.ext.NumberSimpledCoder; -import com.wentch.redkale.convert.ext.TypeSimpledCoder; -import com.wentch.redkale.convert.ext.ShortArraySimpledCoder; -import com.wentch.redkale.convert.ext.BoolArraySimpledCoder; -import com.wentch.redkale.convert.ext.ShortSimpledCoder; -import com.wentch.redkale.convert.ext.FloatArraySimpledCoder; -import com.wentch.redkale.convert.ext.FloatSimpledCoder; -import com.wentch.redkale.util.TwoLong; -import com.wentch.redkale.util.Creator; -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.ParameterizedType; +import com.wentch.redkale.convert.ext.*; +import com.wentch.redkale.util.*; import java.lang.reflect.Type; import java.util.Collection; import java.util.Map; diff --git a/src/com/wentch/redkale/source/DataJDBCSource.java b/src/com/wentch/redkale/source/DataJDBCSource.java index 807ee6208..1bf0d919a 100644 --- a/src/com/wentch/redkale/source/DataJDBCSource.java +++ b/src/com/wentch/redkale/source/DataJDBCSource.java @@ -571,6 +571,26 @@ public final class DataJDBCSource implements DataSource { } } + @Override + public void delete(Class clazz, int[] ids) { + if (ids == null) return; + Serializable[] newids = new Serializable[ids.length]; + for (int i = 0; i < ids.length; i++) { + newids[i] = ids[i]; + } + delete(clazz, newids); + } + + @Override + public void delete(Class clazz, long[] ids) { + if (ids == null) return; + Serializable[] newids = new Serializable[ids.length]; + for (int i = 0; i < ids.length; i++) { + newids[i] = ids[i]; + } + delete(clazz, newids); + } + /** * 根据主键值删除对象, 必须是Entity Class * @@ -910,10 +930,8 @@ public final class DataJDBCSource implements DataSource { final EntityCache cache = info.inner.getCache(); if (cache == null) return; Attribute attr = (Attribute) info.getAttribute(column); - T value = find(clazz, id); - if (value == null) return; - cache.update(id, attr, attr.get(value)); - if (cacheListener != null) cacheListener.update(name, clazz, value); + T value = cache.updateColumnIncrement(id, attr, incvalue); + if (value != null && cacheListener != null) cacheListener.update(name, clazz, value); } catch (SQLException e) { throw new RuntimeException(e); } finally { @@ -1855,6 +1873,11 @@ public final class DataJDBCSource implements DataSource { this.fieldName = fieldname; } + @Override + public Class type() { + return type; + } + @Override public String field() { return attribute.field(); diff --git a/src/com/wentch/redkale/source/DataJPASource.java b/src/com/wentch/redkale/source/DataJPASource.java index d7ac29d71..eba69d740 100644 --- a/src/com/wentch/redkale/source/DataJPASource.java +++ b/src/com/wentch/redkale/source/DataJPASource.java @@ -59,6 +59,16 @@ final class DataJPASource implements DataSource { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override + public void delete(Class clazz, int[] ids) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void delete(Class clazz, long[] ids) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + private static class DataJPAConnection extends DataConnection { private final EntityManager manager; diff --git a/src/com/wentch/redkale/source/DataSource.java b/src/com/wentch/redkale/source/DataSource.java index ced5c3f4d..28a33e157 100644 --- a/src/com/wentch/redkale/source/DataSource.java +++ b/src/com/wentch/redkale/source/DataSource.java @@ -83,6 +83,10 @@ public interface DataSource { */ public void delete(Class clazz, Serializable... ids); + public void delete(Class clazz, int[] ids); + + public void delete(Class clazz, long[] ids); + /** * 根据主键值删除对象, 必须是Entity Class * diff --git a/src/com/wentch/redkale/source/EntityCache.java b/src/com/wentch/redkale/source/EntityCache.java index 7aa6e6bd9..6c325f24b 100644 --- a/src/com/wentch/redkale/source/EntityCache.java +++ b/src/com/wentch/redkale/source/EntityCache.java @@ -198,6 +198,34 @@ final class EntityCache { return rs; } + public T updateColumnIncrement(final Serializable id, Attribute attr, final long incvalue) { + if (id == null) return null; + T rs = this.map.get(id); + if (rs == null) return rs; + Number numb = (Number) attr.get(rs); + if (numb == null) { + numb = incvalue; + } else { + numb = numb.longValue() + incvalue; + } + final Class ft = attr.type(); + if (ft == int.class || ft == Integer.class) { + numb = numb.intValue(); + } else if (ft == long.class || ft == Long.class) { + numb = numb.longValue(); + } else if (ft == short.class || ft == Short.class) { + numb = numb.shortValue(); + } else if (ft == float.class || ft == Float.class) { + numb = numb.floatValue(); + } else if (ft == double.class || ft == Double.class) { + numb = numb.doubleValue(); + } else if (ft == byte.class || ft == Byte.class) { + numb = numb.byteValue(); + } + attr.set(rs, (V) numb); + return rs; + } + public boolean isParallel() { return this.list.size() > 1024 * 16; } diff --git a/src/com/wentch/redkale/util/Attribute.java b/src/com/wentch/redkale/util/Attribute.java index c8d2898cd..3cc383110 100644 --- a/src/com/wentch/redkale/util/Attribute.java +++ b/src/com/wentch/redkale/util/Attribute.java @@ -19,6 +19,8 @@ import jdk.internal.org.objectweb.asm.Type; */ public interface Attribute { + public Class type(); + public String field(); public F get(T obj); @@ -158,6 +160,31 @@ public interface Attribute { mv.visitMaxs(1, 1); mv.visitEnd(); } + { //type 方法 + mv = cw.visitMethod(ACC_PUBLIC, "type", "()Ljava/lang/Class;", null, null); + if (pcolumn == boolean.class) { + mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;"); + } else if (pcolumn == byte.class) { + mv.visitFieldInsn(GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;"); + } else if (pcolumn == char.class) { + mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;"); + } else if (pcolumn == short.class) { + mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;"); + } else if (pcolumn == int.class) { + mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;"); + } else if (pcolumn == float.class) { + mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;"); + } else if (pcolumn == long.class) { + mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;"); + } else if (pcolumn == double.class) { + mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;"); + } else { + mv.visitLdcInsn(Type.getType(pcolumn)); + } + mv.visitInsn(ARETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } { //get 方法 mv = cw.visitMethod(ACC_PUBLIC, "get", "(" + interDesc + ")" + columnDesc, null, null); int m = 1;