List of usage examples for org.hibernate.mapping PersistentClass getSuperclass
public abstract PersistentClass getSuperclass();
From source file:com.fiveamsolutions.nci.commons.audit.AuditLogInterceptor.java
License:Open Source License
/** * Retrieves the column name for the given PersistentClass and fieldName. * * @param pc/* w ww.ja v a 2 s . c o m*/ * @param fieldName * @return columnName */ private static String getColumnName(PersistentClass pc, String fieldName) { if (pc == null) { return null; } String columnName = null; Property property = pc.getProperty(fieldName); for (Iterator<?> it3 = property.getColumnIterator(); it3.hasNext();) { Object o = it3.next(); if (!(o instanceof Column)) { LOG.debug("Skipping non-column (probably a formula"); continue; } Column column = (Column) o; columnName = column.getName(); break; } if (columnName == null) { try { columnName = getColumnName(pc.getSuperclass(), fieldName); } catch (MappingException e) { // in this case the annotation / mapping info was at the current class and not the base class // but for some reason the column name could not be determined. // This will happen when a subclass of an entity uses a joined subclass. // in this case just set column Name to null and let the caller default to the property name. columnName = null; } } return columnName; }
From source file:edu.wustl.common.util.dbManager.HibernateMetaData.java
License:BSD License
/** * This method returns the super class of the obj passed * @author aarti_sharma//from w w w . ja v a 2 s .c om * @param objClass * @return */ public static Class getSuperClass(Object obj) { Class objClass = obj.getClass(); PersistentClass persistentClass = cfg.getClassMapping(objClass.getName()); PersistentClass superClass = persistentClass.getSuperclass(); return superClass.getClass(); }
From source file:edu.wustl.common.util.dbManager.HibernateMetaData.java
License:BSD License
/** * This method returns the supermost class * of the class passed that is in the same package as class * @author aarti_sharma/*from ww w .j av a 2s.com*/ * @param objClass * @return */ public static Class getSupermostClassInPackage(Object obj) { Class objClass = obj.getClass(); Package objPackage = objClass.getPackage(); //Logger.out.debug("Input Class: " + objClass.getName()+" Package:"+objPackage.getName()); PersistentClass persistentClass = cfg.getClassMapping(objClass.getName()); if (persistentClass != null && persistentClass.getSuperclass() != null) { //Logger.out.debug(objPackage.getName()+" "+persistentClass.getClassName()+"*********"+persistentClass.getSuperclass().getMappedClass().getPackage().getName()); // Logger.out.debug("!!!!!!!!!!! "+persistentClass.getSuperclass().getMappedClass().getPackage().getName() // .equals(objPackage.getName())); do { persistentClass = persistentClass.getSuperclass(); } while (persistentClass != null); // Logger.out.debug("Supermost class in the same package:" // + persistentClass.getMappedClass().getName()); } else { return objClass; } return persistentClass.getMappedClass(); }
From source file:gov.nih.nci.system.dao.impl.orm.ORMDAOImpl.java
License:Open Source License
/** * If query is from grid then create the target object * and set the attributes by iterating over attributes defined in HBM * @param pclass// ww w. j a v a2 s.c o m * @param entityName * @param rows * @return * @throws Exception */ private List createObjectList(PersistentClass pclass, String entityName, List rows) throws Exception { List retrunList = new ArrayList(); List<Field> fieldList = new ArrayList<Field>(); PersistentClass targetClass = pclass; pclass = targetClass; /** * Get the field list of Target class */ getFieldList(pclass, fieldList); /** * Loop over all the super classes of target class */ while (pclass.getSuperclass() != null) { pclass = pclass.getSuperclass(); /** * Get the field list of Super class */ getFieldList(pclass, fieldList); } /** * get the identifier field */ String identifier = pclass.getIdentifierProperty().getName(); Field idField = pclass.getMappedClass().getDeclaredField(identifier); idField.setAccessible(true); fieldList.add(idField); /** * Call caCOREAppServiceDelegator to create domain object instanes */ final String DELEGATOR_CLASS = "edu.wustl.catissuecore.client.CaCoreAppServicesDelegator"; Class delegator = Class.forName(DELEGATOR_CLASS); Object obj = delegator.newInstance(); Method method = delegator.getDeclaredMethod("createTargetObjectList", new Class[] { String.class, List.class, List.class }); Object[] args = { entityName, fieldList, rows }; retrunList = (List) method.invoke(obj, args); return retrunList; }
From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java
License:Open Source License
protected boolean isClassOrSuperClassEAVMapped(PersistentClass pc) { if (pc == null) { return false; }/*ww w . j a va 2 s . co m*/ // don't do the EAV mapped ones if (pc.getEntityName().equals(Constants.EAV_EOBJECT_ENTITY_NAME)) { return true; } return isClassOrSuperClassEAVMapped(pc.getSuperclass()); }
From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java
License:Open Source License
/** Recursively check the container prop in the super hierarchy */ private boolean hasEContainerProp(PersistentClass pc) { final Iterator<?> it = pc.getPropertyIterator(); while (it.hasNext()) { final Property prop = (Property) it.next(); if (prop.getName().equals(HbConstants.PROPERTY_ECONTAINER)) { return true; }/* w ww . j a v a 2s . com*/ } if (pc.getSuperclass() == null) { return false; } return hasEContainerProp(pc.getSuperclass()); }
From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java
License:Open Source License
/** * Adds a econtainer mapping to the class mapping, is only called for * eclasses which do not have am explicit feature which points to the * container//from www . j av a 2 s . c o m */ protected void addContainerMapping(PersistentClass pc) { // always first check if the super class should have a container mapping if (pc.getSuperclass() != null) { addContainerMapping(pc.getSuperclass()); } // always add for the eav object // todo: externalize if (pc.getEntityName().equals(Constants.EAV_EOBJECT_ENTITY_NAME) && !hasEContainerProp(pc)) { addContainerMappingToPC(pc); return; } if (!isContained(pc)) { return; } if (hasEContainerProp(pc)) { return; } if (log.isDebugEnabled()) { log.debug("Adding container mapping for " + getMappedName(pc)); } // check if there are not alreadyecontai ner features for the eclass final EClass eclass; if (pc.getEntityName() != null) { eclass = getEntityNameStrategy().toEClass(pc.getEntityName()); } else { eclass = EModelResolver.instance().getEClass(pc.getMappedClass()); } // DCB: Provide a way to avoid container mappings for a particular // class. You'd do this if, for example, // you never load the contained objects except through the containers... // or, you don't fit the use case // for which this was put together (i.e., the generated model editing // code tries to eagerly resolve the // container) if (eclass == null || eclass.getEAnnotation("http://facet.elver.org/SkipContainerMappings") != null) { return; // featuremap } for (EReference eref : eclass.getEAllReferences()) { if (eref.isContainer()) { if (log.isDebugEnabled()) { log.debug( "There are container ereferences present, assuming that no separate econtainer columns are required."); } return; } } addContainerMappingToPC(pc); }
From source file:org.eclipse.emf.teneo.hibernate.HbUtil.java
License:Open Source License
public static boolean isEAVMapped(PersistentClass mappedEntity) { if (mappedEntity.getEntityName() != null && mappedEntity.getEntityName().equals(Constants.EAV_EOBJECT_ENTITY_NAME)) { return true; }// www .j a v a2 s . c o m if (mappedEntity.getSuperclass() == null) { return false; } return isEAVMapped(mappedEntity.getSuperclass()); }
From source file:org.web4thejob.orm.EntityMetadataImpl.java
License:Open Source License
void initUniqueKeyConstraints() { // unique key constraints uniqueKeyConstraints = new ArrayList<UniqueKeyConstraint>(); PersistentClass pc = persistentClass; while (pc != null) { for (final Iterator<?> iter = pc.getTable().getUniqueKeyIterator(); iter.hasNext();) { if (persistentClass.equals(pc)) { uniqueKeyConstraints.add(new UniqueKeyConstraintImpl(this, (UniqueKey) iter.next())); } else { uniqueKeyConstraints.add(new UniqueKeyConstraintImpl( MetaReaderServiceImpl.metaCache.get(pc.getEntityName()), (UniqueKey) iter.next())); }/* ww w . j a va2s . c om*/ } if (!RootClass.class.isInstance(pc)) { for (final Iterator<?> iter = pc.getJoinIterator(); iter.hasNext();) { Join join = (Join) iter.next(); for (final Iterator<?> iter2 = join.getTable().getUniqueKeyIterator(); iter2.hasNext();) { uniqueKeyConstraints.add(new UniqueKeyConstraintImpl(this, (UniqueKey) iter2.next())); } } } pc = pc.getSuperclass(); } uniqueKeyConstraints = Collections.unmodifiableList(uniqueKeyConstraints); }
From source file:org.web4thejob.orm.PropertyMetadataImpl.java
License:Open Source License
@Override public boolean isUniqueKeyWith(String propertyName) { if (getName().equals(propertyName)) { return false; }/* w w w .ja va 2 s .c om*/ PersistentClass pc = entityMetadata.getPersistentClass(); while (pc != null) { Table table = pc.getTable(); for (Iterator<?> iterUK = table.getUniqueKeyIterator(); iterUK.hasNext();) { UniqueKey uniqueKey = (UniqueKey) iterUK.next(); if (!(uniqueKey.getColumnSpan() > 1)) { continue; } int totcols = 0; boolean keyMembers = true; for (PropertyMetadataImpl propertyMetadata : Arrays.asList(this, (PropertyMetadataImpl) entityMetadata.getPropertyMetadata(propertyName))) { if (!propertyMetadata.hasColumns()) { return false; } for (final Iterator<?> iterCol = propertyMetadata.property.getColumnIterator(); iterCol .hasNext();) { Column column = (Column) iterCol.next(); keyMembers &= column != null && uniqueKey.containsColumn(column); } totcols += propertyMetadata.property.getColumnSpan(); } if (keyMembers && totcols == uniqueKey.getColumnSpan()) { return true; } } pc = pc.getSuperclass(); } return false; }