diff --git a/pom.xml b/pom.xml index 6c573b800895638975e8fa95337b19716ea78a51..17494539b6fbf0478e9b46aeaa02cf2b17c8de14 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.teasoft bee - 1.17 + 2.0-SNAPSHOT jar @@ -36,7 +36,7 @@ - + diff --git a/src/main/java/org/teasoft/bee/osql/BeeSql.java b/src/main/java/org/teasoft/bee/osql/BeeSql.java index 7027b6bf146a5e480a8ec5b546367d88f7505ca9..a6d89c80199f57c7ff3136bb48255a8d3267cc77 100644 --- a/src/main/java/org/teasoft/bee/osql/BeeSql.java +++ b/src/main/java/org/teasoft/bee/osql/BeeSql.java @@ -39,17 +39,6 @@ public interface BeeSql { */ public List select(String sql,T entity ); - - /** - * According to SQL query more table data, data type is consistent with entity type. - * @param sql SQL select statement - * @param entity The entity corresponding to table and can not be null. - * @return List can contain more than one entity. - * @since 1.7 - */ - public List moreTableSelect(String sql,T entity ); - - /** * Select some field. * @param sql SQL select statement @@ -75,14 +64,6 @@ public interface BeeSql { */ public List select(String sql); - /** - * Select and transform every record to Map. - * @param sql SQL select statement - * @return List, every element is a Map(transform from record). - * @since 1.9 - */ - public List> selectMapList(String sql); - /** * Select and return json format result. * @param sql SQL select statement @@ -118,4 +99,21 @@ public interface BeeSql { * @return Affected rows. */ public int batch(String []sqls,int batchSize); + + /** + * According to SQL query more table data, data type is consistent with entity type. + * @param sql SQL select statement + * @param entity The entity corresponding to table and can not be null. + * @return List can contain more than one entity. + * @since 1.7 + */ + public List moreTableSelect(String sql,T entity ); + + /** + * Select and transform every record to Map. + * @param sql SQL select statement + * @return List, every element is a Map(transform from record). + * @since 1.9 + */ + public List> selectMapList(String sql); } diff --git a/src/main/java/org/teasoft/bee/osql/BeeVersion.java b/src/main/java/org/teasoft/bee/osql/BeeVersion.java index 6e59ad55e9c3cbddef3dc4fb2c99eb41a0623cfb..00c8228c6a7e65077d42dd7ebc693c53db38ff84 100644 --- a/src/main/java/org/teasoft/bee/osql/BeeVersion.java +++ b/src/main/java/org/teasoft/bee/osql/BeeVersion.java @@ -24,8 +24,8 @@ package org.teasoft.bee.osql; */ public final class BeeVersion { - public static final String version = "1.17"; - public static final String buildId = "1.17.0.99"; + public static final String version = "2.0"; + public static final String buildId = "2.0.0.1"; private BeeVersion() {} diff --git a/src/main/java/org/teasoft/bee/osql/Cache.java b/src/main/java/org/teasoft/bee/osql/Cache.java index 651d7b7f3a85ce133ac09a794eec6fd91978c996..6517463af176573a73bc2c0a0cddca559b290d69 100644 --- a/src/main/java/org/teasoft/bee/osql/Cache.java +++ b/src/main/java/org/teasoft/bee/osql/Cache.java @@ -17,13 +17,15 @@ package org.teasoft.bee.osql; +import java.io.Serializable; + /** * Cache interface. *
Gen the key via sql string, then operate the cache by the key. * @author Kingstar * @since 1.4 */ -public interface Cache { +public interface Cache extends Serializable{ /** * Get the cache result by sql. diff --git a/src/main/java/org/teasoft/bee/osql/Condition.java b/src/main/java/org/teasoft/bee/osql/Condition.java index a254c59cd370d95cc29ad61ef031d5a6804b2ae7..e30817eeb7d8fbf604a9f4fe313b9607021d9da6 100644 --- a/src/main/java/org/teasoft/bee/osql/Condition.java +++ b/src/main/java/org/teasoft/bee/osql/Condition.java @@ -119,13 +119,13 @@ public interface Condition extends ConditionAssistant { public Condition or(); /** - * Add left parentheses. + * Add left parentheses '('. * @return Condition */ public Condition lParentheses(); /** - * Add right parentheses. + * Add right parentheses ')'. * @return Condition */ public Condition rParentheses(); diff --git a/src/main/java/org/teasoft/bee/osql/LowerKey.java b/src/main/java/org/teasoft/bee/osql/LowerKey.java index dcf68f41480780b30a4ce79514393fb8e74c0f25..6ceb12bba3b709633c834df9333089fa22279632 100644 --- a/src/main/java/org/teasoft/bee/osql/LowerKey.java +++ b/src/main/java/org/teasoft/bee/osql/LowerKey.java @@ -65,6 +65,10 @@ public class LowerKey implements SqlKeyWord { private static final String notIn = "not in"; private static final String exists = "exists"; private static final String notExists = "not exists"; + + //2.0 + public static final String union="union"; + public static final String unionAll="union all"; @Override public String select() { @@ -255,5 +259,15 @@ public class LowerKey implements SqlKeyWord { public String notExists() { return notExists; } + + @Override + public String union() { + return union; + } + + @Override + public String unionAll() { + return unionAll; + } } diff --git a/src/main/java/org/teasoft/bee/osql/ObjToSQLRich.java b/src/main/java/org/teasoft/bee/osql/ObjToSQLRich.java index a99a50045db5a5ecde03b4959c1877f5cadfd2c3..2f0bbe449e433244071e4fb9e98ee967ec976ee7 100644 --- a/src/main/java/org/teasoft/bee/osql/ObjToSQLRich.java +++ b/src/main/java/org/teasoft/bee/osql/ObjToSQLRich.java @@ -25,7 +25,7 @@ package org.teasoft.bee.osql; */ public interface ObjToSQLRich extends ObjToSQL { - public String toSelectSQL(T entity,int size); +// public String toSelectSQL(T entity,int size); public String toSelectSQL(T entity,int start,int size); public String toSelectSQL(T entity,String... fields); public String toSelectSQL(T entity,String selectFields,int start,int size); @@ -43,8 +43,8 @@ public interface ObjToSQLRich extends ObjToSQL { public String toInsertSQL(T entity, IncludeType includeType); public String toUpdateSQL(T entity, IncludeType includeType); - public String[] toInsertSQL(T[] entity); - public String[] toInsertSQL(T[] entity,String excludeFields); +// public String[] toInsertSQL(T[] entity); +// public String[] toInsertSQL(T[] entity,String excludeFields); public String[] toInsertSQL(T[] entity,int batchSize,String excludeFields); public String toDeleteByIdSQL(Class c, Integer id); diff --git a/src/main/java/org/teasoft/bee/osql/SqlKeyWord.java b/src/main/java/org/teasoft/bee/osql/SqlKeyWord.java index 308ad4a3bc21ad066c9f375da9bd5fb67543d853..27f9422949aef0c4fc57d9556d7cda6549ac88c4 100644 --- a/src/main/java/org/teasoft/bee/osql/SqlKeyWord.java +++ b/src/main/java/org/teasoft/bee/osql/SqlKeyWord.java @@ -69,4 +69,7 @@ public interface SqlKeyWord { String notIn(); String exists(); String notExists(); + + String union();//2.0 + String unionAll();//2.0 } diff --git a/src/main/java/org/teasoft/bee/osql/UpperKey.java b/src/main/java/org/teasoft/bee/osql/UpperKey.java index 7dff9123947f812b16ccc3ce84ee1f7db912f895..886df14d16e3671254e0caa5a35ec0af3f98f1aa 100644 --- a/src/main/java/org/teasoft/bee/osql/UpperKey.java +++ b/src/main/java/org/teasoft/bee/osql/UpperKey.java @@ -66,6 +66,10 @@ public class UpperKey implements SqlKeyWord { private static final String notIn = "NOT IN"; private static final String EXISTS = "EXISTS"; private static final String notExists = "NOT EXISTS"; + + //2.0 + public static final String union="UNION"; + public static final String unionAll="UNION ALL"; @Override public String select() { @@ -256,5 +260,15 @@ public class UpperKey implements SqlKeyWord { public String notExists() { return notExists; } + + @Override + public String union() { + return union; + } + + @Override + public String unionAll() { + return unionAll; + } } diff --git a/src/main/java/org/teasoft/bee/osql/annotation/Sharding.java b/src/main/java/org/teasoft/bee/osql/annotation/Sharding.java new file mode 100644 index 0000000000000000000000000000000000000000..ccc415bf2b7191d6a45778870438c0dd6106c894 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/annotation/Sharding.java @@ -0,0 +1,99 @@ +/* + * Copyright 2016-2022 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * 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 org.teasoft.bee.osql.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.teasoft.bee.osql.annotation.customizable.DsTabHandler; + +/** + * Sharding. + *
Specify different tables in the same database after calculation; Specify different databases after calculation. + *
When there are multiple tables, cross table is not supported. + *
The dataSource of the sub table is consistent with the main table. + *
Order: 1->2 + *
1. Special (if special is configured, others will not be detected) + *
2. Calculate by algorithm (default if there is no match) + * @author AiTeaSoft + * @since 2.0 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Sharding { + + /** + * appoint dataSource + * @return appointed dataSource + */ + String appointDS() default ""; + + /** + * appoint table name + * @return appointed table name + */ + String appointTab() default ""; + + /** + * 0: operations that can be calculated directly such as remainder; 1: Take part of the string such as date; 2: Custom + * @return value of dsAlgorithm + */ + int dsAlgorithm() default 0; + + /** + * 0: operations that can be calculated directly such as remainder; 1: Take part of the string such as date; 2: Custom + * @return value of tabAlgorithm + */ + int tabAlgorithm() default 0; + + /** + * If dsRule is not set, that is, the default empty value is used, it means that is not to consider the database name. + *
eg: "id%dsSize + * @return value of dsRule + */ + String dsRule() default ""; + + /** + * If dsRule is empty and the value of dsName is not set, the database name is not required. + *
By default, the value calculated by dsRule() will be automatically used as the suffix of dsName. + * @return dsName + */ + String dsName() default ""; + + /** + * get tabRule + * @return tabRule + */ + String tabRule() default ""; + /** + * get tabName. + *
The default is the value calculated by tabRule() as the suffix of tabName. + *
eg:tab${tabRule} + * @return tabName + */ + String tabName() default ""; + + /** + * use for define DsTabHandler. + * @return class of DsTabHandler type + */ + Class handler() default DsTabHandler.class; + +} diff --git a/src/main/java/org/teasoft/bee/osql/annotation/customizable/DsTabHandler.java b/src/main/java/org/teasoft/bee/osql/annotation/customizable/DsTabHandler.java index aef6b3949a7413544451397b951284c051d1b897..ab687dd597e334cab70e70f35e408fc50c6ab623 100644 --- a/src/main/java/org/teasoft/bee/osql/annotation/customizable/DsTabHandler.java +++ b/src/main/java/org/teasoft/bee/osql/annotation/customizable/DsTabHandler.java @@ -17,8 +17,8 @@ package org.teasoft.bee.osql.annotation.customizable; -import org.teasoft.bee.distribution.sharding.DsTabStruct; -import org.teasoft.bee.distribution.sharding.ShardingStruct; +import org.teasoft.bee.sharding.DsTabStruct; +import org.teasoft.bee.sharding.ShardingSimpleStruct; /** * DataSource and Table Handler @@ -27,6 +27,6 @@ import org.teasoft.bee.distribution.sharding.ShardingStruct; */ public interface DsTabHandler { - public DsTabStruct process(ShardingStruct shardingStruct); + public DsTabStruct process(ShardingSimpleStruct shardingSimpleStruct); } diff --git a/src/main/java/org/teasoft/bee/osql/chain/UnionSelect.java b/src/main/java/org/teasoft/bee/osql/chain/UnionSelect.java index 7185db51276dbc0b3af4ed78fccc43cb7a084b33..460e2066187c2bd4a056cffd39462343d3eeb423 100644 --- a/src/main/java/org/teasoft/bee/osql/chain/UnionSelect.java +++ b/src/main/java/org/teasoft/bee/osql/chain/UnionSelect.java @@ -30,4 +30,6 @@ public interface UnionSelect extends ToSql{ public UnionSelect unionAll(Select subSelect1,Select subSelect2); public UnionSelect unionAll(String subSelect1,String subSelect2); + + public UnionSelect unionAll(String[] subSelects); } diff --git a/src/main/java/org/teasoft/bee/osql/exception/ShardingErrorException.java b/src/main/java/org/teasoft/bee/osql/exception/ShardingErrorException.java new file mode 100644 index 0000000000000000000000000000000000000000..0bd8c238542ab500755ff5253143d339ed747894 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/exception/ShardingErrorException.java @@ -0,0 +1,48 @@ +/* + * Copyright 2016-2020 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * 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 org.teasoft.bee.osql.exception; + +import org.teasoft.bee.osql.BeeException; + +/** + * Sharding Error Exception + * @author AiTeaSoft + * @since 2.0 + */ +public class ShardingErrorException extends BeeException { + + static final long serialVersionUID = -875516993124221125L; + + + public ShardingErrorException() { + super(); + } + + public ShardingErrorException(String message) { + super(message); + } + + public ShardingErrorException(String message, Throwable cause) { + super(message, cause); + } + + public ShardingErrorException(Throwable cause) { + super(cause); + } + +} diff --git a/src/main/java/org/teasoft/bee/distribution/sharding/DsTabStruct.java b/src/main/java/org/teasoft/bee/sharding/DsTabStruct.java similarity index 93% rename from src/main/java/org/teasoft/bee/distribution/sharding/DsTabStruct.java rename to src/main/java/org/teasoft/bee/sharding/DsTabStruct.java index 22427a2c7b78170b3e689970c2b7b1b43e3ea158..ada08a5ca13e6f5afdd6250c927e02c90efaa742 100644 --- a/src/main/java/org/teasoft/bee/distribution/sharding/DsTabStruct.java +++ b/src/main/java/org/teasoft/bee/sharding/DsTabStruct.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.teasoft.bee.distribution.sharding; +package org.teasoft.bee.sharding; /** * DataSource and Table Struct. diff --git a/src/main/java/org/teasoft/bee/sharding/ShardingBean.java b/src/main/java/org/teasoft/bee/sharding/ShardingBean.java new file mode 100644 index 0000000000000000000000000000000000000000..bf18c47ccb0b0a9417de15eb41882da309cd64f7 --- /dev/null +++ b/src/main/java/org/teasoft/bee/sharding/ShardingBean.java @@ -0,0 +1,103 @@ +/* + * Copyright 2020-2022 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * 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 org.teasoft.bee.sharding; + +import org.teasoft.bee.sharding.algorithm.Calculate; + +/** + * @author AiTeaSoft + * @since 2.0 + */ +public class ShardingBean extends ShardingSimpleStruct { + + private String dsField; + private String tabField; + + private Class dsAlgorithmClass = Calculate.class; + private Class tabAlgorithmClass = Calculate.class; + private String actualDataNodes; + + private int tabAssignType; // 0: order; 1: polling + + public ShardingBean() {} + + public ShardingBean(String actualDataNodes, String tabField) { + super(); + this.tabField = tabField; + this.actualDataNodes = actualDataNodes; + } + + public ShardingBean(ShardingSimpleStruct shardingSimpleStruct) { + super.setDsAlgorithm(shardingSimpleStruct.getDsAlgorithm()); + super.setDsName(shardingSimpleStruct.getDsName()); + super.setDsRule(shardingSimpleStruct.getDsRule()); + super.setDsShardingValue(shardingSimpleStruct.getDsShardingValue()); + super.setTabAlgorithm(shardingSimpleStruct.getTabAlgorithm()); + super.setTabName(shardingSimpleStruct.getTabName()); + super.setTabRule(shardingSimpleStruct.getTabRule()); + super.setTabShardingValue(shardingSimpleStruct.getTabShardingValue()); + } + + public String getDsField() { + return dsField; + } + + public void setDsField(String dsField) { + this.dsField = dsField; + } + + public String getTabField() { + return tabField; + } + + public void setTabField(String tabField) { + this.tabField = tabField; + } + + public Class getDsAlgorithmClass() { + return dsAlgorithmClass; + } + + public void setDsAlgorithmClass(Class dsAlgorithmClass) { + this.dsAlgorithmClass = dsAlgorithmClass; + } + + public Class getTabAlgorithmClass() { + return tabAlgorithmClass; + } + + public void setTabAlgorithmClass(Class tabAlgorithmClass) { + this.tabAlgorithmClass = tabAlgorithmClass; + } + + public String getActualDataNodes() { + return actualDataNodes; + } + + public void setActualDataNodes(String actualDataNodes) { + this.actualDataNodes = actualDataNodes; + } + + public int getTabAssignType() { + return tabAssignType; + } + + public void setTabAssignType(int tabAssignType) { + this.tabAssignType = tabAssignType; + } +} diff --git a/src/main/java/org/teasoft/bee/sharding/ShardingPageStruct.java b/src/main/java/org/teasoft/bee/sharding/ShardingPageStruct.java new file mode 100644 index 0000000000000000000000000000000000000000..8f39a28c1f651dda6184d57c312eba7f1c181431 --- /dev/null +++ b/src/main/java/org/teasoft/bee/sharding/ShardingPageStruct.java @@ -0,0 +1,73 @@ +/* + * Copyright 2016-2022 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * 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 org.teasoft.bee.sharding; + +/** + * @author AiTeaSoft + * @since 2.0 + */ +public class ShardingPageStruct { + + private String beforeSql; + private String pagingSql; + private int pagingType; // MoreTablesInSameDsUseUnionAll:1, MoreDs:2, FullSelectPage:3 + private Integer start = -1; // -1 do not use + private Integer size; + + public String getBeforeSql() { + return beforeSql; + } + + public void setBeforeSql(String beforeSql) { + this.beforeSql = beforeSql; + } + + public String getPagingSql() { + return pagingSql; + } + + public void setPagingSql(String pagingSql) { + this.pagingSql = pagingSql; + } + + public int getPagingType() { + return pagingType; + } + + // MoreTablesInSameDsUseUnionAll:1, MoreDs:2, FullSelectPage:3 + public void setPagingType(int pagingType) { + this.pagingType = pagingType; + } + + public Integer getStart() { + return start; + } + + public void setStart(Integer start) { + this.start = start; + } + + public Integer getSize() { + return size; + } + + public void setSize(Integer size) { + this.size = size; + } + +} diff --git a/src/main/java/org/teasoft/bee/distribution/sharding/ShardingStruct.java b/src/main/java/org/teasoft/bee/sharding/ShardingSimpleStruct.java similarity index 63% rename from src/main/java/org/teasoft/bee/distribution/sharding/ShardingStruct.java rename to src/main/java/org/teasoft/bee/sharding/ShardingSimpleStruct.java index 9e05a2f9d1e4e93a7e733e2cb24e4bab7d0c45a9..b7dbe153f4ecda0ce7378e2b2ff9e811be264b07 100644 --- a/src/main/java/org/teasoft/bee/distribution/sharding/ShardingStruct.java +++ b/src/main/java/org/teasoft/bee/sharding/ShardingSimpleStruct.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package org.teasoft.bee.distribution.sharding; +package org.teasoft.bee.sharding; /** - * ShardingStruct + * Sharding Simple Struct * @author Kingstar * @since 1.11 */ -public class ShardingStruct { +public class ShardingSimpleStruct { private int dsAlgorithm; private String dsRule; @@ -31,7 +31,8 @@ public class ShardingStruct { private String tabRule; private String tabName; - private Object shardingValue; + private Object dsShardingValue; //2.0 + private Object tabShardingValue;//2.0 /** * get dataSource algorithm @@ -129,20 +130,51 @@ public class ShardingStruct { this.tabName = tabName; } +// /** +// * get sharding value +// * @return sharding value +// */ +// public Object getShardingValue() { +// return shardingValue; +// } +// +// /** +// * set sharding value +// * @param shardingValue sharding value +// */ +// public void setShardingValue(Object shardingValue) { +// this.shardingValue = shardingValue; +// } + + /** + * get dataSource sharding value + * @return dataSource sharding value + */ + public Object getDsShardingValue() { + return dsShardingValue; + } + /** - * get sharding value - * @return sharding value + * set dataSource sharding value + * @param dsShardingValue dataSource sharding value */ - public Object getShardingValue() { - return shardingValue; + public void setDsShardingValue(Object dsShardingValue) { + this.dsShardingValue = dsShardingValue; } /** - * set sharding value - * @param shardingValue sharding value + * get table name Sharding Value + * @return table name Sharding Value */ - public void setShardingValue(Object shardingValue) { - this.shardingValue = shardingValue; + public Object getTabShardingValue() { + return tabShardingValue; } + /** + * set table name Sharding Value + * @param tabShardingValue table name Sharding Value + */ + public void setTabShardingValue(Object tabShardingValue) { + this.tabShardingValue = tabShardingValue; + } } diff --git a/src/main/java/org/teasoft/bee/sharding/ShardingSortStruct.java b/src/main/java/org/teasoft/bee/sharding/ShardingSortStruct.java new file mode 100644 index 0000000000000000000000000000000000000000..2793947f05062e7fb9520d7ef970586e18e49586 --- /dev/null +++ b/src/main/java/org/teasoft/bee/sharding/ShardingSortStruct.java @@ -0,0 +1,127 @@ +/* + * Copyright 2016-2022 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * 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 org.teasoft.bee.sharding; + +import org.teasoft.bee.osql.OrderType; + +/** + * + * the array element 's order corresponds to orderFields[] except index[]. 除了index[]外,其它数组元素的排序顺序与orderFields[]对应. + * + * select id,name,age from student order by age desc,name asc; struct: orderFields[]{age,name} new OrderType[] + * {OrderType.DESC,OrderType.ASC} struct.setType(new String[] { "Integer", "String"}); struct.setIndex(new int[] { 2,1}); + * + * result: c0 c1 c2 id,name,age + * + * @author AiTeaSoft + * @since 2.0 + */ +public class ShardingSortStruct { + + private String orderSql; + private String orderFields[]; + private OrderType orderTypes[]; + +// 以下5个属性用于处理: +// public List select(String sql) + + // 排序顺序与orderFields[]对应. + private String type[]; + private boolean nullFirst[]; + private boolean caseSensitive[]; + // the field value in the select column index + // 字段值在结果中的列索引 + private int index[]; + public volatile boolean regFlag = false; + + public ShardingSortStruct() {} + + public ShardingSortStruct(String orderSql, String[] orderFields, OrderType[] orderTypes) { + super(); + this.orderSql = orderSql; + this.orderFields = orderFields; + this.orderTypes = orderTypes; + } + + public String getOrderSql() { + return orderSql; + } + + public void setOrderSql(String orderSql) { + this.orderSql = orderSql; + } + + public String[] getOrderFields() { + return orderFields; + } + + public void setOrderFields(String[] orderFields) { + this.orderFields = orderFields; + } + + public OrderType[] getOrderTypes() { + return orderTypes; + } + + public void setOrderTypes(OrderType[] orderTypes) { + this.orderTypes = orderTypes; + } + + /** + * 字段值在结果中的列索引 the field value in the select column index + * + * @return + */ + public int[] getIndex() { + return index; + } + + /** + * 字段值在结果中的列索引 the field value in the select column index + * + * @param index + */ + public void setIndex(int[] index) { + this.index = index; + } + + public String[] getType() { + return type; + } + + public void setType(String[] type) { + this.type = type; + } + + public boolean[] getNullFirst() { + return nullFirst; + } + + public void setNullFirst(boolean[] nullFirst) { + this.nullFirst = nullFirst; + } + + public boolean[] getCaseSensitive() { + return caseSensitive; + } + + public void setCaseSensitive(boolean[] caseSensitive) { + this.caseSensitive = caseSensitive; + } + +} diff --git a/src/main/java/org/teasoft/bee/distribution/sharding/algorithm/Calculate.java b/src/main/java/org/teasoft/bee/sharding/algorithm/Calculate.java similarity index 91% rename from src/main/java/org/teasoft/bee/distribution/sharding/algorithm/Calculate.java rename to src/main/java/org/teasoft/bee/sharding/algorithm/Calculate.java index 80f625d0a2d37d607063fdc6e4d6c10f6bbb6d77..08c071b106f70a31e36d0bc62081f223d9fef653 100644 --- a/src/main/java/org/teasoft/bee/distribution/sharding/algorithm/Calculate.java +++ b/src/main/java/org/teasoft/bee/sharding/algorithm/Calculate.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.teasoft.bee.distribution.sharding.algorithm; +package org.teasoft.bee.sharding.algorithm; /** * sharding algorithm Calculate interface. diff --git a/src/main/java/org/teasoft/bee/distribution/sharding/algorithm/CalculateRegistry.java b/src/main/java/org/teasoft/bee/sharding/algorithm/CalculateRegistry.java similarity index 92% rename from src/main/java/org/teasoft/bee/distribution/sharding/algorithm/CalculateRegistry.java rename to src/main/java/org/teasoft/bee/sharding/algorithm/CalculateRegistry.java index c2917b2782856e28ef78a8bd4da82944d31bf0c4..c73828739b4fd92403009a5069515f9aaf49d62a 100644 --- a/src/main/java/org/teasoft/bee/distribution/sharding/algorithm/CalculateRegistry.java +++ b/src/main/java/org/teasoft/bee/sharding/algorithm/CalculateRegistry.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.teasoft.bee.distribution.sharding.algorithm; +package org.teasoft.bee.sharding.algorithm; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/org/teasoft/bee/spi/BeanSort.java b/src/main/java/org/teasoft/bee/spi/BeanSort.java new file mode 100644 index 0000000000000000000000000000000000000000..e0c2b59af1c5832a96762266155fd11cd6a63419 --- /dev/null +++ b/src/main/java/org/teasoft/bee/spi/BeanSort.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016-2022 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * 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 org.teasoft.bee.spi; + +import java.io.Serializable; +import java.util.List; + +import org.teasoft.bee.spi.entity.SortStruct; + +/** + * @author AiTeaSoft + * @since 2.0 + */ +public interface BeanSort extends Serializable{ + + public void sort(List entityList, List sortStructList); +} diff --git a/src/main/java/org/teasoft/bee/spi/JsonTransform.java b/src/main/java/org/teasoft/bee/spi/JsonTransform.java new file mode 100644 index 0000000000000000000000000000000000000000..064cbfc2a189f03ae9dea0a55da3bc452b040986 --- /dev/null +++ b/src/main/java/org/teasoft/bee/spi/JsonTransform.java @@ -0,0 +1,33 @@ +/* + * Copyright 2016-2022 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * 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 org.teasoft.bee.spi; + +import java.io.Serializable; + +/** + * @author AiTeaSoft + * @since 2.0 + */ +public interface JsonTransform extends Serializable{ + + public T toEntity(String json, Class clazz); + + public String toJson(Object obj); + + public T toEntity(String json, Class clazz, Class elementClass); +} diff --git a/src/main/java/org/teasoft/bee/spi/AnnoAdapterBeeDefault.java b/src/main/java/org/teasoft/bee/spi/defaultimpl/AnnoAdapterBeeDefault.java similarity index 90% rename from src/main/java/org/teasoft/bee/spi/AnnoAdapterBeeDefault.java rename to src/main/java/org/teasoft/bee/spi/defaultimpl/AnnoAdapterBeeDefault.java index 0bce364c4811c7057679402381d010533e716c03..40bf8a0a98d6ec54a1d601b56f0a5919536612bf 100644 --- a/src/main/java/org/teasoft/bee/spi/AnnoAdapterBeeDefault.java +++ b/src/main/java/org/teasoft/bee/spi/defaultimpl/AnnoAdapterBeeDefault.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.teasoft.bee.spi; +package org.teasoft.bee.spi.defaultimpl; import java.lang.reflect.Field; @@ -23,6 +23,7 @@ import org.teasoft.bee.osql.annotation.Column; import org.teasoft.bee.osql.annotation.Ignore; import org.teasoft.bee.osql.annotation.PrimaryKey; import org.teasoft.bee.osql.annotation.Table; +import org.teasoft.bee.spi.AnnoAdapter; /** * @author Kingstar @@ -67,8 +68,6 @@ public class AnnoAdapterBeeDefault implements AnnoAdapter { public String getValue(Class clazz) { if (clazz.isAnnotationPresent(Table.class)) { -// Table tab = (Table) clazz.getAnnotation(Table.class); -// return tab.value(); return clazz.getAnnotation(Table.class).value(); } diff --git a/src/main/java/org/teasoft/bee/spi/entity/SortStruct.java b/src/main/java/org/teasoft/bee/spi/entity/SortStruct.java new file mode 100644 index 0000000000000000000000000000000000000000..59cf4333c69b10378db62ab6e15194e973797536 --- /dev/null +++ b/src/main/java/org/teasoft/bee/spi/entity/SortStruct.java @@ -0,0 +1,51 @@ +/* + * Copyright 2016-2022 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * 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 org.teasoft.bee.spi.entity; + +/** + * @author AiTeaSoft + * @since 2.0 + */ +public class SortStruct { + + private String fieldName; + private boolean isReverse; //降序,默认是false; 即默认是升序 + + public SortStruct(String fieldName) { + this.fieldName=fieldName; + } + + public SortStruct(String fieldName, boolean isReverse) { + this.fieldName = fieldName; + this.isReverse = isReverse; + } + + public String getFieldName() { + return fieldName; + } + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } + public boolean isReverse() { + return isReverse; + } + public void setReverse(boolean isReverse) { + this.isReverse = isReverse; + } + +}