List of usage examples for org.hibernate.mapping PersistentClass getEntityName
public String getEntityName()
From source file:com.github.shyiko.rook.target.hibernate4.cache.SynchronizationContext.java
License:Apache License
private void loadClassMappings(Configuration configuration) throws SQLException { for (Iterator<PersistentClass> iterator = configuration.getClassMappings(); iterator.hasNext();) { PersistentClass persistentClass = iterator.next(); String entityName = persistentClass.getEntityName(); boolean isCacheable = ((SessionFactoryImplementor) sessionFactory).getEntityPersister(entityName) .hasCache();// w w w.j a va 2 s .c om if (isCacheable) { Table table = persistentClass.getTable(); PrimaryKey primaryKey = new PrimaryKey(persistentClass, getColumnIndexByNameMap(table)); evictionTargetsOf(table).add(new EvictionTarget(entityName, primaryKey, false)); } } }
From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.SynchronizationContext.java
License:Apache License
@SuppressWarnings("unchecked") private void loadIndexingDirectives(Configuration configuration) { Map<String, IndexingDirective> directivesByEntityNameMap = new HashMap<String, IndexingDirective>(); Collection<Property> allContainedInProperties = new ArrayList<Property>(); for (Iterator<PersistentClass> classIterator = configuration.getClassMappings(); classIterator.hasNext();) { PersistentClass persistentClass = classIterator.next(); boolean suppressSelfIndexing = true; Class mappedClass = persistentClass.getMappedClass(); Indexed indexed = (Indexed) mappedClass.getAnnotation(Indexed.class); EntityIndexingInterceptor indexingInterceptor = null; if (indexed != null) { suppressSelfIndexing = false; Class<? extends EntityIndexingInterceptor> interceptorClass = indexed.interceptor(); if (interceptorClass != DefaultEntityInterceptor.class) { try { indexingInterceptor = interceptorClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + interceptorClass, e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + interceptorClass, e); }/*from w w w . j a v a 2 s .c o m*/ } } Collection<Property> containedInProperties = extractAnnotatedProperties(persistentClass, ContainedIn.class); if (suppressSelfIndexing && containedInProperties.isEmpty()) { continue; } allContainedInProperties.addAll(containedInProperties); PrimaryKey primaryKey = new PrimaryKey(persistentClass); Collection<Reference> containers = new ArrayList<Reference>(); for (Property property : containedInProperties) { containers.add(new Reference(property.getGetter(mappedClass))); } IndexingDirective indexingDirective = new IndexingDirective(primaryKey, suppressSelfIndexing, indexingInterceptor, containers); Table table = persistentClass.getTable(); directivesByTable.put(schema + "." + table.getName().toLowerCase(), indexingDirective); directivesByEntityClass.put(mappedClass, indexingDirective); directivesByEntityNameMap.put(persistentClass.getEntityName(), indexingDirective); } loadIndexingDirectivesForJoinTables(allContainedInProperties, directivesByEntityNameMap); }
From source file:com.googlecode.hibernate.audit.extension.auditable.DefaultAuditableInformationProvider.java
License:Open Source License
public String getEntityName(Metadata metadata, Session session, String auditTypeClassName) { if (provider != null) { return provider.getEntityName(metadata, session, auditTypeClassName); }// ww w .ja v a 2s.c o m for (PersistentClass classMapping : metadata.getEntityBindings()) { Class mappedClass = classMapping.getMappedClass(); if (mappedClass == null) { mappedClass = classMapping.getProxyInterface(); } if (mappedClass.getName().equals(auditTypeClassName)) { return classMapping.getEntityName(); } } return auditTypeClassName; }
From source file:com.googlecode.hibernate.audit.listener.AuditListener.java
License:Open Source License
private void processDynamicUpdate(Metadata metadata, SessionFactoryServiceRegistry serviceRegistry) { if (serviceRegistry.getService(ConfigurationService.class).getSetting( HibernateAudit.AUDIT_SET_DYNAMIC_UPDATE_FOR_AUDITED_MODEL_PROPERTY, StandardConverters.BOOLEAN, false)) {/*from w w w . j a v a 2 s . c o m*/ for (PersistentClass persistentClass : metadata.getEntityBindings()) { persistentClass.setDynamicUpdate(true); if (log.isInfoEnabled()) { log.info("Set dynamic-update to true for entity: " + persistentClass.getEntityName()); } } } }
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected void createM2O(Configuration config, Mappings mappings, ForeignKey relationship) { com.manydesigns.portofino.model.database.Table manyMDTable = relationship.getFromTable(); com.manydesigns.portofino.model.database.Table oneMDTable = relationship.getToTable(); String manyMDQualifiedTableName = manyMDTable.getActualEntityName(); String oneMDQualifiedTableName = oneMDTable.getActualEntityName(); RootClass clazz = (RootClass) mappings.getClass(manyMDQualifiedTableName); if (clazz == null) { logger.error("Cannot find table '{}' as 'many' side of foreign key '{}'. Skipping relationship.", manyMDQualifiedTableName, relationship.getName()); return;// ww w .ja v a 2 s . c o m } Table tab = clazz.getTable(); List<String> columnNames = new ArrayList<String>(); for (Reference ref : relationship.getReferences()) { if (ref.getActualFromColumn() == null) { logger.error("Missing from column {}, skipping relationship", ref.getFromColumn()); return; } columnNames.add(ref.getFromColumn()); } ManyToOne m2o = new ManyToOne(mappings, tab); m2o.setLazy(LAZY); final HashMap<String, PersistentClass> persistentClasses = new HashMap<String, PersistentClass>(); persistentClasses.put(oneMDQualifiedTableName, config.getClassMapping(oneMDQualifiedTableName)); m2o.setReferencedEntityName(oneMDQualifiedTableName); m2o.createPropertyRefConstraints(persistentClasses); PersistentClass manyClass = config.getClassMapping(manyMDQualifiedTableName); for (String columnName : columnNames) { Column col = new Column(); col.setName(escapeName(columnName)); //Recupero la colonna precedentemente associata alla tabella: //essa ha uno uniqueIdentifier generato al momento dell'associazione alla tabella; //questo viene utilizzato per disambiguare l'alias della colonna nelle query //SQL generate da Hibernate. col = manyClass.getTable().getColumn(col); if (col == null) { logger.error("Column not found in 'many' entity {}: {}, " + "skipping relationship", manyClass.getEntityName(), columnName); return; } m2o.addColumn(col); } Property prop = new Property(); prop.setName(relationship.getActualOnePropertyName()); //prop.setNodeName(relationship.getActualOnePropertyName()); prop.setValue(m2o); prop.setCascade("none"); //TODO era "all", capire prop.setInsertable(false); prop.setUpdateable(false); clazz.addProperty(prop); }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticeam.IteraplanMetamodelLoaderImpl.java
License:Open Source License
/** * Create necessary information (={@link HbMappedClass}) about all persisted classes * /* w w w .j av a 2 s .c om*/ * @return {@link Map} of {@link HbMappedClass} for all persisted model classes */ private Map<String, HbMappedClass> getHbMappedClasses() { Map<String, ClassMetadata> allClassMetadata = sessionFactory.getAllClassMetadata(); Map<String, HbMappedClass> hbMappedClasses = Maps.newHashMap(); Iterator<PersistentClass> pcs = configuration.getClassMappings(); PersistentClass persistentClass = null; ClassMetadata cm = null; while (pcs.hasNext()) { persistentClass = pcs.next(); cm = allClassMetadata.get(persistentClass.getEntityName()); if (cm != null) { HbMappedClass hbmClass = new HbMappedClass(hbMappedClasses, cm, persistentClass); hbMappedClasses.put(cm.getEntityName(), hbmClass); } else { // abstract class HbMappedClass hbmClass = new HbMappedClass(hbMappedClasses, persistentClass); hbMappedClasses.put(persistentClass.getEntityName(), hbmClass); } } return hbMappedClasses; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticmi.IteraplanMiLoadTask.java
License:Open Source License
/** * Create necessary information (={@link HbMappedClass}) about all persisted classes * /* w w w . j a va2 s . co m*/ * @return {@link Map} of {@link HbMappedClass} for all persisted model classes */ private Map<String, HbMappedClass> getHbMappedClasses() { Map<String, ClassMetadata> allClassMetadata = sessionFactory.getAllClassMetadata(); Map<String, HbMappedClass> hbMappedClasses = Maps.newHashMap(); Iterator<PersistentClass> pcs = configuration.getClassMappings(); PersistentClass persistentClass = null; ClassMetadata cm = null; while (pcs.hasNext()) { persistentClass = pcs.next(); cm = allClassMetadata.get(persistentClass.getEntityName()); if (cm != null) { HbMappedClass hbmClass = new HbMappedClass(hbMappedClasses, cm, persistentClass); hbMappedClasses.put(cm.getEntityName(), hbmClass); } else { // abstract class HbMappedClass hbmClass = new HbMappedClass(hbMappedClasses, persistentClass); hbMappedClasses.put(persistentClass.getEntityName(), hbmClass); } } return hbMappedClasses; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.exporter.ecore.EntityBeanIntrospectionServiceBean.java
License:Open Source License
private Map<String, HbMappedClass> getHbMappedClasses() { Map<String, ClassMetadata> allClassMetadata = sessionFactory.getAllClassMetadata(); Map<String, HbMappedClass> hbMappedClasses = Maps.newHashMap(); Iterator<PersistentClass> pcs = configuration.getClassMappings(); PersistentClass persistentClass = null; ClassMetadata cm = null;/*from w w w. j av a 2 s. com*/ while (pcs.hasNext()) { persistentClass = pcs.next(); cm = allClassMetadata.get(persistentClass.getEntityName()); if (cm != null && !cm.getEntityName().startsWith("HIST_")) { HbMappedClass hbmClass = new HbMappedClass(hbMappedClasses, cm, persistentClass); hbMappedClasses.put(cm.getEntityName(), hbmClass); } } for (HbMappedClass hbmClass : hbMappedClasses.values()) { hbmClass.cleanUpSuperProperties(); } return hbMappedClasses; }
From source file:gov.nih.nci.system.util.ClassCache.java
License:BSD License
@SuppressWarnings("unchecked") private Map<String, List<Object>> getISOPropertiesForObject(PersistentClass pclass, Configuration cfg) { Map<String, List<Object>> isoFieldsMap = new HashMap<String, List<Object>>(); if (pclass.getEntityName().startsWith("_xxEntityxx_gov_nih_nci_cacoresdk_domain_other_datatype")) { Iterator<? extends Object> properties = pclass.getPropertyIterator(); while (properties != null && properties.hasNext()) { Property prop = (Property) properties.next(); List<Object> searchableFields = getPersistentFieldsForISOObject(prop, cfg); isoFieldsMap.put(prop.getName(), searchableFields); }// w ww . j a va 2 s. c o m } else { Class klass; try { klass = Class.forName(pclass.getClassName()); } catch (ClassNotFoundException e) { log.error("Error: Class not found for: " + pclass.getClassName(), e); return isoFieldsMap; } while (!klass.getName().equals("java.lang.Object")) { pclass = cfg.getClassMapping(klass.getName()); if (pclass != null) { Iterator<? extends Object> properties = pclass.getPropertyIterator(); while (properties != null && properties.hasNext()) { Property prop = (Property) properties.next(); List<Object> searchableFields = getPersistentFieldsForISOObject(prop, cfg); isoFieldsMap.put(prop.getName(), searchableFields); } } klass = klass.getSuperclass(); } } return isoFieldsMap; }
From source file:it.eng.qbe.datasource.hibernate.HibernateDataSource.java
License:Mozilla Public License
protected void addDbLink(String modelName, Configuration srcCfg, Configuration dstCfg) { String dbLink = null;/*from ww w . j ava2 s .co m*/ PersistentClass srcPersistentClass = null; PersistentClass dstPersistentClass = null; String targetEntityName = null; Table targetTable = null; dbLink = (String) getDbLinkMap().get(modelName); if (dbLink != null) { Iterator it = srcCfg.getClassMappings(); while (it.hasNext()) { srcPersistentClass = (PersistentClass) it.next(); targetEntityName = srcPersistentClass.getEntityName(); dstPersistentClass = dstCfg.getClassMapping(targetEntityName); targetTable = dstPersistentClass.getTable(); targetTable.setName(targetTable.getName() + "@" + dbLink); } } }