├── CNAME ├── sqli-repo ├── src │ └── main │ │ ├── resources │ │ ├── x7.rar │ │ └── favicon.ico │ │ └── java │ │ └── io │ │ └── xream │ │ └── sqli │ │ ├── starter │ │ ├── InitPhaseable.java │ │ ├── EnumSupportListener.java │ │ ├── TemporaryTableParserListener.java │ │ ├── DialectListener.java │ │ └── SqliListener.java │ │ └── repository │ │ ├── dao │ │ ├── TemporaryDao.java │ │ └── Dao.java │ │ ├── exception │ │ ├── UninitializedException.java │ │ └── TooManyResultsException.java │ │ ├── internal │ │ ├── DefaultEnumSupport.java │ │ ├── DefaultNativeRepository.java │ │ └── SafeRefreshBiz.java │ │ ├── core │ │ ├── CreateOrReplaceOptimization.java │ │ └── InOptimization.java │ │ ├── init │ │ ├── SqlInit.java │ │ ├── SqlTemplate.java │ │ └── DefaultTemporaryTableParser.java │ │ └── util │ │ └── SqlParserUtil.java └── pom.xml ├── sqli-builder ├── src │ └── main │ │ ├── resources │ │ └── favicon.ico │ │ └── java │ │ └── io │ │ └── xream │ │ └── sqli │ │ ├── builder │ │ ├── internal │ │ │ ├── JOIN.java │ │ │ ├── CondQ.java │ │ │ ├── PageSqlSupport.java │ │ │ ├── SqlSubsAndValueBinding.java │ │ │ ├── ValueCollector.java │ │ │ ├── PageBuilder.java │ │ │ ├── Distinct.java │ │ │ ├── Q2Sql.java │ │ │ ├── ResultKeyGenerator.java │ │ │ ├── SqlBuilt.java │ │ │ ├── ON.java │ │ │ ├── PageBuilderHelper.java │ │ │ ├── Bb.java │ │ │ ├── DialectSupport.java │ │ │ └── SqlScript.java │ │ ├── FromX.java │ │ ├── Sub.java │ │ ├── Bool.java │ │ ├── Direction.java │ │ ├── On.java │ │ ├── Having.java │ │ ├── SubCond.java │ │ ├── Any.java │ │ ├── Then.java │ │ ├── ThenRefresh.java │ │ ├── Pageable.java │ │ ├── ReduceType.java │ │ ├── KV.java │ │ ├── JoinType.java │ │ ├── FunctionResultKey.java │ │ ├── Reduce.java │ │ ├── Op.java │ │ ├── ResultKeyAlia.java │ │ ├── RemoveRefreshCreate.java │ │ ├── Sort.java │ │ └── In.java │ │ ├── support │ │ ├── EnumSupport.java │ │ └── XSingleSourceSupport.java │ │ ├── api │ │ ├── customizer │ │ │ └── EnumSupportCustomizer.java │ │ └── Routable.java │ │ ├── mapping │ │ ├── Script.java │ │ ├── XHelpful.java │ │ └── Mappable.java │ │ ├── exception │ │ ├── QSyntaxException.java │ │ ├── JsonException.java │ │ ├── ProxyException.java │ │ ├── ParsingException.java │ │ ├── SqlBuildException.java │ │ ├── NotSupportedException.java │ │ ├── UnexpectedEnumValueException.java │ │ ├── QueryException.java │ │ ├── SqliRuntimeException.java │ │ ├── PersistenceException.java │ │ └── ExceptionTranslator.java │ │ ├── page │ │ └── Paged.java │ │ ├── parser │ │ └── ParserListener.java │ │ ├── filter │ │ ├── UnsafeSyntaxFilter.java │ │ └── BaseTypeFilter.java │ │ └── util │ │ ├── SqliStringUtil.java │ │ ├── EnumUtil.java │ │ ├── BeanUtil.java │ │ ├── JsonStyleMapUtil.java │ │ ├── SqliExceptionUtil.java │ │ └── SqliLoggerProxy.java └── pom.xml ├── .gitignore ├── sqli-core ├── pom.xml ├── src │ └── main │ │ └── java │ │ └── io │ │ └── xream │ │ └── sqli │ │ ├── core │ │ ├── Typed.java │ │ ├── RowHandler.java │ │ ├── IdGenerator.java │ │ ├── KeyOne.java │ │ ├── Keys.java │ │ ├── NativeSupport.java │ │ ├── RepositoryManagement.java │ │ ├── ValuePost.java │ │ ├── Repository.java │ │ ├── BaseFinder.java │ │ └── XFinder.java │ │ ├── exception │ │ ├── NoResultUnderProtectionException.java │ │ ├── NotQueryUnderProtectionException.java │ │ └── L2CacheException.java │ │ ├── api │ │ ├── NativeRepository.java │ │ ├── customizer │ │ │ └── DialectCustomizer.java │ │ ├── CacheFilter.java │ │ ├── RepositoryX.java │ │ ├── TemporaryRepository.java │ │ └── BaseRepository.java │ │ ├── spi │ │ ├── IdGeneratorProxy.java │ │ ├── Schema.java │ │ ├── customizer │ │ │ ├── L2CacheStorageCustomizer.java │ │ │ └── L2CacheConsistencyCustomizer.java │ │ ├── L2CacheConsistency.java │ │ ├── L2CacheStorage.java │ │ ├── JdbcHelper.java │ │ └── L2CacheResolver.java │ │ ├── cache │ │ ├── QueryForCache.java │ │ ├── Protection.java │ │ ├── L2CacheFilter.java │ │ ├── CacheKeyBuildable.java │ │ └── internal │ │ │ └── CacheKeyBuilder.java │ │ ├── dialect │ │ ├── DynamicDialectKeyRemovable.java │ │ ├── DynamicDialectHolder.java │ │ └── Dialect.java │ │ └── converter │ │ └── X2Bean.java └── README.md └── sqli-dialect ├── pom.xml └── src └── main └── java └── io └── xream └── sqli └── dialect ├── ImpalaDialect.java └── ClickhouseDialect.java /CNAME: -------------------------------------------------------------------------------- 1 | sqli.xream.io -------------------------------------------------------------------------------- /sqli-repo/src/main/resources/x7.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/x-ream/sqli/HEAD/sqli-repo/src/main/resources/x7.rar -------------------------------------------------------------------------------- /sqli-repo/src/main/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/x-ream/sqli/HEAD/sqli-repo/src/main/resources/favicon.ico -------------------------------------------------------------------------------- /sqli-builder/src/main/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/x-ream/sqli/HEAD/sqli-builder/src/main/resources/favicon.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | */target/ 3 | */classes/ 4 | *.jar 5 | *.class 6 | */application-test.properties 7 | */application-prod.properties 8 | *.iml 9 | .idea/ 10 | .settings/ 11 | -------------------------------------------------------------------------------- /sqli-builder/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | sqli-parent 7 | io.xream.sqli 8 | 2.1.10 9 | 10 | 4.0.0 11 | 12 | sqli-builder 13 | 14 | -------------------------------------------------------------------------------- /sqli-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | sqli-parent 7 | io.xream.sqli 8 | 2.1.10 9 | 10 | 4.0.0 11 | 12 | sqli-core 13 | 14 | 15 | 16 | io.xream.sqli 17 | sqli-builder 18 | ${sqli.version} 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sqli-dialect/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | sqli-parent 7 | io.xream.sqli 8 | 2.1.10 9 | 10 | 4.0.0 11 | sqli-dialect 12 | 13 | 14 | 15 | 16 | io.xream.sqli 17 | sqli-core 18 | ${sqli.version} 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/JOIN.java: -------------------------------------------------------------------------------- 1 | package io.xream.sqli.builder.internal; 2 | 3 | import io.xream.sqli.builder.JoinType; 4 | 5 | /** 6 | * @author sim 7 | */ 8 | public class JOIN { 9 | 10 | private String join; 11 | private String alia; 12 | private ON on; 13 | 14 | public String getJoin() { 15 | return join; 16 | } 17 | 18 | public void setJoin(String join) { 19 | this.join = join; 20 | } 21 | 22 | public String getAlia() { 23 | return alia; 24 | } 25 | 26 | public void setAlia(String alia) { 27 | this.alia = alia; 28 | } 29 | 30 | public ON getOn() { 31 | return on; 32 | } 33 | 34 | public void setOn(ON on) { 35 | this.on = on; 36 | } 37 | 38 | public void setJoin(JoinType joinType) { 39 | this.join = joinType.sql(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sqli-repo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | sqli-parent 7 | io.xream.sqli 8 | 2.1.10 9 | 10 | 4.0.0 11 | 12 | sqli-repo 13 | 14 | 15 | 16 | io.xream.sqli 17 | sqli-builder 18 | ${sqli.version} 19 | 20 | 21 | io.xream.sqli 22 | sqli-core 23 | ${sqli.version} 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/FromX.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | public interface FromX { 22 | 23 | void buildBy(FromBuilder fromBuilder); 24 | } 25 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/Typed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface Typed { 25 | 26 | Class getClzz(); 27 | } 28 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/RowHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface RowHandler { 25 | void handle(T t); 26 | } 27 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/exception/NoResultUnderProtectionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | public class NoResultUnderProtectionException extends Exception{ 22 | } 23 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/exception/NotQueryUnderProtectionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | public class NotQueryUnderProtectionException extends Exception{ 22 | } 23 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Sub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | 22 | /** 23 | * @author Sim 24 | */ 25 | public interface Sub { 26 | void buildBy(QB.X subBuilder); 27 | } 28 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface IdGenerator { 25 | long createId(String clzName); 26 | } 27 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/starter/InitPhaseable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.starter; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface InitPhaseable { 25 | 26 | boolean init(); 27 | } 28 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Bool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface Bool { 25 | boolean isOk(); 26 | } 27 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Direction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | 22 | /** 23 | * @author Sim 24 | */ 25 | public enum Direction { 26 | 27 | ASC, 28 | DESC, 29 | ; 30 | } 31 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/On.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | 22 | /** 23 | * @author Sim 24 | */ 25 | public interface On { 26 | void buildBy(CondBuilder subBuilder); 27 | } 28 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/KeyOne.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface KeyOne { 25 | 26 | Object get(); 27 | Class getClzz(); 28 | } 29 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Having.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | 22 | /** 23 | * @author Sim 24 | */ 25 | public interface Having { 26 | void buildBy(CondBuilder subBuilder); 27 | } 28 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/SubCond.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | 22 | /** 23 | * @author Sim 24 | */ 25 | public interface SubCond { 26 | void buildBy(CondBuilder subBuilder); 27 | } 28 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Any.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface Any { 25 | void build(CondBuilder builder); 26 | } 27 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Then.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface Then { 25 | void build(CondBuilder builder); 26 | } 27 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/ThenRefresh.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface ThenRefresh { 25 | void build(QrB builder); 26 | } 27 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/CondQ.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import java.util.List; 22 | 23 | 24 | /** 25 | * @author Sim 26 | */ 27 | public interface CondQ { 28 | List getBbs(); 29 | } 30 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/api/NativeRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.api; 20 | 21 | import io.xream.sqli.core.NativeSupport; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface NativeRepository extends NativeSupport { 27 | } 28 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/spi/IdGeneratorProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.spi; 20 | 21 | import io.xream.sqli.core.IdGenerator; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface IdGeneratorProxy extends IdGenerator { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/Keys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface Keys { 27 | 28 | List list(); 29 | Class getClzz(); 30 | } 31 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/exception/L2CacheException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | public class L2CacheException extends RuntimeException{ 22 | 23 | public L2CacheException(String message){ 24 | super(message); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/api/customizer/DialectCustomizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.api.customizer; 20 | 21 | import io.xream.sqli.dialect.Dialect; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface DialectCustomizer { 27 | Dialect customize(); 28 | } 29 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/support/EnumSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.support; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface EnumSupport { 25 | 26 | Object serialize(Enum obj); 27 | 28 | Enum deserialize(Class clzz, Object obj); 29 | } 30 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/cache/QueryForCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.cache; 20 | 21 | import io.xream.sqli.builder.In; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public interface QueryForCache { 29 | List in(In in); 30 | } 31 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Pageable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | import io.xream.sqli.builder.internal.PageBuilder; 22 | 23 | /** 24 | * @author sim 25 | */ 26 | public interface Pageable { 27 | 28 | void buildBy(PageBuilder pageBuilder); 29 | } 30 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/PageSqlSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface PageSqlSupport { 25 | StringBuilder buildPageSql(StringBuilder sb, long start, long rows, long last); 26 | } 27 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/spi/Schema.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.spi; 20 | 21 | import io.xream.sqli.parser.Parsed; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface Schema { 27 | 28 | String createTableSqlUnMapped(Parsed parsed, boolean isTemporaryTable); 29 | } 30 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/api/customizer/EnumSupportCustomizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.api.customizer; 20 | 21 | import io.xream.sqli.support.EnumSupport; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface EnumSupportCustomizer { 27 | EnumSupport customize(); 28 | } 29 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/spi/customizer/L2CacheStorageCustomizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.spi.customizer; 20 | 21 | import io.xream.sqli.spi.L2CacheStorage; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface L2CacheStorageCustomizer { 27 | L2CacheStorage customize(); 28 | } 29 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/mapping/Script.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.mapping; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface Script { 25 | String SPACE = " "; 26 | String DOT = "."; 27 | String LEFT_PARENTTHESIS = "("; 28 | String RIGHT_PARENTTHESIS = ")"; 29 | } 30 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/QSyntaxException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class QSyntaxException extends RuntimeException{ 25 | 26 | public QSyntaxException(String message){ 27 | super(message); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/mapping/XHelpful.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.mapping; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface XHelpful extends Mappable { 27 | Map getMapperPropertyMap(); 28 | boolean isResultWithDottedKey(); 29 | } 30 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/spi/customizer/L2CacheConsistencyCustomizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.spi.customizer; 20 | 21 | import io.xream.sqli.spi.L2CacheConsistency; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface L2CacheConsistencyCustomizer { 27 | L2CacheConsistency customize(); 28 | } 29 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/JsonException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class JsonException extends RuntimeException { 25 | 26 | public JsonException(Exception e) { 27 | super(e); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/dao/TemporaryDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.dao; 20 | 21 | import io.xream.sqli.builder.Q; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface TemporaryDao { 27 | boolean findToCreate(Class clzz, Q.X xq); 28 | boolean execute(String sql); 29 | } 30 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/SqlSubsAndValueBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface SqlSubsAndValueBinding { 27 | 28 | List getValueList(); 29 | List getSubList(); 30 | } 31 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/cache/Protection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.cache; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface Protection extends L2CacheFilter{ 25 | String DEFAULT_VALUE = "NULL"; 26 | int DEFAULT_NUM = Integer.MIN_VALUE; 27 | 28 | default void close(){ 29 | remove(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/exception/UninitializedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class UninitializedException extends RuntimeException { 25 | 26 | public UninitializedException(String message){ 27 | super(message); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/dialect/DynamicDialectKeyRemovable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.dialect; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public interface DynamicDialectKeyRemovable { 25 | 26 | ThreadLocal THREAD_DIALECT = new ThreadLocal<>(); 27 | default void removeDialectKey(){ 28 | THREAD_DIALECT.remove(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/ReduceType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public enum ReduceType { 25 | 26 | MAX, 27 | MIN, 28 | SUM, 29 | COUNT, 30 | AVG, 31 | GROUP_CONCAT, 32 | SUM_DISTINCT, 33 | COUNT_DISTINCT, 34 | AVG_DISTINCT, 35 | GROUP_CONCAT_DISTINCT 36 | } 37 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/mapping/Mappable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.mapping; 20 | 21 | import io.xream.sqli.parser.Parsed; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public interface Mappable { 29 | Parsed getParsed(); 30 | Map getAliaMap(); 31 | Map getResultKeyAliaMap(); 32 | } 33 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/page/Paged.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.page; 20 | 21 | 22 | import io.xream.sqli.builder.Sort; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * @author Sim Wang 28 | */ 29 | public interface Paged { 30 | boolean isTotalRowsIgnored(); 31 | int getPage(); 32 | int getRows(); 33 | long getLast(); 34 | List getSortList(); 35 | } 36 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/NativeSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * @author Sim 26 | */ 27 | public interface NativeSupport { 28 | 29 | boolean execute(String sql, Object...objs); 30 | 31 | List> list(String sql, List conditionList); 32 | } 33 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/ProxyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class ProxyException extends RuntimeException { 25 | 26 | public ProxyException(String message){ 27 | super(message); 28 | } 29 | 30 | public ProxyException(Throwable t) { 31 | super(t); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/RepositoryManagement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | import io.xream.sqli.api.BaseRepository; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * @author Sim 28 | */ 29 | public interface RepositoryManagement { 30 | 31 | List REPOSITORY_LIST = new ArrayList(); 32 | } 33 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/ParsingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class ParsingException extends RuntimeException { 25 | 26 | public ParsingException(String message){ 27 | super(message); 28 | } 29 | 30 | public ParsingException(Throwable t) { 31 | super(t); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/SqlBuildException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class SqlBuildException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = 5741842995896266081L; 27 | 28 | public SqlBuildException(String message){ 29 | super(message); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/NotSupportedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class NotSupportedException extends RuntimeException{ 25 | 26 | private static final long serialVersionUID = 5749142995896243581L; 27 | 28 | public NotSupportedException(String message) { 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/ValueCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import io.xream.sqli.mapping.Mapper; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public interface ValueCollector extends Mapper { 29 | 30 | default void add(List valueList, Object value){ 31 | valueList.add(value); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/PageBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | 22 | /** 23 | * @author Sim 24 | */ 25 | 26 | public interface PageBuilder { 27 | 28 | PageBuilder ignoreTotalRows(); 29 | PageBuilder ignoreTotalRows(boolean ignored); 30 | PageBuilder rows(int rows); 31 | PageBuilder page(int page); 32 | PageBuilder last(long last); 33 | } 34 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/cache/L2CacheFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.cache; 20 | 21 | 22 | /** 23 | * @author Sim 24 | */ 25 | public interface L2CacheFilter { 26 | 27 | ThreadLocal threadLocal = new ThreadLocal<>(); 28 | 29 | default Object get() { 30 | return threadLocal.get(); 31 | } 32 | 33 | default void remove() { 34 | threadLocal.remove(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/exception/TooManyResultsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class TooManyResultsException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = 5741842995845366081L; 27 | 28 | public TooManyResultsException(String message){ 29 | super(message); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/starter/EnumSupportListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.starter; 20 | 21 | import io.xream.sqli.support.EnumSupport; 22 | import io.xream.sqli.util.EnumUtil; 23 | 24 | /** 25 | * @author Sim 26 | */ 27 | public class EnumSupportListener extends EnumUtil { 28 | 29 | public static void onStarted(EnumSupport enumSupport) { 30 | EnumUtil.setEnumSupport(enumSupport); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/api/Routable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.api; 20 | 21 | /** 22 | * to find target unit, 23 | * not for db sharding, 24 | * not suggest having Q,qr as the request object, the interface 25 | * of Routeable maybe meaningless, of cource, your request object clzz can implements 26 | * Routeable 27 | * 28 | * @author Sim 29 | */ 30 | public interface Routable { 31 | Object getRouteKey(); 32 | } 33 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/UnexpectedEnumValueException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class UnexpectedEnumValueException extends RuntimeException { 25 | 26 | public UnexpectedEnumValueException(String message){ 27 | super(message); 28 | } 29 | 30 | public UnexpectedEnumValueException(Throwable t) { 31 | super(t); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/QueryException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class QueryException extends RuntimeException{ 25 | 26 | private static final long serialVersionUID = 5749142995896266081L; 27 | 28 | public QueryException(String message){ 29 | super(message); 30 | } 31 | 32 | public QueryException(Throwable t) { 33 | super(t); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/SqliRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class SqliRuntimeException extends RuntimeException{ 25 | 26 | public SqliRuntimeException(String message) { 27 | super(message); 28 | } 29 | 30 | public SqliRuntimeException(Throwable t) { 31 | super(t); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sqli-dialect/src/main/java/io/xream/sqli/dialect/ImpalaDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.dialect; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public final class ImpalaDialect extends MySqlDialect{ 25 | 26 | @Override 27 | public String getKey(){ 28 | return "impala"; 29 | } 30 | 31 | @Override 32 | public String createOrReplaceSql(String sql) { 33 | return sql.replaceFirst("INSERT","UPSERT"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/dialect/DynamicDialectHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.dialect; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public final class DynamicDialectHolder implements DynamicDialectKeyRemovable { 25 | 26 | protected static String getDialectKey(){ 27 | return THREAD_DIALECT.get(); 28 | } 29 | 30 | public static void dialetKey(String dialetKey) { 31 | THREAD_DIALECT.set(dialetKey); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/PersistenceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public class PersistenceException extends RuntimeException{ 25 | 26 | private static final long serialVersionUID = 5749142995896236081L; 27 | 28 | public PersistenceException(String message){ 29 | super(message); 30 | } 31 | 32 | public PersistenceException(Throwable t) { 33 | super(t); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/parser/ParserListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.parser; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | final public class ParserListener { 25 | 26 | private static ParserListener instance; 27 | 28 | private ParserListener(){} 29 | 30 | public static void onStarted(){ 31 | if (instance == null) { 32 | instance = new ParserListener(); 33 | Parser.onStarted(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sqli-core/README.md: -------------------------------------------------------------------------------- 1 | # sqli 2 | [http://sqli.xream.io](http://sqli.xream.io) 3 | 4 | [![license](https://img.shields.io/github/license/x-ream/sqli.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 5 | [![maven](https://img.shields.io/maven-central/v/io.xream.sqli/sqli-parent.svg)](https://search.maven.org/search?q=io.xream) 6 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/8e414bcc7a6944529c5a35b27b2d5e37)](https://www.codacy.com/gh/x-ream/sqli?utm_source=github.com&utm_medium=referral&utm_content=x-ream/sqli&utm_campaign=Badge_Grade) 7 | [![Gitter](https://badges.gitter.im/x-ream/x-ream.svg)](https://gitter.im/x-ream/community) 8 | 9 | [WIKI](https://github.com/x-ream/sqli/wiki) 10 | 11 | sqli/sqli-builder 12 | sqli/sqli-core 13 | sqli/sqli-dialect 14 | sqli/sqli-repo 15 | 16 | ## sqli/sqli-core 17 | 18 | ### API 19 | BaseRepository 20 | RepositoryX 21 | TemporaryRepository 22 | CacheFilter 23 | 24 | ### SPI 25 | JdbcHelper //io.xream.x7/x7/x7-repo/x7-jdbc-template-plus 26 | IdGenerator //io.xream.x7/x7/x7-repo/x7-id-generator 27 | L2CacheStorage //io.xream.x7/x7/x7-repo/x7-redis-integration 28 | L2CacheResolver //io.xream.sqli/sqli/sqli-core 29 | L2CacheConsistency //Optional SPI, do it by deleyed queue, or kafka 30 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/cache/CacheKeyBuildable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.cache; 20 | 21 | import io.xream.sqli.builder.Q; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface CacheKeyBuildable { 27 | 28 | default String buildCacheKey(Q q){ 29 | return buildCacheKey(q,false); 30 | } 31 | 32 | default String buildCacheKeyOfTotalRows(Q q){ 33 | return buildCacheKey(q,true); 34 | } 35 | 36 | String buildCacheKey(Q q, boolean isOfTotalRows); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultEnumSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.internal; 20 | 21 | import io.xream.sqli.support.EnumSupport; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public class DefaultEnumSupport implements EnumSupport { 27 | @Override 28 | public Object serialize(Enum obj) { 29 | return obj.name(); 30 | } 31 | 32 | @Override 33 | public Enum deserialize(Class clzz, Object obj) { 34 | return Enum.valueOf(clzz, obj.toString()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/spi/L2CacheConsistency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.spi; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | * Optional SPI
25 | * Suggest send message to MQ to refresh again
26 | * @author Sim 27 | */ 28 | public interface L2CacheConsistency { 29 | 30 | /** 31 | * set(key,timeNs), get nsString async at kafka listener 32 | * @param key 33 | */ 34 | void markForRefresh(final String key); 35 | void remove(final String key); 36 | void remove(final Set keySet); 37 | } 38 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/api/CacheFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.api; 20 | 21 | 22 | import io.xream.sqli.cache.L2CacheFilter; 23 | import io.xream.sqli.util.SqliStringUtil; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public final class CacheFilter implements L2CacheFilter { 29 | 30 | /** 31 | * partialKey maybe is userId 32 | * @param partialKey 33 | */ 34 | public static void filter(Object partialKey) { 35 | if (SqliStringUtil.isNullOrEmpty(partialKey)) 36 | return; 37 | threadLocal.set(partialKey); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/spi/L2CacheStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.spi; 20 | 21 | import java.util.List; 22 | import java.util.Set; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public interface L2CacheStorage { 29 | boolean set(String key, String time); 30 | 31 | boolean delete(String key); 32 | 33 | Set keys(String key); 34 | 35 | String get(String nsKey); 36 | 37 | boolean set(String key, String toJson, int validSecond, TimeUnit timeUnit); 38 | 39 | List multiGet(List keyArr); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/filter/UnsafeSyntaxFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.filter; 20 | 21 | import io.xream.sqli.mapping.Script; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface UnsafeSyntaxFilter { 27 | 28 | default String filter(String sql) { 29 | return sql.replace("'", "''"); 30 | } 31 | 32 | default String noSpace(String sql) { 33 | if (sql.contains(Script.SPACE)) 34 | throw new IllegalArgumentException("While building ORDER BY, find the property contains SPACE, after normalized: " + sql ); 35 | return sql; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/starter/TemporaryTableParserListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.starter; 20 | 21 | import io.xream.sqli.api.TemporaryRepository; 22 | import io.xream.sqli.repository.internal.DefaultTemporaryRepository; 23 | import io.xream.sqli.spi.Schema; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public class TemporaryTableParserListener { 29 | 30 | public static void onStarted(TemporaryRepository temporaryRepository, Schema schema){ 31 | DefaultTemporaryRepository dt = (DefaultTemporaryRepository) temporaryRepository; 32 | dt.setSchema(schema); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/Distinct.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public final class Distinct { 29 | 30 | private List list = new ArrayList<>(); 31 | 32 | public List getList(){ 33 | return list; 34 | } 35 | 36 | public void add(String resultKey){ 37 | this.list.add(resultKey); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "Distinct{" + 43 | "list=" + list + 44 | '}'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/Q2Sql.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import io.xream.sqli.builder.Q; 22 | import io.xream.sqli.builder.Qr; 23 | import io.xream.sqli.mapping.Mappable; 24 | import io.xream.sqli.parser.Parsed; 25 | 26 | import java.util.List; 27 | 28 | 29 | /** 30 | * @author Sim 31 | */ 32 | public interface Q2Sql extends CondQToSql, CondQToSql.Filter, CondQToSql.Pre { 33 | 34 | String toCondSql(CondQ condQ, List valueList, Mappable mappable) ; 35 | 36 | void toSql(boolean isSub, Q q, SqlBuilt sqlBuilt, SqlSubsAndValueBinding subsAndValueBinding) ; 37 | 38 | String toSql(Parsed parsed, Qr Qr, DialectSupport dialectSupport); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/util/SqliStringUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.util; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public final class SqliStringUtil { 25 | 26 | private SqliStringUtil(){} 27 | 28 | public static boolean isNotNull(String str){ 29 | return !isNullOrEmpty(str); 30 | } 31 | 32 | public static boolean isNullOrEmpty(String str){ 33 | return str == null || str.equals("") || str.trim().equals(""); 34 | } 35 | 36 | public static boolean isNullOrEmpty(Object obj) { 37 | 38 | if (obj == null) 39 | return true; 40 | Class clz = obj.getClass(); 41 | if (clz == String.class) { 42 | return isNullOrEmpty(obj.toString()); 43 | } 44 | return false; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/core/CreateOrReplaceOptimization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.core; 20 | 21 | import io.xream.sqli.parser.Parsed; 22 | import io.xream.sqli.util.ParserUtil; 23 | import io.xream.sqli.util.SqliStringUtil; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public interface CreateOrReplaceOptimization { 29 | 30 | static Object tryToGetId(Object obj, Parsed parsed){ 31 | Object id = ParserUtil.tryToGetId(obj, parsed); 32 | String idStr = String.valueOf(id); 33 | if (SqliStringUtil.isNullOrEmpty(idStr) || idStr.equals("0")) 34 | throw new IllegalArgumentException("createOrReplace(obj), obj keyOne = " + id); 35 | return id; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/KV.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public final class KV { 25 | 26 | public String k; 27 | public Object v; 28 | public KV(){} 29 | private KV(String k, Object v){ 30 | this.k = k; 31 | this.v = v; 32 | } 33 | 34 | public static KV of(String k, Object v) { 35 | return new KV(k,v); 36 | } 37 | 38 | public String getK() { 39 | return k; 40 | } 41 | public void setK(String k) { 42 | this.k = k; 43 | } 44 | public Object getV() { 45 | return v; 46 | } 47 | public void setV(Object v) { 48 | this.v = v; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "KV{" + 54 | "k='" + k + '\'' + 55 | ", v=" + v + 56 | '}'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/init/SqlInit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.init; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public interface SqlInit extends SqlTemplate{ 27 | 28 | String getLoadSql(Class clz); 29 | 30 | String getCreateSql(Class clz); 31 | 32 | String getOneSql(Class clz); 33 | 34 | String getRemoveSql(Class clz); 35 | 36 | String getRemoveInSql(Class clz); 37 | 38 | List getCreatEle(Class clz); 39 | 40 | default void tryToParse(Class clz) { 41 | 42 | getRemoveSql(clz); 43 | getRemoveInSql(clz); 44 | getOneSql(clz); 45 | getLoadSql(clz); 46 | getCreateSql(clz); 47 | getCreatEle(clz); 48 | 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/ResultKeyGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import io.xream.sqli.builder.Q; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public interface ResultKeyGenerator { 29 | 30 | default String generate(String mapper, Q.X qx) { 31 | 32 | if (mapper.contains(".") && (!mapper.contains(SqlScript.SPACE) || !mapper.contains(SqlScript.AS) )) { 33 | Map resultKeyAliaMap = qx.getResultKeyAliaMap(); 34 | String alian = "c" + resultKeyAliaMap.size(); 35 | resultKeyAliaMap.put(alian, mapper); 36 | String target = mapper + SqlScript.AS + alian; 37 | return target; 38 | } 39 | return mapper; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/SqlBuilt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public final class SqlBuilt { 25 | 26 | private String countSql; 27 | private StringBuilder sb; 28 | private boolean isWith; 29 | 30 | public String getCountSql() { 31 | return countSql; 32 | } 33 | 34 | public void setCountSql(String countSql) { 35 | this.countSql = countSql; 36 | } 37 | 38 | public StringBuilder getSb() { 39 | return sb; 40 | } 41 | 42 | public void setSb(StringBuilder sb) { 43 | this.sb = sb; 44 | } 45 | 46 | public boolean isWith() { 47 | return isWith; 48 | } 49 | 50 | public void setWith(boolean with) { 51 | isWith = with; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/api/RepositoryX.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.api; 20 | 21 | import io.xream.sqli.builder.Q; 22 | import io.xream.sqli.core.RowHandler; 23 | import io.xream.sqli.page.Page; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | /** 29 | * X API 30 | * @author Sim 31 | */ 32 | public interface RepositoryX { 33 | 34 | Page> findX(Q.X xq); 35 | 36 | List> listX(Q.X xq); 37 | 38 | List listPlainValue(Class clzz, Q.X xq); 39 | 40 | K getPlainValue(Class clzz, Q.X xq); 41 | /** 42 | * like stream, fetchSize=50, the api not fast, to avoid OOM when scheduling 43 | * @param xq 44 | * @param handler 45 | */ 46 | void findToHandleX(Q.X xq, RowHandler> handler); 47 | } 48 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/support/XSingleSourceSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.support; 20 | 21 | import io.xream.sqli.builder.Q; 22 | import io.xream.sqli.builder.internal.Froms; 23 | import io.xream.sqli.parser.Parsed; 24 | import io.xream.sqli.parser.Parser; 25 | 26 | /** 27 | * @author Sim 28 | */ 29 | public interface XSingleSourceSupport { 30 | 31 | default void supportSingleSource(Q.X xq) { 32 | if (xq.getSourceScripts().size() == 1 && xq.getParsed() == null) { 33 | Froms froms = xq.getSourceScripts().get(0); 34 | String source = froms.getSource(); 35 | if (source != null) { 36 | Parsed parsed = Parser.get(source); 37 | xq.setParsed(parsed); 38 | xq.setClzz(parsed.getClzz()); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/JoinType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public enum JoinType { 27 | NON_JOIN, 28 | JOIN, 29 | INNER, 30 | OUTER, 31 | LEFT, 32 | RIGHT, 33 | COMMA; 34 | 35 | // private String sql; 36 | // private JoinType(String sql){ //UNWORKABLE IN JAVA 17+ 37 | // this.sql = sql; 38 | // } 39 | 40 | private static Map config = Map.of( 41 | NON_JOIN,",", 42 | JOIN,"JOIN", 43 | INNER,"INNER JOIN", 44 | OUTER,"OUTER JOIN", 45 | LEFT,"LEFT JOIN", 46 | RIGHT,"RIGHT JOIN", 47 | COMMA,"," 48 | ); 49 | 50 | public String sql(){ 51 | return config.get(this); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sqli-dialect/src/main/java/io/xream/sqli/dialect/ClickhouseDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.dialect; 20 | 21 | import io.xream.sqli.builder.internal.SqlScript; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public final class ClickhouseDialect extends MySqlDialect{ 27 | 28 | @Override 29 | public String getKey(){ 30 | return "clickhouse"; 31 | } 32 | 33 | @Override 34 | public String getAlterTableUpdate() { 35 | return SqlScript.ALTER_TABLE; 36 | } 37 | 38 | @Override 39 | public String getAlterTableDelete() { 40 | return SqlScript.ALTER_TABLE ; 41 | } 42 | 43 | @Override 44 | public String getCommandUpdate() { 45 | return SqlScript.UPDATE; 46 | } 47 | 48 | @Override 49 | public String getCommandDelete() { 50 | return SqlScript.DELETE; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/starter/DialectListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.starter; 20 | 21 | import io.xream.sqli.api.customizer.DialectCustomizer; 22 | import io.xream.sqli.dialect.Dialect; 23 | import io.xream.sqli.dialect.DynamicDialect; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public class DialectListener { 29 | 30 | protected static void customizeOnStarted(Dialect dialect, DialectCustomizer dialectCustomizer) { 31 | if (dialectCustomizer == null) 32 | return; 33 | Dialect customedDialect = dialectCustomizer.customize(); 34 | if (customedDialect == null) 35 | return; 36 | if (dialect instanceof DynamicDialect) { 37 | DynamicDialect dynamicDialect = (DynamicDialect) dialect; 38 | dynamicDialect.setDefaultDialect(customedDialect); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/api/TemporaryRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.api; 20 | 21 | import io.xream.sqli.builder.Q; 22 | import io.xream.sqli.spi.Schema; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * How to update with TemporaryRepository? 28 | * suggest: 29 | * .findToHandle(Q.X, map -> { 30 | * 31 | * refresh( 32 | * qr.build().... 33 | * ) 34 | * 35 | * }); 36 | * 37 | * @author Sim 38 | */ 39 | public interface TemporaryRepository { 40 | 41 | boolean create(Object obj); 42 | boolean createBatch(List objList); 43 | boolean findToCreate(Class clzz, Q.X xq); 44 | 45 | boolean createRepository(Class clzz); 46 | boolean dropRepository(Class clzz); 47 | 48 | interface Parser { 49 | void setSchema(Schema schema); 50 | String parseAndGetSql(Class clzz); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/ValuePost.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | import io.xream.sqli.util.EnumUtil; 22 | 23 | import java.util.Objects; 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public interface ValuePost { 29 | default Object filter(Object object, MoreFilter moreFilter) { 30 | Object o = null; 31 | if (object instanceof String) { 32 | String str = (String) object; 33 | o = str.replace("<", "<").replace(">", ">"); 34 | }else if (Objects.nonNull(object) && EnumUtil.isEnum(object.getClass())){ 35 | o = EnumUtil.serialize((Enum) object); 36 | }else{ 37 | o = object; 38 | } 39 | 40 | if (moreFilter == null) 41 | return o; 42 | 43 | return moreFilter.filter(o); 44 | } 45 | 46 | interface MoreFilter{ 47 | Object filter(Object object); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/ON.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import io.xream.sqli.builder.CondBuilder; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * @author Sim 28 | */ 29 | public final class ON { 30 | 31 | private List bbs = new ArrayList<>(); 32 | private CondBuilder builder; 33 | private String orUsingKey; 34 | 35 | public List getBbs() { 36 | return bbs; 37 | } 38 | 39 | public void setBbs(List bbs) { 40 | this.bbs = bbs; 41 | } 42 | 43 | public CondBuilder getBuilder() { 44 | return builder; 45 | } 46 | 47 | public void setBuilder(CondBuilder builder) { 48 | this.builder = builder; 49 | } 50 | 51 | public String getOrUsingKey() { 52 | return orUsingKey; 53 | } 54 | 55 | public void setOrUsingKey(String orUsingKey) { 56 | this.orUsingKey = orUsingKey; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/spi/JdbcHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.spi; 20 | 21 | import io.xream.sqli.core.BaseFinder; 22 | import io.xream.sqli.core.XFinder; 23 | import io.xream.sqli.dialect.Dialect; 24 | 25 | import java.util.Collection; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Sim 30 | */ 31 | public interface JdbcHelper extends BaseFinder, XFinder { 32 | 33 | boolean createBatch(Class clzz, String sql, BatchObjectValues batchObjectValues, int batchSize, Dialect dialect); 34 | 35 | boolean create(boolean isAutoIncreaseId, String sql, List valueList); 36 | 37 | boolean createOrReplace(String sql, List valueList); 38 | 39 | boolean refresh(String sql, Object[] valueList); 40 | 41 | boolean remove(String sql, Object id); 42 | 43 | boolean execute(String sql,Object...objs); 44 | 45 | List queryForPlainValueList(Class clzz, String sql, Collection valueList, Dialect dialect); 46 | 47 | interface BatchObjectValues { 48 | List> valuesList(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/FunctionResultKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public final class FunctionResultKey { 25 | 26 | private String script; 27 | private String alia; 28 | private Object[] values; 29 | 30 | public String getScript() { 31 | return script; 32 | } 33 | 34 | public void setScript(String script) { 35 | this.script = script; 36 | } 37 | 38 | public String getAlia() { 39 | return alia; 40 | } 41 | 42 | public void setAlia(String alia) { 43 | this.alia = alia; 44 | } 45 | 46 | public Object[] getValues() { 47 | return values; 48 | } 49 | 50 | public void setValues(Object[] values) { 51 | this.values = values; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "FunctionResultKey{" + 57 | "script='" + script + '\'' + 58 | ", alia='" + alia + '\'' + 59 | ", values=" + values + 60 | '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Reduce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | 22 | import io.xream.sqli.builder.internal.Bb; 23 | 24 | /** 25 | * @author Sim 26 | */ 27 | public final class Reduce { 28 | private ReduceType type; 29 | private String property; 30 | private Bb having; 31 | 32 | public ReduceType getType() { 33 | return type; 34 | } 35 | 36 | public void setType(ReduceType type) { 37 | this.type = type; 38 | } 39 | 40 | public String getProperty() { 41 | return property; 42 | } 43 | 44 | public void setProperty(String property) { 45 | this.property = property; 46 | } 47 | 48 | public Bb getHaving() { 49 | return having; 50 | } 51 | 52 | public void setHaving(Bb having) { 53 | this.having = having; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "Reduce{" + 59 | "type=" + type + 60 | ", property='" + property + '\'' + 61 | ", having=" + having + 62 | '}'; 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Op.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | /** 22 | * @author Sim 23 | */ 24 | public enum Op { 25 | EQ ("="), 26 | NE( "<>"), 27 | GT(">"), 28 | LT ("<"), 29 | GTE (">="), 30 | LTE ("<="), 31 | LIKE("LIKE"), 32 | NOT_LIKE("NOT LIKE"), 33 | IN("IN"), 34 | NOT_IN("NOT IN"), 35 | IS_NOT_NULL("IS NOT NULL"), 36 | IS_NULL("IS NULL"), 37 | X(""), 38 | LIMIT("LIMIT"), 39 | OFFSET("OFFSET"), 40 | SUB("SUB"), 41 | 42 | NONE(""), 43 | AND(" AND "), 44 | OR(" OR "), 45 | ORDER_BY(" ORDER BY "), 46 | GROUP_BY(" GROUP BY "), 47 | HAVING(" HAVING "), 48 | WHERE(" WHERE "), 49 | X_AGGR(""); 50 | 51 | private String op; 52 | Op(String str){ 53 | op = str; 54 | } 55 | public String sql(){ 56 | return op; 57 | } 58 | 59 | public static Op valueOfSql(String str) { 60 | String t = str.trim(); 61 | for (Op op : values()) { 62 | if (op.sql().equals(str)) 63 | return op; 64 | } 65 | return NONE; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/init/SqlTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.init; 20 | 21 | import io.xream.sqli.dialect.Dialect; 22 | 23 | import java.util.HashMap; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | /** 28 | * @author Sim 29 | */ 30 | public interface SqlTemplate { 31 | 32 | Map> SQLS_MAP = new HashMap<>(); 33 | Map> CREATE_ELE_MAP = new HashMap<>(); 34 | 35 | 36 | String CREATE = "CREATE"; 37 | String REMOVE = "REMOVE"; 38 | String REMOVE_IN = "REMOVE_IN"; 39 | String LOAD = "LOAD"; 40 | String GET_ONE = "GET_ONE"; 41 | 42 | Dialect getDialect(); 43 | void setDialect(Dialect dialect); 44 | 45 | default Map getSqlMap(Class clzz) { 46 | Map sqlMap = SQLS_MAP.get(clzz); 47 | if (sqlMap == null) { 48 | sqlMap = new HashMap<>(); 49 | SQLS_MAP.put(clzz, sqlMap); 50 | } 51 | return sqlMap; 52 | } 53 | 54 | default String getSql(Class clzz, String type) { 55 | return getSqlMap(clzz).get(type); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/Repository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | import io.xream.sqli.builder.Q; 22 | import io.xream.sqli.builder.Qr; 23 | import io.xream.sqli.cache.QueryForCache; 24 | import io.xream.sqli.page.Page; 25 | 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | 30 | /** 31 | * 32 | * @author Sim 33 | * 34 | */ 35 | public interface Repository extends QueryForCache { 36 | 37 | void refreshCache(Class clz); 38 | 39 | boolean create(Object obj); 40 | boolean createOrReplace(Object obj); 41 | boolean createOrReplaceBatch(Class clz, List> propValueList); 42 | 43 | boolean refresh(Qr qr); 44 | 45 | boolean remove(KeyOne keyOne); 46 | 47 | boolean removeIn(Keys keys); 48 | 49 | T get(KeyOne keyOne); 50 | 51 | Page find(Q q); 52 | 53 | Page> find(Q.X xq); 54 | 55 | List> list(Q.X xq); 56 | 57 | List listPlainValue(Class clzz, Q.X xq); 58 | 59 | List list(Q q); 60 | 61 | boolean createBatch(List objList); 62 | 63 | T getOne(Q q); 64 | 65 | boolean refresh(T t); 66 | 67 | void findToHandle(Q q, RowHandler handler); 68 | 69 | void findToHandle(Q.X xq, RowHandler> handler); 70 | 71 | boolean exists(Q q); 72 | 73 | } -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/BaseFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | import io.xream.sqli.converter.DataObjectConverter; 22 | import io.xream.sqli.dialect.Dialect; 23 | import io.xream.sqli.parser.BeanElement; 24 | import io.xream.sqli.parser.Parsed; 25 | 26 | import java.util.Collection; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * @author Sim 32 | */ 33 | public interface BaseFinder { 34 | 35 | List queryForList(String sql, Collection list, Parsed parsed, Dialect dialect); 36 | 37 | default List toObjectList(DataObjectQuery dataObjectQuery) { 38 | return dataObjectQuery.query(DataObjectQuery.FIXED_ROW_MAPPER); 39 | } 40 | 41 | default void toObject(T t, Map dataMap, List list, Dialect dialect) throws Exception{ 42 | DataObjectConverter.initObj(t,dataMap,list,dialect); 43 | } 44 | 45 | interface DataObjectQuery { 46 | FixedRowMapper FIXED_ROW_MAPPER = (t, dataMap, beanElementList, dialect) -> DataObjectConverter.initObj(t,dataMap,beanElementList,dialect); 47 | List query(FixedRowMapper fixedObjectBuilder) ; 48 | } 49 | 50 | interface FixedRowMapper { 51 | void mapRow(T t, Map dataMap, List beanElementList, Dialect dialect) throws Exception ; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/util/EnumUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.util; 20 | 21 | import io.xream.sqli.support.EnumSupport; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public class EnumUtil { 27 | 28 | private static EnumSupport enumSupport; 29 | protected static void setEnumSupport(EnumSupport es) { 30 | enumSupport = es; 31 | } 32 | 33 | public static boolean isEnum(Class clzz) { 34 | Class superClzz = clzz.getSuperclass(); 35 | return clzz.isEnum() || (superClzz != null && superClzz.isEnum()); 36 | } 37 | 38 | public static Object serialize(Enum enumObj) { 39 | return enumSupport.serialize(enumObj); 40 | } 41 | 42 | public static Enum deserialize(Class clzz, Object enumNameOrCode) { 43 | return enumSupport.deserialize(clzz, enumNameOrCode); 44 | } 45 | 46 | public static Object filterInComplexScriptSimply(Object maybeEnum) { 47 | if (maybeEnum == null) 48 | return null; 49 | if (isEnum(maybeEnum.getClass())) { 50 | return serialize((Enum) maybeEnum); 51 | } 52 | return maybeEnum; 53 | } 54 | 55 | public static Object serialize(Class clzz, Object strOrEnum) { 56 | if (strOrEnum instanceof String){ 57 | strOrEnum = deserialize(clzz,strOrEnum); 58 | } 59 | return serialize((Enum)strOrEnum); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/util/BeanUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.util; 20 | 21 | 22 | /** 23 | * @author Sim 24 | */ 25 | public final class BeanUtil { 26 | 27 | protected BeanUtil(){} 28 | 29 | public static String getSetter(String property) { 30 | if (property.startsWith("is")) { 31 | String rest = property.substring(2); 32 | return "set" + rest; 33 | } 34 | 35 | String a = property.substring(0, 1); 36 | String rest = property.substring(1); 37 | return "set" + a.toUpperCase() + rest; 38 | } 39 | 40 | public static String getByFirstLower(String str) { 41 | if (SqliStringUtil.isNullOrEmpty(str)) 42 | return str; 43 | 44 | String a = str.substring(0, 1); 45 | String rest = str.substring(1); 46 | String result = a.toLowerCase() + rest; 47 | return result; 48 | 49 | } 50 | 51 | public static String getProperty(String methodName) { 52 | if (methodName.startsWith("is")) 53 | return methodName; 54 | String str = methodName.substring(3); 55 | return getByFirstLower(str); 56 | } 57 | 58 | public static String getBooleanPropertyNoIs(String property) { 59 | if (property.startsWith("is")) { 60 | String str = property.substring(2); 61 | return getByFirstLower(str); 62 | } 63 | return property; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/exception/ExceptionTranslator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.exception; 20 | 21 | import io.xream.sqli.parser.Parser; 22 | import io.xream.sqli.util.SqliExceptionUtil; 23 | import org.slf4j.Logger; 24 | 25 | import java.sql.SQLIntegrityConstraintViolationException; 26 | 27 | /** 28 | * @author Sim 29 | */ 30 | public class ExceptionTranslator { 31 | 32 | private ExceptionTranslator(){} 33 | 34 | public static SqliRuntimeException onRollback(Class clzz, Exception e, Logger logger) { 35 | Throwable t = SqliExceptionUtil.unwrapThrowable(e); 36 | logger.error(SqliExceptionUtil.getMessage(t)); 37 | if ( t instanceof SQLIntegrityConstraintViolationException){ 38 | String msg = t.getMessage(); 39 | if (msg.contains("cannot be null")) { 40 | String prefix = (clzz == null ? "" : ("Table of "+ Parser.get(clzz).getTableName())); 41 | throw new SqliRuntimeException(prefix+", " + msg); 42 | } 43 | } 44 | if (t instanceof RuntimeException) 45 | throw (RuntimeException)t; 46 | return new SqliRuntimeException(t); 47 | } 48 | 49 | public static QueryException onQuery(Exception e, Logger logger) { 50 | Throwable t = SqliExceptionUtil.unwrapThrowable(e); 51 | logger.error(SqliExceptionUtil.getMessage(t)); 52 | if (t instanceof RuntimeException) 53 | throw (RuntimeException)t; 54 | return new QueryException(e); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/spi/L2CacheResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.spi; 20 | 21 | import io.xream.sqli.builder.Q; 22 | import io.xream.sqli.cache.Protection; 23 | import io.xream.sqli.cache.QueryForCache; 24 | import io.xream.sqli.page.Page; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * 30 | * 缓存
31 | * @author Sim 32 | * 33 | */ 34 | public interface L2CacheResolver extends Protection { 35 | 36 | void setL2CacheConsistency(L2CacheConsistency l2CacheConsistency); 37 | void setCacheStorage(L2CacheStorage cacheStorage); 38 | 39 | boolean isEnabled(); 40 | /** 41 | * 标记缓存要更新 42 | * @param clz 43 | * @return nanuTime_String 44 | */ 45 | @SuppressWarnings("rawtypes") 46 | String markForRefresh(Class clz); 47 | 48 | boolean refresh(Class clz, String key); 49 | boolean refresh(Class clz); 50 | 51 | List listUnderProtection(Class clz, Object conditionObj, QueryForCache queryForCache, QueryFromDb> queryList); 52 | List listUnderProtection(Q q, QueryForCache queryForCache, QueryFromDb> queryList); 53 | T getUnderProtection(Class clz, Object conditonObj, QueryFromDb queryObject); 54 | T getOneUnderProtection(Class clz, Object conditonObj, QueryFromDb queryObject); 55 | Page findUnderProtection(Q q, QueryForCache queryForCache, QueryFromDb> queryPage, QueryFromDb> queryList); 56 | 57 | default Object getFilterFactor(){ 58 | return get(); 59 | } 60 | 61 | interface QueryFromDb { 62 | V query(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/util/JsonStyleMapUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.util; 20 | 21 | import java.util.*; 22 | import java.util.Map.Entry; 23 | 24 | /** 25 | * 26 | * Bean <--> Map 27 | * @author Sim 28 | * 29 | */ 30 | public final class JsonStyleMapUtil { 31 | 32 | private JsonStyleMapUtil(){} 33 | 34 | public static Map toJsonableMap(Map stringKeyMap){ 35 | Map jsonableMap = new HashMap(); 36 | for (Entry es : stringKeyMap.entrySet()){ 37 | String stringKey = es.getKey(); 38 | if (stringKey.contains(".")){ 39 | String[] arr = stringKey.split("\\."); 40 | String jsonKey = arr[0]; 41 | String propKey = arr[1]; 42 | Object obj = jsonableMap.get(jsonKey); 43 | Map objMap = null; 44 | if (Objects.isNull(obj)){ 45 | objMap = new HashMap<>(); 46 | jsonableMap.put(jsonKey, objMap); 47 | }else { 48 | objMap = (Map) obj; 49 | } 50 | objMap.put(propKey, es.getValue()); 51 | }else{ 52 | jsonableMap.put(stringKey, es.getValue()); 53 | } 54 | } 55 | return jsonableMap; 56 | } 57 | 58 | public static List> toJsonableMapList (List> stringKeyList){ 59 | 60 | List> list = new ArrayList>(); 61 | 62 | for (Map map : stringKeyList){ 63 | Map jsonKeyMap = toJsonableMap(map); 64 | list.add(jsonKeyMap); 65 | } 66 | 67 | return list; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/util/SqliExceptionUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.util; 20 | 21 | import java.lang.reflect.InvocationTargetException; 22 | import java.lang.reflect.UndeclaredThrowableException; 23 | 24 | 25 | /** 26 | * @author Sim 27 | */ 28 | public class SqliExceptionUtil { 29 | 30 | private SqliExceptionUtil(){} 31 | 32 | public static void throwRuntimeExceptionFirst(Throwable e) { 33 | if (e instanceof RuntimeException){ 34 | throw (RuntimeException) e; 35 | } 36 | } 37 | 38 | public static String getMessage(Throwable e){ 39 | String msg = e.getMessage(); 40 | msg += "\n"; 41 | StackTraceElement[] eleArr = e.getStackTrace(); 42 | if (eleArr == null || eleArr.length == 0) 43 | return msg; 44 | for (StackTraceElement ele : eleArr) { 45 | msg += ele.toString(); 46 | msg += "\n"; 47 | } 48 | return msg; 49 | } 50 | 51 | public static Throwable unwrapThrowable(Throwable wrapped) { 52 | Throwable unwrapped = wrapped; 53 | while (true) { 54 | if (unwrapped instanceof InvocationTargetException ite) { 55 | unwrapped = ite.getTargetException(); 56 | } else if (unwrapped instanceof UndeclaredThrowableException ute) { 57 | unwrapped = ute.getUndeclaredThrowable(); 58 | } else { 59 | Throwable t = wrapped.getCause(); 60 | if (t != null) 61 | return t; 62 | return unwrapped; 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/PageBuilderHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import io.xream.sqli.builder.Q; 22 | import io.xream.sqli.page.Page; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | /** 28 | * @author Sim 29 | */ 30 | public final class PageBuilderHelper { 31 | 32 | private PageBuilderHelper(){} 33 | 34 | public static Page build(Q q, List list, TotalRows totalRows) { 35 | 36 | long count = 0; 37 | int rows = q.getRows(); 38 | int page = q.getPage(); 39 | if (!q.isTotalRowsIgnored()) { 40 | int size = list.size(); 41 | if (page == 0) { 42 | count = size; 43 | } else { 44 | try { 45 | count = totalRows.count(); 46 | }catch (Exception e){ 47 | 48 | } 49 | } 50 | }else{ 51 | count = -1; 52 | } 53 | 54 | Page pagination = new Page<>(); 55 | if (q instanceof Q.X) 56 | pagination.setClzz(Map.class); 57 | else 58 | pagination.setClzz(q.getClzz()); 59 | pagination.setPage(page == 0 ? 1 : page); 60 | pagination.setRows(rows == 0 ? Integer.MAX_VALUE : rows); 61 | pagination.setSortList(q.getSortList()); 62 | pagination.setTotalRowsIgnored(q.isTotalRowsIgnored()); 63 | pagination.setList(list); 64 | pagination.setTotalRows(count); 65 | 66 | return pagination; 67 | } 68 | 69 | public interface TotalRows { 70 | long count(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/dao/Dao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.dao; 20 | 21 | import io.xream.sqli.builder.In; 22 | import io.xream.sqli.builder.Q; 23 | import io.xream.sqli.builder.Qr; 24 | import io.xream.sqli.cache.QueryForCache; 25 | import io.xream.sqli.core.KeyOne; 26 | import io.xream.sqli.core.Keys; 27 | import io.xream.sqli.core.RowHandler; 28 | import io.xream.sqli.page.Page; 29 | 30 | import java.util.List; 31 | import java.util.Map; 32 | 33 | 34 | /** 35 | * 36 | * @author Sim 37 | * 38 | */ 39 | public interface Dao extends QueryForCache { 40 | 41 | boolean create(Object obj); 42 | 43 | boolean createOrReplace(Object obj); 44 | 45 | boolean createBatch(List objList); 46 | 47 | boolean remove(KeyOne keyOne); 48 | 49 | boolean removeIn(Keys keys); 50 | 51 | boolean refreshByCondition(Qr conditon); 52 | 53 | List> list(String sql, 54 | List conditionSet); 55 | 56 | T get(KeyOne keyOne); 57 | 58 | List in(In in); 59 | 60 | Page> find(Q.X xq); 61 | 62 | List> list(Q.X xq); 63 | 64 | List listPlainValue(Class clzz, Q.X xq); 65 | 66 | Page find(Q q); 67 | 68 | List list(Q q); 69 | 70 | boolean execute(String sql, Object...objs); 71 | 72 | T getOne(Q q); 73 | 74 | boolean refresh(T t); 75 | 76 | void findToHandle(Q q, RowHandler handler); 77 | void findToHandle(Q.X xq, RowHandler> handler); 78 | 79 | boolean exists(Q q); 80 | 81 | boolean createOrReplaceBatch(Class clz, List> propValueList); 82 | } -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/ResultKeyAlia.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | 22 | import io.xream.sqli.util.SqliStringUtil; 23 | 24 | /** 25 | * @author Sim 26 | */ 27 | public final class ResultKeyAlia { 28 | 29 | private String objectOrAlia; 30 | private String propertyOrAlia; 31 | 32 | public void setObjectOrAlia(String objectOrAlia) { 33 | this.objectOrAlia = objectOrAlia; 34 | } 35 | 36 | public void setPropertyOrAlia(String propertyOrAlia) { 37 | this.propertyOrAlia = propertyOrAlia; 38 | } 39 | 40 | public static ResultKeyAlia of(String propertyOrAlia) { 41 | ResultKeyAlia functionAlia = new ResultKeyAlia(); 42 | functionAlia.setPropertyOrAlia(propertyOrAlia); 43 | return functionAlia; 44 | } 45 | 46 | public static ResultKeyAlia of(String objectOrAlia, String propertyOrAlia) { 47 | ResultKeyAlia functionAlia = new ResultKeyAlia(); 48 | functionAlia.setObjectOrAlia(objectOrAlia); 49 | functionAlia.setPropertyOrAlia(propertyOrAlia); 50 | return functionAlia; 51 | } 52 | 53 | public String getAlia(){ 54 | if (SqliStringUtil.isNullOrEmpty(objectOrAlia)) 55 | return propertyOrAlia; 56 | return objectOrAlia + "." + propertyOrAlia; 57 | } 58 | 59 | public String getKey(){ 60 | if (SqliStringUtil.isNullOrEmpty(objectOrAlia)) 61 | return propertyOrAlia; 62 | return objectOrAlia + "_" + propertyOrAlia; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "FunctionAlia{" + 68 | "objectOrAlia='" + objectOrAlia + '\'' + 69 | ", propertyOrAlia='" + propertyOrAlia + '\'' + 70 | '}'; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/internal/DefaultNativeRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.internal; 20 | 21 | 22 | import io.xream.sqli.api.NativeRepository; 23 | import io.xream.sqli.core.NativeSupport; 24 | import io.xream.sqli.dialect.DynamicDialectKeyRemovable; 25 | import io.xream.sqli.exception.PersistenceException; 26 | import io.xream.sqli.exception.QueryException; 27 | import io.xream.sqli.util.SqliExceptionUtil; 28 | 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | 33 | /** 34 | * @author Sim 35 | */ 36 | public final class DefaultNativeRepository implements NativeRepository, DynamicDialectKeyRemovable { 37 | 38 | private static NativeRepository instance; 39 | private NativeSupport nativeSupport; 40 | 41 | private DefaultNativeRepository(){} 42 | public static NativeRepository newInstance(){ 43 | if (instance == null){ 44 | instance = new DefaultNativeRepository(); 45 | return instance; 46 | } 47 | return null; 48 | } 49 | 50 | public void setNativeSupport(NativeSupport nativeSupport){ 51 | if (this.nativeSupport == null){ 52 | this.nativeSupport = nativeSupport; 53 | } 54 | } 55 | 56 | @Override 57 | public boolean execute(String sql, Object...objs){ 58 | try { 59 | return nativeSupport.execute(sql, objs); 60 | }catch (Exception e) { 61 | SqliExceptionUtil.throwRuntimeExceptionFirst(e); 62 | throw new PersistenceException(e); 63 | }finally { 64 | removeDialectKey(); 65 | } 66 | } 67 | @Override 68 | public List> list(String sql, List conditionList){ 69 | try { 70 | return nativeSupport.list(sql, conditionList); 71 | }catch (Exception e) { 72 | SqliExceptionUtil.throwRuntimeExceptionFirst(e); 73 | throw new QueryException(SqliExceptionUtil.getMessage(e)); 74 | }finally { 75 | removeDialectKey(); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/dialect/Dialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.dialect; 20 | 21 | 22 | import io.xream.sqli.builder.internal.DialectSupport; 23 | import io.xream.sqli.builder.internal.PageSqlSupport; 24 | import io.xream.sqli.core.ValuePost; 25 | import io.xream.sqli.parser.BeanElement; 26 | import io.xream.sqli.parser.Parsed; 27 | import io.xream.sqli.util.BeanUtil; 28 | 29 | import java.util.Collection; 30 | import java.util.List; 31 | import java.util.Map; 32 | 33 | /** 34 | * @author Sim 35 | */ 36 | public interface Dialect extends DialectSupport, PageSqlSupport, ValuePost { 37 | 38 | 39 | String transformAlia(String mapper, Map aliaMap, Map resultKeyAliaMap); 40 | 41 | Object[] toArr(Collection list); 42 | 43 | Object mappingToObject(Object obj, BeanElement element); 44 | 45 | String createOrReplaceSql(String sql); 46 | 47 | String createSql(Parsed parsed, List tempList); 48 | 49 | default String getDefaultCreateSql(Parsed parsed, List tempList) { 50 | String space = " "; 51 | StringBuilder sb = new StringBuilder(); 52 | sb.append("INSERT INTO "); 53 | 54 | sb.append(BeanUtil.getByFirstLower(parsed.getClzName())).append(space); 55 | sb.append("("); 56 | int size = tempList.size(); 57 | for (int i = 0; i < size; i++) { 58 | String p = tempList.get(i).getProperty(); 59 | 60 | sb.append(" ").append(p).append(" "); 61 | if (i < size - 1) { 62 | sb.append(","); 63 | } 64 | } 65 | 66 | sb.append(") VALUES ("); 67 | 68 | for (int i = 0; i < size; i++) { 69 | 70 | sb.append("?"); 71 | if (i < size - 1) { 72 | sb.append(","); 73 | } 74 | } 75 | sb.append(")"); 76 | 77 | return sb.toString(); 78 | } 79 | } -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/RemoveRefreshCreate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | import com.fasterxml.jackson.annotation.JsonIgnore; 22 | import io.xream.sqli.api.Routable; 23 | 24 | import java.util.List; 25 | 26 | 27 | /** 28 | * @author Sim 29 | */ 30 | public final class RemoveRefreshCreate implements Routable { 31 | 32 | private Object routeKey; 33 | @JsonIgnore 34 | private transient Class clz; 35 | private List list; 36 | private Object[] ins; 37 | @Deprecated 38 | public RemoveRefreshCreate(){} 39 | public static RemoveRefreshCreate of(List list, Object[] ins){ 40 | return of(null,list,ins); 41 | } 42 | 43 | public static RemoveRefreshCreate of(Object routeKey, List list, Object[] ins){ 44 | RemoveRefreshCreate rrc = new RemoveRefreshCreate(); 45 | rrc.routeKey = routeKey; 46 | rrc.list = list; 47 | rrc.ins = ins; 48 | return rrc; 49 | } 50 | 51 | @Override 52 | public Object getRouteKey() { 53 | return routeKey; 54 | } 55 | 56 | public void setRouteKey(Object routeKey) { 57 | this.routeKey = routeKey; 58 | } 59 | 60 | public Class getClz() { 61 | return clz; 62 | } 63 | 64 | public void setClz(Class clz) { 65 | this.clz = clz; 66 | } 67 | 68 | public List getList() { 69 | return list; 70 | } 71 | 72 | public void setList(List list) { 73 | this.list = list; 74 | } 75 | 76 | public Object[] getIns() { 77 | return ins; 78 | } 79 | 80 | public void setIns(Object[] ins) { 81 | this.ins = ins; 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | return "RemoveRefreshCreate{" + 87 | "routeKey=" + routeKey + 88 | ", list=" + list + 89 | ", ins=" + ins + 90 | '}'; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/util/SqliLoggerProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.util; 20 | 21 | import org.slf4j.Logger; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | 27 | /** 28 | * @author Sim 29 | */ 30 | public final class SqliLoggerProxy { 31 | 32 | private final static Map loggerMap = new HashMap<>(); 33 | 34 | private SqliLoggerProxy(){} 35 | 36 | public static void put(Class clzz, Logger logger) { 37 | loggerMap.put(clzz,logger); 38 | } 39 | 40 | public static void debug(Class clzz, Object obj) { 41 | Logger logger = loggerMap.get(clzz); 42 | if (logger == null || obj == null) 43 | return; 44 | if (logger.isDebugEnabled()) { 45 | logger.debug(obj.toString()); 46 | } 47 | } 48 | 49 | 50 | public static void debug(Class clzz, LogCallable callable) { 51 | Logger logger = loggerMap.get(clzz); 52 | if (logger == null ) 53 | return; 54 | if (logger.isDebugEnabled()) { 55 | if (callable == null) 56 | return; 57 | String str = callable.call(); 58 | if (SqliStringUtil.isNullOrEmpty(str)) 59 | return; 60 | logger.debug(str); 61 | } 62 | } 63 | 64 | public static void info(Class clzz, Object obj) { 65 | Logger logger = loggerMap.get(clzz); 66 | if (logger == null || obj == null) 67 | return; 68 | else if (logger.isInfoEnabled()){ 69 | logger.info(obj.toString()); 70 | } 71 | } 72 | 73 | public static long getTimeMills(Class clzz){ 74 | Logger logger = loggerMap.get(clzz); 75 | if (logger == null) 76 | return 0; 77 | if (logger.isDebugEnabled()) 78 | return System.currentTimeMillis(); 79 | return 0; 80 | } 81 | 82 | public interface LogCallable{ 83 | String call(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/starter/SqliListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.starter; 20 | 21 | import io.xream.sqli.api.customizer.DialectCustomizer; 22 | import io.xream.sqli.core.NativeSupport; 23 | import io.xream.sqli.dialect.Dialect; 24 | import io.xream.sqli.parser.ParserListener; 25 | import io.xream.sqli.repository.exception.UninitializedException; 26 | import io.xream.sqli.repository.init.SqlInit; 27 | import io.xream.sqli.spi.L2CacheConsistency; 28 | import io.xream.sqli.spi.L2CacheResolver; 29 | import io.xream.sqli.spi.Schema; 30 | import io.xream.sqli.util.SqliJsonUtil; 31 | 32 | /** 33 | * @author Sim 34 | */ 35 | public class SqliListener { 36 | 37 | private static SqliListener instance; 38 | private static boolean initialized = false; 39 | 40 | private SqliListener(){} 41 | 42 | public static void cusomizeJsonConfig(SqliJsonUtil.Customizer customizer) { 43 | customizer.customize(); 44 | } 45 | 46 | public static void onBeanCreated(InitPhaseable initPhaseable){ 47 | initialized |= initPhaseable.init(); 48 | } 49 | 50 | public static void onL2CacheEnabled(L2CacheResolver l2CacheResolver, L2CacheConsistency l2CacheConsistency) { 51 | if (l2CacheResolver != null && l2CacheConsistency != null) { 52 | l2CacheResolver.setL2CacheConsistency(l2CacheConsistency); 53 | } 54 | } 55 | 56 | public static void customizeDialectOnStarted(Dialect dialect, DialectCustomizer dialectCustomizer) { 57 | DialectListener.customizeOnStarted(dialect,dialectCustomizer); 58 | } 59 | 60 | public static void onStarted(NativeSupport nativeSupport, SqlInit sqlInit, Schema schema){ 61 | if (instance != null) 62 | return; 63 | 64 | if (! initialized) 65 | throw new UninitializedException("to confirm all bean initialized, please call SqliListener.onBeanCreated(...) at leaset one time"); 66 | 67 | instance = new SqliListener(); 68 | 69 | InitializerListener.onStarted(nativeSupport,sqlInit, schema); 70 | ParserListener.onStarted(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/Sort.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author Sim 25 | */ 26 | public final class Sort { 27 | 28 | private Direction direction = Direction.DESC; 29 | private String orderBy; 30 | 31 | public Sort(){} 32 | 33 | public Sort(String orderBy, Direction direction){ 34 | this.orderBy = orderBy; 35 | this.direction = direction; 36 | } 37 | 38 | public Direction getDirection() { 39 | return direction; 40 | } 41 | 42 | public void setDirection(Direction direction) { 43 | this.direction = direction; 44 | } 45 | 46 | public String getOrderBy() { 47 | return orderBy; 48 | } 49 | 50 | public void setOrderBy(String orderBy) { 51 | this.orderBy = orderBy; 52 | } 53 | 54 | 55 | public static void sortKeyListByMask(List keyList, final byte[] keyMask, Direction direction) { 56 | 57 | int temp = 0; 58 | int l = keyMask.length; 59 | for (int in=0; in < l; in++){ 60 | if (keyMask[in] == 0){ 61 | temp = in; 62 | break; 63 | } 64 | } 65 | final int maskStart = temp; 66 | int length = keyMask.length; 67 | int directionValue = direction == Direction.ASC ? 1 : -1; 68 | 69 | keyList.sort((a, b) -> { 70 | char[] ac = a.toCharArray(); 71 | char[] bc = b.toCharArray(); 72 | 73 | for (int i= maskStart; i< length; i++) { 74 | if (keyMask[i] == 0) { 75 | if (ac[i] > bc[i]) 76 | return 1 * directionValue; 77 | if (ac[i] < bc[i]) 78 | return -1 * directionValue; 79 | } 80 | } 81 | return 0; 82 | }); 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "Sort{" + 88 | "direction=" + direction + 89 | ", orderBy='" + orderBy + '\'' + 90 | '}'; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/core/XFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.core; 20 | 21 | import io.xream.sqli.converter.DataObjectConverter; 22 | import io.xream.sqli.dialect.Dialect; 23 | import io.xream.sqli.mapping.XHelpful; 24 | import io.xream.sqli.parser.Parsed; 25 | import io.xream.sqli.util.JsonStyleMapUtil; 26 | 27 | import java.util.Collection; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | /** 32 | * @author Sim 33 | */ 34 | public interface XFinder { 35 | 36 | List> queryForXList(String sql, Collection list, XHelpful xHelpful, Class orClzz, Dialect dialect); 37 | 38 | void queryForMapToHandle(String sql, Collection valueList, Dialect dialect, XHelpful xHelpful, Parsed orParsed, RowHandler handler); 39 | 40 | default List> toXList(boolean isResultWithDottedKey, DataMapQuery dataMapQuery) { 41 | 42 | List> objectPropertyMapList = dataMapQuery.query(DataMapQuery.FIXED_ROW_MAPPER); 43 | if (isResultWithDottedKey) 44 | return objectPropertyMapList; 45 | 46 | if (!objectPropertyMapList.isEmpty()) 47 | return JsonStyleMapUtil.toJsonableMapList(objectPropertyMapList); 48 | 49 | return objectPropertyMapList; 50 | } 51 | 52 | default Map toXq(XHelpful xHelpful, Dialect dialect, Map dataMap) { 53 | Map map = DataMapQuery.FIXED_ROW_MAPPER.mapRow(dataMap,null, xHelpful,dialect); 54 | if (xHelpful.isResultWithDottedKey()) 55 | return map; 56 | if (!map.isEmpty()) 57 | return JsonStyleMapUtil.toJsonableMap(map); 58 | return map; 59 | } 60 | 61 | interface DataMapQuery { 62 | FixedRowMapper FIXED_ROW_MAPPER = (dataMap, clzz, xHelpful, dialect) -> DataObjectConverter.toMapWithKeyOfObjectProperty(dataMap,clzz, xHelpful,dialect); 63 | List> query(FixedRowMapper fixedRowMapper); 64 | } 65 | 66 | interface FixedRowMapper{ 67 | Map mapRow(Map dataMap, Class clzz, XHelpful xHelpful, Dialect dialect); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/internal/SafeRefreshBiz.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.internal; 20 | 21 | import io.xream.sqli.builder.Op; 22 | import io.xream.sqli.builder.Qr; 23 | import io.xream.sqli.builder.internal.Bb; 24 | import io.xream.sqli.exception.QSyntaxException; 25 | import io.xream.sqli.parser.Parsed; 26 | import io.xream.sqli.parser.Parser; 27 | 28 | import java.lang.reflect.Field; 29 | import java.util.List; 30 | import java.util.Objects; 31 | 32 | /** 33 | * @author Sim 34 | */ 35 | public interface SafeRefreshBiz { 36 | 37 | default void tryToRefreshSafe(Class clzz, Qr qr) { 38 | qr.setClz(clzz); 39 | Parsed parsed = Parser.get(clzz); 40 | Field keyField = parsed.getKeyField(); 41 | if (Objects.isNull(keyField)) 42 | throw new QSyntaxException("No PrimaryKey, UnSafe Refresh, try to invoke DefaultRepository.refreshUnSafe(qr rq)"); 43 | 44 | boolean unSafe = true;//Safe 45 | 46 | if (unSafe) { 47 | String key = parsed.getKey(); 48 | List bbList = qr.getBbs(); 49 | for (Bb bb : bbList) { 50 | String k = bb.getKey(); 51 | boolean b = k.contains(".") ? k.endsWith("."+key) : key.equals(k); 52 | if (b) { 53 | Object value = bb.getValue(); 54 | if (Objects.nonNull(value) && !value.toString().equals("0")) { 55 | unSafe = false;//Safe 56 | if (bb.getP() == Op.EQ || bb.getP() == Op.IN) { 57 | int size = 1; 58 | if (value instanceof List) { 59 | size = ((List) value).size(); 60 | } 61 | if (size > qr.getLimit()) { 62 | qr.setLimit(size); 63 | } 64 | } 65 | break; 66 | } 67 | } 68 | } 69 | } 70 | 71 | if (unSafe) 72 | throw new QSyntaxException("UnSafe Refresh, try to invoke DefaultRepository.refreshUnSafe(qr rq)"); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/In.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder; 20 | 21 | import com.fasterxml.jackson.annotation.JsonIgnore; 22 | import io.xream.sqli.api.Routable; 23 | 24 | import java.util.List; 25 | 26 | 27 | /** 28 | * @author Sim 29 | */ 30 | public final class In implements Routable { 31 | 32 | private String property; 33 | private List inList; 34 | 35 | private Object routeKey; 36 | 37 | @JsonIgnore 38 | private transient Class clz; 39 | 40 | public String getProperty() { 41 | return property; 42 | } 43 | 44 | public void setProperty(String property) { 45 | this.property = property; 46 | } 47 | 48 | public List getInList() { 49 | return inList; 50 | } 51 | 52 | public void setInList(List inList) { 53 | this.inList = inList; 54 | } 55 | 56 | public Class getClz() { 57 | return clz; 58 | } 59 | 60 | public void setClz(Class clz) { 61 | this.clz = clz; 62 | } 63 | 64 | @Override 65 | public Object getRouteKey() { 66 | return routeKey; 67 | } 68 | 69 | public void setRouteKey(Object routeKey) { 70 | this.routeKey = routeKey; 71 | } 72 | 73 | @Deprecated 74 | public In(){ 75 | } 76 | 77 | @Deprecated 78 | public In(String property, List inList ){ 79 | this.property = property; 80 | this.inList = inList; 81 | } 82 | 83 | public static In of(String property, List inList ){ 84 | return of(null,property,inList); 85 | } 86 | 87 | public static In of(Object routeKey, String property, List inList ){ 88 | In in = new In(); 89 | in.setRouteKey(routeKey); 90 | in.setProperty(property); 91 | in.setInList(inList); 92 | return in; 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | return "In{" + 98 | "property='" + property + '\'' + 99 | ", inList=" + inList + 100 | ", clz=" + clz + 101 | '}'; 102 | } 103 | } -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/converter/X2Bean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.converter; 20 | 21 | import io.xream.sqli.util.SqliJsonUtil; 22 | 23 | import java.lang.reflect.Field; 24 | import java.lang.reflect.Modifier; 25 | import java.util.ArrayList; 26 | import java.util.Arrays; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * @author Sim 32 | */ 33 | public class X2Bean { 34 | 35 | private X2Bean(){} 36 | 37 | /** 38 | * not support q by builder.resultWithDottedKey(); 39 | */ 40 | public static T copy(Class clz, Map map) { 41 | 42 | if (clz == Map.class) 43 | return (T) map; 44 | 45 | List filedList = new ArrayList<>(); 46 | 47 | if (clz.getSuperclass() != Object.class) { 48 | filedList.addAll(Arrays.asList(clz.getSuperclass().getDeclaredFields())); 49 | } 50 | filedList.addAll(Arrays.asList(clz.getDeclaredFields())); 51 | 52 | if (clz.isRecord()) { 53 | return SqliJsonUtil.toObject(map,clz); 54 | } 55 | 56 | T obj = null; 57 | try { 58 | obj = clz.getDeclaredConstructor().newInstance(); 59 | } catch (Exception e) { 60 | throw new UnsupportedOperationException(e); 61 | } 62 | 63 | try { 64 | for (Field field : filedList) { 65 | int modifiers = field.getModifiers(); 66 | if (Modifier.isStatic(modifiers)) 67 | continue; 68 | if (Modifier.isFinal(modifiers)) 69 | continue; 70 | 71 | field.setAccessible(true); 72 | 73 | String key = field.getName(); 74 | Object v = map.get(key); 75 | if (v == null) 76 | continue; 77 | 78 | if (v instanceof Map) { 79 | Class fc = field.getType(); 80 | field.set(obj, copy(fc, (Map) v)); 81 | }else { 82 | field.set(obj, v); 83 | } 84 | } 85 | } catch (Exception e) { 86 | throw new UnsupportedOperationException(e); 87 | } 88 | return obj; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/api/BaseRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.api; 20 | 21 | import io.xream.sqli.builder.Q; 22 | import io.xream.sqli.builder.Qr; 23 | import io.xream.sqli.builder.RemoveRefreshCreate; 24 | import io.xream.sqli.core.RowHandler; 25 | import io.xream.sqli.core.Typed; 26 | import io.xream.sqli.page.Page; 27 | 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | /** 32 | * API 33 | * 34 | * @param 35 | * @author Sim 36 | */ 37 | public interface BaseRepository extends Typed { 38 | 39 | long createId(); 40 | 41 | void refreshCache(); 42 | 43 | boolean createBatch(List objList); 44 | 45 | boolean create(T obj); 46 | 47 | /** 48 | * replace: REPLACE INTO, clear all the value of the row, and insert the new value 49 | * is not refreshOrCreate 50 | * x7 will not support refreshOrCreate, coding: query at first, then refresh of create
51 | */ 52 | boolean createOrReplace(T obj); 53 | 54 | boolean refresh(Qr qr); 55 | 56 | boolean createOrReplaceBatch(List> propValueList); 57 | /** 58 | * 59 | * qr without keyOne 60 | */ 61 | boolean refreshUnSafe(Qr qr); 62 | 63 | boolean remove(String id); 64 | 65 | boolean remove(long id); 66 | 67 | boolean removeIn(List idList); 68 | /** 69 | * 70 | * caution: sometimes, should not use the api 71 | * 72 | */ 73 | boolean removeRefreshCreate(RemoveRefreshCreate removeRefreshCreate_of); 74 | /** 75 | * @param keyOne 76 | */ 77 | T get(long keyOne); 78 | 79 | T get(String keyOne); 80 | 81 | T getOne(Q q); 82 | /** 83 | * in API 84 | * 85 | */ 86 | List in(String property, List inList); 87 | /** 88 | * Standard query pageable API 89 | * 90 | * @param q 91 | */ 92 | Page find(Q q); 93 | 94 | List list(Q q); 95 | 96 | /** 97 | * like stream, fetchSize=50, the api not fast, to avoid OOM when scheduling 98 | * @param q 99 | * @param handler 100 | * @param 101 | */ 102 | void findToHandle(Q q, RowHandler handler); 103 | 104 | boolean exists(Q q); 105 | 106 | } -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/core/InOptimization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.core; 20 | 21 | import io.xream.sqli.builder.In; 22 | import io.xream.sqli.filter.BaseTypeFilter; 23 | import io.xream.sqli.parser.Parsed; 24 | import io.xream.sqli.parser.Parser; 25 | 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | import java.util.Objects; 29 | 30 | /** 31 | * @author Sim 32 | */ 33 | public interface InOptimization { 34 | 35 | int IN_MAX = 500; 36 | 37 | static List in(In in, CacheableRepository repository){ 38 | 39 | if (in.getInList().isEmpty()) 40 | return new ArrayList(); 41 | 42 | List inList = new ArrayList(); 43 | 44 | for (Object obj : in.getInList()) { 45 | if (Objects.isNull(obj)) 46 | continue; 47 | Parsed parsed = Parser.get(in.getClz()); 48 | if (BaseTypeFilter.isBaseType(in.getProperty(), obj, parsed)) 49 | continue; 50 | if (!inList.contains(obj)) { 51 | inList.add(obj); 52 | } 53 | } 54 | 55 | if (inList.isEmpty()) 56 | return new ArrayList(); 57 | 58 | int size = inList.size(); 59 | 60 | if (size <= IN_MAX) { 61 | in.setInList(inList); 62 | return repository.in0(in); 63 | } 64 | 65 | List list = new ArrayList<>(size); 66 | int i = 0; 67 | while (size > 0) { 68 | int segSize = (size > IN_MAX ? IN_MAX : size); 69 | size -= segSize; 70 | int fromIndex = i++ * IN_MAX; 71 | int toIndex = fromIndex + segSize; 72 | List segInList = inList.subList(fromIndex, toIndex); 73 | 74 | In ic = In.of(in.getProperty(), segInList); 75 | ic.setClz(in.getClz()); 76 | List segList = repository.in0(ic); 77 | list.addAll(segList); 78 | } 79 | 80 | return list; 81 | } 82 | 83 | static String keyCondition(In in) { 84 | String inProperty = in.getProperty(); 85 | List inList = in.getInList(); 86 | 87 | StringBuilder sb = new StringBuilder(); 88 | sb.append(inProperty).append(":"); 89 | for (Object obj : inList) { 90 | sb.append(obj.toString()).append("_"); 91 | } 92 | return sb.toString(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/util/SqlParserUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.util; 20 | 21 | import io.xream.sqli.parser.Parsed; 22 | import io.xream.sqli.util.BeanUtil; 23 | 24 | /** 25 | * @author Sim 26 | */ 27 | public final class SqlParserUtil { 28 | 29 | public final static String SPACE = " "; 30 | public final static String SQL_KEYWORD_MARK = "`"; 31 | 32 | 33 | public static String mapper(String sql, Parsed parsed) { 34 | 35 | if (parsed.isNoSpec()) 36 | return sql; 37 | 38 | sql = mapperName(sql, parsed); 39 | 40 | boolean flag = sql.contains(SQL_KEYWORD_MARK); 41 | for (String property : parsed.getPropertyMapperMap().keySet()){//FIXME 解析之后, 替换,拼接 42 | if (flag){ 43 | String key = SQL_KEYWORD_MARK+property+SQL_KEYWORD_MARK; 44 | if (sql.contains(key)) { 45 | String value = parsed.getMapper(property); 46 | if (!value.startsWith(SQL_KEYWORD_MARK)) { 47 | value = SQL_KEYWORD_MARK + parsed.getMapper(property) + SQL_KEYWORD_MARK; 48 | } 49 | sql = sql.replace(key, value); 50 | continue; 51 | } 52 | } 53 | String key = SPACE + property + SPACE; 54 | String value = SPACE + parsed.getMapper(property) + SPACE; 55 | if (!sql.startsWith(SPACE)){ 56 | sql = SPACE + sql; 57 | } 58 | sql = sql.replaceAll(key, value); 59 | } 60 | sql = sql.trim(); 61 | return sql; 62 | } 63 | 64 | 65 | public static String mapperName(String sql, Parsed parsed) { 66 | 67 | String clzName = parsed.getClzName(); 68 | clzName = BeanUtil.getByFirstLower(clzName); 69 | String tableName = parsed.getTableName(); 70 | 71 | return mapperName (sql, clzName, tableName); 72 | } 73 | 74 | public static String mapperName(String sql, String clzName, String tableName) { 75 | 76 | if (sql.endsWith(clzName)){ 77 | sql += SPACE; 78 | } 79 | sql = sql.replace(SPACE +clzName+SPACE, SPACE+tableName+SPACE); 80 | if (sql.contains(SQL_KEYWORD_MARK)) { 81 | sql = sql.replace(SQL_KEYWORD_MARK +clzName+SQL_KEYWORD_MARK, SQL_KEYWORD_MARK+tableName+SQL_KEYWORD_MARK); 82 | } 83 | 84 | return sql; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sqli-core/src/main/java/io/xream/sqli/cache/internal/CacheKeyBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.cache.internal; 20 | 21 | import io.xream.sqli.builder.KV; 22 | import io.xream.sqli.builder.Q; 23 | import io.xream.sqli.builder.Sort; 24 | import io.xream.sqli.builder.internal.Bb; 25 | import io.xream.sqli.cache.CacheKeyBuildable; 26 | import io.xream.sqli.util.SqliStringUtil; 27 | 28 | import java.util.HashSet; 29 | import java.util.List; 30 | import java.util.Objects; 31 | import java.util.Set; 32 | 33 | /** 34 | * @author Sim 35 | */ 36 | public class CacheKeyBuilder implements CacheKeyBuildable { 37 | 38 | @Override 39 | public String buildCacheKey(Q q, boolean isOfTotalRows){ 40 | StringBuilder sb = new StringBuilder(); 41 | sb.append(q.getRouteKey()); 42 | buildCacheKeyByBbList(q.getBbs(), sb); 43 | 44 | if (! isOfTotalRows) { 45 | sb.append(q.getPage()).append(q.getRows()); 46 | if (q.getSortList() != null) { 47 | for (Sort sort : (List)q.getSortList()) { 48 | sb.append(sort.getOrderBy()).append(sort.getDirection()); 49 | } 50 | } 51 | if (q.getFixedSortList() != null) { 52 | for (KV kv : (List)q.getFixedSortList()) { 53 | sb.append(kv.k).append(kv.v); 54 | } 55 | } 56 | } 57 | return sb.toString(); 58 | } 59 | 60 | private void buildCacheKeyByBbBlock(Bb bb, StringBuilder sb) { 61 | sb.append(bb.getC()).append(bb.getP()); 62 | if (SqliStringUtil.isNotNull(bb.getKey()) || Objects.nonNull(bb.getValue())) { 63 | sb.append(bb.getKey()).append(bb.getValue()); 64 | } 65 | List subList = bb.getSubList(); 66 | if (subList != null && !subList.isEmpty()){ 67 | buildCacheKeyByBbList(subList,sb); 68 | } 69 | } 70 | 71 | private void buildCacheKeyByBbList(List bbList, StringBuilder sb){ 72 | int size = bbList.size(); 73 | if (size == 0) 74 | return; 75 | if (size == 1){ 76 | Bb bb = bbList.get(0); 77 | buildCacheKeyByBbBlock(bb,sb); 78 | }else{ 79 | Set set = new HashSet<>(); 80 | for (Bb bb : bbList) { 81 | set.add(bb); 82 | } 83 | for (Bb bb : set){ 84 | buildCacheKeyByBbBlock(bb,sb); 85 | } 86 | } 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/Bb.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | 22 | import io.xream.sqli.builder.Op; 23 | 24 | import java.util.List; 25 | import java.util.Objects; 26 | 27 | /** 28 | * @author Sim 29 | */ 30 | public final class Bb { 31 | 32 | private Op c; 33 | private Op p; 34 | private String key; 35 | private Object value; 36 | private List subList; 37 | public Bb(){} 38 | 39 | public static Bb of(Op c, Op p, String key, Object value){ 40 | Bb bb = new Bb(); 41 | bb.setC(c); 42 | bb.setP(p); 43 | bb.setKey(key); 44 | bb.setValue(value); 45 | return bb; 46 | } 47 | 48 | public Bb(boolean isOr){ 49 | if (isOr) 50 | c = Op.OR; 51 | else 52 | c = Op.AND; 53 | } 54 | public Op getC() { 55 | return c; 56 | } 57 | public void setC(Op c) { 58 | this.c = c; 59 | } 60 | public Op getP() { 61 | return p; 62 | } 63 | public void setP(Op p) { 64 | this.p = p; 65 | } 66 | public String getKey() { 67 | return key; 68 | } 69 | public void setKey(String key) { 70 | this.key = key; 71 | } 72 | public Object getValue() { 73 | return value; 74 | } 75 | public void setValue(Object value) { 76 | this.value = value; 77 | } 78 | public List getSubList() { 79 | return subList; 80 | } 81 | public void setSubList(List subList) { 82 | this.subList = subList; 83 | } 84 | 85 | 86 | @Override 87 | public boolean equals(Object object) { 88 | if (this == object) return true; 89 | if (object == null || getClass() != object.getClass()) return false; 90 | Bb that = (Bb) object; 91 | return c == that.c && 92 | p == that.p && 93 | Objects.equals(key, that.key) && 94 | Objects.equals(value, that.value) ; 95 | } 96 | 97 | @Override 98 | public int hashCode() { 99 | return Objects.hash(c, p, key, value); 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return "Bb{" + 105 | "c=" + c + 106 | ", p=" + p + 107 | ", key=" + key + 108 | ", value=" + value + 109 | ", subList=" + subList + 110 | '}'; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /sqli-repo/src/main/java/io/xream/sqli/repository/init/DefaultTemporaryTableParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.repository.init; 20 | 21 | import io.xream.sqli.api.TemporaryRepository; 22 | import io.xream.sqli.dialect.Dialect; 23 | import io.xream.sqli.exception.ParsingException; 24 | import io.xream.sqli.parser.Parsed; 25 | import io.xream.sqli.parser.Parser; 26 | import io.xream.sqli.repository.util.SqlParserUtil; 27 | import io.xream.sqli.spi.Schema; 28 | 29 | import java.util.Map; 30 | import java.util.concurrent.ConcurrentHashMap; 31 | 32 | /** 33 | * @author Sim 34 | */ 35 | public final class DefaultTemporaryTableParser implements TemporaryRepository.Parser, SqlTemplate { 36 | 37 | private static DefaultTemporaryTableParser instance; 38 | 39 | private Map sqlMap = new ConcurrentHashMap<>(); 40 | 41 | private Dialect dialect; 42 | 43 | private Schema schema; 44 | 45 | private Object lock = new Object(); 46 | 47 | private DefaultTemporaryTableParser(){} 48 | 49 | public static DefaultTemporaryTableParser newInstance(){ 50 | if (instance == null){ 51 | instance = new DefaultTemporaryTableParser(); 52 | return instance; 53 | } 54 | return null; 55 | } 56 | 57 | public void setDialect(Dialect dialect) { 58 | this.dialect = dialect; 59 | } 60 | 61 | public Dialect getDialect(){ 62 | return this.dialect; 63 | } 64 | 65 | public void setSchema(Schema schema) { 66 | this.schema = schema; 67 | } 68 | 69 | @Override 70 | public String parseAndGetSql(Class clzz){ 71 | 72 | if (schema == null) { 73 | throw new UnsupportedOperationException("Not support temporary table, dialect: " + dialect.getKey() + 74 | ", try to implements Schema, and configure it"); 75 | } 76 | 77 | String sql = sqlMap.get(clzz); 78 | if (sql != null) 79 | return sql; 80 | 81 | synchronized (lock) { 82 | Parsed parsed = Parser.get(clzz.getSimpleName()); 83 | if (parsed != null) 84 | throw new ParsingException("Table exists while parse temporary table entity to get sql: " + clzz.getName()); 85 | Parser.parse(clzz); 86 | parsed = Parser.get(clzz); 87 | 88 | String createTableSql = schema.createTableSqlUnMapped(parsed, true); 89 | createTableSql = SqlParserUtil.mapper(createTableSql, parsed); 90 | sqlMap.put(clzz, createTableSql); 91 | return createTableSql; 92 | } 93 | } 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/filter/BaseTypeFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.filter; 20 | 21 | import io.xream.sqli.builder.internal.SqlScript; 22 | import io.xream.sqli.mapping.Mappable; 23 | import io.xream.sqli.parser.BeanElement; 24 | import io.xream.sqli.parser.Parsed; 25 | import io.xream.sqli.parser.Parser; 26 | 27 | 28 | /** 29 | * @author Sim 30 | */ 31 | public final class BaseTypeFilter { 32 | 33 | public static boolean baseTypeSupported = false; 34 | 35 | public static boolean isBaseType(String key, Object v, Mappable m) { 36 | if (! baseTypeSupported) 37 | return false; 38 | String[] arr = key.split("\\."); 39 | String alia = arr[0]; 40 | String clzName = m.getAliaMap().get(alia); 41 | if (clzName == null) 42 | clzName = alia; 43 | Parsed parsed = Parser.get(clzName); 44 | 45 | return isBaseType(arr[1],v,parsed); 46 | } 47 | 48 | public static boolean isBaseType(String prop, Object v, Parsed parsed) { 49 | 50 | if (!baseTypeSupported) 51 | return false; 52 | 53 | if (v instanceof String) 54 | return false; 55 | 56 | double d = 0; 57 | try { 58 | d = Double.valueOf(v.toString()); 59 | if (d != 0) return false; 60 | } catch (Exception e) { 61 | return false; 62 | } 63 | 64 | BeanElement be = getBeanElement(prop, parsed); 65 | 66 | if (be == null) { 67 | return false; //FIXME 68 | } 69 | 70 | Class vType = be.getClz(); 71 | 72 | return vType == int.class || vType == long.class || vType == float.class 73 | || vType == double.class 74 | || vType == short.class 75 | || vType == byte.class ; 76 | } 77 | 78 | private static BeanElement getBeanElement(String prop, Parsed parsed) { 79 | 80 | String property = prop; 81 | String str = null; 82 | if (property.contains(SqlScript.SPACE)) { 83 | String[] arr = property.split(SqlScript.SPACE); 84 | str = arr[0]; 85 | } else { 86 | str = property; 87 | } 88 | if (str.contains(SqlScript.DOT)) { 89 | String[] xxx = str.split("\\."); 90 | if (xxx.length == 1) 91 | property = xxx[0]; 92 | else 93 | property = xxx[1]; 94 | } else { 95 | property = str; 96 | } 97 | 98 | return parsed.getElement(property); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/DialectSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import io.xream.sqli.exception.ParsingException; 22 | import io.xream.sqli.exception.PersistenceException; 23 | import io.xream.sqli.parser.BeanElement; 24 | import io.xream.sqli.parser.Parsed; 25 | import io.xream.sqli.util.EnumUtil; 26 | import io.xream.sqli.util.SqliExceptionUtil; 27 | import io.xream.sqli.util.SqliJsonUtil; 28 | 29 | import java.lang.reflect.Field; 30 | import java.util.List; 31 | 32 | /** 33 | * @author Sim 34 | */ 35 | public interface DialectSupport { 36 | 37 | String getKey(); 38 | 39 | Object convertJsonToPersist(Object json); 40 | 41 | String getAlterTableUpdate(); 42 | String getAlterTableDelete(); 43 | String getCommandUpdate(); 44 | String getCommandDelete(); 45 | 46 | String getLimitOne(); 47 | 48 | String getInsertTagged(); 49 | 50 | Object filterValue(Object value); 51 | 52 | void filterTags(List list,List tagList); 53 | List objectToListForCreate(Object obj, Parsed parsed); 54 | 55 | default void objectToListForCreate(List list, Object obj, List tempList) { 56 | 57 | try { 58 | for (BeanElement ele : tempList) { 59 | Object value = ele.getGetMethod().invoke(obj); 60 | Class clz = ele.getClz(); 61 | if (value == null) { 62 | if (EnumUtil.isEnum(clz)) 63 | throw new PersistenceException( 64 | "ENUM CAN NOT NULL, property:" + obj.getClass().getName() + "." + ele.getProperty()); 65 | // if (clz == Boolean.class || clz == Integer.class || clz == Long.class 66 | // || clz == Double.class || clz == Float.class || clz == BigDecimal.class 67 | // || clz == Byte.class || clz == Short.class) 68 | // list.add(0); 69 | // else 70 | list.add(null); 71 | } else { 72 | if (ele.isJson()) { 73 | String str = SqliJsonUtil.toJson(value); 74 | Object jsonStr = convertJsonToPersist(str); 75 | list.add(jsonStr); 76 | } else if (EnumUtil.isEnum(clz)) { 77 | list.add(EnumUtil.serialize((Enum) value)); 78 | } else { 79 | value = filterValue(value); 80 | list.add(value); 81 | } 82 | } 83 | } 84 | } catch (Exception e) { 85 | SqliExceptionUtil.throwRuntimeExceptionFirst(e); 86 | throw new ParsingException(e); 87 | } 88 | 89 | 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /sqli-builder/src/main/java/io/xream/sqli/builder/internal/SqlScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 io.xream.sqli 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package io.xream.sqli.builder.internal; 20 | 21 | import io.xream.sqli.mapping.Script; 22 | 23 | import java.util.Arrays; 24 | import java.util.List; 25 | 26 | /** 27 | * @author Sim 28 | */ 29 | public interface SqlScript extends Script { 30 | 31 | List SOURCE_SCRIPT = Arrays.asList("INNER","LEFT","RIGHT","OUTER","JOIN",",","FULL","ON", "AND","OR","LIKE", "!=", "<=", ">=", "<>", "=", "<",">", "(",")"); 32 | 33 | String[] KEYWORDS = { 34 | "order", 35 | "state", 36 | "desc", 37 | "group", 38 | "asc", 39 | "key", 40 | "select", 41 | "delete", 42 | "from", 43 | "update", 44 | "create", 45 | "drop", 46 | "dump", 47 | "alter", 48 | "all", 49 | "distinct", 50 | "table", 51 | "column", 52 | "database", 53 | "left", 54 | "right", 55 | "inner", 56 | "join", 57 | "union", 58 | "natural", 59 | "between", 60 | "except", 61 | "in", 62 | "as", 63 | "into", 64 | "set", 65 | "values", 66 | "min", 67 | "max", 68 | "sum", 69 | "avg", 70 | "count", 71 | "on", 72 | "where", 73 | "and", 74 | "add", 75 | "index", 76 | "exists", 77 | "or", 78 | "null", 79 | "is", 80 | "not", 81 | "by", 82 | "having", 83 | "concat", 84 | "cast", 85 | "convert", 86 | "case", 87 | "when", 88 | "like", 89 | "replace", 90 | "primary", 91 | "foreign", 92 | "references", 93 | "char", 94 | "varchar", 95 | "varchar2", 96 | "int", 97 | "bigint", 98 | "smallint", 99 | "tinyint", 100 | "text", 101 | "longtext", 102 | "tinytext", 103 | "decimal", 104 | "numeric", 105 | "float", 106 | "double", 107 | "timestamp", 108 | "date", 109 | "real", 110 | "precision", 111 | "date", 112 | "datetime", 113 | "boolean", 114 | "bool", 115 | "blob", 116 | "now", 117 | "function", 118 | "procedure", 119 | "trigger" 120 | }; 121 | 122 | String ALTER_TABLE = "ALTER TABLE"; 123 | String SELECT = "SELECT"; 124 | String DISTINCT = "DISTINCT"; 125 | String WHERE = " WHERE "; 126 | String FROM = "FROM"; 127 | String LIMIT = " LIMIT "; 128 | String OFFSET = " OFFSET "; 129 | String SET = "SET"; 130 | String UPDATE = "UPDATE"; 131 | String DELETE = " DELETE "; 132 | String DELETE_FROM = "DELETE FROM"; 133 | String IN = " IN "; 134 | String ON = " ON "; 135 | 136 | String AS = " AS "; 137 | 138 | String PLACE_HOLDER = "?"; 139 | String EQ_PLACE_HOLDER = " = ?"; 140 | String LIKE_HOLDER = "%"; 141 | String COMMA = ","; 142 | String STAR = "*"; 143 | String UNDER_LINE = "_"; 144 | String DOLLOR = "$"; 145 | String SINGLE_QUOTES = "'"; 146 | String KEYWORD_MARK = "`"; 147 | String SUB = "${SUB}"; 148 | String WITH_PLACE = "${WP}"; 149 | String LIMIT_ONE = " LIMIT 1"; 150 | 151 | String CREATE_TEMPORARY_TABLE = "CREATE TEMPORARY TABLE IF NOT EXISTS "; 152 | 153 | String sql(); 154 | } 155 | --------------------------------------------------------------------------------