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:com.ejushang.steward.common.genericdao.search.hibernate.HibernateNonEntityMetadata.java
License:Apache License
public Object getPropertyValue(Object object, String property) { if (!type.isComponentType()) return null; int i = getPropertyIndex(property); if (i == -1) { return null; } else {// ww w . j a va 2s . c o m return ((ComponentType) type).getPropertyValue(object, i, EntityMode.POJO); } }
From source file:com.gisgraphy.hibernate.criterion.FulltextRestriction.java
License:Open Source License
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { return new TypedValue[] { new TypedValue(Hibernate.STRING, StringHelper.normalize(searchedText), EntityMode.POJO) }; }
From source file:com.gisgraphy.hibernate.criterion.PartialWordSearchRestriction.java
License:Open Source License
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { return new TypedValue[] { new TypedValue(Hibernate.STRING, StringHelper.transformStringForPartialWordSearch(searchedText, StringHelper.WHITESPACE_CHAR_DELIMITER), EntityMode.POJO) }; }
From source file:com.javaetmoi.core.persistence.hibernate.LazyLoadingUtil.java
License:Apache License
@SuppressWarnings("unchecked") private static void deepInflateEntity(final Session currentSession, Object entity, Set<String> recursiveGuard) throws HibernateException { if (entity == null) { return;/* w ww.j a v a 2 s .c o m*/ } Class<? extends Object> persistentClass = entity.getClass(); if (entity instanceof HibernateProxy) { persistentClass = ((HibernateProxy) entity).getHibernateLazyInitializer().getPersistentClass(); } ClassMetadata classMetadata = currentSession.getSessionFactory().getClassMetadata(persistentClass); if (classMetadata == null) { return; } Serializable identifier = classMetadata.getIdentifier(entity, (AbstractSessionImpl) currentSession); String key = persistentClass.getName() + "|" + identifier; if (recursiveGuard.contains(key)) { return; } recursiveGuard.add(key); if (!Hibernate.isInitialized(entity)) { Hibernate.initialize(entity); } for (int i = 0, n = classMetadata.getPropertyNames().length; i < n; i++) { String propertyName = classMetadata.getPropertyNames()[i]; Type propertyType = classMetadata.getPropertyType(propertyName); Object propertyValue = null; if (entity instanceof javassist.util.proxy.ProxyObject) { // For javassist proxy, the classMetadata.getPropertyValue(..) method return en // emppty collection. So we have to call the property's getter in order to call the // JavassistLazyInitializer.invoke(..) method that will initialize the collection by // loading it from the database. propertyValue = callCollectionGetter(entity, propertyName); } else { propertyValue = classMetadata.getPropertyValue(entity, propertyName, EntityMode.POJO); } deepInflateProperty(propertyValue, propertyType, currentSession, recursiveGuard); } }
From source file:com.javaetmoi.core.persistence.hibernate.TestIssue3.java
License:Apache License
@Test public void listWithMappedEntityWithAdditionalSpecificCriteria() { List<System> dbContainer = transactionTemplate.execute(new TransactionCallback<List<System>>() { public List<System> doInTransaction(TransactionStatus status) { List<System> system = (List<System>) hibernateTemplate.getSessionFactory().getCurrentSession() .createCriteria(System.class).addOrder(Order.asc("systemNumber")).list(); LazyLoadingUtil.deepHydrate( hibernateTemplate.getSessionFactory().getCurrentSession().getSession(EntityMode.POJO), system);//from w w w. j a v a 2s .c o m return system; } }); assertNotNull(dbContainer); assertFalse(dbContainer.isEmpty()); assertEquals(2, dbContainer.size()); assertEquals(new Integer(1), dbContainer.get(0).getId()); assertNotNull(dbContainer.get(0).getSubSystems()); assertEquals(2, dbContainer.get(0).getSubSystems().size()); }
From source file:com.javaetmoi.core.persistence.hibernate.TestIssue3.java
License:Apache License
@Test public void retrieveEntityWhenAlreadyInsSessionOnAccountOfSave() { List<System> dbContainer = transactionTemplate.execute(new TransactionCallback<List<System>>() { public List<System> doInTransaction(TransactionStatus status) { Holder holder = new Holder(); System system = new System(); system.setName("system1"); system.setSystemNumber("1"); SubSystem subSystem1 = new SubSystem(); subSystem1.setName("subsystem1"); subSystem1.setParent(system); subSystem1.setSystemNumber("1-1"); SubSystem subSystem2 = new SubSystem(); subSystem2.setName("subsystem2"); subSystem2.setParent(system); subSystem2.setSystemNumber("1-2"); holder.setSystem(system);//from w w w. j a v a 2 s .c o m List<SubSystem> subSystems = new ArrayList<SubSystem>(); subSystems.add(subSystem1); subSystems.add(subSystem2); system.setSubSystems(subSystems); hibernateTemplate.getSessionFactory().getCurrentSession().save(subSystem1); hibernateTemplate.getSessionFactory().getCurrentSession().save(subSystem2); hibernateTemplate.getSessionFactory().getCurrentSession().save(system); hibernateTemplate.getSessionFactory().getCurrentSession().save(holder); List<System> retrievedSystems = (List<System>) hibernateTemplate.getSessionFactory() .getCurrentSession().createCriteria(System.class).addOrder(Order.asc("systemNumber")) .list(); LazyLoadingUtil.deepHydrate( hibernateTemplate.getSessionFactory().getCurrentSession().getSession(EntityMode.POJO), system); return retrievedSystems; } }); }
From source file:com.klistret.cmdb.utility.hibernate.XPathRestriction.java
License:Open Source License
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { /**/*from w ww .j a v a 2 s . c o m*/ * Establish dialect, property information about this column */ Dialect dialect = criteriaQuery.getFactory().getDialect(); String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName); if (columns.length != 1) { logger.error("XMLEXISTS may only be used with single-column properties [property: {}]", propertyName); throw new HibernateException("XMLEXISTS may only be used with single-column properties"); } /** * Path Expression */ BaseExpression be = step.getRelativePath().getBaseExpression(); /** * Property type is generalized to wild-card "*" leaving only the * predicate */ String axis = String.format("%s:%s", step.getQName().getPrefix(), step.getQName().getLocalPart()); /** * Passing clause */ String passingClause = String.format("PASSING %s AS \"%s\"", columns[0], variableReference); /** * Setup XPath first with the variable reference (acts a root), the axis * is replaced and then XPath is built up again either from generated * string or the raw XPath for each step (depending on if it is a * readable step or irresolute). */ String xpath = String.format("$%s", variableReference); String sqlMask = baseMask; for (Expr expr : step.getRelativePath().getSteps()) { if (expr instanceof Step) { if (((Step) expr).getDepth() >= step.getDepth()) { if (expr instanceof StepExpr) { xpath = String.format("%s/%s", xpath, expr.getXPath(true)); for (Value value : ((StepExpr) expr).getValues()) { if (value.getText().length() > varcharLimit) throw new ApplicationException( String.format("Literal value [%s] is larger than VARCHAR limiation [%d]", value.getText(), varcharLimit)); String xpathMask = value.getMask(); passingClause = String.format("%s, CAST (? AS VARCHAR(%d)) AS \"%s\"", passingClause, varcharLimit, xpathMask); typedValues.add(new TypedValue(stringType, value.getText(), EntityMode.POJO)); logger.debug("Adding StringType [value: {}] to restriction with variable [{}]", value.getText(), xpathMask); /** * Use a common mask to reduce the variation in * generated SQL */ xpath = xpath.replaceAll(xpathMask, sqlMask); passingClause = passingClause.replaceAll(xpathMask, sqlMask); logger.debug("Replaced XPath mask {} with a common SQL mask {}", xpathMask, sqlMask); sqlMask = incrementMask(sqlMask); } } if (expr instanceof IrresoluteExpr) { xpath = String.format("%s/%s", xpath, step.getRelativePath().getRawXPath(((Step) expr).getDepth())); } } } } xpath = xpath.replaceFirst(axis, "*"); logger.debug("XPath [{}] prior prefixing default function declaration and namespace declarations", xpath); /** * Concatenate namespace declarations */ for (String namespace : be.getNamespaces()) xpath = namespace.concat(xpath); /** * Concatenate default element namespace declaration */ if (be.getDefaultElementNamespace() != null) xpath = be.getDefaultElementNamespace().concat(xpath); if (dialect instanceof DB2Dialect) { /** * DB2 only allows SQL with double quotes (or at least that is the * extend of my knowledge) */ Matcher sq = singleQuotes.matcher(xpath); if (sq.find()) throw new ApplicationException(String .format("XPath [%s] contains surrounding single quotes which DB2 does not allow", xpath), new UnsupportedOperationException()); } /** * Return the XMLEXISTS predicate */ return String.format("XMLEXISTS(\'%s\' %s)", xpath, passingClause); }
From source file:com.mg.framework.service.DatabaseAuditServiceImpl.java
License:Open Source License
private String entityPropertyToString(Object state, ClassMetadata metadata) { if (state != null) { Serializable id = metadata.getIdentifier(state, EntityMode.POJO); return MessageHelper.infoString(metadata.getEntityName(), id); } else/*from w w w. j a v a 2 s. c o m*/ return null; }
From source file:com.mg.framework.service.PersistentObjectHibernate.java
License:Open Source License
private static EntityMode getEntityMode() { return EntityMode.POJO; }
From source file:com.mg.jet.birt.report.data.oda.ejbql.HibernateUtil.java
License:Open Source License
public static Object getHibernatePropVal(Object instObj, String className, String propName) { Session session = HibernateUtil.currentSession(); SessionFactory sf = session.getSessionFactory(); Object hibObj = sf.getClassMetadata(className).getPropertyValue(instObj, propName, EntityMode.POJO); return (hibObj); }