This commit is contained in:
@@ -34,12 +34,12 @@ public class DataSourceService implements DataSource, Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> void insert(@SncpCall(EntityCallAttribute.class) T... values) {
|
public <T> void insert(@SncpCall(DataCallArrayAttribute.class) T... values) {
|
||||||
source.insert(values);
|
source.insert(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> void insert(DataConnection conn, @SncpCall(EntityCallAttribute.class) T... values) {
|
public <T> void insert(DataConnection conn, @SncpCall(DataCallArrayAttribute.class) T... values) {
|
||||||
source.insert(conn, values);
|
source.insert(conn, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
57
src/com/wentch/redkale/source/DataCallArrayAttribute.java
Normal file
57
src/com/wentch/redkale/source/DataCallArrayAttribute.java
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.wentch.redkale.source;
|
||||||
|
|
||||||
|
import com.wentch.redkale.util.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
* @param <T>
|
||||||
|
* @param <F>
|
||||||
|
*/
|
||||||
|
public final class DataCallArrayAttribute<T, F> implements Attribute<T[], F> {
|
||||||
|
|
||||||
|
public static final DataCallArrayAttribute instance = new DataCallArrayAttribute();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends F> type() {
|
||||||
|
return (Class<F>) Object.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<T[]> declaringClass() {
|
||||||
|
return (Class<T[]>) (Class) Object[].class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String field() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public F get(final T[] objs) {
|
||||||
|
if (objs == null || objs.length == 0) return null;
|
||||||
|
final Attribute<T, Serializable> attr = DataCallAttribute.load(objs[0].getClass());
|
||||||
|
final Object keys = Array.newInstance(attr.type(), objs.length);
|
||||||
|
for (int i = 0; i < objs.length; i++) {
|
||||||
|
Array.set(keys, i, attr.get(objs[i]));
|
||||||
|
}
|
||||||
|
return (F) keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(final T[] objs, final F keys) {
|
||||||
|
if (objs == null || objs.length == 0) return;
|
||||||
|
final Attribute<T, Serializable> attr = DataCallAttribute.load(objs[0].getClass());
|
||||||
|
for (int i = 0; i < objs.length; i++) {
|
||||||
|
attr.set(objs[i], (Serializable) Array.get(keys, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,16 +13,14 @@ import java.util.concurrent.*;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
* @param <T>
|
|
||||||
* @param <F>
|
|
||||||
*/
|
*/
|
||||||
public final class EntityCallAttribute<T, F> implements Attribute<T[], F> {
|
public class DataCallAttribute implements Attribute<Object, Serializable> {
|
||||||
|
|
||||||
public static final EntityCallAttribute instance = new EntityCallAttribute();
|
public static final DataCallAttribute instance = new DataCallAttribute();
|
||||||
|
|
||||||
private static final ConcurrentHashMap<Class, Attribute> attributes = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<Class, Attribute> attributes = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static Attribute load(final Class clazz) {
|
static <T> Attribute<T, Serializable> load(final Class clazz) {
|
||||||
Attribute rs = attributes.get(clazz);
|
Attribute rs = attributes.get(clazz);
|
||||||
if (rs != null) return rs;
|
if (rs != null) return rs;
|
||||||
synchronized (attributes) {
|
synchronized (attributes) {
|
||||||
@@ -46,13 +44,13 @@ public final class EntityCallAttribute<T, F> implements Attribute<T[], F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends F> type() {
|
public Class<Serializable> type() {
|
||||||
return (Class<F>) Object.class;
|
return Serializable.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<T[]> declaringClass() {
|
public Class<Object> declaringClass() {
|
||||||
return (Class<T[]>) (Class) Object[].class;
|
return Object.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,23 +59,14 @@ public final class EntityCallAttribute<T, F> implements Attribute<T[], F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public F get(final T[] objs) {
|
public Serializable get(final Object obj) {
|
||||||
if (objs == null || objs.length == 0) return null;
|
if (obj == null) return null;
|
||||||
final Attribute<T, Serializable> attr = (Attribute<T, Serializable>) load(objs[0].getClass());
|
return load(obj.getClass()).get(obj);
|
||||||
final Object keys = Array.newInstance(attr.type(), objs.length);
|
|
||||||
for (int i = 0; i < objs.length; i++) {
|
|
||||||
Array.set(keys, i, attr.get(objs[i]));
|
|
||||||
}
|
|
||||||
return (F) keys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(final T[] objs, final F keys) {
|
public void set(final Object obj, final Serializable key) {
|
||||||
if (objs == null || objs.length == 0) return;
|
if (obj == null) return;
|
||||||
final Attribute<T, F> attr = (Attribute<T, F>) load(objs[0].getClass());
|
load(obj.getClass()).set(obj, key);
|
||||||
for (int i = 0; i < objs.length; i++) {
|
|
||||||
attr.set(objs[i], (F) Array.get(keys, i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user