修复bson问题
This commit is contained in:
@@ -192,7 +192,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
|||||||
//------------------------------ convertTo -----------------------------------------------------------
|
//------------------------------ convertTo -----------------------------------------------------------
|
||||||
@Override
|
@Override
|
||||||
public byte[] convertTo(final Type type, final Object value) {
|
public byte[] convertTo(final Type type, final Object value) {
|
||||||
if (value == null) {
|
if (type == null && value == null) {
|
||||||
final BsonWriter out = pollWriter();
|
final BsonWriter out = pollWriter();
|
||||||
out.writeNull();
|
out.writeNull();
|
||||||
byte[] result = out.toArray();
|
byte[] result = out.toArray();
|
||||||
@@ -214,7 +214,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
|||||||
@Override
|
@Override
|
||||||
public void convertToBytes(final Type type, final Object value, final ConvertBytesHandler handler) {
|
public void convertToBytes(final Type type, final Object value, final ConvertBytesHandler handler) {
|
||||||
final BsonWriter writer = pollWriter();
|
final BsonWriter writer = pollWriter();
|
||||||
if (type == null) {
|
if (type == null && type == null) {
|
||||||
writer.writeNull();
|
writer.writeNull();
|
||||||
} else {
|
} else {
|
||||||
factory.loadEncoder(type).convertTo(writer, value);
|
factory.loadEncoder(type).convertTo(writer, value);
|
||||||
@@ -226,7 +226,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
|||||||
public void convertToBytes(final ByteArray array, final Type type, final Object value) {
|
public void convertToBytes(final ByteArray array, final Type type, final Object value) {
|
||||||
Objects.requireNonNull(array);
|
Objects.requireNonNull(array);
|
||||||
final BsonWriter writer = configWrite(new BsonWriter(array).withFeatures(features));
|
final BsonWriter writer = configWrite(new BsonWriter(array).withFeatures(features));
|
||||||
if (value == null) {
|
if (type == null && value == null) {
|
||||||
writer.writeNull();
|
writer.writeNull();
|
||||||
} else {
|
} else {
|
||||||
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);
|
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);
|
||||||
@@ -239,7 +239,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void convertTo(final OutputStream out, final Type type, final Object value) {
|
public void convertTo(final OutputStream out, final Type type, final Object value) {
|
||||||
if (value == null) {
|
if (type == null && value == null) {
|
||||||
pollWriter(out).writeNull();
|
pollWriter(out).writeNull();
|
||||||
} else {
|
} else {
|
||||||
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(pollWriter(out), value);
|
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(pollWriter(out), value);
|
||||||
@@ -250,7 +250,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
|||||||
public ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Type type, final Object value) {
|
public ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Type type, final Object value) {
|
||||||
Objects.requireNonNull(supplier);
|
Objects.requireNonNull(supplier);
|
||||||
BsonByteBufferWriter writer = pollWriter(supplier);
|
BsonByteBufferWriter writer = pollWriter(supplier);
|
||||||
if (value == null) {
|
if (type == null && value == null) {
|
||||||
writer.writeNull();
|
writer.writeNull();
|
||||||
} else {
|
} else {
|
||||||
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);
|
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);
|
||||||
@@ -260,7 +260,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void convertTo(final BsonWriter writer, final Type type, final Object value) {
|
public void convertTo(final BsonWriter writer, final Type type, final Object value) {
|
||||||
if (value == null) {
|
if (type == null && value == null) { //必须判断type==null
|
||||||
writer.writeNull();
|
writer.writeNull();
|
||||||
} else {
|
} else {
|
||||||
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);
|
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);
|
||||||
|
|||||||
@@ -330,20 +330,18 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
|
|||||||
if (authenticate != null) {
|
if (authenticate != null) {
|
||||||
future = future.thenCompose(authenticate);
|
future = future.thenCompose(authenticate);
|
||||||
}
|
}
|
||||||
return future.thenCompose(c -> {
|
return future.thenApply(c -> {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
c.setAuthenticated(true);
|
||||||
c.setAuthenticated(true);
|
if (pool) {
|
||||||
if (pool) {
|
this.connArray[connIndex] = c;
|
||||||
this.connArray[connIndex] = c;
|
CompletableFuture<C> f;
|
||||||
CompletableFuture<C> f;
|
while ((f = waitQueue.poll()) != null) {
|
||||||
while ((f = waitQueue.poll()) != null) {
|
if (!f.isDone()) {
|
||||||
if (!f.isDone()) {
|
f.complete(c);
|
||||||
f.complete(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c;
|
}
|
||||||
}, c.channel.getWriteIOThread());
|
return c;
|
||||||
}).whenComplete((r, t) -> {
|
}).whenComplete((r, t) -> {
|
||||||
if (pool && t != null) {
|
if (pool && t != null) {
|
||||||
this.connOpenStates[connIndex].set(false);
|
this.connOpenStates[connIndex].set(false);
|
||||||
@@ -392,20 +390,18 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
|
|||||||
if (authenticate != null) {
|
if (authenticate != null) {
|
||||||
future = future.thenCompose(authenticate);
|
future = future.thenCompose(authenticate);
|
||||||
}
|
}
|
||||||
return future.thenCompose(c -> {
|
return future.thenApply(c -> {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
c.setAuthenticated(true);
|
||||||
c.setAuthenticated(true);
|
if (pool) {
|
||||||
if (pool) {
|
entry.connection = c;
|
||||||
entry.connection = c;
|
CompletableFuture<C> f;
|
||||||
CompletableFuture<C> f;
|
while ((f = waitQueue.poll()) != null) {
|
||||||
while ((f = waitQueue.poll()) != null) {
|
if (!f.isDone()) {
|
||||||
if (!f.isDone()) {
|
f.complete(c);
|
||||||
f.complete(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c;
|
}
|
||||||
}, c.channel.getWriteIOThread());
|
return c;
|
||||||
}).whenComplete((r, t) -> {
|
}).whenComplete((r, t) -> {
|
||||||
if (pool && t != null) {
|
if (pool && t != null) {
|
||||||
entry.connOpenState.set(false);
|
entry.connOpenState.set(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user