List of usage examples for org.hibernate.mapping Property getType
public Type getType() throws MappingException
From source file:lucee.runtime.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl.java
License:Open Source License
private Serializable toIdentifier(Serializable id) { if (id instanceof Component) { HashMap<String, Object> map = new HashMap<String, Object>(); Component cfc = (Component) id; ComponentScope scope = cfc.getComponentScope(); lucee.runtime.component.Property[] props = HibernateUtil.getIDProperties(cfc, true, true); lucee.runtime.component.Property p; String name;/* w w w.j ava 2 s . co m*/ Object value; for (int i = 0; i < props.length; i++) { p = props[i]; name = p.getName(); value = scope.get(CommonUtil.createKey(name), null); String type = p.getType(); if (Decision.isAnyType(type)) { type = "string"; try { Object o = p.getMetaData(); if (o instanceof Struct) { Struct meta = (Struct) o; String gen = Caster.toString(meta.get(KeyConstants._generator, null), null); if (!StringUtil.isEmpty(gen)) { type = HBMCreator.getDefaultTypeForGenerator(gen, "string"); } } } catch (Throwable t) { } } try { value = HibernateCaster.toHibernateValue(ThreadLocalPageContext.get(), value, type); } catch (PageException pe) { } map.put(name, value); } return map; } return id; }
From source file:org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer.java
License:Open Source License
private void setIdentifierTypeAsAnnotation(Property prop) { EAnnotation eAnnotation = getEClass().getEAnnotation(HibernateStore.ID_TYPE_EANNOTATION_SOURCE); if (eAnnotation == null) { eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); eAnnotation.setSource(HibernateStore.ID_TYPE_EANNOTATION_SOURCE); eAnnotation.getDetails().put(HibernateStore.ID_TYPE_EANNOTATION_KEY, prop.getType().getName()); getEClass().getEAnnotations().add(eAnnotation); } else if (!eAnnotation.getDetails().containsKey(HibernateStore.ID_TYPE_EANNOTATION_KEY)) { eAnnotation.getDetails().put(HibernateStore.ID_TYPE_EANNOTATION_KEY, prop.getType().getName()); }/*from ww w . j ava2 s .c o m*/ }
From source file:org.openeos.erp.core.ui.internal.ClientFilterProvider.java
License:Apache License
private boolean hasProperty(PersistentClass persistentClass, String propertyName, Class<?> propertyClass) { try {//w ww . ja va2 s .c om Property property = persistentClass.getProperty(propertyName); return property.getType().getReturnedClass().isAssignableFrom(propertyClass); } catch (MappingException ex) { return false; } }
From source file:org.sns.tool.hibernate.analyzer.HibernateAnalysis.java
License:Open Source License
public HibernateAnalysis(final Configuration configuration, final List<HibernateAnalysisRule> analyzers) { this.configuration = configuration; this.analysisRules = analyzers; // the following was copied from org.hibernate.cfg.Configuration.buildMapping() because buildMapping() was private this.mapping = new Mapping() { /**/*from w w w.j a v a2s. co m*/ * Returns the identifier type of a mapped class */ public Type getIdentifierType(String persistentClass) throws MappingException { final PersistentClass pc = configuration.getClassMapping(persistentClass); if (pc == null) throw new MappingException("persistent class not known: " + persistentClass); return pc.getIdentifier().getType(); } public String getIdentifierPropertyName(String persistentClass) throws MappingException { final PersistentClass pc = configuration.getClassMapping(persistentClass); if (pc == null) throw new MappingException("persistent class not known: " + persistentClass); if (!pc.hasIdentifierProperty()) return null; return pc.getIdentifierProperty().getName(); } public Type getPropertyType(String persistentClass, String propertyName) throws MappingException { final PersistentClass pc = configuration.getClassMapping(persistentClass); if (pc == null) throw new MappingException("persistent class not known: " + persistentClass); Property prop = pc.getProperty(propertyName); if (prop == null) throw new MappingException("property not known: " + persistentClass + '.' + propertyName); return prop.getType(); } }; String dialectName = configuration.getProperty(Environment.DIALECT); if (dialectName == null) dialectName = org.hibernate.dialect.GenericDialect.class.getName(); try { final Class cls = Class.forName(dialectName); this.dialect = (Dialect) cls.newInstance(); } catch (Exception e) { throw new HibernateDiagramGeneratorException(e); } for (final Iterator classes = configuration.getClassMappings(); classes.hasNext();) { final PersistentClass pclass = (PersistentClass) classes.next(); final Table table = (Table) pclass.getTable(); tableToClassMap.put(table, pclass); } }
From source file:org.sns.tool.hibernate.struct.impl.DefaultTableStructure.java
License:Open Source License
public DefaultTableStructure(final Configuration configuration, final TableStructureRules rules) { this.configuration = configuration; this.configuration.buildMappings(); this.rules = rules; for (final Iterator classes = configuration.getClassMappings(); classes.hasNext();) { final PersistentClass pclass = (PersistentClass) classes.next(); final Table table = (Table) pclass.getTable(); boolean isChildTable = false; for (final Iterator fKeys = table.getForeignKeyIterator(); fKeys.hasNext();) { final ForeignKey foreignKey = (ForeignKey) fKeys.next(); if (rules.isParentRelationship(this, foreignKey)) { isChildTable = true;//from w w w . j a va2 s. c o m break; } } if (!isChildTable) { final TableStructureNode topLevelNode = createNode(pclass, table, null, 0); topLevelTableNodes.add(topLevelNode); categorize(topLevelNode); } } for (final Iterator classes = configuration.getClassMappings(); classes.hasNext();) { final PersistentClass pclass = (PersistentClass) classes.next(); final Table table = (Table) pclass.getTable(); tableToClassMap.put(table, pclass); } // the following was copied from org.hibernate.cfg.Configuration.buildMapping() because buildMapping() was private this.mapping = new Mapping() { public Type getReferencedPropertyType(String string, String string1) throws MappingException { return null; } /** * Returns the identifier type of a mapped class */ public Type getIdentifierType(String persistentClass) throws MappingException { final PersistentClass pc = configuration.getClassMapping(persistentClass); if (pc == null) throw new MappingException("persistent class not known: " + persistentClass); return pc.getIdentifier().getType(); } public String getIdentifierPropertyName(String persistentClass) throws MappingException { final PersistentClass pc = configuration.getClassMapping(persistentClass); if (pc == null) throw new MappingException("persistent class not known: " + persistentClass); if (!pc.hasIdentifierProperty()) return null; return pc.getIdentifierProperty().getName(); } public Type getPropertyType(String persistentClass, String propertyName) throws MappingException { final PersistentClass pc = configuration.getClassMapping(persistentClass); if (pc == null) throw new MappingException("persistent class not known: " + persistentClass); Property prop = pc.getProperty(propertyName); if (prop == null) throw new MappingException("property not known: " + persistentClass + '.' + propertyName); return prop.getType(); } }; String dialectName = configuration.getProperty(Environment.DIALECT); if (dialectName == null) dialectName = org.hibernate.dialect.GenericDialect.class.getName(); try { final Class cls = Class.forName(dialectName); this.dialect = (Dialect) cls.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } resolveDependencies(); }
From source file:org.teiid.spring.autoconfigure.SchemaBuilderUtility.java
License:Apache License
private static Mapping buildMapping(final Metadata metadata) { return new Mapping() { /**//w w w .ja v a 2 s .co m * Returns the identifier type of a mapped class */ @Override public Type getIdentifierType(String persistentClass) throws MappingException { final PersistentClass pc = metadata.getEntityBinding(persistentClass); if (pc == null) { throw new MappingException("persistent class not known: " + persistentClass); } return pc.getIdentifier().getType(); } @Override public String getIdentifierPropertyName(String persistentClass) throws MappingException { final PersistentClass pc = metadata.getEntityBinding(persistentClass); if (pc == null) { throw new MappingException("persistent class not known: " + persistentClass); } if (!pc.hasIdentifierProperty()) { return null; } return pc.getIdentifierProperty().getName(); } @Override public Type getReferencedPropertyType(String persistentClass, String propertyName) throws MappingException { final PersistentClass pc = metadata.getEntityBinding(persistentClass); if (pc == null) { throw new MappingException("persistent class not known: " + persistentClass); } Property prop = pc.getProperty(propertyName); if (prop == null) { throw new MappingException("property not known: " + persistentClass + '.' + propertyName); } return prop.getType(); } @Override public IdentifierGeneratorFactory getIdentifierGeneratorFactory() { return null; } }; }
From source file:tools.xor.HibernateType.java
License:Apache License
@Override public List<Type> getEmbeddableTypes() { List<Type> result = new ArrayList<Type>(); Iterator<?> itr = getPropertyIterator(); while (itr.hasNext()) { org.hibernate.mapping.Property property = (org.hibernate.mapping.Property) itr.next(); if (property.getType().isComponentType()) { HibernateType type = new HibernateType(property.getType(), property.getValue()); result.add(type);//w w w. jav a 2 s . co m } } return result; }
From source file:tools.xor.HibernateType.java
License:Apache License
public void setProperty(HibernateDAS dataAccessService) { if (properties == null) { // populate the properties for this type properties = new HashMap<String, Property>(); Iterator<?> propertyIterator = getPropertyIterator(); while (propertyIterator.hasNext()) { org.hibernate.mapping.Property hibernateProperty = (org.hibernate.mapping.Property) propertyIterator .next();/* www. j a va 2 s.co m*/ logger.debug("[" + getName() + "] hibernate property name: " + hibernateProperty.getName() + ", type name: " + hibernateProperty.getType().getReturnedClass()); Type propertyType = dataAccessService.getType(hibernateProperty.getType().getReturnedClass()); HibernateProperty property = new HibernateProperty(hibernateProperty, propertyType, this, dataAccessService.getConfiguration()); property.init(dataAccessService); properties.put(property.getName(), property); } // Components don't have identifiers if (!hibernateType.isComponentType()) { org.hibernate.mapping.Property idProperty = ((PersistentClass) hibernateClass) .getIdentifierProperty(); if (idProperty != null) { logger.debug("Hibernate Identifier attribute name: " + idProperty.getName()); Type propertyType = dataAccessService.getType(idProperty.getType().getReturnedClass()); identifierProperty = new HibernateProperty(idProperty, propertyType, this, dataAccessService.getConfiguration()); properties.put(identifierProperty.getName(), identifierProperty); } org.hibernate.mapping.Property verProperty = ((PersistentClass) hibernateClass).getVersion(); if (verProperty != null) { logger.debug("Hibernate version attribute name: " + verProperty.getName()); Type propertyType = dataAccessService.getType(verProperty.getType().getReturnedClass()); versionProperty = new HibernateProperty(verProperty, propertyType, this, dataAccessService.getConfiguration()); properties.put(versionProperty.getName(), versionProperty); } } } }