Skip to content

Commit

Permalink
complete configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1t3p1g committed Oct 10, 2020
1 parent 74f3a3b commit bd8bb6a
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/tabby/dal/cache/CacheHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tabby.dal.cache;

import tabby.bean.ref.ClassReference;
import tabby.bean.ref.MethodReference;

/**
* @author wh1t3P1g
* @since 2020/10/10
*/
public interface CacheHelper {

public <T> void add(T ref);

public <T> void remove(T ref);

public void clear(String type);

public <T> void update(T ref);

public void save(String path);

public void loadFromFile(String path);

public ClassReference loadClassRef(String name);

public ClassReference loadClassRefByHandle(ClassReference.Handle handle);

public MethodReference loadMethodRef(ClassReference.Handle classReference, String name, String signature);

public MethodReference loadMethodRefByHandle(MethodReference.Handle handle);
}
103 changes: 103 additions & 0 deletions src/main/java/tabby/dal/cache/CacheHelperImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package tabby.dal.cache;

import tabby.bean.ref.ClassReference;
import tabby.bean.ref.MethodReference;

import java.util.HashMap;
import java.util.Map;

/**
* @author wh1t3P1g
* @since 2020/10/10
* 这里实际选择用内存作为cache
*/
public class CacheHelperImpl implements CacheHelper{

private Map<ClassReference.Handle, ClassReference> savedClassRefs = new HashMap<>();
private Map<MethodReference.Handle, MethodReference> savedMethodRefs = new HashMap<>();

@Override
public <T> void add(T ref) {
if(ref instanceof ClassReference){
ClassReference classRef = (ClassReference) ref;
savedClassRefs.put(classRef.getHandle(), classRef);
}else if(ref instanceof MethodReference){
MethodReference methodRef = (MethodReference) ref;
savedMethodRefs.put(methodRef.getHandle(), methodRef);
}
}

@Override
public <T> void remove(T ref) {
if(ref instanceof ClassReference){
ClassReference classRef = (ClassReference) ref;
savedClassRefs.remove(classRef.getHandle());
}else if(ref instanceof MethodReference){
MethodReference methodRef = (MethodReference) ref;
savedMethodRefs.remove(methodRef.getHandle());
}
}

@Override
public void clear(String type) {
if("class".equals(type)){
savedClassRefs.clear();
}else if("method".equals(type)){
savedMethodRefs.clear();
}else{
savedMethodRefs.clear();
savedClassRefs.clear();
}
}

@Override
public <T> void update(T ref) {
if(ref instanceof ClassReference){
ClassReference classRef = (ClassReference) ref;
if(savedClassRefs.containsKey(classRef.getHandle())){
savedClassRefs.replace(classRef.getHandle(), classRef);
return;
}
}else if(ref instanceof MethodReference){
MethodReference methodRef = (MethodReference) ref;
if(savedMethodRefs.containsKey(methodRef.getHandle())){
savedMethodRefs.replace(methodRef.getHandle(), methodRef);
return;
}
}
// 不存在相应的key,选择新增
add(ref);
}

@Override
public void save(String path) {
// TODO 保存到文件
}

@Override
public void loadFromFile(String path) {
// TODO 从文件中恢复以前的解析内容
}

@Override
public ClassReference loadClassRef(String name) {
ClassReference.Handle handle = new ClassReference.Handle(name);
return loadClassRefByHandle(handle);
}

@Override
public ClassReference loadClassRefByHandle(ClassReference.Handle handle) {
return savedClassRefs.get(handle);
}

@Override
public MethodReference loadMethodRef(ClassReference.Handle classReference, String name, String signature) {
MethodReference.Handle handle = new MethodReference.Handle(classReference, name, signature);
return loadMethodRefByHandle(handle);
}

@Override
public MethodReference loadMethodRefByHandle(MethodReference.Handle handle) {
return savedMethodRefs.get(handle);
}
}

0 comments on commit bd8bb6a

Please sign in to comment.