-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #701: cache sql parser result for (prepare) statement
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
sharding-core/src/main/java/io/shardingjdbc/core/parsing/ParsingResultCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 1999-2015 dangdang.com. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* </p> | ||
*/ | ||
|
||
package io.shardingjdbc.core.parsing; | ||
|
||
import io.shardingjdbc.core.parsing.parser.sql.SQLStatement; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Map; | ||
import java.util.WeakHashMap; | ||
|
||
/** | ||
* Parsing result cache. | ||
* | ||
* @author zhangliang | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.NONE) | ||
public final class ParsingResultCache { | ||
|
||
private static final ParsingResultCache INSTANCE = new ParsingResultCache(); | ||
|
||
private volatile Map<String, SQLStatement> cache = new WeakHashMap<>(65535, 1); | ||
|
||
/** | ||
* Get parsing result cache instance. | ||
* | ||
* @return parsing result cache instance | ||
*/ | ||
public static ParsingResultCache getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
/** | ||
* Put SQL and parsing result into cache. | ||
* | ||
* @param sql SQL | ||
* @param sqlStatement SQL statement | ||
*/ | ||
public void put(final String sql, final SQLStatement sqlStatement) { | ||
cache.put(sql, sqlStatement); | ||
} | ||
|
||
/** | ||
* Get SQL statement. | ||
* | ||
* @param sql SQL | ||
* @return SQL statement | ||
*/ | ||
public SQLStatement getSQLStatement(final String sql) { | ||
return cache.get(sql); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters