数据库对象添加深度复制

back_recharge
zhangshanxue 2020-04-23 19:52:54 +08:00
parent c8534de2de
commit ab36222035
13 changed files with 381 additions and 38 deletions

View File

@ -9,6 +9,7 @@ import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
@ -19,6 +20,17 @@ import java.util.jar.JarFile;
*/ */
public class ClassLoaderHelper { public class ClassLoaderHelper {
final static ConcurrentHashMap<String, Class<?>> CLS_CACHE = new ConcurrentHashMap<>();
public static Class<?> forName(String clsname) throws ClassNotFoundException{
Class<?> cls = CLS_CACHE.get(clsname);
if(null == cls){
cls = Class.forName(clsname);
CLS_CACHE.put(clsname, cls);
}
return cls;
}
/** /**
* *
*/ */

View File

@ -1,39 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Ldb > <Ldb >
<Jbean name="ItemEntity">
<Variable name="id" type="int"/>
<Variable name="uniqueid" type="long"/>
<Variable name="count" type="int"/>
<Variable name="position" type="int"/>包裹属性位置。从0开始编号
<Variable name="createTime" type="int"/>
</Jbean>
<Jbean name="BagEntity">
<Variable name="bagid" type="long"/>
<Variable name="nextId" type="int"/>
<Variable name="capacity" type="int"/>
<Variable name="itemMap" type="map" key="int" value="ItemEntity" /> 道具map
</Jbean>
<Jbean name="BagManager">背包管理器
<Variable name="bagMap" type="map" key="int" value="BagEntity" />背包map
</Jbean>
<Jbean name="PropertyItem">
<Variable name="id" type="string"/>
<Variable name="equipId" type="int"/>
<Variable name="level" type="int"/>
<Variable name="heroId" type="string"/>
<Variable name="propertyValueByIdMap" type="map" key="int" value="int" /> 主属性 key 对应PropertyConfig id
<Variable name="secondValueByIdMap" type="map" key="int" value="int" /> //副属性
<Variable name="createTime" type="int"/>
<Variable name="skill" type="int"/>
<Variable name="isLocked" type="int"/>
</Jbean>
<Jbean name="ActivityProgressInfo"> <Jbean name="ActivityProgressInfo">
<Variable name="state" type="int"/> <Variable name="state" type="int"/>

View File

@ -0,0 +1,101 @@
package com.dbgen;
import java.io.PrintStream;
import java.util.Collection;
public class Construct implements Visitor {
private final PrintStream ps;
private final String variable;
private final String varname;
private final String prefix;
private static void make(Collection<Variable> variables, String name, PrintStream ps, String prefix, Naming variableParent) {
ps.println(prefix + "public " + name + "() {");
if (!variableParent.baseclass.isEmpty()) {
ps.println(prefix + prefix + "super();");
}
for (Variable var : variables)
make(var, ps, prefix + " ");
ps.println(prefix + "}");
ps.println();
}
public static void make(Jbean bean, PrintStream ps, String prefix) {
make(bean.getVariables(), bean.getLastName(), ps, prefix,bean);
}
public static void make(Variable var, PrintStream ps, String prefix) {
var.getType().accept(new Construct(var.getName(), ps, prefix));
}
public Construct(String varname, PrintStream ps, String prefix) {
this.variable = varname;
this.varname = varname;
this.ps = ps;
this.prefix = prefix;
}
private void initial() {
}
private void newVariable(Type type) {
ps.println(prefix + variable + " = new " + TypeName.getName(type) + "();");
}
@Override
public void visit(TypeFloat type) {
initial();
}
@Override
public void visit(TypeDouble type) {
initial();
}
@Override
public void visit(TypeBoolean type) {
initial();
}
@Override
public void visit(TypeInt type) {
initial();
}
@Override
public void visit(TypeShort type) {
initial();
}
@Override
public void visit(TypeLong type) {
initial();
}
@Override
public void visit(TypeString type) {
ps.println(prefix + variable + " = \"\";");
}
@Override
public void visit(TypeList type) {
newVariable(type);
}
@Override
public void visit(TypeSet type) {
newVariable(type);
}
@Override
public void visit(TypeMap type) {
newVariable(type);
}
@Override
public void visit(Jbean type) {
ps.println(prefix + variable + " = new " + type.getName() + "(this, " + StringUtils.quote(varname) + ");");
}
}

View File

@ -0,0 +1,103 @@
package com.dbgen;
import java.io.PrintStream;
class VarCopyFrom implements Visitor {
static void make(Variable var, PrintStream ps, String prefix) {
var.getType().accept(new VarCopyFrom(var, ps, prefix));
}
private static String getCopy(Type type, String fullvarname, String parentVarname) {
if (type instanceof Jbean) {
return "new " + type.getName() + "(" + fullvarname + ")";
} else {
return fullvarname;
}
}
private PrintStream ps;
private String prefix;
private String varname;
private String this_varname;
private VarCopyFrom(Variable var, PrintStream ps, String prefix) {
this.ps = ps;
this.prefix = prefix;
this.varname = var.getName();
this.this_varname = "this." + this.varname;
}
private void simple() {
ps.println(prefix + this_varname + " = _o_." + varname + ";");
}
@Override
public void visit(TypeBoolean type) {
simple();
}
@Override
public void visit(TypeShort type) {
simple();
}
@Override
public void visit(TypeInt type) {
simple();
}
@Override
public void visit(TypeLong type) {
simple();
}
@Override
public void visit(TypeFloat type) {
simple();
}
@Override
public void visit(TypeDouble type) {
simple();
}
private void collection(Type type, Type value, String posttype) {
ps.println(prefix + "_o_." + varname + ".forEach(_v_ -> this_" + varname + ".add("
+ getCopy(value, "_v_", varname) + "));");
}
@Override
public void visit(TypeString type) {
simple();
}
@Override
public void visit(TypeList type) {
collection(type, type.getValueType(), "List");
}
@Override
public void visit(TypeSet type) {
collection(type, type.getValueType(), "Set");
}
@Override
public void visit(TypeMap type) {
Type key = type.getKeyType();
Type value = type.getValueType();
String keycopy = getCopy(key, "_k_", varname);
String valuecopy = getCopy(value, "_v_", varname);
ps.println(prefix + "_o_." + varname + ".forEach((_k_, _v_) -> this." + varname + ".put(" + keycopy + ", "
+ valuecopy + "));");
}
@Override
public void visit(Jbean type) {
ps.println(prefix + this_varname + ".copyFrom(_o_." + varname + ");");
}
}

View File

@ -0,0 +1,107 @@
package com.dbgen;
import java.io.PrintStream;
class VarDeepCopy implements Visitor {
static void make(Variable var, PrintStream ps, String prefix) {
var.getType().accept(new VarDeepCopy(var.getName(), ps, prefix));
}
private static String getCopy(Type type, String fullvarname, String parentVarname) {
if (type instanceof Jbean) {
return "new " + type.getName() + "(" + fullvarname + ")";
} else {
return fullvarname;
}
}
private String varname;
private String this_varname;
private PrintStream ps;
private String prefix;
private VarDeepCopy(String varname, PrintStream ps, String prefix) {
this.varname = varname;
this.ps = ps;
this.prefix = prefix;
this.this_varname = "this." + varname;
}
@Override
public void visit(Jbean type) {
ps.println(prefix + this_varname + " = new " + type.getName() + "(_o_." + varname +");");
}
@Override
public void visit(TypeString type) {
simple();
}
private void simple() {
ps.println(prefix + this_varname + " = _o_." + varname + ";");
}
@Override
public void visit(TypeBoolean type) {
simple();
}
@Override
public void visit(TypeShort type) {
simple();
}
@Override
public void visit(TypeInt type) {
simple();
}
@Override
public void visit(TypeLong type) {
simple();
}
@Override
public void visit(TypeFloat type) {
simple();
}
@Override
public void visit(TypeDouble type) {
simple();
}
private void collection(Type type, Type value) {
ps.println(prefix + this_varname + " = new " + TypeName.getName(type) + "();");
ps.println(prefix + "_o_." + varname + ".forEach(_v_ -> " + this_varname + ".add("
+ getCopy(value, "_v_", varname) + "));");
}
@Override
public void visit(TypeList type) {
collection(type, type.getValueType());
}
@Override
public void visit(TypeSet type) {
collection(type, type.getValueType());
}
@Override
public void visit(TypeMap type) {
ps.println(prefix + this_varname + " = new " + TypeName.getName(type) + "();");
Type key = type.getKeyType();
Type value = type.getValueType();
String keycopy = getCopy(key, "_k_", varname);
String valuecopy =getCopy(value, "_v_", varname);
ps.println(prefix + "_o_." + varname + ".forEach((_k_, _v_) -> " + this_varname + ".put(" + keycopy + ", "
+ valuecopy + "));");
}
}

View File

@ -21,6 +21,15 @@ public final class ActivityManager extends MongoBase {
public ActivityManager() { public ActivityManager() {
} }
public ActivityManager(ActivityManager _o_ ) {
this.activityMissionMap = new HashMap<Integer, com.ljsd.jieling.jbean.ActivityMission>();
_o_.activityMissionMap.forEach((_k_, _v_) -> this.activityMissionMap.put(_k_, new ActivityMission(_v_)));
this.senvenTime = _o_.senvenTime;
this.luckWheel = new LuckWheelMission(_o_.luckWheel);
this.luckWheelAdvance = new LuckWheelMission(_o_.luckWheelAdvance);
}
public Map<Integer, com.ljsd.jieling.jbean.ActivityMission> getActivityMissionMap() { public Map<Integer, com.ljsd.jieling.jbean.ActivityMission> getActivityMissionMap() {
if( null == activityMissionMapLog && activityMissionMap != null) if( null == activityMissionMapLog && activityMissionMap != null)
activityMissionMapLog = new LogHashMap( this,"activityMissionMap",activityMissionMap); activityMissionMapLog = new LogHashMap( this,"activityMissionMap",activityMissionMap);

View File

@ -21,6 +21,15 @@ public final class ActivityMission extends MongoBase {
public ActivityMission() { public ActivityMission() {
} }
public ActivityMission(ActivityMission _o_ ) {
this.activityMissionMap = new HashMap<Integer, com.ljsd.jieling.jbean.ActivityProgressInfo>();
_o_.activityMissionMap.forEach((_k_, _v_) -> this.activityMissionMap.put(_k_, new ActivityProgressInfo(_v_)));
this.activityState = _o_.activityState;
this.openType = _o_.openType;
this.v = _o_.v;
}
public Map<Integer, com.ljsd.jieling.jbean.ActivityProgressInfo> getActivityMissionMap() { public Map<Integer, com.ljsd.jieling.jbean.ActivityProgressInfo> getActivityMissionMap() {
if( null == activityMissionMapLog && activityMissionMap != null) if( null == activityMissionMapLog && activityMissionMap != null)
activityMissionMapLog = new LogHashMap( this,"activityMissionMap",activityMissionMap); activityMissionMapLog = new LogHashMap( this,"activityMissionMap",activityMissionMap);

View File

@ -17,6 +17,12 @@ public final class ActivityProgressInfo extends MongoBase {
public ActivityProgressInfo() { public ActivityProgressInfo() {
} }
public ActivityProgressInfo(ActivityProgressInfo _o_ ) {
this.state = _o_.state;
this.progrss = _o_.progrss;
}
public int getState() { public int getState() {
return this.state; return this.state;
} }

View File

@ -19,6 +19,13 @@ public final class LuckWheelMission extends MongoBase {
public LuckWheelMission() { public LuckWheelMission() {
} }
public LuckWheelMission(LuckWheelMission _o_ ) {
this.posInfoMap = new HashMap<Integer, com.ljsd.jieling.jbean.LuckWheelPosInfo>();
_o_.posInfoMap.forEach((_k_, _v_) -> this.posInfoMap.put(_k_, new LuckWheelPosInfo(_v_)));
this.refreshTime = _o_.refreshTime;
}
public Map<Integer, com.ljsd.jieling.jbean.LuckWheelPosInfo> getPosInfoMap() { public Map<Integer, com.ljsd.jieling.jbean.LuckWheelPosInfo> getPosInfoMap() {
if( null == posInfoMapLog && posInfoMap != null) if( null == posInfoMapLog && posInfoMap != null)
posInfoMapLog = new LogHashMap( this,"posInfoMap",posInfoMap); posInfoMapLog = new LogHashMap( this,"posInfoMap",posInfoMap);

View File

@ -17,6 +17,12 @@ public final class LuckWheelPosInfo extends MongoBase {
public LuckWheelPosInfo() { public LuckWheelPosInfo() {
} }
public LuckWheelPosInfo(LuckWheelPosInfo _o_ ) {
this.luckId = _o_.luckId;
this.progrss = _o_.progrss;
}
public int getLuckId() { public int getLuckId() {
return this.luckId; return this.luckId;
} }

View File

@ -28,6 +28,21 @@ public final class PropertyItem extends MongoBase {
public PropertyItem() { public PropertyItem() {
} }
public PropertyItem(PropertyItem _o_ ) {
this.id = _o_.id;
this.equipId = _o_.equipId;
this.level = _o_.level;
this.heroId = _o_.heroId;
this.propertyValueByIdMap = new HashMap<Integer, Integer>();
_o_.propertyValueByIdMap.forEach((_k_, _v_) -> this.propertyValueByIdMap.put(_k_, _v_));
this.secondValueByIdMap = new HashMap<Integer, Integer>();
_o_.secondValueByIdMap.forEach((_k_, _v_) -> this.secondValueByIdMap.put(_k_, _v_));
this.createTime = _o_.createTime;
this.skill = _o_.skill;
this.isLocked = _o_.isLocked;
}
public String getId() { public String getId() {
return this.id; return this.id;
} }

View File

@ -91,6 +91,10 @@ public class ProtocolsManager implements ProtocolsAbstract {
{ {
simpleName = simpleName.substring(0, index); simpleName = simpleName.substring(0, index);
int number = getProtoIdBySimpleName(simpleName); int number = getProtoIdBySimpleName(simpleName);
if(number == 0){
//没写协议号
return;
}
handlers.put(number, handler); handlers.put(number, handler);
} }
return; return;

View File

@ -613,10 +613,7 @@ public class ItemUtil {
} }
/** /**
* * //zsx 保留 TODO 由事件分发到 playlogic 去处理
*
* @param user
* @param addExp
*/ */
public static void userLevelUp(User user, int addExp) throws Exception { public static void userLevelUp(User user, int addExp) throws Exception {
PlayerManager playerInfoManager = user.getPlayerInfoManager(); PlayerManager playerInfoManager = user.getPlayerInfoManager();
@ -676,7 +673,7 @@ public class ItemUtil {
} }
/** /**
* * //zsx 保留 TODO 由事件分发到 Activitylogic 去处理
* @param user * @param user
*/ */
public static void treasureLevelUp(User user) throws Exception { public static void treasureLevelUp(User user) throws Exception {