public class CollatorProvider extends Object
关键设计:
Collator 非线程安全,使用 ThreadLocal 缓存
使用示例:
CollatorProvider provider = new CollatorProvider();
// 获取 Collator(自动 ThreadLocal 缓存)
Collator collator = provider.getCollator("SQL_Latin1_General_CP1_CI_AS");
// 比较标识符
int result = collator.compare("MyTable", "MYTABLE");
// CI (Case Insensitive): result == 0
// CS (Case Sensitive): result != 0
性能特性:
| Constructor and Description |
|---|
CollatorProvider() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearCache()
清理缓存(用于测试或内存管理)
|
int |
getCacheSize()
获取缓存大小(不同 collation 的数量)
|
Collator |
getCollator(String collationName)
获取 Collator 实例(ThreadLocal 缓存)
|
int |
testCompare(String collationName,
String str1,
String str2)
测试 collation 比较(用于调试)
|
public CollatorProvider()
public Collator getCollator(String collationName)
此方法线程安全,每个线程获得独立的 Collator 实例。
collationName - SQL Server collation 名称(例如:SQL_Latin1_General_CP1_CI_AS)public void clearCache()
警告:调用此方法后,所有线程的 Collator 实例将失效,下次访问时重新创建。
public int getCacheSize()
public int testCompare(String collationName, String str1, String str2)
collationName - collation 名称str1 - 字符串 1str2 - 字符串 2