|
|
@@ -20,8 +20,10 @@ import java.util.concurrent.ConcurrentHashMap; |
|
|
|
* Created by Akmm at 2022/3/17 19:56 |
|
|
|
*/ |
|
|
|
public class TreeHelper<T extends DefaultEntity> { |
|
|
|
private static Map<String, Class<? extends TreeHelper>> mapDef; |
|
|
|
private static Map<String, TreeHelper> mapInstance; |
|
|
|
static { |
|
|
|
mapDef = new HashMap<>(); |
|
|
|
mapInstance = new ConcurrentHashMap<>(); |
|
|
|
} |
|
|
|
private String tableName; |
|
|
@@ -36,20 +38,24 @@ public class TreeHelper<T extends DefaultEntity> { |
|
|
|
|
|
|
|
|
|
|
|
public static TreeHelper getTreeHelper(String tableName) { |
|
|
|
return mapInstance.computeIfAbsent(tableName, k-> new TreeHelper(tableName)); |
|
|
|
} |
|
|
|
|
|
|
|
public static TreeHelper getTreeHelper(String tableName, Class<? extends TreeHelper> clazz) { |
|
|
|
TreeHelper helper = mapInstance.get(tableName); |
|
|
|
if (helper == null) { |
|
|
|
TreeHelper bean = mapInstance.get(tableName); |
|
|
|
if (bean != null) return bean; |
|
|
|
Class<? extends TreeHelper> clazz = mapDef.get(tableName); |
|
|
|
if (clazz == null) { |
|
|
|
bean = new TreeHelper(tableName); |
|
|
|
} else { |
|
|
|
try { |
|
|
|
helper = clazz.newInstance(); |
|
|
|
mapInstance.put(tableName, helper); |
|
|
|
bean = clazz.newInstance(); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new SwException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
return helper; |
|
|
|
mapInstance.put(tableName, bean); |
|
|
|
return bean; |
|
|
|
} |
|
|
|
|
|
|
|
public static void regTreeHelper(String tableName, Class<? extends TreeHelper> clazz) { |
|
|
|
mapDef.put(tableName, clazz); |
|
|
|
} |
|
|
|
|
|
|
|
//先禁止外部创建 |
|
|
|