Example usage for org.hibernate.engine.spi Mapping Mapping

List of usage examples for org.hibernate.engine.spi Mapping Mapping

Introduction

In this page you can find the example usage for org.hibernate.engine.spi Mapping Mapping.

Prototype

Mapping

Source Link

Usage

From source file:com.zutubi.pulse.master.hibernate.MutableConfiguration.java

License:Apache License

public Mapping getMapping() {
    return new Mapping() {
        public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
            return null;
        }/*w w  w .j a v a2s  .  c o  m*/

        public Type getIdentifierType(String persistentClass) throws MappingException {
            PersistentClass pc = classes.get(persistentClass);
            if (pc == null) {
                throw new MappingException(I18N.format("unknown.persistent.class", persistentClass));
            }
            return pc.getIdentifier().getType();
        }

        public String getIdentifierPropertyName(String persistentClass) throws MappingException {
            final PersistentClass pc = classes.get(persistentClass);
            if (pc == null) {
                throw new MappingException(I18N.format("unknown.persistent.class", persistentClass));
            }
            if (!pc.hasIdentifierProperty())
                return null;
            return pc.getIdentifierProperty().getName();
        }

        public Type getReferencedPropertyType(String persistentClass, String propertyName)
                throws MappingException {
            final PersistentClass pc = classes.get(persistentClass);
            if (pc == null) {
                throw new MappingException(I18N.format("unknown.persistent.class", persistentClass));
            }
            Property prop = pc.getReferencedProperty(propertyName);
            if (prop == null) {
                throw new MappingException(
                        I18N.format("unknown.persistent.class.property", persistentClass + '.' + propertyName));
            }
            return prop.getType();
        }
    };
}

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  . ja  va2  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;
        }
    };
}