From da0a9c47b20130a411053e27b85ea3dc323773e2 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 1 Nov 2018 18:37:39 +0800 Subject: [PATCH] =?UTF-8?q?MOBILE-17909&MOBILE-17908=2010.0=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E3=80=8B=E5=AE=9A=E6=97=B6=E8=B0=83=E5=BA=A6=E6=9C=89?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E4=BB=BB=E5=8A=A1=E6=97=B6=E5=8D=B8=E8=BD=BD?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8F=92=E4=BB=B6=EF=BC=8C=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/hibernate/tuple/PojoInstantiator.java | 7 +++- .../tuple/entity/DefaultEntityRegister.java | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 fine-hibernate/src/com/fr/third/org/hibernate/tuple/entity/DefaultEntityRegister.java diff --git a/fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java b/fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java index 8fbd1780b..ac3f255f4 100755 --- a/fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java +++ b/fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java @@ -17,6 +17,7 @@ import com.fr.third.org.hibernate.internal.CoreLogging; import com.fr.third.org.hibernate.internal.CoreMessageLogger; import com.fr.third.org.hibernate.internal.util.ReflectHelper; import com.fr.third.org.hibernate.mapping.Component; +import com.fr.third.org.hibernate.tuple.entity.DefaultEntityRegister; /** * Defines a POJO-based instantiator for use from the tuplizers. @@ -72,7 +73,11 @@ public class PojoInstantiator implements Instantiator, Serializable { public Object instantiate() { if ( isAbstract ) { - throw new InstantiationException( "Cannot instantiate abstract class or interface: ", mappedClass ); + try { + return DefaultEntityRegister.getInstance().getDefaultEntityClass().newInstance(); + } catch (Exception e) { + throw new InstantiationException("class not found: ", mappedClass); + } } else if ( optimizer != null ) { return optimizer.newInstance(); diff --git a/fine-hibernate/src/com/fr/third/org/hibernate/tuple/entity/DefaultEntityRegister.java b/fine-hibernate/src/com/fr/third/org/hibernate/tuple/entity/DefaultEntityRegister.java new file mode 100644 index 000000000..fe3932ea7 --- /dev/null +++ b/fine-hibernate/src/com/fr/third/org/hibernate/tuple/entity/DefaultEntityRegister.java @@ -0,0 +1,41 @@ +package com.fr.third.org.hibernate.tuple.entity; + +/** + * Created by Zed on 2018/11/1. + */ +public class DefaultEntityRegister { + + private static volatile DefaultEntityRegister instance; + private Class defaultEntityClass = null; + + public static DefaultEntityRegister getInstance() { + if (instance == null) { + synchronized (DefaultEntityRegister.class) { + if (instance == null) { + instance = new DefaultEntityRegister(); + } + } + } + return instance; + } + + private DefaultEntityRegister() { + + } + + public void registerDefaultClass(Class defaultEntityClass) { + this.defaultEntityClass = defaultEntityClass; + } + + public void resetDefaultClass() { + this.defaultEntityClass = null; + } + + public Class getDefaultEntityClass() { + return defaultEntityClass; + } + + public void setDefaultEntityClass(Class defaultEntityClass) { + this.defaultEntityClass = defaultEntityClass; + } +}