List of usage examples for org.hibernate EntityMode POJO
EntityMode POJO
To view the source code for org.hibernate EntityMode POJO.
Click Source Link
From source file:org.springframework.flex.core.io.HibernateConfigProcessor.java
License:Apache License
/** * // www .j ava 2s .co m * {@inheritDoc} */ @Override protected Set<Class<?>> findTypesToRegister() { Set<Class<?>> typesToRegister = new HashSet<Class<?>>(); if (hibernateConfigured) { for (ClassMetadata classMetadata : this.classMetadata) { if (!classMetadata.getMappedClass(EntityMode.POJO).isInterface()) { typesToRegister.add(classMetadata.getMappedClass(EntityMode.POJO)); findComponentProperties(classMetadata.getPropertyTypes(), typesToRegister); } } for (CollectionMetadata collectionMetadata : this.collectionMetadata) { Type elementType = collectionMetadata.getElementType(); if (elementType instanceof ComponentType) { if (!elementType.getReturnedClass().isInterface()) { typesToRegister.add(elementType.getReturnedClass()); findComponentProperties(((ComponentType) elementType).getSubtypes(), typesToRegister); } } } } return typesToRegister; }
From source file:org.yestech.maven.HibernateSearchBuildIndexesMojo.java
License:Apache License
@SuppressWarnings({ "unchecked" }) private FullTextSession processObjects(FullTextSession fullTextSession, Connection con, Configuration configuration) { SessionFactory sessionFactory = configuration.buildSessionFactory(); Session session = sessionFactory.openSession(con); fullTextSession = Search.getFullTextSession(session); Map<String, ClassMetadata> metadata = sessionFactory.getAllClassMetadata(); for (Map.Entry<String, ClassMetadata> entry : metadata.entrySet()) { Class clazz = entry.getValue().getMappedClass(EntityMode.POJO); if (clazz.isAnnotationPresent(Indexed.class)) { getLog().info("Indexing " + entry); Transaction tx = fullTextSession.beginTransaction(); Criteria criteria = fullTextSession.createCriteria(clazz); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); DirectoryProvider[] providers = fullTextSession.getSearchFactory().getDirectoryProviders(clazz); for (DirectoryProvider provider : providers) { getLog().info("Index directory: " + provider.getDirectory()); }// w w w . j a va 2 s .co m List<?> list = criteria.list(); for (Object o : list) { fullTextSession.index(o); } fullTextSession.flushToIndexes(); tx.commit(); } } return fullTextSession; }
From source file:owldb.util.OWLDBEventListener.java
License:Open Source License
/** {@inheritDoc} */ @Override// w ww .ja v a2 s .c o m public void onPostDelete(final PostDeleteEvent event) { final SessionImplementor source = event.getSession(); final EntityPersister per = event.getPersister(); final Session session = source.getFactory().openSession(); Transaction t = null; try { t = session.beginTransaction(); final Object deletedObject = event.getEntity(); if (deletedObject instanceof OWLObject) { final Type[] types = per.getPropertyTypes(); final String[] names = per.getPropertyNames(); for (int i = 0; i < names.length; i++) { if (types[i] instanceof ManyToOneType) { final Object value = per.getPropertyValue(deletedObject, names[i], EntityMode.POJO); this.deleteReference(session, source, value); } else if (types[i] instanceof CollectionType) { final Object values = per.getPropertyValue(deletedObject, names[i], EntityMode.POJO); if (values instanceof PersistentCollection) { final PersistentCollection pc = (PersistentCollection) values; pc.forceInitialization(); for (final Object value : (Collection<?>) values) this.deleteReference(session, source, value); } } } } t.commit(); } catch (final RuntimeException ex) { if (t != null) t.rollback(); throw ex; } finally { session.close(); } }
From source file:owldb.util.OWLDBEventListener.java
License:Open Source License
/** {@inheritDoc} */ @Override// w ww . ja v a2s.co m public void onPostInsert(final PostInsertEvent event) { final SessionImplementor source = event.getSession(); final EntityPersister per = event.getPersister(); final Session session = source.getFactory().openSession(); Transaction t = null; try { t = session.beginTransaction(); final Object insObject = event.getEntity(); if (insObject instanceof OWLObject) { // Set hash code when insert new owlobject final Serializable keyOfInsObject = source.getContextEntityIdentifier(insObject); final AnnotatedOWLObject annotatedObj = AnnotatedOWLObject.load(session, keyOfInsObject); annotatedObj.setHashCode(Long.valueOf(OWLObjectIdGenerator.getHashCode(insObject))); session.update(annotatedObj); final Type[] types = per.getPropertyTypes(); final String[] names = per.getPropertyNames(); for (int i = 0; i < names.length; i++) { if (types[i] instanceof ManyToOneType) { final Object value = per.getPropertyValue(insObject, names[i], EntityMode.POJO); this.addReference(session, source, value); } else if (types[i] instanceof CollectionType) { final Object values = per.getPropertyValue(insObject, names[i], EntityMode.POJO); if (values instanceof PersistentCollection) { for (final Object value : (Collection<?>) values) this.addReference(session, source, value); } } } } t.commit(); } catch (final RuntimeException ex) { if (t != null) t.rollback(); throw ex; } finally { session.close(); } }
From source file:owldb.util.OWLDBInterceptor.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w . j a v a 2s . c o m public Object instantiate(final String entityName, final EntityMode entityMode, final Serializable id) { if (entityMode != EntityMode.POJO) return null; try { final IRI iri = IRI.create( new StringBuilder("jdbc:OWLDB://").append(entityName).append('/').append(id).toString()); final IInstantiator instantiator = INSTANTIATORS.get(entityName); OWLDataFactory nullFactory = null; if (instantiator != null) return instantiator.instantiate(nullFactory, entityName, iri, id); //DEPRICATED: return instantiator.instantiate (null, entityName, iri, id); if (!entityName.startsWith("uk.ac.manchester.cs.owl.")) return null; final Class<?> clazz = Class.forName(entityName); String clazzName = clazz.getSimpleName(); if (clazzName.endsWith("Impl")) clazzName = clazzName.replaceAll("Impl", ""); for (final Method m : FACTORY_METHODS) { if (!m.getName().endsWith(clazzName)) continue; final Class<?>[] paramTypes = m.getParameterTypes(); final Object[] args = new Object[paramTypes.length]; for (int i = 0; i < args.length; i++) { if (Set.class.isAssignableFrom(paramTypes[i])) args[i] = new HashSet<Object>(); else if (List.class.isAssignableFrom(paramTypes[i])) args[i] = new ArrayList<Object>(); else if (paramTypes[i].isArray()) { final Class<?> type = paramTypes[i].getComponentType(); args[i] = Array.newInstance(type, 0); } else args[i] = null; } try { return m.invoke(this.ontologyManager.getOWLDataFactory(), args); } catch (final Exception ex) { LOGGER.log(Level.SEVERE, "Error while instantiating: " + entityName, ex); } } } catch (final ClassNotFoundException ex) { LOGGER.log(Level.SEVERE, "Error while instantiating: " + entityName, ex); } return null; }
From source file:py.una.pol.karaku.dao.where.NumberLike.java
License:Open Source License
/** * {@inheritDoc}// w w w .j a v a 2 s . co m */ @Override public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) { TypedValue tv = new TypedValue(new org.hibernate.type.StringType(), matchMode.toString(valor), EntityMode.POJO); return new TypedValue[] { tv }; }
From source file:py.una.pol.karaku.dao.where.Regex.java
License:Open Source License
/** * {@inheritDoc}//from ww w. jav a 2 s. c o m */ @Override public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) { TypedValue tv = new TypedValue(new org.hibernate.type.StringType(), value, EntityMode.POJO); return new TypedValue[] { tv }; }
From source file:test.eurocarbdb.dataaccess.HibernateEntityManagerTest.java
License:Open Source License
public void isDatabasePopulated___shows_all_entities() { super.setup(); long total = 0; HibernateEntityManager hem = (HibernateEntityManager) getEntityManager(); SessionFactory sf = hem.getSessionFactory(); Map<String, ClassMetadata> hash = (Map<String, ClassMetadata>) sf.getAllClassMetadata(); List<String> list = new ArrayList(hash.keySet()); Collections.sort(list);/*from ww w . j a v a 2 s. c o m*/ out.println("Class : database count"); for (String entity_name : list) { ClassMetadata class_metadata = null; Class<?> c = null; try { class_metadata = hash.get(entity_name); c = class_metadata.getMappedClass(EntityMode.POJO); long count = getEntityManager().countAll(c); out.println(c + ": " + count); total += count; } catch (HibernateException ex) { out.println(c + ": " + join(" -> ", ex.getMessages())); } } super.teardown(); out.println(); out.println("Total count of entities in data store: " + total); assert total > 0; }