This commit is contained in:
Redkale
2016-09-26 10:18:21 +08:00
parent 43102b9d35
commit 940af0b251
2 changed files with 14 additions and 1 deletions

View File

@@ -471,7 +471,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
int index = 0;
for (final T value : values) {
int i = 0;
if (info.distributed) info.createPrimaryValue(value);
if (info.distributed || info.autoUUID) info.createPrimaryValue(value);
for (Attribute<T, Serializable> attr : attrs) {
Object a = attr.get(value);
ps[i] = FilterNode.formatToString(a);

View File

@@ -93,6 +93,8 @@ public final class EntityInfo<T> {
final boolean autoGenerated;
final boolean autoUUID;
final boolean distributed;
boolean initedPrimaryValue = false;
@@ -173,6 +175,7 @@ public final class EntityInfo<T> {
List<String> updatecols = new ArrayList<>();
List<Attribute<T, Serializable>> updateattrs = new ArrayList<>();
boolean auto = false;
boolean uuid = false;
boolean sqldistribute = false;
int allocationSize0 = 0;
@@ -213,6 +216,11 @@ public final class EntityInfo<T> {
allocationSize0 = dg.allocationSize();
primaryValue.set(dg.initialValue());
}
if (gv != null && field.getType() == String.class) { //UUID
uuid = true;
auto = false;
}
if (!auto) {
insertcols.add(sqlfield);
insertattrs.add(attr);
@@ -264,6 +272,7 @@ public final class EntityInfo<T> {
this.querySQL = null;
}
this.autoGenerated = auto;
this.autoUUID = uuid;
this.distributed = sqldistribute;
this.allocationSize = allocationSize0;
//----------------cache--------------
@@ -282,6 +291,10 @@ public final class EntityInfo<T> {
}
public void createPrimaryValue(T src) {
if (autoUUID) {
getPrimary().set(src, Utility.uuid());
return;
}
long v = allocationSize > 1 ? (primaryValue.incrementAndGet() * allocationSize + nodeid) : primaryValue.incrementAndGet();
if (primary.type() == int.class || primary.type() == Integer.class) {
getPrimary().set(src, (Integer) ((Long) v).intValue());