Example usage for org.hibernate FetchMode DEFAULT

List of usage examples for org.hibernate FetchMode DEFAULT

Introduction

In this page you can find the example usage for org.hibernate FetchMode DEFAULT.

Prototype

FetchMode DEFAULT

To view the source code for org.hibernate FetchMode DEFAULT.

Click Source Link

Document

Default to the setting configured in the mapping file.

Usage

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * First pass to bind collection to Hibernate metamodel, sets up second pass
 *
 * @param property   The GrailsDomainClassProperty instance
 * @param collection The collection// www . j av  a  2 s . c om
 * @param owner      The owning persistent class
 * @param mappings   The Hibernate mappings instance
 * @param path
 */
protected void bindCollection(ToMany property, Collection collection, PersistentClass owner, Mappings mappings,
        String path, String sessionFactoryBeanName) {

    // set role
    String propertyName = getNameForPropertyAndPath(property, path);
    collection.setRole(qualify(property.getOwner().getName(), propertyName));

    PropertyConfig pc = getPropertyConfig(property);
    // configure eager fetching
    final FetchMode fetchMode = pc.getFetchMode();
    if (fetchMode == FetchMode.JOIN) {
        collection.setFetchMode(FetchMode.JOIN);
    } else if (pc.getFetchMode() != null) {
        collection.setFetchMode(pc.getFetchMode());
    } else {
        collection.setFetchMode(FetchMode.DEFAULT);
    }

    if (pc.getCascade() != null) {
        collection.setOrphanDelete(pc.getCascade().equals(CASCADE_ALL_DELETE_ORPHAN));
    }
    // if it's a one-to-many mapping
    if (shouldBindCollectionWithForeignKey(property)) {
        OneToMany oneToMany = new OneToMany(mappings, collection.getOwner());
        collection.setElement(oneToMany);
        bindOneToMany((org.grails.datastore.mapping.model.types.OneToMany) property, oneToMany, mappings);
    } else {
        bindCollectionTable(property, mappings, collection, owner.getTable(), sessionFactoryBeanName);

        if (!property.isOwningSide()) {
            collection.setInverse(true);
        }
    }

    if (pc.getBatchSize() != null) {
        collection.setBatchSize(pc.getBatchSize());
    }

    // set up second pass
    if (collection instanceof org.hibernate.mapping.Set) {
        mappings.addSecondPass(
                new GrailsCollectionSecondPass(property, mappings, collection, sessionFactoryBeanName));
    } else if (collection instanceof org.hibernate.mapping.List) {
        mappings.addSecondPass(new ListSecondPass(property, mappings, collection, sessionFactoryBeanName));
    } else if (collection instanceof org.hibernate.mapping.Map) {
        mappings.addSecondPass(new MapSecondPass(property, mappings, collection, sessionFactoryBeanName));
    } else { // Collection -> Bag
        mappings.addSecondPass(
                new GrailsCollectionSecondPass(property, mappings, collection, sessionFactoryBeanName));
    }
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne,
        String path, String sessionFactoryBeanName) {
    PropertyConfig config = getPropertyConfig(property);
    final Association otherSide = property.getInverseSide();

    final boolean hasOne = isHasOne(otherSide);
    oneToOne.setConstrained(hasOne);//from ww w  .j a va 2s  .c  o m
    oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT
            : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
    oneToOne.setAlternateUniqueKey(true);

    if (config != null && config.getFetchMode() != null) {
        oneToOne.setFetchMode(config.getFetchMode());
    } else {
        oneToOne.setFetchMode(FetchMode.DEFAULT);
    }

    oneToOne.setReferencedEntityName(otherSide.getOwner().getName());
    oneToOne.setPropertyName(property.getName());

    bindOneToOneInternal(property, oneToOne, path);

    if (hasOne) {
        PropertyConfig pc = getPropertyConfig(property);
        bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName);
    } else {
        oneToOne.setReferencedPropertyName(otherSide.getName());
    }
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 *//*from  ww w.  j a  v a  2s  .  c om*/
protected void bindManyToOneValues(org.grails.datastore.mapping.model.types.Association property,
        ManyToOne manyToOne) {
    PropertyConfig config = getPropertyConfig(property);

    if (config != null && config.getFetchMode() != null) {
        manyToOne.setFetchMode(config.getFetchMode());
    } else {
        manyToOne.setFetchMode(FetchMode.DEFAULT);
    }

    manyToOne.setLazy(getLaziness(property));

    if (config != null) {
        manyToOne.setIgnoreNotFound(config.getIgnoreNotFound());
    }

    // set referenced entity
    manyToOne.setReferencedEntityName(property.getAssociatedEntity().getName());
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * First pass to bind collection to Hibernate metamodel, sets up second pass
 *
 * @param property   The GrailsDomainClassProperty instance
 * @param collection The collection/*from  ww w . jav  a  2s.  co m*/
 * @param owner      The owning persistent class
 * @param mappings   The Hibernate mappings instance
 * @param path
 */
protected void bindCollection(ToMany property, Collection collection, PersistentClass owner,
        InFlightMetadataCollector mappings, String path, String sessionFactoryBeanName) {

    // set role
    String propertyName = getNameForPropertyAndPath(property, path);
    collection.setRole(qualify(property.getOwner().getName(), propertyName));

    PropertyConfig pc = getPropertyConfig(property);
    // configure eager fetching
    final FetchMode fetchMode = pc.getFetchMode();
    if (fetchMode == FetchMode.JOIN) {
        collection.setFetchMode(FetchMode.JOIN);
    } else if (pc.getFetchMode() != null) {
        collection.setFetchMode(pc.getFetchMode());
    } else {
        collection.setFetchMode(FetchMode.DEFAULT);
    }

    if (pc.getCascade() != null) {
        collection.setOrphanDelete(pc.getCascade().equals(CASCADE_ALL_DELETE_ORPHAN));
    }
    // if it's a one-to-many mapping
    if (shouldBindCollectionWithForeignKey(property)) {
        OneToMany oneToMany = new OneToMany(mappings, collection.getOwner());
        collection.setElement(oneToMany);
        bindOneToMany((org.grails.datastore.mapping.model.types.OneToMany) property, oneToMany, mappings);
    } else {
        bindCollectionTable(property, mappings, collection, owner.getTable(), sessionFactoryBeanName);

        if (!property.isOwningSide()) {
            collection.setInverse(true);
        }
    }

    if (pc.getBatchSize() != null) {
        collection.setBatchSize(pc.getBatchSize());
    }

    // set up second pass
    if (collection instanceof org.hibernate.mapping.Set) {
        mappings.addSecondPass(
                new GrailsCollectionSecondPass(property, mappings, collection, sessionFactoryBeanName));
    } else if (collection instanceof org.hibernate.mapping.List) {
        mappings.addSecondPass(new ListSecondPass(property, mappings, collection, sessionFactoryBeanName));
    } else if (collection instanceof org.hibernate.mapping.Map) {
        mappings.addSecondPass(new MapSecondPass(property, mappings, collection, sessionFactoryBeanName));
    } else { // Collection -> Bag
        mappings.addSecondPass(
                new GrailsCollectionSecondPass(property, mappings, collection, sessionFactoryBeanName));
    }
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

protected void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne,
        String path, String sessionFactoryBeanName) {
    PropertyConfig config = getPropertyConfig(property);
    final Association otherSide = property.getInverseSide();

    final boolean hasOne = isHasOne(otherSide);
    oneToOne.setConstrained(hasOne);//w w w  . ja  v a  2s  .  c  o  m
    oneToOne.setForeignKeyType(
            oneToOne.isConstrained() ? ForeignKeyDirection.FROM_PARENT : ForeignKeyDirection.TO_PARENT);
    oneToOne.setAlternateUniqueKey(true);

    if (config != null && config.getFetchMode() != null) {
        oneToOne.setFetchMode(config.getFetchMode());
    } else {
        oneToOne.setFetchMode(FetchMode.DEFAULT);
    }

    oneToOne.setReferencedEntityName(otherSide.getOwner().getName());
    oneToOne.setPropertyName(property.getName());
    oneToOne.setReferenceToPrimaryKey(false);

    bindOneToOneInternal(property, oneToOne, path);

    if (hasOne) {
        PropertyConfig pc = getPropertyConfig(property);
        bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName);
    } else {
        oneToOne.setReferencedPropertyName(otherSide.getName());
    }
}

From source file:org.grouter.domain.dao.spring.MessageDAOImpl.java

License:Apache License

public List<Message> findMessagesBy(final Long messageId, final Date fromDate, final Date toDate,
        final String nodeId) {
    Criteria crit = getSession().createCriteria(getEntityClass());

    crit.setFetchMode("receivers", FetchMode.DEFAULT);
    crit.setFetchMode("node", FetchMode.DEFAULT);

    if (messageId == null && fromDate == null && toDate == null && nodeId == null) {
        return new ArrayList<Message>();
    }//from   w  w  w. j  a v  a 2 s. c  o m

    if (messageId != null) {
        crit.add(Restrictions.idEq(messageId));
        crit.addOrder(Order.asc("id"));

    }
    if (nodeId != null) {
        crit.add(Restrictions.eq("node.id", nodeId));
        crit.addOrder(Order.asc("id"));

    }
    if (fromDate != null) {
        crit.add(Restrictions.ge("auditInfo.createdOn", fromDate));
        crit.addOrder(Order.asc("auditInfo.createdOn"));
    }
    if (toDate != null) {
        crit.add(Restrictions.le("auditInfo.createdOn", toDate));
        crit.addOrder(Order.asc("auditInfo.createdOn"));
    }
    List<Message> messages = crit.list();
    return messages;
}

From source file:se.sperber.cryson.repository.CrysonRepository.java

License:Apache License

private void setFetchModeForAssociations(Criteria criteria, Set<String> associationsToFetch) {
    for (String associationToFetch : associationsToFetch) {
        criteria.setFetchMode(associationToFetch, FetchMode.DEFAULT);
    }/*from ww  w.  j a v a  2  s.c  o  m*/
}