This commit is contained in:
地平线
2015-04-15 18:40:12 +08:00
parent 151273cce3
commit bba2766ee9
6 changed files with 98 additions and 33 deletions

View File

@@ -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;

View File

@@ -571,6 +571,26 @@ public final class DataJDBCSource implements DataSource {
}
}
@Override
public <T> void delete(Class<T> 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 <T> void delete(Class<T> 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<T> cache = info.inner.getCache();
if (cache == null) return;
Attribute<T, Object> attr = (Attribute<T, Object>) 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();

View File

@@ -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 <T> void delete(Class<T> clazz, int[] ids) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public <T> void delete(Class<T> 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;

View File

@@ -83,6 +83,10 @@ public interface DataSource {
*/
public <T> void delete(Class<T> clazz, Serializable... ids);
public <T> void delete(Class<T> clazz, int[] ids);
public <T> void delete(Class<T> clazz, long[] ids);
/**
* 根据主键值删除对象, 必须是Entity Class
*

View File

@@ -198,6 +198,34 @@ final class EntityCache<T> {
return rs;
}
public <V> T updateColumnIncrement(final Serializable id, Attribute<T, V> 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;
}

View File

@@ -19,6 +19,8 @@ import jdk.internal.org.objectweb.asm.Type;
*/
public interface Attribute<T, F> {
public Class type();
public String field();
public F get(T obj);
@@ -158,6 +160,31 @@ public interface Attribute<T, F> {
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;