This commit is contained in:
@@ -7,8 +7,6 @@ package org.redkale.test.util;
|
|||||||
|
|
||||||
import java.math.*;
|
import java.math.*;
|
||||||
import javax.annotation.*;
|
import javax.annotation.*;
|
||||||
import org.redkale.convert.*;
|
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,139 +15,139 @@ import org.redkale.util.*;
|
|||||||
*/
|
*/
|
||||||
public class ResourceTest {
|
public class ResourceTest {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
ResourceFactory factory = ResourceFactory.root();
|
ResourceFactory factory = ResourceFactory.root();
|
||||||
factory.register("property.id", "2345");
|
factory.register("property.id", "2345"); //注入String类型的property.id
|
||||||
TestService service = new TestService();
|
AService aservice = new AService();
|
||||||
TwinService twinService = new TwinService("eeeee");
|
BService bservice = new BService("eeeee");
|
||||||
|
|
||||||
factory.register(service);
|
factory.register(aservice); //放进Resource池内,默认的资源名name为""
|
||||||
factory.register(twinService);
|
factory.register(bservice); //放进Resource池内,默认的资源名name为""
|
||||||
|
|
||||||
factory.inject(service);
|
factory.inject(aservice); //给aservice注入id、bservice,bigint没有资源,所以为null
|
||||||
System.out.println("--------------------------------------");
|
factory.inject(bservice); //给bservice注入id、aservice
|
||||||
factory.inject(twinService);
|
System.out.println(aservice); //输出结果为:{id:"2345", intid: 2345, bigint:null, bservice:{name:eeeee}}
|
||||||
System.out.println(service);
|
System.out.println(bservice); //输出结果为:{name:"eeeee", id: 2345, aserivce:{id:"2345", intid: 2345, bigint:null, bservice:{name:eeeee}}}
|
||||||
System.out.println(twinService);
|
|
||||||
factory.register("seqid", 200);
|
factory.register("seqid", 200); //放进Resource池内, 同时ResourceFactory会自动更新aservice的seqid值
|
||||||
factory.register("bigint", new BigInteger("666666666666666"));
|
System.out.println(factory.find("seqid", int.class)); //输出结果为:200
|
||||||
System.out.println(factory.find("seqid", int.class));
|
factory.register("bigint", new BigInteger("666666666666666")); //放进Resource池内, 同时ResourceFactory会自动更新aservice对象的bigint值
|
||||||
factory.register("property.id", "6789");
|
System.out.println(aservice); //输出结果为:{id:"2345", intid: 2345, bigint:666666666666666, bservice:{name:eeeee}} 可以看出seqid与bigint值都已自动更新
|
||||||
twinService = new TwinService("ffff");
|
|
||||||
factory.inject(twinService);
|
factory.register("property.id", "6789"); //更新Resource池内的id资源值, 同时ResourceFactory会自动更新aservice、bservice的id值
|
||||||
factory.register(twinService);
|
System.out.println(aservice); //输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}}
|
||||||
System.out.println(service);
|
System.out.println(bservice); //输出结果为:{name:"eeeee", id: 6789, aserivce:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}}}
|
||||||
System.out.println(twinService);
|
|
||||||
factory.register("seqid", int.class, null);
|
bservice = new BService("ffff");
|
||||||
System.out.println(service);
|
factory.register(bservice); //更新Resource池内name=""的BService资源, 同时ResourceFactory会自动更新aservice的bservice对象
|
||||||
|
factory.inject(bservice);
|
||||||
|
System.out.println(aservice); //输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:ffff}}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class BService {
|
||||||
|
|
||||||
|
@Resource(name = "property.id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AService aservice;
|
||||||
|
|
||||||
|
private String name = "";
|
||||||
|
|
||||||
|
@java.beans.ConstructorProperties({"name"})
|
||||||
|
public BService(String name) {
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TwinService {
|
public String getName() {
|
||||||
|
return name;
|
||||||
@Resource(name = "property.id")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private TestService service;
|
|
||||||
|
|
||||||
private String name = "";
|
|
||||||
|
|
||||||
@java.beans.ConstructorProperties({"name"})
|
|
||||||
public TwinService(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestService getService() {
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setService(TestService service) {
|
|
||||||
this.service = service;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "{name:\"" + name + "\", id: " + id + ", serivce:" + service + "}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestService {
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
@Resource(name = "property.id")
|
public String getId() {
|
||||||
private String id;
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
@Resource(name = "property.id")
|
public void setId(String id) {
|
||||||
private int intid;
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
@Resource(name = "bigint")
|
public AService getAservice() {
|
||||||
private BigInteger bigint;
|
return aservice;
|
||||||
|
}
|
||||||
|
|
||||||
@Resource(name = "seqid")
|
public void setAservice(AService aservice) {
|
||||||
private int seqid;
|
this.aservice = aservice;
|
||||||
|
}
|
||||||
|
|
||||||
@Resource
|
@Override
|
||||||
private TwinService service;
|
public String toString() {
|
||||||
|
return "{name:\"" + name + "\", id: " + id + ", aserivce:" + aservice + "}";
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIntid() {
|
|
||||||
return intid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIntid(int intid) {
|
|
||||||
this.intid = intid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSeqid() {
|
|
||||||
return seqid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSeqid(int seqid) {
|
|
||||||
this.seqid = seqid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigInteger getBigint() {
|
|
||||||
return bigint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBigint(BigInteger bigint) {
|
|
||||||
this.bigint = bigint;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConvertColumn(ignore = true)
|
|
||||||
public TwinService getService() {
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setService(TwinService service) {
|
|
||||||
this.service = service;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return JsonConvert.root().convertTo(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AService {
|
||||||
|
|
||||||
|
@Resource(name = "property.id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Resource(name = "property.id") //property.开头的资源名允许String自动转换成primitive数值类型
|
||||||
|
private int intid;
|
||||||
|
|
||||||
|
@Resource(name = "bigint")
|
||||||
|
private BigInteger bigint;
|
||||||
|
|
||||||
|
@Resource(name = "seqid")
|
||||||
|
private int seqid;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BService bservice;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{id:\"" + id + "\", intid: " + intid + ", bigint:" + bigint + ", bservice:" + (bservice == null ? null : ("{name:" + bservice.getName() + "}")) + "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIntid() {
|
||||||
|
return intid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIntid(int intid) {
|
||||||
|
this.intid = intid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSeqid() {
|
||||||
|
return seqid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeqid(int seqid) {
|
||||||
|
this.seqid = seqid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigInteger getBigint() {
|
||||||
|
return bigint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBigint(BigInteger bigint) {
|
||||||
|
this.bigint = bigint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBservice(BService bservice) {
|
||||||
|
this.bservice = bservice;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user