Browse Source

fix

research/11.0
zed 6 years ago
parent
commit
d78f153f0e
  1. 29
      fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java
  2. 41
      fine-hibernate/src/com/fr/third/org/hibernate/tuple/entity/DefaultEntityRegister.java

29
fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java

@ -6,10 +6,6 @@
*/
package com.fr.third.org.hibernate.tuple;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import com.fr.third.org.hibernate.InstantiationException;
import com.fr.third.org.hibernate.PropertyNotFoundException;
import com.fr.third.org.hibernate.bytecode.spi.ReflectionOptimizer;
@ -17,6 +13,11 @@ 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;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Constructor;
/**
* Defines a POJO-based instantiator for use from the tuplizers.
@ -42,8 +43,7 @@ public class PojoInstantiator implements Instantiator, Serializable {
try {
constructor = ReflectHelper.getDefaultConstructor(mappedClass);
}
catch ( PropertyNotFoundException pnfe ) {
} catch (PropertyNotFoundException pnfe) {
LOG.noDefaultConstructor(mappedClass.getName());
constructor = null;
}
@ -58,8 +58,7 @@ public class PojoInstantiator implements Instantiator, Serializable {
try {
constructor = ReflectHelper.getDefaultConstructor(mappedClass);
}
catch ( PropertyNotFoundException pnfe ) {
} catch (PropertyNotFoundException pnfe) {
LOG.noDefaultConstructor(mappedClass.getName());
constructor = null;
}
@ -73,22 +72,18 @@ public class PojoInstantiator implements Instantiator, Serializable {
public Object instantiate() {
if (isAbstract) {
try {
return Class.forName("com.fr.schedule.base.entity.output.DefaultOutputEntity").newInstance();
return DefaultEntityRegister.getInstance().getDefaultEntityClass().newInstance();
} catch (Exception e) {
throw new InstantiationException("class not found: ", mappedClass);
}
}
else if ( optimizer != null ) {
} else if (optimizer != null) {
return optimizer.newInstance();
}
else if ( constructor == null ) {
} else if (constructor == null) {
throw new InstantiationException("No default constructor for entity: ", mappedClass);
}
else {
} else {
try {
return applyInterception(constructor.newInstance((Object[]) null));
}
catch ( Exception e ) {
} catch (Exception e) {
throw new InstantiationException("Could not instantiate entity: ", mappedClass, e);
}
}

41
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;
}
}
Loading…
Cancel
Save