You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by xi...@apache.org on 2020/11/19 12:23:16 UTC

[shardingsphere] branch master updated: Create new constructor to accept cache option (#8232)

This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 14860e2  Create new constructor to accept cache option (#8232)
14860e2 is described below

commit 14860e2c458c409a1fc3e58787d04da426097331
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Nov 19 20:22:49 2020 +0800

    Create new constructor to accept cache option (#8232)
---
 .../shardingsphere/sql/parser/api/CacheOption.java | 35 ++++++++++++++++++++++
 .../sql/parser/api/SQLParserEngine.java            | 14 +++++++--
 2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/CacheOption.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/CacheOption.java
new file mode 100644
index 0000000..5031634
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/CacheOption.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sql.parser.api;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * Cache option.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class CacheOption {
+    
+    private final int initialCapacity;
+    
+    private final long maximumSize;
+    
+    private final int concurrencyLevel;
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/SQLParserEngine.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/SQLParserEngine.java
index cc924aa..6753fe1 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/SQLParserEngine.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/SQLParserEngine.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sql.parser.api;
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
-import lombok.RequiredArgsConstructor;
 import org.antlr.v4.runtime.BailErrorStrategy;
 import org.antlr.v4.runtime.Parser;
 import org.antlr.v4.runtime.atn.PredictionMode;
@@ -36,12 +35,21 @@ import java.util.Optional;
 /**
  * SQL parser engine.
  */
-@RequiredArgsConstructor
 public final class SQLParserEngine {
     
     private final String databaseType;
     
-    private final Cache<String, ParseTree> cache = CacheBuilder.newBuilder().softValues().initialCapacity(2000).maximumSize(65535).build();
+    private final Cache<String, ParseTree> cache;
+    
+    public SQLParserEngine(final String databaseType) {
+        this(databaseType, new CacheOption(128, 1024L, 4));
+    }
+    
+    public SQLParserEngine(final String databaseType, final CacheOption cacheOption) {
+        this.databaseType = databaseType;
+        cache = CacheBuilder.newBuilder().softValues()
+                .initialCapacity(cacheOption.getInitialCapacity()).maximumSize(cacheOption.getMaximumSize()).concurrencyLevel(cacheOption.getConcurrencyLevel()).build();
+    }
     
     /**
      * Parse SQL.