hugh
4 years ago
15 changed files with 761 additions and 0 deletions
@ -0,0 +1,124 @@
|
||||
|
||||
apply plugin: 'java' |
||||
|
||||
[compileJava,compileTestJava]*.options*.encoding = 'UTF-8' |
||||
|
||||
ext { |
||||
/** |
||||
* 项目中依赖的jar的路径 |
||||
* 1.如果依赖的jar需要打包到zip中,放置在lib根目录下 |
||||
* 2.如果依赖的jar仅仅是编译时需要,防止在lib下子目录下即可 |
||||
*/ |
||||
libPath = "$projectDir/../webroot/WEB-INF/lib" |
||||
|
||||
/** |
||||
* 是否对插件的class进行加密保护,防止反编译 |
||||
*/ |
||||
guard = false |
||||
|
||||
def pluginInfo = getPluginInfo() |
||||
pluginPre = "fine-plugin" |
||||
pluginName = pluginInfo.id |
||||
pluginVersion = pluginInfo.version |
||||
|
||||
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes" |
||||
} |
||||
|
||||
group = 'com.fr.plugin' |
||||
version = '10.0' |
||||
sourceCompatibility = '8' |
||||
|
||||
sourceSets { |
||||
main { |
||||
java.outputDir = file(outputPath) |
||||
output.resourcesDir = file(outputPath) |
||||
} |
||||
} |
||||
|
||||
ant.importBuild("encrypt.xml") |
||||
//定义ant变量 |
||||
ant.projectDir = projectDir |
||||
ant.references["compile.classpath"] = ant.path { |
||||
fileset(dir: libPath, includes: '**/*.jar') |
||||
fileset(dir: ".",includes:"**/*.jar" ) |
||||
} |
||||
|
||||
classes.dependsOn('clean') |
||||
|
||||
task copyFiles(type: Copy,dependsOn: 'classes'){ |
||||
from outputPath |
||||
into "$projectDir/classes" |
||||
} |
||||
|
||||
task preJar(type:Copy,dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas'){ |
||||
from "$projectDir/classes" |
||||
into "$projectDir/transform-classes" |
||||
include "**/*.*" |
||||
} |
||||
jar.dependsOn("preJar") |
||||
|
||||
task makeJar(type: Jar,dependsOn: preJar){ |
||||
from fileTree(dir: "$projectDir/transform-classes") |
||||
baseName pluginPre |
||||
appendix pluginName |
||||
version pluginVersion |
||||
destinationDir = file("$buildDir/libs") |
||||
|
||||
doLast(){ |
||||
delete file("$projectDir/classes") |
||||
delete file("$projectDir/transform-classes") |
||||
} |
||||
} |
||||
|
||||
task copyFile(type: Copy,dependsOn: ["makeJar"]){ |
||||
from "$buildDir/libs" |
||||
from("$projectDir/lib") { |
||||
include "*.jar" |
||||
} |
||||
from "$projectDir/plugin.xml" |
||||
into file("$buildDir/temp/plugin") |
||||
} |
||||
|
||||
task zip(type:Zip,dependsOn:["copyFile"]){ |
||||
from "$buildDir/temp/plugin" |
||||
destinationDir file("$buildDir/install") |
||||
baseName pluginPre |
||||
appendix pluginName |
||||
version pluginVersion |
||||
} |
||||
|
||||
//控制build时包含哪些文件,排除哪些文件 |
||||
processResources { |
||||
// exclude everything |
||||
// 用*.css没效果 |
||||
// exclude '**/*.css' |
||||
// except this file |
||||
// include 'xx.xml' |
||||
} |
||||
|
||||
/*读取plugin.xml中的version*/ |
||||
def getPluginInfo(){ |
||||
def xmlFile = file("plugin.xml") |
||||
if (!xmlFile.exists()) { |
||||
return ["id":"none", "version":"1.0.0"] |
||||
} |
||||
def plugin = new XmlParser().parse(xmlFile) |
||||
def version = plugin.version[0].text() |
||||
def id = plugin.id[0].text() |
||||
return ["id":id,"version":version] |
||||
} |
||||
|
||||
repositories { |
||||
mavenLocal() |
||||
maven { |
||||
url = uri('http://mvn.finedevelop.com/repository/maven-public/') |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
//使用本地jar |
||||
implementation fileTree(dir: 'lib', include: ['**/*.jar']) |
||||
implementation fileTree(dir: libPath, include: ['**/*.jar']) |
||||
} |
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<project> |
||||
<target name="compile_encrypt_javas" depends="copyFiles"> |
||||
<echo message="加密文件"/> |
||||
<echo message="${projectDir}"/> |
||||
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask"> |
||||
<classpath refid="compile.classpath"/> |
||||
</taskdef> |
||||
<pretreatment baseDir="${projectDir}"/> |
||||
</target> |
||||
<target name="compile_plain_javas" depends="copyFiles"> |
||||
</target> |
||||
</project> |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.tptj.demo.hg.db.access.provider.v10</id> |
||||
<name><![CDATA[ DBAccessProvider ]]></name> |
||||
<active>yes</active> |
||||
<version>1.0</version> |
||||
<env-version>10.0</env-version> |
||||
<vendor>tptj</vendor> |
||||
<jartime>2019-07-18</jartime> |
||||
<description><![CDATA[ ]]></description> |
||||
<change-notes><![CDATA[]]></change-notes> |
||||
<main-package>com.tptj.demo.hg.db.access.provider</main-package> |
||||
<function-recorder class="com.tptj.demo.hg.db.access.provider.DemoDbController"/> |
||||
<extra-core> |
||||
<DBAccessProvider class="com.tptj.demo.hg.db.access.provider.DemoDbController"/> |
||||
</extra-core> |
||||
<extra-decision> |
||||
<ControllerRegisterProvider class="com.tptj.demo.hg.db.access.provider.ControllerBridge"/> |
||||
</extra-decision> |
||||
</plugin> |
@ -0,0 +1,31 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.json.revise.EmbedJson; |
||||
import com.fr.stable.db.entity.converter.BaseConverter; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
public class BeanConverter extends BaseConverter<DemoBean,String> { |
||||
@Override |
||||
public String convertToDatabaseColumn(DemoBean bean) { |
||||
if( null == bean ){ |
||||
return "{}"; |
||||
} |
||||
return JSONObject.mapFrom(bean).toString(); |
||||
} |
||||
|
||||
@Override |
||||
public DemoBean convertToEntityAttribute(String val ) { |
||||
try{ |
||||
return EmbedJson.MAPPER.readValue(val,DemoBean.class); |
||||
}catch(Exception e){ |
||||
LogKit.error(e,"{} can not convert to DemoBean for {}",val,e.getMessage()); |
||||
} |
||||
return new DemoBean(); |
||||
} |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
public class ControllerBridge extends AbstractControllerRegisterProvider { |
||||
@Override |
||||
public Class<?>[] getControllers() { |
||||
return new Class[]{DemoController.class}; |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
public class DataBean { |
||||
private String id; |
||||
private String key; |
||||
private DemoBean bean; |
||||
private List<DemoBean> attr3; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getKey() { |
||||
return key; |
||||
} |
||||
|
||||
public void setKey(String key) { |
||||
this.key = key; |
||||
} |
||||
|
||||
public DemoBean getBean() { |
||||
return bean; |
||||
} |
||||
|
||||
public void setBean(DemoBean bean) { |
||||
this.bean = bean; |
||||
} |
||||
|
||||
public List<DemoBean> getAttr3() { |
||||
return attr3; |
||||
} |
||||
|
||||
public void setAttr3(List<DemoBean> attr3) { |
||||
this.attr3 = attr3; |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
public class DemoBean { |
||||
|
||||
private String attr1 = null; |
||||
private String attr2 = null; |
||||
|
||||
public String getAttr1() { |
||||
return attr1; |
||||
} |
||||
|
||||
public void setAttr1(String attr1) { |
||||
this.attr1 = attr1; |
||||
} |
||||
|
||||
public String getAttr2() { |
||||
return attr2; |
||||
} |
||||
|
||||
public void setAttr2(String attr2) { |
||||
this.attr2 = attr2; |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import com.fr.decision.webservice.Response; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.*; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
@Controller("DBAccessDemoController") |
||||
@LoginStatusChecker(required = false) |
||||
@RequestMapping(value = "/db/demo") |
||||
public class DemoController { |
||||
|
||||
@RequestMapping( value = "/dm_entity", method = RequestMethod.POST ) |
||||
@ResponseBody |
||||
public Response add( @RequestBody DataBean bean )throws Exception{ |
||||
DemoDbController.add(bean); |
||||
return Response.ok( bean ); |
||||
} |
||||
|
||||
@RequestMapping( value = "/dm_entity/{entity}", method = RequestMethod.DELETE ) |
||||
@ResponseBody |
||||
public Response delete( @PathVariable("entity") String entity )throws Exception{ |
||||
return Response.ok( DemoDbController.delete(entity) ); |
||||
} |
||||
|
||||
@RequestMapping( value = "/dm_entity", method = RequestMethod.PUT ) |
||||
@ResponseBody |
||||
public Response update( @RequestBody DataBean bean )throws Exception{ |
||||
DemoDbController.update(bean); |
||||
return Response.ok( bean ); |
||||
} |
||||
|
||||
@RequestMapping( value = "/dm_entity", method = RequestMethod.GET ) |
||||
@ResponseBody |
||||
public Response like( @RequestParam(value = "key") String key )throws Exception{ |
||||
return Response.ok( DemoDbController.like(key) ); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,63 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
public class DemoDao extends BaseDAO<DemoEntity> { |
||||
|
||||
public DemoDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<DemoEntity> getEntityClass() { |
||||
return DemoEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return DemoEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return DemoDao.class; |
||||
} |
||||
}; |
||||
|
||||
public List<DemoEntity> likeByKey( String key )throws Exception{ |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.like(DemoEntity.COLUMN_KEY, key)); |
||||
return find(condition); |
||||
} |
||||
|
||||
public void add(DemoEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void update(DemoEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
public DemoEntity getById(String id) throws Exception { |
||||
return getSession().getById(id, DemoEntity.class); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
} |
@ -0,0 +1,182 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
import com.fr.decision.base.util.UUIDUtil; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
@EnableMetrics |
||||
public class DemoDbController extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor accessor; |
||||
|
||||
public static DBAccessor getAccessor() { |
||||
return accessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
DemoDao.DAO, |
||||
LinkDao.DAO |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor accessor) { |
||||
DemoDbController.accessor = accessor; |
||||
} |
||||
|
||||
/** |
||||
* 业务对象——增 |
||||
* @param bean |
||||
*/ |
||||
public static void add( final DataBean bean ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(DemoDao.class).add( loadDemoEntity(bean,true) ); |
||||
context.getDAO(LinkDao.class).add( loadLinkEntities(bean,true) ); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
LogKit.error(e,"Add DataBean Error:{}",e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 业务对象——删 |
||||
* @param id |
||||
*/ |
||||
public static DataBean delete( final String id ){ |
||||
try{ |
||||
return accessor.runDMLAction(new DBAction<DataBean>() { |
||||
@Override |
||||
public DataBean run(DAOContext context) throws Exception { |
||||
DemoEntity entity = context.getDAO(DemoDao.class).getById(id); |
||||
if( null == entity ){ |
||||
return null; |
||||
} |
||||
context.getDAO(DemoDao.class).remove( id ); |
||||
List<LinkEntity> list = context.getDAO(LinkDao.class).removeByKey(entity.getKey()); |
||||
return toDataBean(entity,list); |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
LogKit.error(e,"Delete DataBean[{}] Error:{}",id,e.getMessage()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 业务对象——改 |
||||
* @param bean |
||||
*/ |
||||
public static void update( DataBean bean ){ |
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(DemoDao.class).update( loadDemoEntity(bean,false) ); |
||||
context.getDAO(LinkDao.class).addOrUpdate( loadLinkEntities(bean,false) ); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
LogKit.error(e,"Update DataBean Error:{}",e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
/** |
||||
* 业务对象——查 |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
@Focus(id = "com.tptj.demo.hg.decision.db.access.provider.v10",text = "DBAccessProvider") |
||||
public static List<DataBean> like(String key ){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<DataBean>>() { |
||||
@Override |
||||
public List<DataBean> run(DAOContext context) throws Exception { |
||||
List<DataBean> result = new ArrayList<DataBean>(); |
||||
List<DemoEntity> list = context.getDAO(DemoDao.class).likeByKey(key); |
||||
for( DemoEntity item : list ){ |
||||
List<LinkEntity> links = context.getDAO(LinkDao.class).getByKey(item.getKey()); |
||||
result.add( toDataBean(item,links) ); |
||||
} |
||||
return result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
LogKit.error(e,"Get DataBeans{} Error:{}",key,e.getMessage()); |
||||
} |
||||
return new ArrayList<DataBean>(); |
||||
} |
||||
|
||||
private static DemoEntity loadDemoEntity( DataBean bean, boolean isAdd ){ |
||||
DemoEntity entity = new DemoEntity(); |
||||
if(isAdd || StringUtils.isEmpty( bean.getId() ) ){ |
||||
bean.setId(UUIDUtil.generate()); |
||||
} |
||||
entity.setId( bean.getId() ); |
||||
entity.setKey( bean.getKey() ); |
||||
entity.setBean( bean.getBean() ); |
||||
return entity; |
||||
} |
||||
|
||||
private static DataBean toDataBean( DemoEntity entity,List<LinkEntity> list ){ |
||||
DataBean bean = new DataBean(); |
||||
bean.setId( entity.getId() ); |
||||
bean.setKey( entity.getKey() ); |
||||
bean.setBean( entity.getBean() ); |
||||
bean.setAttr3( toAttrBeans(list) ); |
||||
return bean; |
||||
} |
||||
|
||||
private static List<DemoBean> toAttrBeans( List<LinkEntity> links ){ |
||||
List<DemoBean> list = new ArrayList<DemoBean>(); |
||||
for( LinkEntity item : links ){ |
||||
DemoBean bean = new DemoBean(); |
||||
bean.setAttr1(item.getId()); |
||||
bean.setAttr2(item.getAttr3()); |
||||
list.add( bean ); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
private static List<LinkEntity> loadLinkEntities( DataBean bean, boolean isAdd ){ |
||||
List<LinkEntity> list = new ArrayList<LinkEntity>(); |
||||
List<DemoBean> attr3 = bean.getAttr3(); |
||||
for( DemoBean item : attr3 ){ |
||||
if(isAdd || StringUtils.isEmpty( item.getAttr1() ) ){ |
||||
item.setAttr1(UUIDUtil.generate()); |
||||
} |
||||
list.add( new LinkEntity() |
||||
.id( item.getAttr1() ) |
||||
.key( bean.getKey() ) |
||||
.attr3( item.getAttr2() ) |
||||
); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Convert; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_demo") |
||||
@TableAssociation(associated = true) |
||||
public class DemoEntity extends BaseEntity { |
||||
|
||||
public static final String COLUMN_KEY = "key"; |
||||
public static final String COLUMN_BEAN = "bean"; |
||||
|
||||
@Column(name = COLUMN_KEY) |
||||
private String key = null; |
||||
|
||||
@Column(name = COLUMN_BEAN) |
||||
@Convert(converter = BeanConverter.class) |
||||
private DemoBean bean = null; |
||||
|
||||
public String getKey() { |
||||
return key; |
||||
} |
||||
|
||||
public void setKey(String key) { |
||||
this.key = key; |
||||
} |
||||
|
||||
public DemoBean getBean() { |
||||
return bean; |
||||
} |
||||
|
||||
public void setBean(DemoBean bean) { |
||||
this.bean = bean; |
||||
} |
||||
} |
@ -0,0 +1,89 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
public class LinkDao extends BaseDAO<LinkEntity> { |
||||
public LinkDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<LinkEntity> getEntityClass() { |
||||
return LinkEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return LinkEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return LinkDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add( List<LinkEntity> list )throws Exception { |
||||
for( LinkEntity item : list ){ |
||||
add(item); |
||||
} |
||||
} |
||||
|
||||
public void addOrUpdate( List<LinkEntity> list )throws Exception { |
||||
for( LinkEntity item : list ){ |
||||
addOrUpdate(item); |
||||
} |
||||
} |
||||
|
||||
public List<LinkEntity> removeByKey( String key )throws Exception{ |
||||
QueryCondition condition = QueryFactory.create().addRestriction(RestrictionFactory.eq(LinkEntity.COLUMN_KEY, key)); |
||||
List<LinkEntity> list = find(condition); |
||||
for( LinkEntity item : list ){ |
||||
remove( item.getId() ); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
public List<LinkEntity> getByKey( String key )throws Exception{ |
||||
QueryCondition condition = QueryFactory.create().addRestriction(RestrictionFactory.eq(LinkEntity.COLUMN_KEY, key)); |
||||
return find(condition); |
||||
} |
||||
|
||||
public void add(LinkEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void update(LinkEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
public void addOrUpdate(LinkEntity entity) throws Exception { |
||||
if (entity != null && this.getById(entity.getId()) != null) { |
||||
update(entity); |
||||
} else { |
||||
add(entity); |
||||
} |
||||
} |
||||
|
||||
public LinkEntity getById(String id) throws Exception { |
||||
return this.getSession().getById(id, LinkEntity.class); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
this.getSession().remove(QueryFactory.create().addRestriction(RestrictionFactory.eq("id", id)), this.getEntityClass()); |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
package com.tptj.demo.hg.db.access.provider; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.stable.db.entity.TableAssociation; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
/** |
||||
* @author 秃破天际 |
||||
* @version 10.0 |
||||
* Created by 秃破天际 on 2021-04-25 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_demo_link") |
||||
@TableAssociation(associated = true) |
||||
public class LinkEntity extends BaseEntity { |
||||
|
||||
public static final String COLUMN_KEY = "key"; |
||||
public static final String COLUMN_ATTR = "attr3"; |
||||
|
||||
@Column(name = COLUMN_KEY) |
||||
private String key = null; |
||||
|
||||
@Column(name = COLUMN_ATTR) |
||||
private String attr3 = null; |
||||
|
||||
public String getKey() { |
||||
return key; |
||||
} |
||||
|
||||
public void setKey(String key) { |
||||
this.key = key; |
||||
} |
||||
|
||||
public String getAttr3() { |
||||
return attr3; |
||||
} |
||||
|
||||
public void setAttr3(String attr3) { |
||||
this.attr3 = attr3; |
||||
} |
||||
|
||||
public LinkEntity key(String key) { |
||||
this.setKey(key); |
||||
return this; |
||||
} |
||||
|
||||
public LinkEntity attr3(String attr3) { |
||||
this.setAttr3(attr3); |
||||
return this; |
||||
} |
||||
|
||||
public LinkEntity id(String id) { |
||||
this.setId(id); |
||||
return this; |
||||
} |
||||
|
||||
|
||||
} |
||||
|
Loading…
Reference in new issue