Create a new Object by given entityClass, if any exception happen, throw
{@link DialectException}
323768
public static Object createNewEntity(Class<?> entityClass) {
		try {
			return entityClass.newInstance();
		} catch (Exception e) {
			throw new DialectException(e);
		}
	}
375704
private AbstractHelperDialect initDialect(String dialectClass, Properties properties) {
        AbstractHelperDialect dialect;
        if (StringUtil.isEmpty(dialectClass)) {
            throw new PageException("使用 PageHelper 分页插件时，必须设置 helper 属性");
        }
        try {
            Class sqlDialectClass = resloveDialectClass(dialectClass);
            if (AbstractHelperDialect.class.isAssignableFrom(sqlDialectClass)) {
                dialect = (AbstractHelperDialect) sqlDialectClass.newInstance();
            } else {
                throw new PageException("使用 PageHelper 时，方言必须是实现 " + AbstractHelperDialect.class.getCanonicalName() + " 接口的实现类!");
            }
        } catch (Exception e) {
            throw new PageException("初始化 helper [" + dialectClass + "]时出错:" + e.getMessage(), e);
        }
        dialect.setProperties(properties);
        return dialect;
    }
987001
@SuppressWarnings("unchecked")
  public <T extends Entity<?>> T newInstance(final Class<T> clazz) {
    return (T) getEntityType(clazz).newInstance();
  }
389350
public T newInstance(Object... args)
    {
        try
        {
            return type.cast(factoryMethod.invoke(null, args));
        }
        catch (IllegalAccessException e)
        {
            throw ExceptionImposter.imposterize( e );
        }
        catch (InvocationTargetException e)
        {
            throw ExceptionImposter.imposterize( e.getCause() );
        }
    }
366382
@SuppressWarnings("unchecked")
    public <T extends BaseWrapper<T>> T create(final Object entity, boolean isRevision) {
        if (entity == null) {
            return null;
        }

        // Create the key
        final DBWrapperKey key = new DBWrapperKey(entity);

        // Check to see if a wrapper has already been cached for the key
        final BaseWrapper cachedWrapper = wrapperCache.get(key);
        if (cachedWrapper != null) {
            return (T) cachedWrapper;
        }

        final DBBaseWrapper wrapper;

        if (entity instanceof ApplicationConfig) {
            // SERVER SETTINGS
            wrapper = new DBServerSettingsWrapper(getProviderFactory(), (ApplicationConfig) entity);
        } else if (entity instanceof EntitiesConfig) {
            // SERVER ENTITIES
            wrapper = new DBServerEntitiesWrapper(getProviderFactory(), (EntitiesConfig) entity);
        } else if (entity instanceof UndefinedEntity) {
            // UNDEFINED ENTITY
            wrapper = new DBServerUndefinedEntityWrapper(getProviderFactory(), (UndefinedEntity) entity);
        } else if (entity instanceof UndefinedSetting) {
            // UNDEFINED SETTING
            wrapper = new DBServerUndefinedSettingWrapper(getProviderFactory(), (UndefinedSetting) entity);
        } else if (entity instanceof Locale) {
            // Locale
            wrapper = new DBLocaleWrapper(getProviderFactory(), (Locale) entity);
        } else if (entity instanceof TranslationServer) {
            // Translation server
            throw new UnsupportedOperationException("A return class needs to be specified for TranslationServer entities.");
        } else if (entity instanceof Topic) {
            // TOPIC
            wrapper = new DBTopicWrapper(getProviderFactory(), (Topic) entity, isRevision);
        } else if (entity instanceof TopicSourceUrl) {
            // TOPIC SOURCE URL
            wrapper = new DBTopicSourceURLWrapper(getProviderFactory(), (TopicSourceUrl) entity, isRevision);
        } else if (entity instanceof TranslatedTopicData) {
            // TRANSLATED TOPIC
            wrapper = new DBTranslatedTopicDataWrapper(getProviderFactory(), (TranslatedTopicData) entity, isRevision);
        } else if (entity instanceof TranslatedTopicString) {
            // TRANSLATED TOPIC STRING
            wrapper = new DBTranslatedTopicStringWrapper(getProviderFactory(), (TranslatedTopicString) entity, isRevision);
        } else if (entity instanceof Tag) {
            // TAG
            wrapper = new DBTagWrapper(getProviderFactory(), (Tag) entity, isRevision);
        } else if (entity instanceof TagToCategory) {
            throw new UnsupportedOperationException("A return class needs to be specified for TagToCategory entities.");
        } else if (entity instanceof Category) {
            // CATEGORY
            wrapper = new DBCategoryWrapper(getProviderFactory(), (Category) entity, isRevision);
        } else if (entity instanceof PropertyTag) {
            // PROPERTY TAGS
            wrapper = new DBPropertyTagWrapper(getProviderFactory(), (PropertyTag) entity, isRevision);
        } else if (entity instanceof TopicToPropertyTag) {
            wrapper = new DBTopicToPropertyTagWrapper(getProviderFactory(), (TopicToPropertyTag) entity, isRevision);
        } else if (entity instanceof TagToPropertyTag) {
            wrapper = new DBTagToPropertyTagWrapper(getProviderFactory(), (TagToPropertyTag) entity, isRevision);
        } else if (entity instanceof ContentSpecToPropertyTag) {
            wrapper = new DBContentSpecToPropertyTagWrapper(getProviderFactory(), (ContentSpecToPropertyTag) entity, isRevision);
        } else if (entity instanceof PropertyTagToPropertyTagCategory) {
            wrapper = new DBPropertyTagToPropertyTagCategoryWrapper(getProviderFactory(), (PropertyTagToPropertyTagCategory) entity,
                    isRevision);
        } else if (entity instanceof BlobConstants) {
            // BLOB CONSTANT
            wrapper = new DBBlobConstantWrapper(getProviderFactory(), (BlobConstants) entity, isRevision);
        } else if (entity instanceof StringConstants) {
            // STRING CONSTANT
            wrapper = new DBStringConstantWrapper(getProviderFactory(), (StringConstants) entity, isRevision);
        } else if (entity instanceof File) {
            // FILE
            wrapper = new DBFileWrapper(getProviderFactory(), (File) entity, isRevision);
        } else if (entity instanceof LanguageFile) {
            // LANGUAGE FILE
            wrapper = new DBLanguageFileWrapper(getProviderFactory(), (LanguageFile) entity, isRevision);
        } else if (entity instanceof ImageFile) {
            // IMAGE
            wrapper = new DBImageWrapper(getProviderFactory(), (ImageFile) entity, isRevision);
        } else if (entity instanceof LanguageImage) {
            // LANGUAGE IMAGE
            wrapper = new DBLanguageImageWrapper(getProviderFactory(), (LanguageImage) entity, isRevision);
        } else if (entity instanceof User) {
            // USER
            wrapper = new DBUserWrapper(getProviderFactory(), (User) entity, isRevision);
        } else if (entity instanceof ContentSpec) {
            // CONTENT SPEC
            throw new UnsupportedOperationException("A return class needs to be specified for ContentSpec entities.");
        } else if (entity instanceof CSNode) {
            // CONTENT SPEC NODE
            wrapper = new DBCSNodeWrapper(getProviderFactory(), (CSNode) entity, isRevision);
        } else if (entity instanceof CSNodeToCSNode) {
            wrapper = new DBCSRelatedNodeWrapper(getProviderFactory(), (CSNodeToCSNode) entity, isRevision);
        } else if (entity instanceof CSInfoNode) {
            // CONTENT SPEC INFO NODE
            wrapper = new DBCSInfoNodeWrapper(getProviderFactory(), (CSInfoNode) entity, isRevision);
        } else if (entity instanceof TranslatedCSNode) {
            // CONTENT SPEC TRANSLATED NODE
            wrapper = new DBTranslatedCSNodeWrapper(getProviderFactory(), (TranslatedCSNode) entity, isRevision);
        } else if (entity instanceof TranslatedCSNodeString) {
            // CONTENT SPEC TRANSLATED NODE STRING
            wrapper = new DBTranslatedCSNodeStringWrapper(getProviderFactory(), (TranslatedCSNodeString) entity, isRevision);
        } else if (entity instanceof CSTranslationDetail) {
            // CONTENT SPEC TRANSLATION DETAIL
            wrapper = new DBCSTranslationDetailWrapper(getProviderFactory(), (CSTranslationDetail) entity);
        } else {
            throw new IllegalArgumentException("Failed to create a Wrapper instance as there is no wrapper available for the Entity.");
        }

        // Add the wrapper to the cache
        wrapperCache.put(key, wrapper);

        return (T) wrapper;
    }
444595
public static Object instantiate(Class clazz) throws InstantiationException
    {
        Object result = null;
        try
        {
            result = ClassHelper.newInstance(clazz);
        }
        catch(IllegalAccessException e)
        {
            try
            {
                result = ClassHelper.newInstance(clazz, true);
            }
            catch(Exception e1)
            {
                throw new ClassNotPersistenceCapableException("Can't instantiate class '"
                        + (clazz != null ? clazz.getName() : "null")
                        + "', message was: " + e1.getMessage() + ")", e1);
            }
        }
        return result;
    }
232818
@Override
  public <T> void insert(Collection<? extends T> batchToSave, Class<T> entityClass) {
    insert(batchToSave, Util.determineCollectionName(entityClass));
  }
781834
public static <T extends Entity<?>> T newInstance(final Class<T> clazz) {
    return meta.newInstance(clazz);
  }
1281469
public static <E> JpaRepositoryConfig.Builder<E> builder(Class<E> entityClass) {
        JpaRepositoryConfig.Builder<E> builder = new JpaRepositoryConfig.Builder<>();
        builder.entityClass = entityClass;
        builder.resourceClass = entityClass;
        return builder;
    }
1058221
@Override
	public OUTPUT newInstance() throws FAILURE {
		
		StringBuilder builder = new StringBuilder()
		.append(getClass().getName())
		.append(".newInstance() is unsupported.");
		
		throw new UnsupportedOperationException(builder.toString());
	}
892220
@Override
    public T create(T entity) {
        EntityManager entityManager = getEntityManager();
        entityManager.persist(entity);
        return entity;
    }
747853
private static <T> T instantiate(Class<T> pojoClass) throws InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException {
        try {
            Constructor<T> constructor = pojoClass.getDeclaredConstructor();
            constructor.setAccessible(true);
            return constructor.newInstance();
        } catch (NoSuchMethodException e) {
            Function<Class<?>,Object> fn = unsafeInstantiator.get();
            if (fn == null) {
                throw new HecateException(e, "Unable to instantiate object of type %s (no-arg constructor missing).", pojoClass.getCanonicalName());
            }
            return (T) fn.apply(pojoClass);
        }
    }
71545
public static Object initialize(Class clazz, Object record)
    {
        try
        {
            if (record == null)
            {
                record = createNewInstance(clazz);
            }
            return record;
        }
        catch (Exception e)
        {
            throw new PersistenceException("Error occured while instantiating entity.", e);
        }
    }
248488
@Override
	public T create()
	{
		try
		{
			T obj = ClassPath.newInstance(creationClass);
			
			//Copy prototype properties
			if(this.prototype != null)
				JavaBean.populate(JavaBean.toMap(prototype), obj);
			
			PropertyDescriptor pd = null;
			Class<?> clz = null;
			
			final boolean throwExceptionForMissingProperty = false;
			
			for (String property : randomizeProperties)
			{
				try
				{
					pd = JavaBean.getPropertyDescriptor(obj, property);
					clz = pd.getPropertyType();
					
					if(clz.isAssignableFrom(Class.class) || clz.isEnum())
						continue;
					
					if(clz.isAssignableFrom(String.class))
					{
						try
						{
							JavaBean.setProperty(obj, property, Text.generateId(),throwExceptionForMissingProperty);  
						}
						catch(IllegalArgumentException e)
						{
							throw new IllegalArgumentException("randomizeProperties:"+randomizeProperties+" invalid property:"+property,e);
						}
						
					}
					else if(clz.isAssignableFrom(Integer.class) || clz.isAssignableFrom(int.class) )
					{
						JavaBean.setProperty(obj, property, digits.generateInteger());
					}
					else if (clz.isAssignableFrom(long.class)  || clz.isAssignableFrom(Long.class))
					{
						JavaBean.setProperty(obj, property, digits.generateLong());
					}
					
					else if (clz.isAssignableFrom(short.class)  || clz.isAssignableFrom(Short.class))
					{
						JavaBean.setProperty(obj, property, digits.generateShort());
					}
					else if (clz.isAssignableFrom(double.class)  || clz.isAssignableFrom(Double.class))
					{
						JavaBean.setProperty(obj, property, digits.generateDouble());
					}
					else if (clz.isAssignableFrom(char.class)  || clz.isAssignableFrom(Character.class))
					{
						JavaBean.setProperty(obj, property, Text.generateId().charAt(0));
					}
					else if (clz.isAssignableFrom(float.class)  || clz.isAssignableFrom(Float.class))
					{
						JavaBean.setProperty(obj, property, digits.generateFloat());
					}
					else if (clz.isAssignableFrom(byte.class)  || clz.isAssignableFrom(Byte.class))
					{
						JavaBean.setProperty(obj, property,Byte.valueOf(Text.generateId().getBytes(IO.CHARSET)[0]));
					}
					else if (clz.isAssignableFrom(boolean.class)  || clz.isAssignableFrom(Boolean.class))
					{
						if(Calendar.getInstance().getTime().getTime()%2 ==0)
							JavaBean.setProperty(obj, property, true);
						else
							JavaBean.setProperty(obj, property, false);
					}
					else if (clz.equals(BigDecimal.class))
					{
						JavaBean.setProperty(obj, property,digits.generateBigDecimal());
					}
					else if (clz.equals(java.sql.Time.class))
					{
						JavaBean.setProperty(obj, property, 
						new java.sql.Time(
						Calendar.getInstance().getTime().getTime()));
					}
					else if (clz.equals(java.sql.Date.class))
					{
						JavaBean.setProperty(obj, property, new java.sql.Date(Calendar.getInstance().getTime().getTime()));
					}
					else if (clz.equals(java.util.Date.class))
					{
						JavaBean.setProperty(obj, property, Calendar.getInstance().getTime());
					}
					//Timestamp
					else if (clz.equals(java.sql.Timestamp.class))
					{
						JavaBean.setProperty(obj, property, new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()));
					}
					else if (clz.equals(java.util.Calendar.class))
					{
						JavaBean.setProperty(obj, property, Calendar.getInstance());
					}
					else if (clz.equals(LocalTime.class))
					{
						JavaBean.setProperty(obj, property, LocalTime.now());
					}
					else if (clz.equals(LocalDate.class))
					{
						JavaBean.setProperty(obj, property, LocalDate.now());
					}
					else if (clz.equals(LocalDateTime.class))
					{
						JavaBean.setProperty(obj, property, LocalDateTime.now());
					}
					else
					{
						JavaBean.setProperty(obj, property, ClassPath.newInstance(clz));
					}
				}
				catch (Exception e)
				{
					throw new SetupException("Cannot create property:"+property+" for object class:"
									+this.creationClass.getName()+"  ERROR:"+e.getMessage(),e); 
				}
			}
			
			return obj;
		}
		catch (RuntimeException e)
		{
			throw e;
			
		}
		catch (Exception e)
		{
			throw new RuntimeException(e.getMessage(),e);
		}
	}
892287
public static <T> T newInstance(Class<T> clazz) throws MjdbcException {
        try {
            return clazz.newInstance();

        } catch (InstantiationException ex) {
            throw new MjdbcException(
                    "Failed to create instance: " + clazz.getName() + " - " + ex.getMessage());

        } catch (IllegalAccessException ex) {
            throw new MjdbcException(
                    "Failed to create instance: " + clazz.getName() + " - " + ex.getMessage());
        }
    }
366001
public static Dialect buildDialect(String dialectName) throws DialectException {
        try {
            return (Dialect) loadDialect(dialectName).newInstance();
        } catch (ClassNotFoundException e) {
            throw new DialectException("Dialect class not found: " + dialectName);
        } catch (Exception e) {
            throw new DialectException("Could not instantiate dialect class", e);
        }
    }
828323
public Object toObject(Entity entity, Class targetClass) {
        if (registry == null) {
            LOG.warn("No ResourceRegistry set, using default which "
                    + "will scan the entire classpath. It would be better to set your own registry that filters by packages.");
            try {
                registry = ResourceRegistryImpl.newInstance((String[]) null);
            } catch (Siren4JException e) {
                throw new Siren4JRuntimeException(e);
            }
        }
        Resource resource = null;
        if (entity != null) {
            String sirenClass = targetClass != null
                    ? targetClass.getName()
                    : (String) entity.getProperties().get(Siren4J.CLASS_RESERVED_PROPERTY);
            String[] eClass = entity.getComponentClass();
            if (StringUtils.isBlank(sirenClass) && (eClass == null || eClass.length == 0)) {
                throw new Siren4JConversionException(
                        "No entity class defined, won't be able to match to Java class. Can't go on.");
            }

            if (StringUtils.isBlank(sirenClass)) {
                sirenClass = eClass[0];
            }
            if (!registry.containsEntityEntry(sirenClass)) {
                throw new Siren4JConversionException("No matching resource found in the registry. Can't go on.");
            }
            Class<?> clazz = registry.getClassByEntityName(sirenClass);
            List<ReflectedInfo> fieldInfo = ReflectionUtils.getExposedFieldInfo(clazz);
            Object obj = null;
            try {
                obj = clazz.newInstance();
            } catch (Exception e) {
                throw new Siren4JConversionException(e);
            }

            // Set properties
            handleSetProperties(obj, clazz, entity, fieldInfo);
            // Set sub entities
            handleSetSubEntities(obj, clazz, entity, fieldInfo);

            resource = (Resource) obj;
        }
        return resource;
    }