From 98ef6a85793123102a9625869c4e91b2b7469c45 Mon Sep 17 00:00:00 2001 From: wenshao Date: Sun, 27 May 2018 18:21:27 +0800 Subject: [PATCH] add license info. --- .../com/alibaba/druid/dfile/DFileReader.java | 24 -- .../com/alibaba/druid/dfile/DFileWriter.java | 213 ------------------ .../druid/pool/ha/DataSourceCreator.java | 15 ++ .../pool/ha/HighAvailableDataSource.java | 15 ++ .../pool/ha/selector/DataSourceSelector.java | 15 ++ .../selector/DataSourceSelectorFactory.java | 15 ++ .../ha/selector/NamedDataSourceSelector.java | 15 ++ .../RandomDataSourceRecoverThread.java | 15 ++ .../ha/selector/RandomDataSourceSelector.java | 15 ++ .../RandomDataSourceValidateThread.java | 15 ++ 10 files changed, 120 insertions(+), 237 deletions(-) delete mode 100644 src/main/java/com/alibaba/druid/dfile/DFileReader.java delete mode 100644 src/main/java/com/alibaba/druid/dfile/DFileWriter.java diff --git a/src/main/java/com/alibaba/druid/dfile/DFileReader.java b/src/main/java/com/alibaba/druid/dfile/DFileReader.java deleted file mode 100644 index bb95601ffb..0000000000 --- a/src/main/java/com/alibaba/druid/dfile/DFileReader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.alibaba.druid.dfile; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.RandomAccessFile; - -public class DFileReader { - private final RandomAccessFile in; - private final int rowCount; - - public DFileReader(RandomAccessFile in, int offset) throws IOException { - this.in = in; - this.rowCount = in.readInt(); - - // block_count - // 20 - // 1024 * 1024 - } - - public int getRowCount() { - return rowCount; - } -} diff --git a/src/main/java/com/alibaba/druid/dfile/DFileWriter.java b/src/main/java/com/alibaba/druid/dfile/DFileWriter.java deleted file mode 100644 index 7d357b24d8..0000000000 --- a/src/main/java/com/alibaba/druid/dfile/DFileWriter.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.dfile; - -import java.math.BigDecimal; -import java.nio.charset.Charset; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Types; - -public class DFileWriter { - final static Charset UTF8 = Charset.forName("UTF-8"); - - private final Column[] columns; - private int rowCount; - - public DFileWriter(ResultSet rs) throws SQLException { - ResultSetMetaData meta = rs.getMetaData(); - final int columnCount = meta.getColumnCount(); - columns = new Column[columnCount]; - for (int i = 0; i < columnCount; ++i) { - columns[i] = new Column(meta, i + 1); - } - - byte[] b = new byte[1024 * 128]; - int off = 0; - off += ((columnCount - 1) / 8); - - while (rs.next()) { - for (int i = 0; i < columnCount; ++i) { - Column column = columns[i]; - int columnIndex = i + 1; - switch (column.type) { - case Types.TINYINT: { - byte val = rs.getByte(columnIndex); - b[off++] = val; - break; - } - case Types.SMALLINT: { - short val = rs.getShort(columnIndex); - b[off + 1] = (byte) (val); - b[off] = (byte) (val >>> 8); - off += 2; - break; - } - case Types.INTEGER: { - int val = rs.getInt(columnIndex); - b[off + 3] = (byte) (val); - b[off + 2] = (byte) (val >>> 8); - b[off + 1] = (byte) (val >>> 16); - b[off] = (byte) (val >>> 24); - off += 4; - break; - } - case Types.BIGINT: { - long val = rs.getLong(columnIndex); - b[off + 7] = (byte) (val); - b[off + 6] = (byte) (val >>> 8); - b[off + 5] = (byte) (val >>> 16); - b[off + 4] = (byte) (val >>> 24); - b[off + 3] = (byte) (val >>> 32); - b[off + 2] = (byte) (val >>> 40); - b[off + 1] = (byte) (val >>> 48); - b[off] = (byte) (val >>> 56); - off += 8; - break; - } - case Types.FLOAT: { - float floatVal = rs.getFloat(columnIndex); - int val = Float.floatToIntBits(floatVal); - b[off + 3] = (byte) (val); - b[off + 2] = (byte) (val >>> 8); - b[off + 1] = (byte) (val >>> 16); - b[off] = (byte) (val >>> 24); - off += 4; - break; - } - case Types.DOUBLE: - double doubleVal = rs.getDouble(columnIndex); - long val = Double.doubleToLongBits(doubleVal); - b[off + 7] = (byte) (val); - b[off + 6] = (byte) (val >>> 8); - b[off + 5] = (byte) (val >>> 16); - b[off + 4] = (byte) (val >>> 24); - b[off + 3] = (byte) (val >>> 32); - b[off + 2] = (byte) (val >>> 40); - b[off + 1] = (byte) (val >>> 48); - b[off] = (byte) (val >>> 56); - off += 8; - break; - case Types.VARCHAR: { - String str = rs.getString(columnIndex); - if (str != null) { - byte[] bytes = str.getBytes(UTF8); - int len = bytes.length; - if (len <= 256 * 256 * 256) { - b[off + 2] = (byte) (len); - b[off + 1] = (byte) (len >>> 8); - b[off + 0] = (byte) (len >>> 16); - off += 3; - } else { - throw new SQLException("TODO : too large string value. " + len); - } - System.arraycopy(bytes, 0, b, off, len); - off += len; - } else { - off += 3; - } - break; - } - case Types.DECIMAL: { - BigDecimal decimal = rs.getBigDecimal(columnIndex); - if (decimal != null) { - byte[] bytes = decimal.toString().getBytes(UTF8); - int len = bytes.length; - b[off + 1] = (byte) (len); - b[off + 0] = (byte) (len >>> 8); - off += 2; - System.arraycopy(bytes, 0, b, off, len); - off += len; - } else { - off += 2; - } - break; - } - case Types.DATE: { - break; - } - default: - throw new SQLException("TODO"); - } - - boolean wasNull = rs.wasNull(); - if (!wasNull) { - int nullFlagIndex = i >> 3; - b[nullFlagIndex] |= (1 << i); - } - } - } - } - - public static class Column { - public final int index; - public final int type; - public final String name; - public final int presion; - public final int scale; - - public Column(ResultSetMetaData meta, int i) throws SQLException { - index = i; - type = meta.getColumnType(i); - name = meta.getColumnName(i); - presion = meta.getPrecision(i); - scale = meta.getScale(i); - } - } - - public static class Row { - private byte[] bytes; - - public Row(ResultSet rs, Column[] columns) { - - } - } - - public static void main(String[] args) throws Exception { -// for (int i = 0; i < 100; ++i) { -// int val = (i - 1) / 8; -// int v1 = (i - 1) >> 3; -// System.out.println(val + " - " + i + " - " + v1); -// } - -// System.out.println(256 * 256 * 256); - byte[] bytes = "ALIDFILE".getBytes(); - System.out.println(bytes.length); - } - - static long getLong(byte[] b, int off) { - return ((b[off + 7] & 0xFFL) ) + - ((b[off + 6] & 0xFFL) << 8) + - ((b[off + 5] & 0xFFL) << 16) + - ((b[off + 4] & 0xFFL) << 24) + - ((b[off + 3] & 0xFFL) << 32) + - ((b[off + 2] & 0xFFL) << 40) + - ((b[off + 1] & 0xFFL) << 48) + - (((long) b[off]) << 56); - } - - static void putLong(byte[] b, int off, long val) { - b[off + 7] = (byte) (val ); - b[off + 6] = (byte) (val >>> 8); - b[off + 5] = (byte) (val >>> 16); - b[off + 4] = (byte) (val >>> 24); - b[off + 3] = (byte) (val >>> 32); - b[off + 2] = (byte) (val >>> 40); - b[off + 1] = (byte) (val >>> 48); - b[off ] = (byte) (val >>> 56); - } -} diff --git a/src/main/java/com/alibaba/druid/pool/ha/DataSourceCreator.java b/src/main/java/com/alibaba/druid/pool/ha/DataSourceCreator.java index b73be23af3..d5fc9dd5b7 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/DataSourceCreator.java +++ b/src/main/java/com/alibaba/druid/pool/ha/DataSourceCreator.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.druid.pool.ha; import com.alibaba.druid.pool.DruidDataSource; diff --git a/src/main/java/com/alibaba/druid/pool/ha/HighAvailableDataSource.java b/src/main/java/com/alibaba/druid/pool/ha/HighAvailableDataSource.java index e8ef1ccd51..0946c1bcc8 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/HighAvailableDataSource.java +++ b/src/main/java/com/alibaba/druid/pool/ha/HighAvailableDataSource.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.druid.pool.ha; import com.alibaba.druid.filter.Filter; diff --git a/src/main/java/com/alibaba/druid/pool/ha/selector/DataSourceSelector.java b/src/main/java/com/alibaba/druid/pool/ha/selector/DataSourceSelector.java index af6099dc33..d8497e3f84 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/selector/DataSourceSelector.java +++ b/src/main/java/com/alibaba/druid/pool/ha/selector/DataSourceSelector.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.druid.pool.ha.selector; import javax.sql.DataSource; diff --git a/src/main/java/com/alibaba/druid/pool/ha/selector/DataSourceSelectorFactory.java b/src/main/java/com/alibaba/druid/pool/ha/selector/DataSourceSelectorFactory.java index 469e619731..5ba620400e 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/selector/DataSourceSelectorFactory.java +++ b/src/main/java/com/alibaba/druid/pool/ha/selector/DataSourceSelectorFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.druid.pool.ha.selector; import com.alibaba.druid.pool.ha.HighAvailableDataSource; diff --git a/src/main/java/com/alibaba/druid/pool/ha/selector/NamedDataSourceSelector.java b/src/main/java/com/alibaba/druid/pool/ha/selector/NamedDataSourceSelector.java index 42d1f04c2a..b53e7caa5a 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/selector/NamedDataSourceSelector.java +++ b/src/main/java/com/alibaba/druid/pool/ha/selector/NamedDataSourceSelector.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.druid.pool.ha.selector; import com.alibaba.druid.pool.ha.HighAvailableDataSource; diff --git a/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceRecoverThread.java b/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceRecoverThread.java index b0a6b52a36..0ab3ed67b5 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceRecoverThread.java +++ b/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceRecoverThread.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.druid.pool.ha.selector; import com.alibaba.druid.pool.DruidDataSource; diff --git a/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceSelector.java b/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceSelector.java index 71def65eea..345bff84bc 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceSelector.java +++ b/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceSelector.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.druid.pool.ha.selector; import com.alibaba.druid.pool.DruidDataSource; diff --git a/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceValidateThread.java b/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceValidateThread.java index 6ccc85e44b..a1900a8634 100644 --- a/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceValidateThread.java +++ b/src/main/java/com/alibaba/druid/pool/ha/selector/RandomDataSourceValidateThread.java @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.druid.pool.ha.selector; import com.alibaba.druid.pool.DruidDataSource;