forked from MyCATApache/abandomed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MyCATApache#23 from karakapi/master
List<SQLAnnotation>
- Loading branch information
Showing
10 changed files
with
234 additions
and
57 deletions.
There are no files selected for viewing
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
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
35 changes: 32 additions & 3 deletions
35
source/src/main/java/io/mycat/mycat2/sqlannotations/SQLAnnotation.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 |
---|---|---|
@@ -1,13 +1,42 @@ | ||
package io.mycat.mycat2.sqlannotations; | ||
|
||
import io.mycat.mycat2.sqlparser.BufferSQLContext; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Created by jamie on 2017/9/15. | ||
*/ | ||
public interface SQLAnnotation<T> extends Function<T, T> { | ||
boolean isDebug=true; | ||
void init(Map<String,String> args); | ||
public abstract class SQLAnnotation { | ||
static final boolean isDebug=true; | ||
String method; | ||
abstract public void init(Map<String,String> args); | ||
abstract public BufferSQLContext apply(BufferSQLContext t); | ||
|
||
public String getMethod() { | ||
return method; | ||
} | ||
|
||
public void setMethod(String method) { | ||
this.method = method; | ||
} | ||
Map<String,String> args; | ||
|
||
public Map<String, String> getArgs() { | ||
return args; | ||
} | ||
|
||
public void setArgs(Map<String, String> args) { | ||
this.args = args; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SQLAnnotation{" + | ||
"method='" + method + '\'' + | ||
", args=" + args + | ||
'}'; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
source/src/main/java/io/mycat/mycat2/sqlannotations/SQLAnnotationList.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,39 @@ | ||
package io.mycat.mycat2.sqlannotations; | ||
|
||
import io.mycat.mycat2.sqlparser.BufferSQLContext; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by jamie on 2017/9/23. | ||
*/ | ||
public class SQLAnnotationList { | ||
List<SQLAnnotation> sqlAnnotations; | ||
public SQLAnnotationList() { | ||
this.sqlAnnotations = new ArrayList<>(); | ||
} | ||
|
||
public List<SQLAnnotation> getSqlAnnotations() { | ||
return sqlAnnotations; | ||
} | ||
|
||
public void setSqlAnnotations(List<SQLAnnotation> sqlAnnotations) { | ||
this.sqlAnnotations = sqlAnnotations; | ||
} | ||
|
||
public BufferSQLContext apply(BufferSQLContext context){ | ||
int size=sqlAnnotations.size(); | ||
for (int i = 0; i <size ; i++) { | ||
sqlAnnotations.get(i).apply(context); | ||
} | ||
return context; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SQLAnnotationList{" + | ||
"sqlAnnotations=" + sqlAnnotations + | ||
'}'; | ||
} | ||
} |
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
24 changes: 18 additions & 6 deletions
24
...mycat/mycat2/sqlparser/byteArrayInterface/dynamicAnnotation/DynamicAnnotationManager.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 |
---|---|---|
@@ -1,33 +1,45 @@ | ||
package io.mycat.mycat2.sqlparser.byteArrayInterface.dynamicAnnotation; | ||
|
||
import io.mycat.mycat2.sqlannotations.SQLAnnotation; | ||
import io.mycat.mycat2.sqlannotations.SQLAnnotationList; | ||
import io.mycat.mycat2.sqlparser.BufferSQLContext; | ||
import io.mycat.mycat2.sqlparser.byteArrayInterface.dynamicAnnotation.impl.DynamicAnnotation; | ||
import io.mycat.mycat2.sqlparser.byteArrayInterface.dynamicAnnotation.impl.DynamicAnnotationKeyRoute; | ||
import io.mycat.mycat2.sqlparser.byteArrayInterface.dynamicAnnotation.impl.SQLType; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by jamie on 2017/9/19. | ||
*/ | ||
public interface DynamicAnnotationManager { | ||
|
||
|
||
public Runnable process(int schema, int sqltype, int[] tables,BufferSQLContext context) throws Exception ; | ||
public Runnable process(int schema, int sqltype, int[] tables, BufferSQLContext context) throws Exception; | ||
|
||
/** | ||
* 动态注解先匹配chema的名字,再sql类型,在匹配表名,在匹配条件 | ||
* | ||
* @param | ||
* @return | ||
*/ | ||
//public void processNow(int schema, int sqltype, int[] tables, BufferSQLContext context) throws Exception ; | ||
|
||
public default Runnable process(String schema, SQLType sqltype, int[] tables, BufferSQLContext context) throws Exception { | ||
|
||
return process(schema.hashCode(), sqltype.getValue(), tables, context); | ||
} | ||
|
||
public default Runnable process(String schema, SQLType sqltype, String[] tables, BufferSQLContext context) throws Exception { | ||
return process(schema.hashCode(), sqltype.getValue(), DynamicAnnotationKeyRoute.stringArray2HashArray(tables), context); | ||
} | ||
} | ||
|
||
public void collectInSQLAnnotationList(int schema, int sqltype, int[] tables, BufferSQLContext context, List<SQLAnnotationList> collect)throws Exception; | ||
public default void collectInSQLAnnotationList(String schema, SQLType sqltype, int[] tables, BufferSQLContext context, List<SQLAnnotationList> collect) throws Exception { | ||
collectInSQLAnnotationList(schema.hashCode(), sqltype.getValue(), tables, context,collect); | ||
} | ||
public void collect(int schema, int sqltype, int[] tables, BufferSQLContext context, List<SQLAnnotation> collect)throws Exception; | ||
public default void collect(String schema, SQLType sqltype, int[] tables, BufferSQLContext context, List<SQLAnnotation> collect) throws Exception { | ||
collect(schema.hashCode(), sqltype.getValue(), tables, context,collect); | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.