private void introspectTableCache(EntityType entityType, Class type) { AmberTableCache tableCache = (AmberTableCache) type.getAnnotation(AmberTableCache.class); if (tableCache != null) { entityType.getTable().setReadOnly(tableCache.readOnly()); long cacheTimeout = Period.toPeriod(tableCache.timeout()); entityType.getTable().setCacheTimeout(cacheTimeout); } }
/** Introspects. */ private EmbeddableType introspectEmbeddableType(Class type) throws ConfigException, SQLException { getInternalEmbeddableConfig(type, _annotationCfg); Embeddable embeddableAnn = (Embeddable) _annotationCfg.getAnnotation(); EmbeddableConfig embeddableConfig = _annotationCfg.getEmbeddableConfig(); /* if (_annotationCfg.isNull()) return null; */ String typeName = type.getName(); EmbeddableType embeddableType = _persistenceUnit.createEmbeddable(typeName, type); _configManager.addType(type, new EmbeddableConfig(type.getName(), this, embeddableType)); try { boolean isField = isField(type, embeddableConfig); if (isField) embeddableType.setFieldAccess(true); // XXX: jpa/0u21 Embeddable ann = (Embeddable) type.getAnnotation(javax.persistence.Embeddable.class); if (ann == null) { isField = true; embeddableType.setIdClass(true); _persistenceUnit.getAmberContainer().addEmbeddable(typeName, embeddableType); } embeddableType.setInstanceClassName(type.getName() + "__ResinExt"); embeddableType.setEnhanced(true); if (isField) introspectFields(_persistenceUnit, embeddableType, null, type, embeddableConfig, true); else introspectMethods(_persistenceUnit, embeddableType, null, type, embeddableConfig); } catch (ConfigException e) { if (embeddableType != null) embeddableType.setConfigException(e); throw e; } catch (RuntimeException e) { if (embeddableType != null) embeddableType.setConfigException(e); throw e; } return embeddableType; }
private void introspectDiscriminatorValue(Class type, EntityType entityType) { DiscriminatorValue discValueAnn = (DiscriminatorValue) type.getAnnotation(DiscriminatorValue.class); String discriminatorValue = null; if (discValueAnn != null) discriminatorValue = discValueAnn.value(); if (discriminatorValue == null || discriminatorValue.equals("")) { String name = entityType.getBeanClass().getSimpleName(); discriminatorValue = name; } entityType.setDiscriminatorValue(discriminatorValue); }
private void introspectAttributeOverrides(EntityType entityType, Class type) { EntityType parent = entityType.getParentType(); if (parent == null) return; boolean isAbstract = Modifier.isAbstract(parent.getBeanClass().getModifiers()); if (parent.isEntity() && !isAbstract) return; HashMap<String, ColumnConfig> overrideMap = new HashMap<String, ColumnConfig>(); getInternalAttributeOverrideConfig(type, _annotationCfg); AttributeOverride attributeOverrideAnn = (AttributeOverride) _annotationCfg.getAnnotation(); boolean hasAttributeOverride = (attributeOverrideAnn != null); AttributeOverrides attributeOverridesAnn = (AttributeOverrides) type.getAnnotation(AttributeOverrides.class); ArrayList<AttributeOverrideConfig> attributeOverrideList = null; EntityConfig entityConfig = getEntityConfig(type.getName()); if (entityConfig != null) attributeOverrideList = entityConfig.getAttributeOverrideList(); boolean hasAttributeOverrides = false; if ((attributeOverrideList != null) && (attributeOverrideList.size() > 0)) { hasAttributeOverrides = true; } else if (attributeOverridesAnn != null) hasAttributeOverrides = true; if (hasAttributeOverride && hasAttributeOverrides) throw new ConfigException( L.l("{0} may not have both @AttributeOverride and @AttributeOverrides", type)); if (attributeOverrideList == null) attributeOverrideList = new ArrayList<AttributeOverrideConfig>(); if (hasAttributeOverride) { // Convert annotation to configuration. AttributeOverrideConfig attOverrideConfig = convertAttributeOverrideAnnotationToConfig(attributeOverrideAnn); attributeOverrideList.add(attOverrideConfig); } else if (hasAttributeOverrides) { if (attributeOverrideList.size() > 0) { // OK: attributeOverrideList came from orm.xml } else { // Convert annotations to configurations. AttributeOverride attOverridesAnn[] = attributeOverridesAnn.value(); AttributeOverrideConfig attOverrideConfig; /* XXX: for (int i = 0; i < attOverridesAnn.length; i++) { attOverrideConfig = convertAttributeOverrideAnnotationToConfig((JAnnotation) attOverridesAnn[i]); attributeOverrideList.add(attOverrideConfig); } * */ } } for (AttributeOverrideConfig override : attributeOverrideList) { overrideMap.put(override.getName(), override.getColumn()); } _depCompletions.add(new AttributeOverrideCompletion(this, entityType, type, overrideMap)); }