Java Code Examples for javax.persistence.metamodel.EntityType#getJavaType()

The following examples show how to use javax.persistence.metamodel.EntityType#getJavaType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JPAPersistenceManager.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private void manageProperty(EntityType targetEntity, Object obj, String aKey, JSONObject aRecord) {

		logger.debug("IN");

		try {
			Attribute a = targetEntity.getAttribute(aKey);
			Class clas = targetEntity.getJavaType();
			Field f = clas.getDeclaredField(aKey);
			f.setAccessible(true);
			Object valueConverted = this.convertValue(aRecord.get(aKey), a);
			f.set(obj, valueConverted);
		} catch (Exception e) {
			throw new SpagoBIRuntimeException("Error setting Field " + aKey + "", e);
		} finally {
			logger.debug("OUT");
		}
	}
 
Example 2
Source File: JPAPersistenceManager.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private void setKeyProperty(EntityType targetEntity, Object obj, String aKey, Integer value) {

		logger.debug("IN");

		try {
			Attribute a = targetEntity.getAttribute(aKey);
			Class clas = targetEntity.getJavaType();
			Field f = clas.getDeclaredField(aKey);
			f.setAccessible(true);
			Object valueConverted = this.convertValue(value, a);
			f.set(obj, valueConverted);
		} catch (Exception e) {
			throw new SpagoBIRuntimeException("Error setting Field " + aKey + "", e);
		} finally {
			logger.debug("OUT");
		}
	}
 
Example 3
Source File: CacheConfiguration.java    From angularjs-springboot-bookstore with MIT License 6 votes vote down vote up
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap", String.class, "16M"));
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getMetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name, "entity cannot exist without a identifier");

        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            cache.getCacheConfiguration().setTimeToLiveSeconds(env.getProperty("cache.timeToLiveSeconds", Long.class, 3600L));
            net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
            cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
 
Example 4
Source File: CacheConfiguration.java    From ServiceCutter with Apache License 2.0 6 votes vote down vote up
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap", String.class, "16M"));
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getMetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name, "entity cannot exist without a identifier");

        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            cache.getCacheConfiguration().setTimeToLiveSeconds(env.getProperty("cache.timeToLiveSeconds", Long.class, 3600L));
            net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
            cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
 
Example 5
Source File: DefaultIdManager.java    From onedev with MIT License 5 votes vote down vote up
@Sessional
@Override
public void init() {
	for (EntityType<?> entityType: ((EntityManagerFactory)persistManager.getSessionFactory()).getMetamodel().getEntities()) {
		Class<?> entityClass = entityType.getJavaType();
		nextIds.put(entityClass, new AtomicLong(getMaxId(entityClass)+1));
	}
}
 
Example 6
Source File: TagManagerImpl.java    From zstack with Apache License 2.0 5 votes vote down vote up
void init() {
    for (EntityType<?> entity : dbf.getEntityManager().getMetamodel().getEntities()) {
        Class type = entity.getJavaType();
        String name = type.getSimpleName();
        resourceTypeClassMap.put(name, type);
        if (logger.isTraceEnabled()) {
            logger.trace(String.format("discovered tag resource type[%s], class[%s]", name, type));
        }
    }

    try {
        // this makes sure DatabaseFacade is injected into every SystemTag object
        initSystemTags();
    } catch (Exception e) {
        throw new CloudRuntimeException(e);
    }

    Set<Class<?>> createMessageClass = BeanUtils.reflections.getTypesAnnotatedWith(TagResourceType.class)
            .stream().filter(i->i.isAnnotationPresent(TagResourceType.class)).collect(Collectors.toSet());
    for (Class cmsgClz : createMessageClass) {
        TagResourceType at = (TagResourceType) cmsgClz.getAnnotation(TagResourceType.class);
        Class resType = at.value();
        if (!resourceTypeClassMap.values().contains(resType)) {
            throw new CloudRuntimeException(String.format(
                    "tag resource type[%s] defined in @TagResourceType of class[%s] is not a VO entity",
                    resType.getName(), cmsgClz.getName()));
        }
        resourceTypeCreateMessageMap.put(cmsgClz, resType);
    }

    autoDeleteTagClasses = new ArrayList<>(BeanUtils.reflections.getTypesAnnotatedWith(AutoDeleteTag.class));
    List<String> clzNames = CollectionUtils.transformToList(autoDeleteTagClasses, new Function<String, Class>() {
        @Override
        public String call(Class arg) {
            return arg.getSimpleName();
        }
    });

    logger.debug(String.format("tags of following resources are auto-deleting enabled: %s", clzNames));
}
 
Example 7
Source File: EntitiesHandler.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
private List<Map<String, ?>> recordsInfo() {
	List<Map<String, ?>> records = U.list();

	for (EntityType<?> type : JPA.getEntityTypes()) {
		Class<?> javaType = type.getJavaType();

		long count = JPA.count(javaType);
		String idType = type.getIdType() != null ? type.getIdType().getJavaType().getSimpleName() : "";
		Object superType = type.getSupertype() != null ? type.getSupertype().getJavaType().getSimpleName() : "";

		records.add(U.map("type", type.getName(), "extends", superType, "ID Type", idType, "count", count));
	}

	return records;
}
 
Example 8
Source File: RootImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public RootImpl(CriteriaBuilderImpl criteriaBuilder, EntityType<X> entityType, boolean allowJoins) {
	super( criteriaBuilder, entityType.getJavaType() );
	this.entityType = entityType;
	this.allowJoins = allowJoins;
}