@Override public int getMaximumPropertyLength(Class<? extends OpenmrsObject> aClass, String fieldName) { if (configuration == null) { HibernateSessionFactoryBean sessionFactoryBean = (HibernateSessionFactoryBean) applicationContext .getBean("&sessionFactory"); configuration = sessionFactoryBean.getConfiguration(); } PersistentClass persistentClass = configuration.getClassMapping(aClass.getName().split("_")[0]); if (persistentClass == null) { throw new APIException("Couldn't find a class in the hibernate configuration named: " + aClass.getName()); } else { int fieldLength; try { fieldLength = ((Column) persistentClass.getProperty(fieldName).getColumnIterator().next()).getLength(); } catch (Exception e) { log.debug("Could not determine maximum length", e); return -1; } return fieldLength; } }
final String mappedClassName = entry.getValue(); PersistentClass persistentClass = configuration.getClassMapping(mappedClassName); if (persistentClass == null) { persistentClass = configuration.getClassMapping(classSimpleName); if (persistentClass == null) { throw new SPersistenceException("Unable to locate an hibernate mapping file for class: " + mappedClassName + ", found mappings are: " + sb.toString());
PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName());
public PersistentClass getClassMapping(String persistentClass) { return cfg.getClassMapping( persistentClass ); }
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { Class<?> valuesEntity; boolean registerValuesEntity = true; try { valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"); } catch (ClassNotFoundException e) { throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e); } Iterator<PersistentClass> iter = configuration.getClassMappings(); while (iter.hasNext()) { PersistentClass clazz = iter.next(); Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } } if (registerValuesEntity) { // Register values entity if wasn't found configuration.addAnnotatedClass(valuesEntity); configuration.buildMappings(); PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver()); serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping())); }
RootClass getRootClassMapping(String clazz) throws MappingException { try { return (RootClass) getClassMapping( clazz ); } catch (ClassCastException cce) { throw new MappingException( "You may only specify a cache for root <class> mappings" ); } }
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { Class<?> valuesEntity; boolean registerValuesEntity = true; try { valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"); } catch (ClassNotFoundException e) { throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e); } Iterator<PersistentClass> iter = configuration.getClassMappings(); while (iter.hasNext()) { PersistentClass clazz = iter.next(); Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } } if (registerValuesEntity) { // Register values entity if wasn't found configuration.addAnnotatedClass(valuesEntity); configuration.buildMappings(); PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver()); serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping())); }
RootClass getRootClassMapping(String clazz) throws MappingException { try { return ( RootClass ) getClassMapping( clazz ); } catch ( ClassCastException cce ) { throw new MappingException( "You may only specify a cache for root <class> mappings" ); } }
RootClass getRootClassMapping(String clazz) throws MappingException { try { return (RootClass) getClassMapping( clazz ); } catch (ClassCastException cce) { throw new MappingException( "You may only specify a cache for root <class> mappings" ); } }
/** * Find the first possible element in the queue of extends. */ protected org.dom4j.Document findPossibleExtends() { Iterator iter = extendsQueue.entrySet().iterator(); while ( iter.hasNext() ) { Map.Entry entry = ( Entry ) iter.next(); String superclass = ( String ) entry.getKey(); if ( getClassMapping( superclass ) != null ) { List queue = (List) entry.getValue(); if(queue.isEmpty()) { iter.remove(); continue; } else { return ( org.dom4j.Document ) queue.remove(0); } } } return null; }
protected ExtendsQueueEntry findPossibleExtends() { Iterator<ExtendsQueueEntry> itr = extendsQueue.keySet().iterator(); while ( itr.hasNext() ) { final ExtendsQueueEntry entry = itr.next(); boolean found = getClassMapping( entry.getExplicitName() ) != null || getClassMapping( HbmBinder.getClassName( entry.getExplicitName(), entry.getMappingPackage() ) ) != null; if ( found ) { itr.remove(); return entry; } } return null; }
protected ExtendsQueueEntry findPossibleExtends() { Iterator<ExtendsQueueEntry> itr = extendsQueue.keySet().iterator(); while ( itr.hasNext() ) { final ExtendsQueueEntry entry = itr.next(); boolean found = getClassMapping( entry.getExplicitName() ) != null || getClassMapping( HbmBinder.getClassName( entry.getExplicitName(), entry.getMappingPackage() ) ) != null; if ( found ) { itr.remove(); return entry; } } return null; }
Mappings.PropertyReference upr = (Mappings.PropertyReference) iter.next(); PersistentClass clazz = getClassMapping( upr.referencedClass ); if ( clazz == null ) { throw new MappingException(
while ( iter.hasNext() ) { Mappings.PropertyReference upr = ( Mappings.PropertyReference ) iter.next(); PersistentClass clazz = getClassMapping( upr.referencedClass ); if ( clazz == null ) throw new MappingException( "property-ref to unmapped class: " + upr.referencedClass ); boolean found = false;
public List getCustomMappingPropertyList(BaseClass bclass) { List list = new ArrayList(); Configuration hibconfig; if (bclass.hasExternalCustomMapping()) { hibconfig = makeMapping(bclass.getName(), bclass.getCustomMapping()); } else { hibconfig = getConfiguration(); } PersistentClass mapping = hibconfig.getClassMapping(bclass.getName()); if (mapping == null) { return null; } Iterator it = mapping.getPropertyIterator(); while (it.hasNext()) { Property hibprop = (Property) it.next(); String propname = hibprop.getName(); list.add(propname); } return list; }
private boolean isValidCustomMapping(String className, Configuration hibconfig, BaseClass bclass) { PersistentClass mapping = hibconfig.getClassMapping(className); if (mapping == null) { return true; } Iterator it = mapping.getPropertyIterator(); while (it.hasNext()) { Property hibprop = (Property) it.next(); String propname = hibprop.getName(); PropertyClass propclass = (PropertyClass) bclass.getField(propname); if (propclass == null) { log.warn("Mapping contains invalid field name " + propname); return false; } boolean result = isValidColumnType(hibprop.getValue().getType().getName(), propclass.getClassName()); if (result == false) { log.warn("Mapping contains invalid type in field " + propname); return false; } } return true; }
public Setter getSetter(final Class theClass, final String propertyName) throws PropertyNotFoundException { Setter setter = null; Property thisProperty = HibernateUtil.getConfiguration().getClassMapping(theClass.getName()).getProperty(propertyName); MetaAttribute propertyMeta = thisProperty.getMetaAttribute(PropertyHelper.NAKED_PROPERTY); if (propertyMeta != null) { String access = null; MetaAttribute accessMeta = thisProperty.getMetaAttribute(PropertyHelper.NAKED_ACCESS); if (accessMeta != null) { access = accessMeta.getValue(); } PropertyAccessor wrappedAccessor = PropertyAccessorFactory.getPropertyAccessor(access); if (wrappedAccessor != null) { setter = wrappedAccessor.getSetter(theClass, propertyMeta.getValue()); } } return new OptimisticLockSetter( theClass, propertyName, getLongVersionAccessor(), setter); }
public Getter getGetter(final Class theClass, final String propertyName) throws PropertyNotFoundException { Property thisProperty = HibernateUtil.getConfiguration().getClassMapping(theClass.getName()).getProperty(propertyName); MetaAttribute propertyMeta = thisProperty.getMetaAttribute(PropertyHelper.NAKED_PROPERTY); if (propertyMeta != null) { String access = null; MetaAttribute accessMeta = thisProperty.getMetaAttribute(PropertyHelper.NAKED_ACCESS); if (accessMeta != null) { access = accessMeta.getValue(); } PropertyAccessor wrappedAccessor = PropertyAccessorFactory.getPropertyAccessor(access); if (wrappedAccessor != null) { return wrappedAccessor.getGetter(theClass, propertyMeta.getValue()); } } return new OptimisticLockGetter( theClass, propertyName, getLongVersionAccessor() ); } }
public static void ensureMapped(final NakedObjectSpecification specification) { if (configuration.getClassMapping(specification.getFullName()) == null) { requiredToMap.add(specification.getFullName()); if (NakedObjectsContext.getConfiguration().getBoolean(PROPERTY_PREFIX + "showremappings", false)) { LOG.info("remapping" + getRequiredClasses()); } commitTransaction(); // Rebuild the session factory but use any Naked Object persistent classes which have their // specifications loaded. configuration = createConfiguration(); auto = true; createMapping(); bindListeners(); if (NakedObjectsContext.getConfiguration().getBoolean(PROPERTY_PREFIX + "schema-update")) { HibernateTools.updateSchema(configuration, false, true); } rebuildSessionFactory(); } }
public boolean injectCustomMapping(BaseClass doc1class, XWikiContext context) throws XWikiException { // If we haven't turned of dynamic custom mappings we should not inject them if (context.getWiki().hasDynamicCustomMappings() == false) { return false; } String custommapping = doc1class.getCustomMapping(); if (!doc1class.hasExternalCustomMapping()) { return false; } Configuration config = getConfiguration(); // don't add a mapping that's already there if (config.getClassMapping(doc1class.getName()) != null) { return true; } Configuration mapconfig = makeMapping(doc1class.getName(), custommapping); if (!isValidCustomMapping(doc1class.getName(), mapconfig, doc1class)) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_INVALID_MAPPING, "Invalid Custom Mapping"); } config.addXML(makeMapping(doc1class.getName(), "xwikicustom_" + doc1class.getName().replaceAll("\\.", "_"), custommapping)); config.buildMappings(); return true; }