This commit is contained in:
@@ -318,7 +318,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
for (FilterFuncColumn ffc : columns) {
|
for (FilterFuncColumn ffc : columns) {
|
||||||
for (String col : ffc.cols()) {
|
for (String col : ffc.cols()) {
|
||||||
Object o = set.getObject(++index);
|
Object o = set.getObject(++index);
|
||||||
Number rs = ffc.defvalue;
|
Number rs = ffc.getDefvalue();
|
||||||
if (o != null) rs = (Number) o;
|
if (o != null) rs = (Number) o;
|
||||||
map.put(ffc.col(col), rs);
|
map.put(ffc.col(col), rs);
|
||||||
}
|
}
|
||||||
@@ -371,7 +371,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
Map<K, N> rs = new LinkedHashMap<>();
|
Map<K, N> rs = new LinkedHashMap<>();
|
||||||
ResultSet set = stmt.executeQuery(sql);
|
ResultSet set = stmt.executeQuery(sql);
|
||||||
ResultSetMetaData rsd = set.getMetaData();
|
ResultSetMetaData rsd = set.getMetaData();
|
||||||
boolean smallint = rsd.getColumnType(1) == Types.SMALLINT;
|
boolean smallint = rsd == null ? false : rsd.getColumnType(1) == Types.SMALLINT;
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
rs.put((K) (smallint ? set.getShort(1) : set.getObject(1)), (N) set.getObject(2));
|
rs.put((K) (smallint ? set.getShort(1) : set.getObject(1)), (N) set.getObject(2));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ package org.redkale.source;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.sql.SQLException;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
@@ -145,6 +145,26 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
//查询一页数据
|
//查询一页数据
|
||||||
protected abstract <T> CompletableFuture<Sheet<T>> querySheetDB(final EntityInfo<T> info, final boolean needtotal, final SelectColumn selects, final Flipper flipper, final FilterNode node);
|
protected abstract <T> CompletableFuture<Sheet<T>> querySheetDB(final EntityInfo<T> info, final boolean needtotal, final SelectColumn selects, final Flipper flipper, final FilterNode node);
|
||||||
|
|
||||||
|
protected <T> T infoGetValue(EntityInfo<T> info, final SelectColumn sels, final ResultSet set) throws SQLException {
|
||||||
|
return info.getValue(sels, set);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> String createSQLOrderby(EntityInfo<T> info, Flipper flipper) {
|
||||||
|
return info.createSQLOrderby(flipper);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<Class, String> getJoinTabalis(FilterNode node) {
|
||||||
|
return node == null ? null : node.getJoinTabalis();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> CharSequence createSQLJoin(FilterNode node, final Function<Class, EntityInfo> func, final boolean update, final Map<Class, String> joinTabalis, final Set<String> haset, final EntityInfo<T> info) {
|
||||||
|
return node == null ? null : node.createSQLJoin(func, update, joinTabalis, haset, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> CharSequence createSQLExpress(FilterNode node, final EntityInfo<T> info, final Map<Class, String> joinTabalis) {
|
||||||
|
return node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ExecutorService getExecutor() {
|
protected ExecutorService getExecutor() {
|
||||||
return executor;
|
return executor;
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ public class FilterFuncColumn implements java.io.Serializable {
|
|||||||
return new FilterFuncColumn(func, defvalue, columns);
|
return new FilterFuncColumn(func, defvalue, columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] cols() {
|
public String[] cols() {
|
||||||
return columns == null || columns.length == 0 ? new String[]{COLUMN_NULL} : columns;
|
return columns == null || columns.length == 0 ? new String[]{COLUMN_NULL} : columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
String col(String column) {
|
public String col(String column) {
|
||||||
return column == null || column.isEmpty() ? COLUMN_NULL : column;
|
return column == null || column.isEmpty() ? COLUMN_NULL : column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
229
src/org/redkale/util/ByteBufferReader.java
Normal file
229
src/org/redkale/util/ByteBufferReader.java
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.redkale.util;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以ByteBuffer为数据载体的Reader <br>
|
||||||
|
* 注意:ByteBuffer必须是BIG_ENDIAN,且最小可读空间至少是8
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 详情见: https://redkale.org
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
*/
|
||||||
|
public class ByteBufferReader {
|
||||||
|
|
||||||
|
private ByteBuffer[] buffers;
|
||||||
|
|
||||||
|
private int currIndex;
|
||||||
|
|
||||||
|
private ByteBuffer currBuffer;
|
||||||
|
|
||||||
|
public ByteBufferReader(Collection<ByteBuffer> buffers) {
|
||||||
|
Objects.requireNonNull(buffers);
|
||||||
|
this.buffers = buffers.toArray(new ByteBuffer[buffers.size()]);
|
||||||
|
this.currBuffer = this.buffers[0];
|
||||||
|
this.currIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteBufferReader(ByteBuffer[] buffers) {
|
||||||
|
Objects.requireNonNull(buffers);
|
||||||
|
this.buffers = buffers;
|
||||||
|
this.currBuffer = this.buffers[0];
|
||||||
|
this.currIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteBufferReader(ByteBuffer buffer) {
|
||||||
|
Objects.requireNonNull(buffer);
|
||||||
|
this.buffers = new ByteBuffer[]{buffer};
|
||||||
|
this.currBuffer = this.buffers[0];
|
||||||
|
this.currIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ByteBufferReader create(ByteBuffer buffer) {
|
||||||
|
return new ByteBufferReader(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ByteBufferReader create(Collection<ByteBuffer> buffers) {
|
||||||
|
return new ByteBufferReader(buffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ByteBufferReader create(ByteBuffer[] buffers) {
|
||||||
|
return new ByteBufferReader(buffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRemaining(){
|
||||||
|
return this.currBuffer.hasRemaining();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte get() {
|
||||||
|
ByteBuffer buf = this.currBuffer;
|
||||||
|
if (!buf.hasRemaining()) {
|
||||||
|
buf = this.buffers[++this.currIndex];
|
||||||
|
this.currBuffer = buf;
|
||||||
|
}
|
||||||
|
return this.currBuffer.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getShort() {
|
||||||
|
ByteBuffer buf = this.currBuffer;
|
||||||
|
int remain = buf.remaining();
|
||||||
|
if (remain >= 2) return buf.getShort();
|
||||||
|
if (remain == 0) {
|
||||||
|
buf = this.buffers[++this.currIndex];
|
||||||
|
this.currBuffer = buf;
|
||||||
|
return buf.getShort();
|
||||||
|
}
|
||||||
|
return (short) ((buf.get() << 8) | (get() & 0xff));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt() {
|
||||||
|
ByteBuffer buf = this.currBuffer;
|
||||||
|
int remain = buf.remaining();
|
||||||
|
if (remain >= 4) return buf.getInt();
|
||||||
|
if (remain == 0) {
|
||||||
|
buf = this.buffers[++this.currIndex];
|
||||||
|
this.currBuffer = buf;
|
||||||
|
return buf.getInt();
|
||||||
|
}
|
||||||
|
if (remain == 1) {
|
||||||
|
return ((buf.get() << 24)
|
||||||
|
| ((get() & 0xff) << 16)
|
||||||
|
| ((get() & 0xff) << 8)
|
||||||
|
| ((get() & 0xff)));
|
||||||
|
}
|
||||||
|
if (remain == 2) {
|
||||||
|
return ((buf.get() << 24)
|
||||||
|
| ((buf.get() & 0xff) << 16)
|
||||||
|
| ((get() & 0xff) << 8)
|
||||||
|
| ((get() & 0xff)));
|
||||||
|
}
|
||||||
|
//remain == 3
|
||||||
|
return ((buf.get() << 24)
|
||||||
|
| ((buf.get() & 0xff) << 16)
|
||||||
|
| ((buf.get() & 0xff) << 8)
|
||||||
|
| ((get() & 0xff)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getFloat() {
|
||||||
|
return Float.intBitsToFloat(getInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLong() {
|
||||||
|
ByteBuffer buf = this.currBuffer;
|
||||||
|
int remain = buf.remaining();
|
||||||
|
if (remain >= 8) return buf.getLong();
|
||||||
|
if (remain == 0) {
|
||||||
|
buf = this.buffers[++this.currIndex];
|
||||||
|
this.currBuffer = buf;
|
||||||
|
return buf.getLong();
|
||||||
|
}
|
||||||
|
if (remain == 1) {
|
||||||
|
return ((((long) buf.get()) << 56)
|
||||||
|
| (((long) get() & 0xff) << 48)
|
||||||
|
| (((long) get() & 0xff) << 40)
|
||||||
|
| (((long) get() & 0xff) << 32)
|
||||||
|
| (((long) get() & 0xff) << 24)
|
||||||
|
| (((long) get() & 0xff) << 16)
|
||||||
|
| (((long) get() & 0xff) << 8)
|
||||||
|
| (((long) get() & 0xff)));
|
||||||
|
}
|
||||||
|
if (remain == 2) {
|
||||||
|
return ((((long) buf.get()) << 56)
|
||||||
|
| (((long) buf.get() & 0xff) << 48)
|
||||||
|
| (((long) get() & 0xff) << 40)
|
||||||
|
| (((long) get() & 0xff) << 32)
|
||||||
|
| (((long) get() & 0xff) << 24)
|
||||||
|
| (((long) get() & 0xff) << 16)
|
||||||
|
| (((long) get() & 0xff) << 8)
|
||||||
|
| (((long) get() & 0xff)));
|
||||||
|
}
|
||||||
|
if (remain == 3) {
|
||||||
|
return ((((long) buf.get()) << 56)
|
||||||
|
| (((long) buf.get() & 0xff) << 48)
|
||||||
|
| (((long) buf.get() & 0xff) << 40)
|
||||||
|
| (((long) get() & 0xff) << 32)
|
||||||
|
| (((long) get() & 0xff) << 24)
|
||||||
|
| (((long) get() & 0xff) << 16)
|
||||||
|
| (((long) get() & 0xff) << 8)
|
||||||
|
| (((long) get() & 0xff)));
|
||||||
|
}
|
||||||
|
if (remain == 4) {
|
||||||
|
return ((((long) buf.get()) << 56)
|
||||||
|
| (((long) buf.get() & 0xff) << 48)
|
||||||
|
| (((long) buf.get() & 0xff) << 40)
|
||||||
|
| (((long) buf.get() & 0xff) << 32)
|
||||||
|
| (((long) get() & 0xff) << 24)
|
||||||
|
| (((long) get() & 0xff) << 16)
|
||||||
|
| (((long) get() & 0xff) << 8)
|
||||||
|
| (((long) get() & 0xff)));
|
||||||
|
}
|
||||||
|
if (remain == 5) {
|
||||||
|
return ((((long) buf.get()) << 56)
|
||||||
|
| (((long) buf.get() & 0xff) << 48)
|
||||||
|
| (((long) buf.get() & 0xff) << 40)
|
||||||
|
| (((long) buf.get() & 0xff) << 32)
|
||||||
|
| (((long) buf.get() & 0xff) << 24)
|
||||||
|
| (((long) get() & 0xff) << 16)
|
||||||
|
| (((long) get() & 0xff) << 8)
|
||||||
|
| (((long) get() & 0xff)));
|
||||||
|
}
|
||||||
|
if (remain == 6) {
|
||||||
|
return ((((long) buf.get()) << 56)
|
||||||
|
| (((long) buf.get() & 0xff) << 48)
|
||||||
|
| (((long) buf.get() & 0xff) << 40)
|
||||||
|
| (((long) buf.get() & 0xff) << 32)
|
||||||
|
| (((long) buf.get() & 0xff) << 24)
|
||||||
|
| (((long) buf.get() & 0xff) << 16)
|
||||||
|
| (((long) get() & 0xff) << 8)
|
||||||
|
| (((long) get() & 0xff)));
|
||||||
|
}
|
||||||
|
//remain == 7
|
||||||
|
return ((((long) buf.get()) << 56)
|
||||||
|
| (((long) buf.get() & 0xff) << 48)
|
||||||
|
| (((long) buf.get() & 0xff) << 40)
|
||||||
|
| (((long) buf.get() & 0xff) << 32)
|
||||||
|
| (((long) buf.get() & 0xff) << 24)
|
||||||
|
| (((long) buf.get() & 0xff) << 16)
|
||||||
|
| (((long) buf.get() & 0xff) << 8)
|
||||||
|
| (((long) get() & 0xff)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDouble() {
|
||||||
|
return Double.longBitsToDouble(getLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteBufferReader get(byte[] dst) {
|
||||||
|
return get(dst, 0, dst.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteBufferReader get(byte[] dst, int offset, int length) {
|
||||||
|
ByteBuffer buf = this.currBuffer;
|
||||||
|
int remain = buf.remaining();
|
||||||
|
if (remain >= length) {
|
||||||
|
buf.get(dst, offset, length);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
buf.get(dst, offset, remain);
|
||||||
|
this.currBuffer = this.buffers[++this.currIndex];
|
||||||
|
return get(dst, offset + remain, length - remain);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteBufferReader skip(int size) {
|
||||||
|
ByteBuffer buf = this.currBuffer;
|
||||||
|
int remain = buf.remaining();
|
||||||
|
if (remain >= size) {
|
||||||
|
buf.position(buf.position() + size);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
buf.position(buf.position() + remain);
|
||||||
|
this.currBuffer = this.buffers[++this.currIndex];
|
||||||
|
return skip(size - remain);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,7 +48,7 @@ public class ByteBufferWriter {
|
|||||||
public ByteBuffer[] toBuffers() {
|
public ByteBuffer[] toBuffers() {
|
||||||
if (buffers == null) return new ByteBuffer[0];
|
if (buffers == null) return new ByteBuffer[0];
|
||||||
for (ByteBuffer buf : this.buffers) {
|
for (ByteBuffer buf : this.buffers) {
|
||||||
if (buf.position() != 0) buf.flip();
|
buf.flip();
|
||||||
}
|
}
|
||||||
return this.buffers;
|
return this.buffers;
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,6 @@ public class ByteBufferWriter {
|
|||||||
// System.out.println(Arrays.toString(b4));
|
// System.out.println(Arrays.toString(b4));
|
||||||
// System.out.println(Arrays.toString(toBytes(writer.toBuffers())));
|
// System.out.println(Arrays.toString(toBytes(writer.toBuffers())));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public ByteBufferWriter putFloat(float value) {
|
public ByteBufferWriter putFloat(float value) {
|
||||||
getLastBuffer(4).putFloat(value);
|
getLastBuffer(4).putFloat(value);
|
||||||
position += 4;
|
position += 4;
|
||||||
|
|||||||
Reference in New Issue
Block a user