gemfire的资料真是少,花了1天时间搞了个demo,技术:spring mvc+spring security+jquery easy ui+spring data gemfire+redis
gemfire配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/geode"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gfe-data="http://www.springframework.org/schema/data/gemfire"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/geode http://www.springframework.org/schema/gemfire/spring-geode.xsd
http://www.springframework.org/schema/data/gemfire http://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd">
<gfe:pool id="myPool" subscription-enabled="true">
<gfe:locator host="127.0.0.1" port="1099"/>
</gfe:pool>
<gfe:pool id="serverPool">
<gfe:server host="127.0.0.1" port="40011"/>
</gfe:pool>
<gfe-data:repositories base-package="com.mark.demo.security.repository" />
<gfe:client-cache id="clientCache" pool-name="myPool" pdx-serializer-ref="mySerializer" pdx-read-serialized="true"/>
<gfe:cache id="gemfireCache" pdx-read-serialized="true" pdx-serializer-ref="mySerializer"></gfe:cache>
<gfe:replicated-region id="user" cache-ref="gemfireCache" persistent="true"
data-policy="PERSISTENT_REPLICATE" key-constraint="java.lang.Integer" value-constraint="com.mark.demo.security.entity.User" name="user"/>
<gfe:replicated-region id="menu" cache-ref="gemfireCache" persistent="true"
data-policy="PERSISTENT_REPLICATE" key-constraint="java.lang.Integer" value-constraint="com.mark.demo.security.entity.Menu" name="menu"/>
<gfe:replicated-region id="resource" cache-ref="gemfireCache" persistent="true"
data-policy="PERSISTENT_REPLICATE" key-constraint="java.lang.Integer" value-constraint="com.mark.demo.security.entity.Resource" name="resource"/>
<bean id="mySerializer" class="org.apache.geode.pdx.ReflectionBasedAutoSerializer"></bean>
<bean id="userGemfireTemplate" class="org.springframework.data.gemfire.GemfireTemplate" >
<property name="region" ref="user"></property>
</bean>
<bean id="menuGemfireTemplate" class="org.springframework.data.gemfire.GemfireTemplate" >
<property name="region" ref="menu"></property>
</bean>
<bean id="instantiatorFactory" class="org.springframework.data.gemfire.serialization.InstantiatorFactoryBean">
<property name="customTypes">
<map>
<entry key="com.mark.demo.security.entity.User" value="1025"/>
<entry key="com.mark.demo.security.entity.Resource" value="1027"/>
<entry key="com.mark.demo.security.entity.Menu" value="1029"/>
</map>
</property>
</bean>
</beans>
package com.mark.demo.security.entity;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import org.apache.geode.DataSerializable;
import org.apache.geode.Instantiator;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.Transient;
import org.springframework.data.gemfire.mapping.annotation.Indexed;
import org.springframework.data.gemfire.mapping.annotation.Region;
import com.mark.demo.security.base.GenericEntity;
/*
*hxp(hxpwangyi@126.com)
*2017年9月5日
*
*/
@Region("user")
public class User extends GenericEntity{
/**
*
*/
private static final long serialVersionUID = -540158452160163175L;
@Indexed
private String userName;
private String password;
private String phone;
private int age;
private int sex;
@Transient
private List<Role> roleList;
@Transient
private List<Group> groupList;
@Transient
private boolean rememberMe;
public User(){}
@PersistenceConstructor
public User(int id,String userName, String password, String phone, int age, int sex) {
this.id=id;
this.userName = userName;
this.password = password;
this.phone = phone;
this.age = age;
this.sex = sex;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public List<Role> getRoleList() {
return roleList;
}
public void setRoleList(List<Role> roleList) {
this.roleList = roleList;
}
public List<Group> getGroupList() {
return groupList;
}
public void setGroupList(List<Group> groupList) {
this.groupList = groupList;
}
public boolean isRememberMe() {
return rememberMe;
}
public void setRememberMe(boolean rememberMe) {
this.rememberMe = rememberMe;
}
static {
Instantiator.register(new Instantiator(User.class, 1025) {
public DataSerializable newInstance() {
return new User();
}
});
}
@Override
public void fromData(DataInput input) throws IOException, ClassNotFoundException {
id=input.readInt();
userName=input.readUTF();
password=input.readUTF();
phone=input.readUTF();
age=input.readInt();
sex=input.readInt();
}
@Override
public void toData(DataOutput output) throws IOException {
output.writeInt(id);
output.writeUTF(userName);
output.writeUTF(password);
output.writeUTF(phone);
output.writeInt(age);
output.writeInt(sex);
}
}
package com.mark.demo.security.entity;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.geode.DataSerializable;
import org.apache.geode.Instantiator;
import org.springframework.data.gemfire.mapping.annotation.Region;
import com.mark.demo.security.base.GenericEntity;
/*
*hxp(hxpwangyi@126.com)
*2017年9月22日
*
*/
@Region("resource")
public class Resource extends GenericEntity {
/**
*
*/
private static final long serialVersionUID = -540158452160163175L;
private String role;
private String url;
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
static {
Instantiator.register(new Instantiator(Resource.class, 1027) {
public DataSerializable newInstance() {
return new Resource();
}
});
}
@Override
public void fromData(DataInput input) throws IOException, ClassNotFoundException {
id=input.readInt();
role=input.readUTF();
url=input.readUTF();
}
@Override
public void toData(DataOutput output) throws IOException {
output.writeInt(id);
output.writeUTF(role);
output.writeUTF(url);
}
}
package com.mark.demo.security.entity;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.geode.DataSerializable;
import org.apache.geode.Instantiator;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.gemfire.mapping.annotation.Region;
import com.mark.demo.security.base.GenericEntity;
/*
*hxp(hxpwangyi@126.com)
*2017年9月5日
*
*/
@Region("menu")
public class Menu extends GenericEntity{
/**
*
*/
private static final long serialVersionUID = -540158452160163175L;
private int pid;
private String menuName;
private String menuDesc;
private String link;
private String icon;
private int order;
public Menu(){}
@PersistenceConstructor
public Menu(int id,int pid, String menuName, String menuDesc, String link, String icon, int order) {
this.id=id;
this.pid = pid;
this.menuName = menuName;
this.menuDesc = menuDesc;
this.link = link;
this.icon = icon;
this.order = order;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getMenuName() {
return menuName;
}
public void setMenuName(String menuName) {
this.menuName = menuName;
}
public String getMenuDesc() {
return menuDesc;
}
public void setMenuDesc(String menuDesc) {
this.menuDesc = menuDesc;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
static {
Instantiator.register(new Instantiator(Menu.class, 1029) {
public DataSerializable newInstance() {
return new Menu();
}
});
}
@Override
public void fromData(DataInput input) throws IOException, ClassNotFoundException {
id=input.readInt();
pid=input.readInt();
menuName=input.readUTF();
menuDesc=input.readUTF();
icon=input.readUTF();
link=input.readUTF();
order=input.readInt();
}
@Override
public void toData(DataOutput output) throws IOException {
output.writeInt(id);
output.writeInt(pid);
output.writeUTF(menuName);
output.writeUTF(menuDesc);
output.writeUTF(icon);
output.writeUTF(link);
output.writeInt(order);
}
}
package com.mark.demo.security.repository;
import org.springframework.data.gemfire.repository.GemfireRepository;
import com.mark.demo.security.entity.User;
/*
*hxp(hxpwangyi@126.com)
*2017年10月7日
*
*/
public interface UserRepository extends GemfireRepository<User, Integer> {
User getByUserName(String userName);
}
package com.mark.demo.security.repository;
import org.springframework.data.gemfire.repository.GemfireRepository;
import com.mark.demo.security.entity.Resource;
/*
*hxp(hxpwangyi@126.com)
*2017年10月7日
*
*/
public interface ResourceRepository extends GemfireRepository<Resource, Integer> {
}
package com.mark.demo.security.repository;
import java.util.List;
import org.springframework.data.gemfire.repository.GemfireRepository;
import org.springframework.data.gemfire.repository.Query;
import com.mark.demo.security.entity.Menu;
/*
*hxp(hxpwangyi@126.com)
*2017年10月7日
*
*/
public interface MenuRepository extends GemfireRepository<Menu, Integer> {
@Query("select * from /menu where pid=-1")
List<Menu> getMenuTopLever();
@Query("select * from /menu where pid=$1 ")
List<Menu> getMenuChildren(int pid);
@Query("update /menu set menuName=$1.menuName ,menuDesc=$1.menuDesc,link=$1.link where id=$1.id ")
void updateMenu(Menu menu);
}