List of usage examples for org.hibernate MappingException MappingException
public MappingException(String message)
From source file:org.openmrs.module.addresshierarchy.util.HibernateEnumType.java
License:Open Source License
public void setParameterValues(Properties params) { String enumClassName = params.getProperty("enumClassName"); if (enumClassName == null) { throw new MappingException("enumClassName parameter not specified"); }/*from ww w . j a v a2s .c o m*/ try { this.clazz = Class.forName(enumClassName); } catch (ClassNotFoundException e) { throw new MappingException("enumClass " + enumClassName + " not found", e); } }
From source file:org.openmrs.module.amrsreports.db.hibernate.type.MohStringEnumType.java
License:Open Source License
@SuppressWarnings("unchecked") public void setParameterValues(final Properties parameters) { String enumClassName = parameters.getProperty("enum"); if (enumClassName == null) { throw new MappingException("enum class parameter not specified ..."); }//from w ww. ja v a2 s . c om try { this.enumClass = (Class<T>) Class.forName(enumClassName); } catch (ClassNotFoundException e) { throw new MappingException("enumClass " + enumClassName + " not found", e); } setDefaultValue(parameters.getProperty("defaultValue")); }
From source file:org.openmrs.module.sync.api.db.hibernate.usertype.GenericEnumUserType.java
License:Open Source License
public void setParameterValues(Properties params) { String enumClassName = params.getProperty("enumClassName"); if (enumClassName == null) { throw new MappingException("enumClassName parameter not specified"); }//from ww w . j a v a2s . co m try { this.clazz = Context.loadClass(enumClassName); } catch (ClassNotFoundException e) { throw new MappingException("enumClass " + enumClassName + " not found", e); } }
From source file:org.ppwcode.vernacular.value_III.hibernate3.PropertyEditorUserType.java
License:Apache License
/** * Set the type of values we will operate for, as a fully qualified name. The name of the * type we will operate for needs to be given in a property with key "<code>propertyType</code>". * We also retrieve a {@link #getPropertyEditor() property editor} from the {@link PropertyEditorManager} * for that type./*from ww w.ja v a 2s . c om*/ * If a type with the given name cannot be loaded, or we cannot find a {@link PropertyEditor} * for that type, this is an error. */ @MethodContract(post = { @Expression("returnedClass() == type(_params.getProperty('propertyType')"), @Expression("propertyEditor == PropertyEditorManager.findEditor(returnedClass())") }) public void setParameterValues(Properties params) { String fqcn = params.getProperty("propertyType"); if (fqcn == null) { throw new MappingException("type parameter not specified in Hibernate configuration"); } try { $valueType = type(fqcn); } catch (AssertionError aErr) { // MUDO booo! type really needs to throw exception throw new MappingException("enumClass " + fqcn + " not found", aErr); } initPropertyEditor(); }
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 . ja v a 2 s.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 . java2s . c om 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() { /**//from w w w . j a v a 2 s .c o 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:org.zanata.model.type.EntityStatusType.java
License:Open Source License
public EntityStatus stringToObject(String xml) throws Exception { if (xml.length() != 1) { throw new MappingException("multiple or zero characters found parsing string"); }//from ww w.ja va 2 s . co m return EntityStatus.valueOf(xml.charAt(0)); }
From source file:org.zanata.model.type.EntityTypeType.java
License:Open Source License
public EntityType stringToObject(String xml) throws Exception { if (xml.length() < 1) { throw new MappingException("multiple or zero characters found parsing string"); }//from w w w . j a va 2 s . c o m return EntityType.getValueOf(xml); }
From source file:org.zanata.model.type.RequestStateType.java
License:Open Source License
public RequestState stringToObject(String xml) throws Exception { if (xml.length() != 1) { throw new MappingException("multiple or zero characters found parsing string '" + xml + "'"); }// w w w. jav a2 s.c o m return RequestState.getEnum(xml); }