org.hibernate.metadata.ClassMetadata - java examples

Here are the examples of the java api org.hibernate.metadata.ClassMetadata taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

67 Examples 7

19 View Complete Implementation : JpaBaseRepository.java
Copyright Apache License 2.0
Author : JadiraOrg
/**
 * Determines the ID for the enreplacedy
 *
 * @param enreplacedy The enreplacedy to retrieve the ID for
 * @return The ID
 */
// No good alternative in the Hibernate API yet
@SuppressWarnings("deprecation")
protected ID extractId(T enreplacedy) {
    final Clreplaced<?> enreplacedyClreplaced = TypeHelper.getTypeArguments(JpaBaseRepository.clreplaced, this.getClreplaced()).get(0);
    final SessionFactory sf = (SessionFactory) (getEnreplacedyManager().getEnreplacedyManagerFactory());
    final ClreplacedMetadata cmd = sf.getClreplacedMetadata(enreplacedyClreplaced);
    final SessionImplementor si = (SessionImplementor) (getEnreplacedyManager().getDelegate());
    @SuppressWarnings("unchecked")
    final ID result = (ID) cmd.getIdentifier(enreplacedy, si);
    return result;
}

19 View Complete Implementation : HibernateQueryTestAction.java
Copyright Apache License 2.0
Author : UniTime
public void printHeader(StringBuffer s, Object o, String[] alias) {
    s.append("<table width='100%' border='0' cellspacing='0' cellpadding='3'>");
    s.append("<tr align='left'>");
    SessionFactory hibSessionFactory = new _RootDAO().getSession().getSessionFactory();
    boolean hasLink = false;
    if (alias != null && alias.length > 0 && alias[0].startsWith("__")) {
        if ("__Clreplaced".equals(alias[0]))
            hasLink = true;
        else if ("__Offering".equals(alias[0]))
            hasLink = true;
        else if ("__Subpart".equals(alias[0]))
            hasLink = true;
        else if ("__Room".equals(alias[0]))
            hasLink = true;
        else if ("__Instructor".equals(alias[0]))
            hasLink = true;
        else if ("__Exam".equals(alias[0]))
            hasLink = true;
        else if ("__Event".equals(alias[0]))
            hasLink = true;
    }
    int idx = 1;
    if (o == null) {
        header(s, idx++, (alias != null && alias.length > 0 && alias[0] != null && !alias[0].isEmpty() ? alias[0] : null));
    } else if (o instanceof Object[]) {
        Object[] x = (Object[]) o;
        for (int i = 0; i < x.length; i++) {
            if (hasLink && i == 0)
                continue;
            String a = (alias != null && alias.length > i && alias[i] != null && !alias[i].isEmpty() ? alias[i] : null);
            if (x[i] == null) {
                header(s, idx++, a);
            } else {
                ClreplacedMetadata meta = hibSessionFactory.getClreplacedMetadata(x[i].getClreplaced());
                if (meta == null) {
                    header(s, idx++, a);
                } else {
                    header(s, idx++, meta.getIdentifierPropertyName());
                    for (int j = 0; j < meta.getPropertyNames().length; j++) {
                        if (!skip(meta.getPropertyTypes()[j], meta.getPropertyLaziness()[j]))
                            header(s, idx++, meta.getPropertyNames()[j]);
                    }
                }
            }
        }
    } else {
        ClreplacedMetadata meta = hibSessionFactory.getClreplacedMetadata(o.getClreplaced());
        if (meta == null) {
            header(s, idx++, (alias != null && alias.length > 0 && alias[0] != null && !alias[0].isEmpty() ? alias[0] : null));
        } else {
            header(s, idx++, meta.getIdentifierPropertyName());
            for (int i = 0; i < meta.getPropertyNames().length; i++) {
                if (!skip(meta.getPropertyTypes()[i], meta.getPropertyLaziness()[i]))
                    header(s, idx++, meta.getPropertyNames()[i]);
            }
        }
    }
    s.append("</tr>");
}

19 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Return the property value for the given enreplacedy.
 * @param meta
 * @param enreplacedy
 * @param propName If null, the identifier property will be returned.
 * @return
 */
private Object getPropertyValue(ClreplacedMetadata meta, Object enreplacedy, String propName) {
    if (propName == null || propName == meta.getIdentifierPropertyName())
        return meta.getIdentifier(enreplacedy, null);
    else
        return meta.getPropertyValue(enreplacedy, propName);
}

19 View Complete Implementation : HibernateLayerUtil.java
Copyright GNU Affero General Public License v3.0
Author : geomajas
/**
 * Return the clreplaced of one of the properties of another clreplaced from which the Hibernate metadata is given.
 *
 * @param meta
 *            The parent clreplaced to search a property in.
 * @param propertyName
 *            The name of the property in the parent clreplaced (provided by meta)
 * @return Returns the clreplaced of the property in question.
 * @throws HibernateLayerException
 *             Throws an exception if the property name could not be retrieved.
 */
protected Clreplaced<?> getPropertyClreplaced(ClreplacedMetadata meta, String propertyName) throws HibernateLayerException {
    // try to replacedure the correct separator is used
    propertyName = propertyName.replace(XPATH_SEPARATOR, SEPARATOR);
    if (propertyName.contains(SEPARATOR)) {
        String directProperty = propertyName.substring(0, propertyName.indexOf(SEPARATOR));
        try {
            Type prop = meta.getPropertyType(directProperty);
            if (prop.isCollectionType()) {
                CollectionType coll = (CollectionType) prop;
                prop = coll.getElementType((SessionFactoryImplementor) sessionFactory);
            }
            ClreplacedMetadata propMeta = sessionFactory.getClreplacedMetadata(prop.getReturnedClreplaced());
            return getPropertyClreplaced(propMeta, propertyName.substring(propertyName.indexOf(SEPARATOR) + 1));
        } catch (HibernateException e) {
            throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_COULD_NOT_RESOLVE, propertyName, meta.getEnreplacedyName());
        }
    } else {
        try {
            return meta.getPropertyType(propertyName).getReturnedClreplaced();
        } catch (HibernateException e) {
            throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_COULD_NOT_RESOLVE, propertyName, meta.getEnreplacedyName());
        }
    }
}

19 View Complete Implementation : SavedHqlExportToCSV.java
Copyright Apache License 2.0
Author : UniTime
private static void line(String[] ret, Object o, SessionImplementor session) {
    if (o == null) {
        ret[0] = "";
    } else if (o instanceof Object[]) {
        int idx = 0;
        for (Object x : (Object[]) o) {
            if (x == null) {
                ret[idx++] = "";
            } else {
                ClreplacedMetadata meta = SavedHQLDAO.getInstance().getSession().getSessionFactory().getClreplacedMetadata(x.getClreplaced());
                if (meta == null) {
                    ret[idx++] = toString(x);
                } else {
                    if (meta.getIdentifierPropertyName() != null)
                        ret[idx++] = toString(meta.getIdentifier(x, session));
                    for (int i = 0; i < meta.getPropertyNames().length; i++) {
                        if (!skip(meta.getPropertyTypes()[i], meta.getPropertyLaziness()[i]))
                            ret[idx++] = toString(meta.getPropertyValue(x, meta.getPropertyNames()[i]));
                    }
                }
            }
        }
    } else {
        ClreplacedMetadata meta = SavedHQLDAO.getInstance().getSession().getSessionFactory().getClreplacedMetadata(o.getClreplaced());
        if (meta == null) {
            ret[0] = toString(o);
        } else {
            int idx = 0;
            if (meta.getIdentifierPropertyName() != null)
                ret[idx++] = toString(meta.getIdentifier(o, session));
            for (int i = 0; i < meta.getPropertyNames().length; i++) {
                if (!skip(meta.getPropertyTypes()[i], meta.getPropertyLaziness()[i]))
                    ret[idx++] = toString(meta.getPropertyValue(o, meta.getPropertyNames()[i]));
            }
        }
    }
}

19 View Complete Implementation : HibernateSaveProcessor.java
Copyright MIT License
Author : Breeze
/**
 * Add, update, or delete the enreplacedy according to its EnreplacedyState.
 * @param enreplacedyInfo
 * @param clreplacedMeta
 */
protected void processEnreplacedy(EnreplacedyInfo enreplacedyInfo) {
    Object enreplacedy = enreplacedyInfo.enreplacedy;
    ClreplacedMetadata clreplacedMeta = getClreplacedMetadata(enreplacedy.getClreplaced());
    EnreplacedyState state = enreplacedyInfo.enreplacedyState;
    // Restore the old value of the concurrency column so Hibernate will be able to save the enreplacedy
    if (clreplacedMeta.isVersioned()) {
        restoreOldVersionValue(enreplacedyInfo, clreplacedMeta);
    }
    if (state == EnreplacedyState.Modified) {
        _session.update(enreplacedy);
    } else if (state == EnreplacedyState.Added) {
        _session.save(enreplacedy);
    } else if (state == EnreplacedyState.Deleted) {
        _session.delete(enreplacedy);
    } else {
    // Ignore EnreplacedyState.Unchanged.  Too many problems using session.Lock or session.Merge
    // session.Lock(enreplacedy, LockMode.None);
    }
}

19 View Complete Implementation : HibernateCompatUtils.java
Copyright GNU General Public License v3.0
Author : micromata
public static void setClreplacedMetaDataSetIdentifier(ClreplacedMetadata clreplacedMetadata, Object enreplacedy, EnreplacedyMode mode) {
    PrivateBeanUtils.invokeMethod(clreplacedMetadata, "setIdentifier", enreplacedy, null, mode);
}

19 View Complete Implementation : DBRequests.java
Copyright GNU Affero General Public License v3.0
Author : BloatIt
public static <T extends DaoIdentifiable> PageIterable<T> getAll(final Clreplaced<T> persistent) {
    final ClreplacedMetadata meta = SessionManager.getSessionFactory().getClreplacedMetadata(persistent);
    final Query query = SessionManager.createQuery("FROM " + meta.getEnreplacedyName() + " ORDER BY id DESC");
    final Query size = SessionManager.createQuery("SELECT count(*) FROM " + meta.getEnreplacedyName());
    return new QueryCollection<T>(query, size);
}

19 View Complete Implementation : SavedHqlExportToCSV.java
Copyright Apache License 2.0
Author : UniTime
private static int length(Object o) {
    if (o == null)
        return 1;
    int len = 0;
    if (o instanceof Object[]) {
        for (Object x : (Object[]) o) {
            if (x == null) {
                len++;
            } else {
                ClreplacedMetadata meta = SavedHQLDAO.getInstance().getSession().getSessionFactory().getClreplacedMetadata(x.getClreplaced());
                if (meta == null) {
                    len++;
                } else {
                    if (meta.getIdentifierPropertyName() != null)
                        len++;
                    for (int i = 0; i < meta.getPropertyNames().length; i++) {
                        if (!skip(meta.getPropertyTypes()[i], meta.getPropertyLaziness()[i]))
                            len++;
                    }
                }
            }
        }
    } else {
        ClreplacedMetadata meta = SavedHQLDAO.getInstance().getSession().getSessionFactory().getClreplacedMetadata(o.getClreplaced());
        if (meta == null) {
            len++;
        } else {
            if (meta.getIdentifierPropertyName() != null)
                len++;
            for (int i = 0; i < meta.getPropertyNames().length; i++) {
                if (!skip(meta.getPropertyTypes()[i], meta.getPropertyLaziness()[i]))
                    len++;
            }
        }
    }
    return len;
}

19 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
public void processRelationships(EnreplacedyInfo enreplacedyInfo, boolean removeMode) {
    this.removeMode = removeMode;
    Clreplaced enreplacedyType = enreplacedyInfo.enreplacedy.getClreplaced();
    ClreplacedMetadata clreplacedMeta = sessionFactory.getClreplacedMetadata(enreplacedyType);
    processRelationships(enreplacedyInfo, clreplacedMeta);
}

19 View Complete Implementation : HibernateUtils.java
Copyright Apache License 2.0
Author : chelu
/**
 * Gets the identifier property name of persistent object
 *
 * @param sessionFactory the hibernate SessionFactory
 * @param obj the persistent object
 * @return the identifier property name
 */
public static String getIdentifierPropertyName(SessionFactory sessionFactory, Object obj) {
    ClreplacedMetadata cm = getClreplacedMetadata(sessionFactory, obj);
    return cm == null ? null : cm.getIdentifierPropertyName();
}

19 View Complete Implementation : GenericBaseCommonDao.java
Copyright Apache License 2.0
Author : zhangdaiscott
/**
 * 获得该类的属性和类型
 *
 * @param enreplacedyName
 *            注解的实体类
 */
private <T> void getProperty(Clreplaced enreplacedyName) {
    ClreplacedMetadata cm = sessionFactory.getClreplacedMetadata(enreplacedyName);
    // 获得该类所有的属性名称
    String[] str = cm.getPropertyNames();
    for (int i = 0; i < str.length; i++) {
        String property = str[i];
        // 获得该名称的类型
        String type = cm.getPropertyType(property).getName();
        org.jeecgframework.core.util.LogUtil.info(property + "--->" + type);
    }
}

19 View Complete Implementation : MemberManager.java
Copyright GNU Affero General Public License v3.0
Author : BloatIt
/**
 * Gets all the members ordered by name.
 *
 * @return the all the members in the DB.
 */
public static PageIterable<Member> getAllMembersOrderByName() {
    final ClreplacedMetadata meta = SessionManager.getSessionFactory().getClreplacedMetadata(DaoMember.clreplaced);
    final Query query = SessionManager.createQuery("FROM " + meta.getEnreplacedyName() + " ORDER BY coalesce(fullname,login) ASC");
    final Query size = SessionManager.createQuery("SELECT count(*) FROM " + meta.getEnreplacedyName());
    return new MemberList(new QueryCollection<DaoMember>(query, size));
}

19 View Complete Implementation : HibernateLayerUtil.java
Copyright GNU Affero General Public License v3.0
Author : geomajas
/**
 * General Hibernate ClreplacedMetadata and SessionFactory provision. Package visibility only.
 *
 * @author Pieter De Graef
 */
clreplaced HibernateLayerUtil {

    public static final String XPATH_SEPARATOR = "/";

    public static final String SEPARATOR = ".";

    public static final String SEPARATOR_REGEXP = "\\.";

    private SessionFactory sessionFactory;

    private ClreplacedMetadata enreplacedyMetadata;

    private VectorLayerInfo layerInfo;

    /**
     * Get feature info.
     *
     * @return feature info
     */
    public FeatureInfo getFeatureInfo() {
        return layerInfo.getFeatureInfo();
    }

    /**
     * Get layer configuration.
     *
     * @return layer info
     */
    public VectorLayerInfo getLayerInfo() {
        return layerInfo;
    }

    /**
     * Set the layer configuration.
     *
     * @param layerInfo layer info
     * @throws LayerException oops
     */
    public void setLayerInfo(VectorLayerInfo layerInfo) throws LayerException {
        this.layerInfo = layerInfo;
        if (null != sessionFactory) {
            setSessionFactory(sessionFactory);
        }
    }

    // -------------------------------------------------------------------------
    // Clreplaced specific functions:
    // -------------------------------------------------------------------------
    /**
     * Retrieve the Hibernate ClreplacedMetadata.
     *
     * @return hibernate meta data
     * @throws HibernateLayerException
     *             Throws an exception if the initialization of the meta data went wrong. In other words if the
     *             Hibernate Configuration is not correct.
     */
    public ClreplacedMetadata getEnreplacedyMetadata() throws HibernateLayerException {
        if (null == enreplacedyMetadata) {
            throw new HibernateLayerException(ExceptionCode.HIBERNATE_NO_META_DATA);
        }
        return enreplacedyMetadata;
    }

    /**
     * Return the clreplaced of one of the properties of another clreplaced from which the Hibernate metadata is given.
     *
     * @param meta
     *            The parent clreplaced to search a property in.
     * @param propertyName
     *            The name of the property in the parent clreplaced (provided by meta)
     * @return Returns the clreplaced of the property in question.
     * @throws HibernateLayerException
     *             Throws an exception if the property name could not be retrieved.
     */
    protected Clreplaced<?> getPropertyClreplaced(ClreplacedMetadata meta, String propertyName) throws HibernateLayerException {
        // try to replacedure the correct separator is used
        propertyName = propertyName.replace(XPATH_SEPARATOR, SEPARATOR);
        if (propertyName.contains(SEPARATOR)) {
            String directProperty = propertyName.substring(0, propertyName.indexOf(SEPARATOR));
            try {
                Type prop = meta.getPropertyType(directProperty);
                if (prop.isCollectionType()) {
                    CollectionType coll = (CollectionType) prop;
                    prop = coll.getElementType((SessionFactoryImplementor) sessionFactory);
                }
                ClreplacedMetadata propMeta = sessionFactory.getClreplacedMetadata(prop.getReturnedClreplaced());
                return getPropertyClreplaced(propMeta, propertyName.substring(propertyName.indexOf(SEPARATOR) + 1));
            } catch (HibernateException e) {
                throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_COULD_NOT_RESOLVE, propertyName, meta.getEnreplacedyName());
            }
        } else {
            try {
                return meta.getPropertyType(propertyName).getReturnedClreplaced();
            } catch (HibernateException e) {
                throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_COULD_NOT_RESOLVE, propertyName, meta.getEnreplacedyName());
            }
        }
    }

    /**
     * Return the Hibernate SessionFactory.
     *
     * @return session factory
     */
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    /**
     * Set session factory.
     *
     * @param sessionFactory session factory
     * @throws HibernateLayerException could not get clreplaced metadata for data source
     */
    public void setSessionFactory(SessionFactory sessionFactory) throws HibernateLayerException {
        try {
            this.sessionFactory = sessionFactory;
            if (null != layerInfo) {
                enreplacedyMetadata = sessionFactory.getClreplacedMetadata(layerInfo.getFeatureInfo().getDataSourceName());
            }
        } catch (Exception e) {
            // NOSONAR
            throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_NO_SESSION_FACTORY);
        }
    }
}

19 View Complete Implementation : DBRequests.java
Copyright GNU Affero General Public License v3.0
Author : BloatIt
public static <T extends DaoUserContent> PageIterable<T> getAllUserContentOrderByDate(final Clreplaced<T> persistent) {
    final ClreplacedMetadata meta = SessionManager.getSessionFactory().getClreplacedMetadata(persistent);
    return new QueryCollection<T>(SessionManager.createQuery("from " + meta.getEnreplacedyName() + " order by creationDate DESC"), SessionManager.createQuery("select count(*) from " + meta.getEnreplacedyName()));
}

19 View Complete Implementation : PortalRawEventsAggregatorImpl.java
Copyright Apache License 2.0
Author : Jasig
private List<String> getCollectionRoles(final SessionFactory sessionFactory, final Clreplaced<?> enreplacedyClreplaced) {
    List<String> collectionRoles = enreplacedyCollectionRoles.get(enreplacedyClreplaced);
    if (collectionRoles != null) {
        return collectionRoles;
    }
    final com.google.common.collect.ImmutableList.Builder<String> collectionRolesBuilder = ImmutableList.builder();
    final ClreplacedMetadata clreplacedMetadata = sessionFactory.getClreplacedMetadata(enreplacedyClreplaced);
    for (final Type type : clreplacedMetadata.getPropertyTypes()) {
        if (type.isCollectionType()) {
            collectionRolesBuilder.add(((CollectionType) type).getRole());
        }
    }
    collectionRoles = collectionRolesBuilder.build();
    enreplacedyCollectionRoles.put(enreplacedyClreplaced, collectionRoles);
    return collectionRoles;
}

19 View Complete Implementation : BasicHibernateDao.java
Copyright Apache License 2.0
Author : biliroy
/**
 * 取得对象的主键名.
 *
 * @return String
 */
public String getIdName() {
    ClreplacedMetadata meta = sessionFactory.getClreplacedMetadata(enreplacedyClreplaced);
    return meta.getIdentifierPropertyName();
}

19 View Complete Implementation : ConnectionManager.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
public ClreplacedMetadata getMetadata(Object target) {
    ClreplacedMetadata retval = null;
    if (target != null) {
        if (target instanceof Clreplaced) {
            retval = sessionFactory.getClreplacedMetadata((Clreplaced) target);
        } else {
            retval = sessionFactory.getClreplacedMetadata(target.getClreplaced());
        }
    }
    return retval;
}

19 View Complete Implementation : HibernateSaveProcessor.java
Copyright MIT License
Author : Breeze
public clreplaced HibernateSaveProcessor extends SaveProcessor {

    private SessionFactory _sessionFactory;

    private Session _session;

    private RelationshipFixer _fixer;

    private List<String> _possibleErrors = new ArrayList<String>();

    /**
     * @param metadata
     * @param sessionFactory
     */
    public HibernateSaveProcessor(Metadata metadata, SessionFactory sessionFactory) {
        super(metadata);
        _sessionFactory = sessionFactory;
    }

    /**
     * Persist the changes to the enreplacedies in the SaveWorkState that is preplaceded in.
     * This implements the abstract method in SaveProcessor.
     * After the completion of this method the saveWorkState.toSaveResult method may be called the will
     * return a SaveResult instance.
     * This method both persists the enreplacedies and creates the collection of KeyMappings,
     * which map the temporary keys to their real generated keys.
     * Note that this method sets session.FlushMode = FlushMode.MANUAL, so manual flushes are required.
     * @param saveWorkState
     */
    @Override
    protected void saveChangesCore(SaveWorkState saveWorkState) {
        _session = _sessionFactory.openSession();
        _session.setFlushMode(FlushMode.MANUAL);
        Transaction tx = _session.getTransaction();
        boolean hasExistingTransaction = tx.isActive();
        if (!hasExistingTransaction)
            tx.begin();
        try {
            // Relate enreplacedies in the saveMap to other enreplacedies, so Hibernate can save the FK values.
            _fixer = new RelationshipFixer(saveWorkState, _session);
            _fixer.fixupRelationships();
            // At this point all enreplacedies are hooked up but are not yet in the session.
            setSaveState(SaveState.AfterFixup);
            // Allow subclreplaced to process enreplacedies before we save them
            saveWorkState.beforeSaveEnreplacedies();
            List<EnreplacedyInfo> saveOrder = _fixer.sortDependencies();
            processSaves(saveOrder);
            // At this point all enreplacedies are hooked up and in the session, and
            // all tempIds have been replaced with real ids.
            // Final chance to process enreplacedies before we save them - all enreplacedies
            // have been added to the session.
            setSaveState(SaveState.BeforeCommit);
            saveWorkState.beforeCommit(_session);
            _session.flush();
            refreshFromSession(saveWorkState);
            if (!hasExistingTransaction)
                tx.commit();
            // so that serialization of saveResult doesn't have issues.
            _fixer.removeRelationships();
        } catch (EnreplacedyErrorsException eee) {
            if (tx.isActive())
                tx.rollback();
            throw eee;
        } catch (PropertyValueException pve) {
            // Hibernate can throw this
            if (tx.isActive())
                tx.rollback();
            EnreplacedyError enreplacedyError = new EnreplacedyError("PropertyValueException", pve.getEnreplacedyName(), null, pve.getPropertyName(), pve.getMessage());
            throw new EnreplacedyErrorsException(enreplacedyError);
        } catch (Exception ex) {
            if (tx.isActive())
                tx.rollback();
            String msg = "Save exception: ";
            if (ex instanceof JDBCException) {
                msg += "SQLException: " + ((JDBCException) ex).getSQLException().getMessage();
            } else {
                // most hibernate exceptions appear here
                msg += ex.getMessage();
            }
            if (_possibleErrors.size() > 0) {
                msg += ". Possible errors: " + _possibleErrors.toString() + " ";
            }
            throw new RuntimeException(msg, ex);
        } finally {
            // if (!hasExistingTransaction) tx.Dispose();
            _session.close();
        }
    }

    @Override
    public void processRelationships(EnreplacedyInfo enreplacedyInfo, boolean removeMode) {
        // _fixer will not be initialized until just before beforeSaveEnreplacedies is called
        // so it will not be available for beforeSaveEnreplacedy calls.
        SaveState saveState = getSaveState();
        if (saveState == SaveState.BeforeFixup)
            return;
        _fixer.processRelationships(enreplacedyInfo, removeMode);
        if (saveState == SaveState.BeforeCommit) {
            processEnreplacedy(enreplacedyInfo);
        }
    }

    // TODO: determine why this is different from getIdentifier commented out below.
    // May have to do with this method only getting called for single part keys.
    @Override
    public Object getIdentifier(Object enreplacedy) {
        Object id = getClreplacedMetadata(enreplacedy.getClreplaced()).getIdentifier(enreplacedy, null);
        return id != null ? id : null;
    }

    /**
     * Persist the changes to the enreplacedies in the saveOrder.
     * @param saveOrder
     */
    protected void processSaves(List<EnreplacedyInfo> saveOrder) {
        for (EnreplacedyInfo enreplacedyInfo : saveOrder) {
            processEnreplacedy(enreplacedyInfo);
        }
    }

    /**
     * Add, update, or delete the enreplacedy according to its EnreplacedyState.
     * @param enreplacedyInfo
     * @param clreplacedMeta
     */
    protected void processEnreplacedy(EnreplacedyInfo enreplacedyInfo) {
        Object enreplacedy = enreplacedyInfo.enreplacedy;
        ClreplacedMetadata clreplacedMeta = getClreplacedMetadata(enreplacedy.getClreplaced());
        EnreplacedyState state = enreplacedyInfo.enreplacedyState;
        // Restore the old value of the concurrency column so Hibernate will be able to save the enreplacedy
        if (clreplacedMeta.isVersioned()) {
            restoreOldVersionValue(enreplacedyInfo, clreplacedMeta);
        }
        if (state == EnreplacedyState.Modified) {
            _session.update(enreplacedy);
        } else if (state == EnreplacedyState.Added) {
            _session.save(enreplacedy);
        } else if (state == EnreplacedyState.Deleted) {
            _session.delete(enreplacedy);
        } else {
        // Ignore EnreplacedyState.Unchanged.  Too many problems using session.Lock or session.Merge
        // session.Lock(enreplacedy, LockMode.None);
        }
    }

    /**
     * Restore the old value of the concurrency column so Hibernate will save the enreplacedy.
     * Otherwise it will complain because Breeze has already changed the value.
     * @param enreplacedyInfo
     * @param clreplacedMeta
     */
    protected void restoreOldVersionValue(EnreplacedyInfo enreplacedyInfo, ClreplacedMetadata clreplacedMeta) {
        if (enreplacedyInfo.originalValuesMap == null || enreplacedyInfo.originalValuesMap.size() == 0)
            return;
        int vcol = clreplacedMeta.getVersionProperty();
        String vname = clreplacedMeta.getPropertyNames()[vcol];
        if (enreplacedyInfo.originalValuesMap.containsKey(vname)) {
            Object oldVersion = enreplacedyInfo.originalValuesMap.get(vname);
            Object enreplacedy = enreplacedyInfo.enreplacedy;
            if (oldVersion == null) {
                _possibleErrors.add("Hibernate does not support 'null' version properties. " + "Enreplacedy: " + enreplacedy + ", Property: " + vname);
            }
            Clreplaced versionClazz = clreplacedMeta.getPropertyTypes()[vcol].getReturnedClreplaced();
            DataType dataType = DataType.fromClreplaced(versionClazz);
            Object oldValue = DataType.coerceData(oldVersion, dataType);
            clreplacedMeta.setPropertyValue(enreplacedy, vname, oldValue);
        }
    }

    /**
     * Refresh the enreplacedies from the database.  This picks up changes due to triggers, etc.
     * and makes Hibernate update the foreign keys.
     * @param saveMap
     */
    protected void refreshFromSession(SaveWorkState saveWorkState) {
        for (Entry<Clreplaced, List<EnreplacedyInfo>> entry : saveWorkState.entrySet()) {
            for (EnreplacedyInfo enreplacedyInfo : entry.getValue()) {
                if (enreplacedyInfo.enreplacedyState == EnreplacedyState.Added || enreplacedyInfo.enreplacedyState == EnreplacedyState.Modified) {
                    _session.refresh(enreplacedyInfo.enreplacedy);
                }
            }
        }
    }

    // perf
    private Clreplaced _clreplacedCached;

    private ClreplacedMetadata _clreplacedMetadataCached;

    private ClreplacedMetadata getClreplacedMetadata(Clreplaced clazz) {
        // perf enhancement - this method gets called a lot in loops.
        if (clazz != _clreplacedCached) {
            _clreplacedCached = clazz;
            _clreplacedMetadataCached = _sessionFactory.getClreplacedMetadata(clazz);
        }
        return _clreplacedMetadataCached;
    }
    // /**
    // * Get the identifier value for the enreplacedy.  If the enreplacedy does not have an
    // * identifier property, or natural identifiers defined, then the enreplacedy itself is returned.
    // * @param enreplacedy
    // * @param meta
    // * @return
    // */
    // protected Object getIdentifier(Object enreplacedy) {
    // Clreplaced type = enreplacedy.getClreplaced();
    // meta = getClreplacedMetadata(type);
    // 
    // Type idType = meta.getIdentifierType();
    // if (idType != null) {
    // Serializable id = meta.getIdentifier(enreplacedy, null);
    // if (idType.isComponentType()) {
    // ComponentType compType = (ComponentType) idType;
    // return compType.getPropertyValues(id, EnreplacedyMode.POJO);
    // } else {
    // return id;
    // }
    // } else if (meta.hasNaturalIdentifier()) {
    // int[] idprops = meta.getNaturalIdentifierProperties();
    // Object[] values = meta.getPropertyValues(enreplacedy);
    // Object[] idvalues = new Object[idprops.length];
    // for (int i = 0; i < idprops.length; i++) {
    // idvalues[i] = values[idprops[i]];
    // }
    // return idvalues;
    // }
    // return enreplacedy;
    // }
}

19 View Complete Implementation : HibernateQueryTestAction.java
Copyright Apache License 2.0
Author : UniTime
public void printLine(StringBuffer s, Object o, SessionImplementor session, String[] alias) {
    String link = null;
    if (alias != null && alias.length > 0 && alias[0].startsWith("__") && o != null && (o instanceof Object[])) {
        if ("__Clreplaced".equals(alias[0]))
            link = "clreplacedDetail.do?cid=" + ((Object[]) o)[0];
        else if ("__Offering".equals(alias[0]))
            link = "instructionalOfferingDetail.do?op=view&io=" + ((Object[]) o)[0];
        else if ("__Subpart".equals(alias[0]))
            link = "schedulingSubpartDetail.do?ssuid=" + ((Object[]) o)[0];
        else if ("__Room".equals(alias[0]))
            link = "gwt.jsp?page=rooms&back=1&id=" + ((Object[]) o)[0];
        else if ("__Instructor".equals(alias[0]))
            link = "instructorDetail.do?instructorId=" + ((Object[]) o)[0];
        else if ("__Exam".equals(alias[0]))
            link = "examDetail.do?examId=" + ((Object[]) o)[0];
        else if ("__Event".equals(alias[0]))
            link = "gwt.jsp?page=events#event=" + ((Object[]) o)[0];
    }
    s.append("<tr align='left' onmouseover=\"this.style.backgroundColor='rgb(223,231,242)';\" onmouseout=\"this.style.backgroundColor='transparent';\" " + (link == null ? "" : "onClick=\"doreplacedent.location='" + link + "';\"") + ">");
    SessionFactory hibSessionFactory = new _RootDAO().getSession().getSessionFactory();
    if (o == null) {
        line(s, null);
    } else if (o instanceof Object[]) {
        Object[] x = (Object[]) o;
        for (int i = 0; i < x.length; i++) {
            if (link != null && i == 0)
                continue;
            if (x[i] == null) {
                line(s, null);
            } else {
                ClreplacedMetadata meta = hibSessionFactory.getClreplacedMetadata(x[i].getClreplaced());
                if (meta == null) {
                    line(s, x[i]);
                } else {
                    line(s, meta.getIdentifier(x[i], session));
                    for (int j = 0; j < meta.getPropertyNames().length; j++) if (!skip(meta.getPropertyTypes()[j], meta.getPropertyLaziness()[j]))
                        line(s, meta.getPropertyValue(x[i], meta.getPropertyNames()[j]));
                }
            }
        }
    } else {
        ClreplacedMetadata meta = hibSessionFactory.getClreplacedMetadata(o.getClreplaced());
        if (meta == null) {
            line(s, o);
        } else {
            line(s, meta.getIdentifier(o, session));
            for (int i = 0; i < meta.getPropertyNames().length; i++) if (!skip(meta.getPropertyTypes()[i], meta.getPropertyLaziness()[i]))
                line(s, meta.getPropertyValue(o, meta.getPropertyNames()[i]));
        }
    }
    s.append("</tr>");
}

19 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Connect the related enreplacedies based on the foreign key values found in a component type.
 * This updates the values of the component's properties.
 * @param propName Name of the (component) property of the enreplacedy.  May be null if the property is the enreplacedy's identifier.
 * @param compType Type of the component
 * @param enreplacedyInfo Breeze EnreplacedyInfo
 * @param meta Metadata for the enreplacedy clreplaced
 */
private void fixupComponentRelationships(String propName, ComponentType compType, EnreplacedyInfo enreplacedyInfo, ClreplacedMetadata meta) {
    String[] compPropNames = compType.getPropertyNames();
    Type[] compPropTypes = compType.getSubtypes();
    Object component = null;
    Object[] compValues = null;
    boolean isChanged = false;
    for (int j = 0; j < compPropNames.length; j++) {
        Type compPropType = compPropTypes[j];
        if (compPropType.isreplacedociationType() && compPropType.isEnreplacedyType()) {
            if (compValues == null) {
                // get the value of the component's subproperties
                component = getPropertyValue(meta, enreplacedyInfo.enreplacedy, propName);
                compValues = compType.getPropertyValues(component, EnreplacedyMode.POJO);
            }
            if (compValues[j] == null) {
                // the related enreplacedy is null
                Object relatedEnreplacedy = getRelatedEnreplacedy(compPropNames[j], (EnreplacedyType) compPropType, enreplacedyInfo, meta);
                if (relatedEnreplacedy != null) {
                    compValues[j] = relatedEnreplacedy;
                    isChanged = true;
                }
            } else if (removeMode) {
                // remove the relationship
                compValues[j] = null;
                isChanged = true;
            }
        }
    }
    if (isChanged) {
        compType.setPropertyValues(component, compValues, EnreplacedyMode.POJO);
    }
}

19 View Complete Implementation : SavedHqlExportToCSV.java
Copyright Apache License 2.0
Author : UniTime
private static void header(String[] ret, Object o, String[] alias) {
    if (o == null) {
        if (alias != null && alias.length >= 1 && alias[0] != null && !alias[0].isEmpty())
            ret[0] = alias[0];
        else
            ret[0] = "Result";
    } else if (o instanceof Object[]) {
        int a = 0, idx = 0;
        for (Object x : (Object[]) o) {
            if (x == null) {
                if (alias != null && alias.length > a && alias[a] != null && !alias[a].isEmpty())
                    ret[idx++] = alias[a];
                else
                    ret[idx++] = "Column" + (a + 1);
            } else {
                ClreplacedMetadata meta = SavedHQLDAO.getInstance().getSession().getSessionFactory().getClreplacedMetadata(x.getClreplaced());
                if (meta == null) {
                    if (alias != null && alias.length > a && alias[a] != null && !alias[a].isEmpty())
                        ret[idx++] = alias[a];
                    else
                        ret[idx++] = "Column" + (a + 1);
                } else {
                    if (meta.getIdentifierPropertyName() != null)
                        ret[idx++] = meta.getIdentifierPropertyName();
                    for (int i = 0; i < meta.getPropertyNames().length; i++) {
                        if (!skip(meta.getPropertyTypes()[i], meta.getPropertyLaziness()[i]))
                            ret[idx++] = format(meta.getPropertyNames()[i]);
                    }
                }
            }
            a++;
        }
    } else {
        ClreplacedMetadata meta = SavedHQLDAO.getInstance().getSession().getSessionFactory().getClreplacedMetadata(o.getClreplaced());
        if (meta == null) {
            if (alias != null && alias.length >= 1 && alias[0] != null && !alias[0].isEmpty())
                ret[0] = alias[0];
            else
                ret[0] = "Result";
        } else {
            int idx = 0;
            if (meta.getIdentifierPropertyName() != null)
                ret[idx++] = meta.getIdentifierPropertyName();
            for (int i = 0; i < meta.getPropertyNames().length; i++) {
                if (!skip(meta.getPropertyTypes()[i], meta.getPropertyLaziness()[i]))
                    ret[idx++] = format(meta.getPropertyNames()[i]);
            }
        }
    }
}

19 View Complete Implementation : HibernateEntityContext.java
Copyright GNU Lesser General Public License v3.0
Author : beangle
/**
 * 按照实体名,构建或者查找实体类型信息.<br>
 * 调用后,实体类型则存放与enreplacedyTypes中.
 *
 * @param enreplacedyName
 */
private EnreplacedyType buildEnreplacedyType(SessionFactory sessionFactory, String enreplacedyName) {
    EnreplacedyType enreplacedyType = (EnreplacedyType) enreplacedyTypes.get(enreplacedyName);
    if (null == enreplacedyType) {
        ClreplacedMetadata cm = sessionFactory.getClreplacedMetadata(enreplacedyName);
        if (null == cm) {
            logger.error("Cannot find ClreplacedMetadata for {}", enreplacedyName);
            return null;
        }
        enreplacedyType = new EnreplacedyType(cm.getEnreplacedyName(), cm.getMappedClreplaced(), cm.getIdentifierPropertyName(), new IdentifierType(cm.getIdentifierType().getReturnedClreplaced()));
        enreplacedyTypes.put(cm.getEnreplacedyName(), enreplacedyType);
        Map<String, Type> propertyTypes = enreplacedyType.getPropertyTypes();
        String[] ps = cm.getPropertyNames();
        for (int i = 0; i < ps.length; i++) {
            org.hibernate.type.Type type = cm.getPropertyType(ps[i]);
            if (type.isEnreplacedyType()) {
                propertyTypes.put(ps[i], buildEnreplacedyType(sessionFactory, type.getName()));
            } else if (type.isComponentType()) {
                propertyTypes.put(ps[i], buildComponentType(sessionFactory, enreplacedyName, ps[i]));
            } else if (type.isCollectionType()) {
                propertyTypes.put(ps[i], buildCollectionType(sessionFactory, defaultCollectionClreplaced(type), enreplacedyName + "." + ps[i]));
            }
        }
    }
    return enreplacedyType;
}

19 View Complete Implementation : SimpleHibernateDao.java
Copyright GNU Affero General Public License v3.0
Author : wkeyuan
/* (non-Javadoc)
	 * @see com.key.common.orm.hibernate.ISimpleHibernateDao#getIdName()
	 */
@Override
public String getIdName() {
    ClreplacedMetadata meta = getSessionFactory().getClreplacedMetadata(enreplacedyClreplaced);
    return meta.getIdentifierPropertyName();
}

19 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Find a foreign key matching the given property, by looking in the fkMap.
 * The property may be defined on the clreplaced or a superclreplaced, so this function calls itself recursively.
 * @param propName Name of the property e.g. "Product"
 * @param meta Clreplaced metadata, for traversing the clreplaced hierarchy
 * @return The name of the foreign key, e.g. "ProductID"
 */
private String findForeignKey(String propName, ClreplacedMetadata meta) {
    String relKey = meta.getEnreplacedyName() + '.' + propName;
    if (fkMap.containsKey(relKey)) {
        return fkMap.get(relKey);
    } else if (meta.isInherited() && meta instanceof AbstractEnreplacedyPersister) {
        String superEnreplacedyName = ((AbstractEnreplacedyPersister) meta).getMappedSuperclreplaced();
        ClreplacedMetadata superMeta = sessionFactory.getClreplacedMetadata(superEnreplacedyName);
        return findForeignKey(propName, superMeta);
    } else {
        throw new IllegalArgumentException("Foreign Key '" + relKey + "' could not be found.");
    }
}

19 View Complete Implementation : MemberManager.java
Copyright GNU Affero General Public License v3.0
Author : BloatIt
public static PageIterable<Member> getAllMembersFollowingAll() {
    final ClreplacedMetadata meta = SessionManager.getSessionFactory().getClreplacedMetadata(DaoMember.clreplaced);
    final Query query = SessionManager.createQuery("FROM " + meta.getEnreplacedyName() + " WHERE globalfollow=true");
    final Query size = SessionManager.createQuery("SELECT count(*) FROM " + meta.getEnreplacedyName() + " WHERE globalfollow=true");
    return new MemberList(new QueryCollection<DaoMember>(query, size));
}

19 View Complete Implementation : DBRequests.java
Copyright GNU Affero General Public License v3.0
Author : BloatIt
public static <T> Long count(final Clreplaced<T> persistent) {
    final ClreplacedMetadata meta = SessionManager.getSessionFactory().getClreplacedMetadata(persistent);
    return ((Long) SessionManager.getSessionFactory().getCurrentSession().createQuery("select count(*) from " + meta.getEnreplacedyName()).uniqueResult());
}

19 View Complete Implementation : BasicHibernateDao.java
Copyright Apache License 2.0
Author : biliroy
/**
 * 获取实体名称
 *
 * @return String
 */
public String getEnreplacedyName() {
    ClreplacedMetadata meta = sessionFactory.getClreplacedMetadata(enreplacedyClreplaced);
    return meta.getEnreplacedyName();
}

19 View Complete Implementation : HibernateBaseDao.java
Copyright GNU General Public License v2.0
Author : caipiao
/**
 * 将更新对象拷贝至实体对象,并处理many-to-one的更新。
 *
 * @param updater
 * @param po
 */
private void updaterCopyToPersistentObject(Updater<T> updater, T po, ClreplacedMetadata cm) {
    String[] propNames = cm.getPropertyNames();
    String identifierName = cm.getIdentifierPropertyName();
    T bean = updater.getBean();
    Object value;
    for (String propName : propNames) {
        if (propName.equals(identifierName)) {
            continue;
        }
        try {
            value = MyBeanUtils.getSimpleProperty(bean, propName);
            if (!updater.isUpdate(propName, value)) {
                continue;
            }
            cm.setPropertyValue(po, propName, value, POJO);
        } catch (Exception e) {
            throw new RuntimeException("copy property to persistent object failed: '" + propName + "'", e);
        }
    }
}

18 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Get a related enreplacedy based on the value of the foreign key.  Attempts to find the related enreplacedy in the
 * saveMap; if its not found there, it is loaded via the Session (which should create a proxy, not actually load
 * the enreplacedy from the database).
 * Related enreplacedies are Promoted in the saveOrder according to their state.
 * @param propName Name of the navigation/replacedociation property of the enreplacedy, e.g. "Customer".  May be null if the property is the enreplacedy's identifier.
 * @param propType Type of the property
 * @param enreplacedyInfo Breeze EnreplacedyInfo
 * @param meta Metadata for the enreplacedy clreplaced
 * @return
 */
private Object getRelatedEnreplacedy(String propName, EnreplacedyType propType, EnreplacedyInfo enreplacedyInfo, ClreplacedMetadata meta) {
    Object relatedEnreplacedy = null;
    String foreignKeyName = findForeignKey(propName, meta);
    Object id = getForeignKeyValue(enreplacedyInfo, meta, foreignKeyName);
    if (id != null) {
        Clreplaced returnEnreplacedyClreplaced = propType.getReturnedClreplaced();
        EnreplacedyInfo relatedEnreplacedyInfo = saveWorkState.findEnreplacedyInfoById(returnEnreplacedyClreplaced, id);
        if (relatedEnreplacedyInfo == null) {
            EnreplacedyState state = enreplacedyInfo.enreplacedyState;
            // if (state == EnreplacedyState.Added || state == EnreplacedyState.Modified || (state == EnreplacedyState.Deleted
            // && propType.getForeignKeyDirection() != ForeignKeyDirection.FOREIGN_KEY_TO_PARENT)) {
            if (state != EnreplacedyState.Deleted || propType.getForeignKeyDirection() != ForeignKeyDirection.FOREIGN_KEY_TO_PARENT) {
                String relatedEnreplacedyName = propType.getName();
                relatedEnreplacedy = session.load(relatedEnreplacedyName, (Serializable) id, LockOptions.NONE);
            }
        } else {
            maybeAddToGraph(enreplacedyInfo, relatedEnreplacedyInfo, propType);
            relatedEnreplacedy = relatedEnreplacedyInfo.enreplacedy;
        }
    }
    return relatedEnreplacedy;
}

18 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Connect the related enreplacedies based on the foreign key values.
 * Note that this may cause related enreplacedies to be loaded from the DB if they are not already in the session.
 * @param enreplacedyInfo Enreplacedy that will be saved
 * @param meta Metadata about the enreplacedy type
 */
private void processRelationships(EnreplacedyInfo enreplacedyInfo, ClreplacedMetadata meta) {
    // make sure every enreplacedy is in the graph
    addToGraph(enreplacedyInfo, null);
    String[] propNames = meta.getPropertyNames();
    Type[] propTypes = meta.getPropertyTypes();
    Type propType = meta.getIdentifierType();
    if (propType != null) {
        processRelationship(meta.getIdentifierPropertyName(), propType, enreplacedyInfo, meta);
    }
    for (int i = 0; i < propNames.length; i++) {
        processRelationship(propNames[i], propTypes[i], enreplacedyInfo, meta);
    }
}

18 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Add or remove the enreplacedy relationships according to the current removeMode.
 */
private void processRelationships() {
    for (Entry<Clreplaced, List<EnreplacedyInfo>> entry : saveWorkState.entrySet()) {
        Clreplaced enreplacedyType = entry.getKey();
        ClreplacedMetadata clreplacedMeta = sessionFactory.getClreplacedMetadata(enreplacedyType);
        for (EnreplacedyInfo enreplacedyInfo : entry.getValue()) {
            processRelationships(enreplacedyInfo, clreplacedMeta);
        }
    }
}

18 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Handle a specific property if it is a replacedociation or Component relationship.
 * @param propName
 * @param propType
 * @param enreplacedyInfo
 * @param meta
 */
private void processRelationship(String propName, Type propType, EnreplacedyInfo enreplacedyInfo, ClreplacedMetadata meta) {
    if (propType.isreplacedociationType() && propType.isEnreplacedyType()) {
        fixupRelationship(propName, (EnreplacedyType) propType, enreplacedyInfo, meta);
    } else if (propType.isComponentType()) {
        fixupComponentRelationships(propName, (ComponentType) propType, enreplacedyInfo, meta);
    }
}

18 View Complete Implementation : Printer.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
/**
 * @param enreplacedy an actual enreplacedy object, not a proxy!
 */
public String toString(Object enreplacedy, EnreplacedyMode enreplacedyMode) throws HibernateException {
    // todo : this call will not work for anything other than pojos!
    ClreplacedMetadata cm = factory.getClreplacedMetadata(enreplacedy.getClreplaced());
    if (cm == null)
        return enreplacedy.getClreplaced().getName();
    Map result = new HashMap();
    if (cm.hasIdentifierProperty()) {
        result.put(cm.getIdentifierPropertyName(), cm.getIdentifierType().toLoggableString(cm.getIdentifier(enreplacedy, enreplacedyMode), factory));
    }
    Type[] types = cm.getPropertyTypes();
    String[] names = cm.getPropertyNames();
    Object[] values = cm.getPropertyValues(enreplacedy, enreplacedyMode);
    for (int i = 0; i < types.length; i++) {
        if (!names[i].startsWith("_")) {
            String strValue = values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ? values[i].toString() : types[i].toLoggableString(values[i], factory);
            result.put(names[i], strValue);
        }
    }
    return cm.getEnreplacedyName() + result.toString();
}

18 View Complete Implementation : HibernateBaseDao.java
Copyright GNU General Public License v2.0
Author : caipiao
/**
 * 通过Updater更新对象
 *
 * @param updater
 * @return
 */
@SuppressWarnings("unchecked")
public T updateByUpdater(Updater<T> updater) {
    ClreplacedMetadata cm = sessionFactory.getClreplacedMetadata(getEnreplacedyClreplaced());
    T bean = updater.getBean();
    T po = (T) getSession().get(getEnreplacedyClreplaced(), cm.getIdentifier(bean, POJO));
    updaterCopyToPersistentObject(updater, po, cm);
    return po;
}

18 View Complete Implementation : DeltaSetCalculator.java
Copyright GNU General Public License v3.0
Author : micromata
/**
 * @param obj1
 * @param obj2
 * @param sf
 * @return
 */
private static boolean areEnreplacediesEqual(Object obj1, Object obj2, SessionFactory sf) {
    try {
        // compare the database identifier
        ClreplacedMetadata clazz = sf.getClreplacedMetadata(obj1.getClreplaced());
        if (clazz != null) {
            if (clazz.hasIdentifierProperty()) {
                if (clazz.getIdentifier(obj1).equals(clazz.getIdentifier(obj2))) {
                    return true;
                }
            }
        }
    } catch (Exception ex) {
        log.error("Exception occured:" + ex, ex);
    }
    return obj1.equals(obj2);
}

18 View Complete Implementation : DeltaSetCalculator.java
Copyright GNU General Public License v3.0
Author : micromata
private static Object convertElement(final SessionFactory factory, Object element) {
    if (element == null) {
        return null;
    }
    try {
        ClreplacedMetadata clreplacedMetadata = factory.getClreplacedMetadata(element.getClreplaced());
        if (clreplacedMetadata != null) {
            return clreplacedMetadata.getIdentifier(element);
        }
    } catch (HibernateException ex) {
        log.error("Exception encountered " + ex, ex);
        return null;
    }
    return element;
}

18 View Complete Implementation : RUtil.java
Copyright Apache License 2.0
Author : Pardus-Engerek
private static void fixCompositeIdentifierInMetaModel(SessionFactory sessionFactory, Clreplaced clazz) {
    ClreplacedMetadata clreplacedMetadata = sessionFactory.getClreplacedMetadata(clazz);
    if (clreplacedMetadata instanceof AbstractEnreplacedyPersister) {
        AbstractEnreplacedyPersister persister = (AbstractEnreplacedyPersister) clreplacedMetadata;
        EnreplacedyMetamodel model = persister.getEnreplacedyMetamodel();
        IdentifierProperty identifier = model.getIdentifierProperty();
        try {
            Field field = IdentifierProperty.clreplaced.getDeclaredField("hasIdentifierMapper");
            field.setAccessible(true);
            field.set(identifier, true);
            field.setAccessible(false);
        } catch (Exception ex) {
            throw new SystemException("Attempt to fix enreplacedy meta model with hack failed, reason: " + ex.getMessage(), ex);
        }
    }
}

18 View Complete Implementation : HibernateUtil.java
Copyright Apache License 2.0
Author : UniTime
public static void clearCache(Clreplaced persistentClreplaced, boolean evictQueries) {
    _RootDAO dao = new _RootDAO();
    org.hibernate.Session hibSession = dao.getSession();
    SessionFactory hibSessionFactory = hibSession.getSessionFactory();
    if (persistentClreplaced == null) {
        for (Iterator i = hibSessionFactory.getAllClreplacedMetadata().entrySet().iterator(); i.hasNext(); ) {
            Map.Entry entry = (Map.Entry) i.next();
            String clreplacedName = (String) entry.getKey();
            ClreplacedMetadata clreplacedMetadata = (ClreplacedMetadata) entry.getValue();
            try {
                hibSessionFactory.getCache().evictEnreplacedyRegion(Clreplaced.forName(clreplacedName));
                for (int j = 0; j < clreplacedMetadata.getPropertyNames().length; j++) {
                    if (clreplacedMetadata.getPropertyTypes()[j].isCollectionType()) {
                        try {
                            hibSessionFactory.getCache().evictCollectionRegion(clreplacedName + "." + clreplacedMetadata.getPropertyNames()[j]);
                        } catch (MappingException e) {
                        }
                    }
                }
            } catch (ClreplacedNotFoundException e) {
            }
        }
        hibSessionFactory.getCache().evictEnreplacedyRegions();
        hibSessionFactory.getCache().evictCollectionRegions();
    } else {
        ClreplacedMetadata clreplacedMetadata = hibSessionFactory.getClreplacedMetadata(persistentClreplaced);
        hibSessionFactory.getCache().evictEnreplacedyRegion(persistentClreplaced);
        if (clreplacedMetadata != null) {
            for (int j = 0; j < clreplacedMetadata.getPropertyNames().length; j++) {
                if (clreplacedMetadata.getPropertyTypes()[j].isCollectionType()) {
                    try {
                        hibSessionFactory.getCache().evictCollectionRegion(persistentClreplaced.getClreplaced().getName() + "." + clreplacedMetadata.getPropertyNames()[j]);
                    } catch (MappingException e) {
                    }
                }
            }
        }
    }
    if (evictQueries) {
        hibSessionFactory.getCache().evictQueryRegions();
        hibSessionFactory.getCache().evictDefaultQueryRegion();
    }
}

18 View Complete Implementation : HibernateBasicDao.java
Copyright Apache License 2.0
Author : xuhuisheng
/**
 * 取得对象的主键名,辅助函数.
 *
 * @param enreplacedyClreplaced
 *            实体类型
 * @return 主键名称
 */
public String getIdName(Clreplaced enreplacedyClreplaced) {
    replacedert.notNull(enreplacedyClreplaced);
    enreplacedyClreplaced = ReflectUtils.getOriginalClreplaced(enreplacedyClreplaced);
    ClreplacedMetadata meta = this.getSessionFactory().getClreplacedMetadata(enreplacedyClreplaced);
    replacedert.notNull(meta, "Clreplaced " + enreplacedyClreplaced + " not define in hibernate session factory.");
    String idName = meta.getIdentifierPropertyName();
    replacedert.hasText(idName, enreplacedyClreplaced.getSimpleName() + " has no identifier property define.");
    return idName;
}

18 View Complete Implementation : HibernateSaveProcessor.java
Copyright MIT License
Author : Breeze
/**
 * Restore the old value of the concurrency column so Hibernate will save the enreplacedy.
 * Otherwise it will complain because Breeze has already changed the value.
 * @param enreplacedyInfo
 * @param clreplacedMeta
 */
protected void restoreOldVersionValue(EnreplacedyInfo enreplacedyInfo, ClreplacedMetadata clreplacedMeta) {
    if (enreplacedyInfo.originalValuesMap == null || enreplacedyInfo.originalValuesMap.size() == 0)
        return;
    int vcol = clreplacedMeta.getVersionProperty();
    String vname = clreplacedMeta.getPropertyNames()[vcol];
    if (enreplacedyInfo.originalValuesMap.containsKey(vname)) {
        Object oldVersion = enreplacedyInfo.originalValuesMap.get(vname);
        Object enreplacedy = enreplacedyInfo.enreplacedy;
        if (oldVersion == null) {
            _possibleErrors.add("Hibernate does not support 'null' version properties. " + "Enreplacedy: " + enreplacedy + ", Property: " + vname);
        }
        Clreplaced versionClazz = clreplacedMeta.getPropertyTypes()[vcol].getReturnedClreplaced();
        DataType dataType = DataType.fromClreplaced(versionClazz);
        Object oldValue = DataType.coerceData(oldVersion, dataType);
        clreplacedMeta.setPropertyValue(enreplacedy, vname, oldValue);
    }
}

18 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Get the value of the foreign key property.  This comes from the enreplacedy, but if that value is
 * null, and the enreplacedy is deleted, we try to get it from the originalValuesMap.
 * @param enreplacedyInfo Breeze EnreplacedyInfo
 * @param meta Metadata for the enreplacedy clreplaced
 * @param foreignKeyName Name of the foreign key property of the enreplacedy, e.g. "CustomerID"
 * @return
 */
private Object getForeignKeyValue(EnreplacedyInfo enreplacedyInfo, ClreplacedMetadata meta, String foreignKeyName) {
    Object enreplacedy = enreplacedyInfo.enreplacedy;
    Object id = null;
    if (foreignKeyName.equalsIgnoreCase(meta.getIdentifierPropertyName())) {
        id = meta.getIdentifier(enreplacedy, null);
    } else if (Arrays.asList(meta.getPropertyNames()).contains(foreignKeyName)) {
        id = meta.getPropertyValue(enreplacedy, foreignKeyName);
    } else if (meta.getIdentifierType().isComponentType()) {
        // compound key
        ComponentType compType = (ComponentType) meta.getIdentifierType();
        int index = Arrays.asList(compType.getPropertyNames()).indexOf(foreignKeyName);
        if (index >= 0) {
            Object idComp = meta.getIdentifier(enreplacedy, null);
            id = compType.getPropertyValue(idComp, index, EnreplacedyMode.POJO);
        }
    }
    if (id == null && enreplacedyInfo.enreplacedyState == EnreplacedyState.Deleted) {
        id = enreplacedyInfo.originalValuesMap.get(foreignKeyName);
    }
    return id;
}

17 View Complete Implementation : HibernateModule.java
Copyright Apache License 2.0
Author : apache
/**
 * Contributes {@link ApplicationStateContribution}s for all registered Hibernate enreplacedy clreplacedes.
 *
 * @param configuration
 *         Configuration to contribute
 * @param enreplacedySessionStatePersistenceStrategyEnabled
 *         indicates if contribution should take place
 * @param sessionSource
 *         creates Hibernate session
 */
public static void contributeApplicationStateManager(MappedConfiguration<Clreplaced, ApplicationStateContribution> configuration, @Symbol(HibernateSymbols.ENreplacedY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED) boolean enreplacedySessionStatePersistenceStrategyEnabled, HibernateSessionSource sessionSource) {
    if (!enreplacedySessionStatePersistenceStrategyEnabled)
        return;
    for (ClreplacedMetadata clreplacedMetadata : sessionSource.getSessionFactory().getAllClreplacedMetadata().values()) {
        final Clreplaced enreplacedyClreplaced = clreplacedMetadata.getMappedClreplaced();
        configuration.add(enreplacedyClreplaced, new ApplicationStateContribution(HibernatePersistenceConstants.ENreplacedY));
    }
}

17 View Complete Implementation : HibernateEntityContext.java
Copyright GNU Lesser General Public License v3.0
Author : beangle
private ComponentType buildComponentType(SessionFactory sessionFactory, String enreplacedyName, String propertyName) {
    EnreplacedyType enreplacedyType = (EnreplacedyType) enreplacedyTypes.get(enreplacedyName);
    if (null != enreplacedyType) {
        Type propertyType = (Type) enreplacedyType.getPropertyTypes().get(propertyName);
        if (null != propertyType) {
            return (ComponentType) propertyType;
        }
    }
    ClreplacedMetadata cm = sessionFactory.getClreplacedMetadata(enreplacedyName);
    org.hibernate.type.ComponentType hcType = (org.hibernate.type.ComponentType) cm.getPropertyType(propertyName);
    String[] propertyNames = hcType.getPropertyNames();
    ComponentType cType = new ComponentType(hcType.getReturnedClreplaced());
    Map<String, Type> propertyTypes = cType.getPropertyTypes();
    for (int j = 0; j < propertyNames.length; j++) {
        org.hibernate.type.Type type = cm.getPropertyType(propertyName + "." + propertyNames[j]);
        if (type.isEnreplacedyType()) {
            propertyTypes.put(propertyNames[j], buildEnreplacedyType(sessionFactory, type.getName()));
        } else if (type.isComponentType()) {
            propertyTypes.put(propertyNames[j], buildComponentType(sessionFactory, enreplacedyName, propertyName + "." + propertyNames[j]));
        } else if (type.isCollectionType()) {
            propertyTypes.put(propertyNames[j], buildCollectionType(sessionFactory, defaultCollectionClreplaced(type), enreplacedyName + "." + propertyName + "." + propertyNames[j]));
        }
    }
    return cType;
}

17 View Complete Implementation : HibernateEntityContext.java
Copyright GNU Lesser General Public License v3.0
Author : beangle
/**
 * Build context from session factory
 */
public void initFrom(SessionFactory sessionFactory) {
    replacedert.notNull(sessionFactory);
    Stopwatch watch = new Stopwatch().start();
    Map<String, ClreplacedMetadata> clreplacedMetadatas = sessionFactory.getAllClreplacedMetadata();
    int enreplacedyCount = enreplacedyTypes.size();
    int collectionCount = collectionTypes.size();
    for (Iterator<ClreplacedMetadata> iter = clreplacedMetadatas.values().iterator(); iter.hasNext(); ) {
        ClreplacedMetadata cm = (ClreplacedMetadata) iter.next();
        buildEnreplacedyType(sessionFactory, cm.getEnreplacedyName());
    }
    logger.info("Find {} enreplacedies,{} collections from hibernate in {}", new Object[] { enreplacedyTypes.size() - enreplacedyCount, collectionTypes.size() - collectionCount, watch });
    if (logger.isDebugEnabled())
        loggerTypeInfo();
    collectionTypes.clear();
}

17 View Complete Implementation : DaoMember.java
Copyright GNU Affero General Public License v3.0
Author : BloatIt
/**
 * Base method to all the get something created by the user.
 *
 * @param asMemberOnly the result must contains only result that are not
 *            done as name of a team.
 */
private <T extends DaoUserContent> PageIterable<T> getUserContent(final Clreplaced<T> theClreplaced, final boolean asMemberOnly) {
    final ClreplacedMetadata meta = SessionManager.getSessionFactory().getClreplacedMetadata(theClreplaced);
    final Query query = SessionManager.createQuery("from " + meta.getEnreplacedyName() + " as x where x.member = :author" + (asMemberOnly ? " AND x.asTeam = null" : ""));
    final Query size = SessionManager.createQuery("SELECT count(*) from " + meta.getEnreplacedyName() + " as x where x.member = :author" + (asMemberOnly ? " AND x.asTeam = null" : ""));
    final QueryCollection<T> q = new QueryCollection<T>(query, size);
    q.setEnreplacedy("author", this);
    return q;
}

17 View Complete Implementation : RelationshipFixer.java
Copyright MIT License
Author : Breeze
/**
 * Set an replacedociation value based on the value of the foreign key.  This updates the property of the enreplacedy.
 * @param propName Name of the navigation/replacedociation property of the enreplacedy, e.g. "Customer".  May be null if the property is the enreplacedy's identifier.
 * @param propType Type of the property
 * @param enreplacedyInfo Breeze EnreplacedyInfo
 * @param meta Metadata for the enreplacedy clreplaced
 */
private void fixupRelationship(String propName, EnreplacedyType propType, EnreplacedyInfo enreplacedyInfo, ClreplacedMetadata meta) {
    Object enreplacedy = enreplacedyInfo.enreplacedy;
    if (removeMode) {
        meta.setPropertyValue(enreplacedy, propName, null);
        return;
    }
    Object relatedEnreplacedy = getPropertyValue(meta, enreplacedy, propName);
    if (relatedEnreplacedy != null) {
        // enreplacedies are already connected - still need to add to dependency graph
        EnreplacedyInfo relatedEnreplacedyInfo = saveWorkState.findEnreplacedyInfo(relatedEnreplacedy);
        maybeAddToGraph(enreplacedyInfo, relatedEnreplacedyInfo, propType);
        return;
    }
    relatedEnreplacedy = getRelatedEnreplacedy(propName, propType, enreplacedyInfo, meta);
    if (relatedEnreplacedy != null) {
        meta.setPropertyValue(enreplacedy, propName, relatedEnreplacedy);
    }
}

17 View Complete Implementation : HibernateDao.java
Copyright Apache License 2.0
Author : chelu
/**
 * Create Order from criteria and property path
 * @param criteria the hibernate criteria to apply order on
 * @param propertyPath the property path
 * @return Order
 */
protected Order createOrder(Criteria criteria, String propertyPath, boolean ascending) {
    Order order = null;
    if (propertyPath != null) {
        String sortProperty = PropertyUtils.getPropertyName(propertyPath);
        try {
            if (PropertyUtils.isNested(propertyPath)) {
                String alias = PropertyUtils.getPropertyName(PropertyUtils.getPath(propertyPath));
                // Need to create alias?
                // String alias = HibernateUtils.findAliasForPropertyPath(criteria, propertyPath);
                HibernateUtils.createAlias(criteria, PropertyUtils.getPath(propertyPath));
                sortProperty = alias + PropertyUtils.PROPERTY_SEPARATOR + sortProperty;
            } else {
                // test if property is an enreplacedy clreplaced
                Type sortType = getClreplacedMetadata().getPropertyType(propertyPath);
                if (sortType.isEnreplacedyType()) {
                    // is enreplacedy, look for 'name' property
                    String[] propertyNames = getClreplacedMetadata(sortType.getReturnedClreplaced()).getPropertyNames();
                    for (String name : propertyNames) {
                        if ("name".equals(name)) {
                            log.info("Found property name on persistent clreplaced: " + sortType.getName());
                            String newPath = propertyPath + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + "name";
                            return createOrder(criteria, newPath, ascending);
                        }
                    }
                }
            }
            if (log.isDebugEnabled())
                log.debug("Setting order as: " + sortProperty);
            order = ascending ? Order.asc(sortProperty) : Order.desc(sortProperty);
        } catch (HibernateException he) {
            log.error("Cannot to create Order for property: " + sortProperty + " for " + getEnreplacedyClreplaced().getSimpleName(), he);
        }
    } else {
        // add default order by id
        ClreplacedMetadata metadata = getClreplacedMetadata();
        if (metadata != null)
            order = Order.asc(metadata.getIdentifierPropertyName());
    }
    return order;
}

17 View Complete Implementation : HibernateUtils.java
Copyright Apache License 2.0
Author : chelu
/**
 * Initialize Object for use with closed Session.
 *
 * @param sessionFactory max depth in recursion
 * @param obj Object to initialize
 * @param initializedObjects list with already initialized Objects
 * @param depth max depth in recursion
 */
private static void initialize(SessionFactory sessionFactory, Object obj, List<Object> initializedObjects, int depth) {
    // return on nulls, depth = 0 or already initialized objects
    if (obj == null || depth == 0) {
        return;
    }
    if (!Hibernate.isInitialized(obj)) {
        // if collection, initialize objects in collection too. Hibernate don't do it.
        if (obj instanceof Collection) {
            initializeCollection(sessionFactory, obj, initializedObjects, depth);
            return;
        }
        sessionFactory.getCurrentSession().buildLockRequest(LockOptions.NONE).lock(obj);
        Hibernate.initialize(obj);
    }
    // now we can call equals safely. If object are already initializated, return
    if (initializedObjects.contains(obj))
        return;
    initializedObjects.add(obj);
    // initialize all persistent replacedociaciations.
    ClreplacedMetadata clreplacedMetadata = getClreplacedMetadata(sessionFactory, obj);
    if (clreplacedMetadata == null) {
        // Not persistent object
        return;
    }
    Object[] pvs = clreplacedMetadata.getPropertyValues(obj, EnreplacedyMode.POJO);
    for (Object pv : pvs) {
        initialize(sessionFactory, pv, initializedObjects, depth - 1);
    }
}

17 View Complete Implementation : HibernateOrderDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.OrderDAO#isOrderFrequencyInUse(org.openmrs.OrderFrequency)
 */
@Override
public boolean isOrderFrequencyInUse(OrderFrequency orderFrequency) {
    Map<String, ClreplacedMetadata> metadata = sessionFactory.getAllClreplacedMetadata();
    for (ClreplacedMetadata clreplacedMetadata : metadata.values()) {
        Clreplaced<?> enreplacedyClreplaced = clreplacedMetadata.getMappedClreplaced();
        if (Order.clreplaced.equals(enreplacedyClreplaced)) {
            // ignore the org.openmrs.Order clreplaced itself
            continue;
        }
        if (!Order.clreplaced.isreplacedignableFrom(enreplacedyClreplaced)) {
            // not a sub clreplaced of Order
            continue;
        }
        String[] names = clreplacedMetadata.getPropertyNames();
        for (String name : names) {
            if (clreplacedMetadata.getPropertyType(name).getReturnedClreplaced().equals(OrderFrequency.clreplaced)) {
                Criteria criteria = sessionFactory.getCurrentSession().createCriteria(enreplacedyClreplaced);
                criteria.add(Restrictions.eq(name, orderFrequency));
                criteria.setMaxResults(1);
                if (!criteria.list().isEmpty()) {
                    return true;
                }
            }
        }
    }
    return false;
}