Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql支持数组的方式,类似Mybatis #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
### Eclipse template

.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
2 changes: 1 addition & 1 deletion src/main/java/org/jfaster/mango/annotation/SQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
*
* @return
*/
String value();
String[] value();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.jfaster.mango.annotation.*;
import org.jfaster.mango.exception.DescriptionException;
import org.jfaster.mango.util.Joiner;
import org.jfaster.mango.util.Strings;
import org.jfaster.mango.util.logging.InternalLogger;
import org.jfaster.mango.util.logging.InternalLoggerFactory;
Expand All @@ -26,6 +27,7 @@
import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -104,7 +106,11 @@ public String getSQL() {
SQL sqlAnno = getAnnotation(SQL.class);
String sql;
if (sqlAnno != null) {
sql = sqlAnno.value();
String[] fragments = sqlAnno.value();
if (fragments.length == 0) {
throw new DescriptionException("sql is null or empty");
}
sql = Joiner.on(' ').join(Arrays.asList(fragments)).trim();
} else {
UseSqlGenerator useSqlGeneratorAnno = getAnnotation(UseSqlGenerator.class);
if (useSqlGeneratorAnno == null) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jfaster/mango/plugin/stats/ExtendStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
package org.jfaster.mango.plugin.stats;

import org.jfaster.mango.annotation.DB;
import org.jfaster.mango.annotation.SQL;
import org.jfaster.mango.annotation.Sharding;
import org.jfaster.mango.sharding.NotUseTableShardingStrategy;
import org.jfaster.mango.stat.OperatorStat;
import org.jfaster.mango.util.Joiner;
import org.jfaster.mango.util.Strings;
import org.jfaster.mango.util.ToStringHelper;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -51,8 +54,8 @@ public String getSimpleMethodName() {
}

public String getSql() {
String sql = operatorStat.getSql();
DB dbAnno = operatorStat.getDaoClass().getAnnotation(DB.class);
String sql = Joiner.on(' ').join(Arrays.asList(method.getAnnotation(SQL.class).value()));
DB dbAnno = method.getDeclaringClass().getAnnotation(DB.class);
String table = dbAnno.table();
if (Strings.isNotEmpty(table)) {
Sharding shardingAnno = method.getAnnotation(Sharding.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import java.util.List;

/**
* 测试{@link org.jfaster.mango.operator.IncorrectSqlException}
* 测试{@link org.jfaster.mango.exception.DescriptionException}
* 测试{@link org.jfaster.mango.parser.SqlParserException}
*
* @author ash
*/
Expand Down Expand Up @@ -81,6 +82,13 @@ public void test5() {
dao.gets(new ArrayList<Integer>(), new ArrayList<Integer>());
}

@Test
public void test6() {
thrown.expect(DescriptionException.class);
Dao dao = mango.create(Dao.class);
dao.add4();
}

@DB
@Cache(prefix = "dao_", expire = Day.class)
static interface Dao {
Expand All @@ -93,6 +101,9 @@ static interface Dao {
@SQL("test")
public int add3();

@SQL({})
public int add4();

@SQL("select ... where a in (:1) and b in (:2)")
public List<Integer> gets(@CacheBy List<Integer> a, List<Integer> b);
}
Expand Down
10 changes: 7 additions & 3 deletions src/test/java/org/jfaster/mango/support/MockSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
*/
public class MockSQL implements Annotation, SQL {

private String value;
private String[] value;

public MockSQL(String value) {
public MockSQL(String[] value) {
this.value = value;
}

public MockSQL(String value) {
this.value = new String[]{value};
}

@Override
public String value() {
public String[] value() {
return value;
}

Expand Down