Browse Source

Merging in latest from upstream (TC/finekit:refs/heads/master)

* commit 'a64da28c498ccc446af75d3085793ca5973b5ff4':
  参数工具类
pull/19/head
Mars.Ma 5 years ago
parent
commit
e5cbabb37e
  1. 37
      src/main/java/com/fanruan/api/cal/ParameterKit.java
  2. 17
      src/test/java/com/fanruan/api/cal/ParameterKitTest.java
  3. 8
      src/test/java/com/fanruan/api/plugin/PluginKitTest.java
  4. 12
      src/test/java/com/fanruan/api/plugin/TestExtraClass.java

37
src/main/java/com/fanruan/api/cal/ParameterKit.java

@ -1,8 +1,11 @@
package com.fanruan.api.cal; package com.fanruan.api.cal;
import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.util.AssistKit;
import com.fr.base.Parameter; import com.fr.base.Parameter;
import com.fr.base.ParameterHelper; import com.fr.base.ParameterHelper;
import com.fr.base.ParameterMapNameSpace; import com.fr.base.ParameterMapNameSpace;
import com.fr.stable.ArrayUtils;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fr.stable.script.NameSpace; import com.fr.stable.script.NameSpace;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -39,6 +42,7 @@ public class ParameterKit {
/** /**
* 根据参数名创建新的参数对象 * 根据参数名创建新的参数对象
*
* @param name 参数名 * @param name 参数名
* @return 参数对象 * @return 参数对象
*/ */
@ -98,15 +102,38 @@ public class ParameterKit {
public static @NotNull NameSpace createParameterMapNameSpace(ParameterProvider[] ps) { public static @NotNull NameSpace createParameterMapNameSpace(ParameterProvider[] ps) {
return ParameterMapNameSpace.create(ps); return ParameterMapNameSpace.create(ps);
} }
/** /**
* 获得新的参数集合 * 获得新的参数集数组新的参数结中参数的值是通过设定的同名参数传递进去的
* *
* @param paramTexts sql语句 * @param paramTexts sql语句
* @param ps 旧的参数集合 * @param ps 用于传值的参数数组
* @return 新参数集合 * @return 新参数素组
*/ */
public static ParameterProvider[] analyzeAndUnionSameParameters(String[] paramTexts, Parameter[] ps){ public static ParameterProvider[] analyzeAndUnionSameParameters(String[] paramTexts, ParameterProvider[] ps) {
return ParameterHelper.analyzeAndUnionSameParameters(paramTexts, ps);
ParameterProvider[] parameters = ParameterKit.analyze4Parameters(paramTexts, false);
if (ArrayUtils.isEmpty(parameters)) {
return parameters;
}
if (ArrayKit.isNotEmpty(ps)) {
for (ParameterProvider newParameter : parameters) {
ParameterProvider existParameter = null;
for (ParameterProvider p : ps) {
if (AssistKit.equals(p.getName(), newParameter.getName())) {
existParameter = p;
break;
}
}
if (existParameter != null) {
newParameter.setValue(existParameter.getValue());
}
}
}
return parameters;
} }
} }

17
src/test/java/com/fanruan/api/cal/ParameterKitTest.java

@ -111,7 +111,22 @@ public class ParameterKitTest extends Prepare {
@Test @Test
public void newParameter2() { public void newParameter2() {
ParameterProvider provider = ParameterKit.newParameter("p1"); ParameterProvider provider = ParameterKit.newParameter("p1");
Assert.assertEquals(provider.getName(),"p1"); Assert.assertEquals(provider.getName(), "p1");
Assert.assertEquals("", provider.getValue()); Assert.assertEquals("", provider.getValue());
} }
@Test
public void analyzeAndUnionSameParameters() {
ParameterProvider p1 = ParameterKit.newParameter("p1", 100);
ParameterProvider p2 = ParameterKit.newParameter("p2", 200);
ParameterProvider[] providers = ParameterKit.analyzeAndUnionSameParameters(
new String[]{"select * from td where name = ${p1} and age = ${p3}"},
new ParameterProvider[]{p1, p2});
for (ParameterProvider provider : providers) {
if ("p1".equals(provider.getName())) {
Assert.assertEquals(100, provider.getValue());
}
}
}
} }

8
src/test/java/com/fanruan/api/plugin/PluginKitTest.java

@ -1,13 +1,13 @@
package com.fanruan.api.plugin; package com.fanruan.api.plugin;
import com.fanruan.api.runtime.PluginKit;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
public class PluginKitTest { public class PluginKitTest {
@Test @Test
public void getArray(){ public void getArray() {
PluginKit p1 = new PluginKit(); Assert.assertFalse(PluginKit.isCurrentPluginAvailable());
TestExtraClass p2 = new TestExtraClass();
Assert.assertEquals(p1.getArray("abcd"), p2.getArray("abcd"));
} }
} }

12
src/test/java/com/fanruan/api/plugin/TestExtraClass.java

@ -1,12 +0,0 @@
package com.fanruan.api.plugin;
import com.fr.plugin.injectable.PluginSingleInjection;
public class TestExtraClass extends com.fr.plugin.AbstractExtraClassManager{
protected boolean mountSpecific(PluginSingleInjection injection){
return true;
}
protected boolean demountSpecific(PluginSingleInjection injection){
return true;
}
}
Loading…
Cancel
Save