本文整理匯總了Java中org.hibernate.FetchMode類的典型用法代碼示例。如果您正苦於以下問題:Java FetchMode類的具體用法?Java FetchMode怎麽用?Java FetchMode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FetchMode類屬於org.hibernate包,在下文中一共展示了FetchMode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: annotationFetchModeToHibernateFetchMode
import org.hibernate.FetchMode; //導入依賴的package包/類
public static FetchMode annotationFetchModeToHibernateFetchMode(org.hibernate.annotations.FetchMode annotationFetchMode) {
switch ( annotationFetchMode ) {
case JOIN: {
return FetchMode.JOIN;
}
case SELECT: {
return FetchMode.SELECT;
}
case SUBSELECT: {
// todo - is this correct? can the conversion be made w/o any additional information, eg
// todo - association nature
return FetchMode.SELECT;
}
default: {
throw new AssertionFailure( "Unknown fetch mode" );
}
}
}
示例2: getJoinType
import org.hibernate.FetchMode; //導入依賴的package包/類
/**
* Determine the appropriate type of join (if any) to use to fetch the
* given association.
*
* @param persister The owner of the association.
* @param path The path to the association
* @param propertyNumber The property number representing the association.
* @param associationType The association type.
* @param metadataFetchMode The metadata-defined fetch mode.
* @param metadataCascadeStyle The metadata-defined cascade style.
* @param lhsTable The owner table
* @param lhsColumns The owner join columns
* @param nullable Is the association nullable.
* @param currentDepth Current join depth
* @return type of join to use ({@link org.hibernate.sql.JoinType#INNER_JOIN},
* {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
* @throws MappingException ??
*/
protected JoinType getJoinType(
OuterJoinLoadable persister,
final PropertyPath path,
int propertyNumber,
AssociationType associationType,
FetchMode metadataFetchMode,
CascadeStyle metadataCascadeStyle,
String lhsTable,
String[] lhsColumns,
final boolean nullable,
final int currentDepth) throws MappingException {
return getJoinType(
associationType,
metadataFetchMode,
path,
lhsTable,
lhsColumns,
nullable,
currentDepth,
metadataCascadeStyle
);
}
示例3: isJoinedFetchEnabledInMapping
import org.hibernate.FetchMode; //導入依賴的package包/類
/**
* Does the mapping, and Hibernate default semantics, specify that
* this association should be fetched by outer joining
*/
protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type)
throws MappingException {
if ( !type.isEntityType() && !type.isCollectionType() ) {
return false;
}
else {
if (config==FetchMode.JOIN) return true;
if (config==FetchMode.SELECT) return false;
if ( type.isEntityType() ) {
//TODO: look at the owning property and check that it
// isn't lazy (by instrumentation)
EntityType entityType =(EntityType) type;
EntityPersister persister = getFactory().getEntityPersister( entityType.getAssociatedEntityName() );
return !persister.hasProxy();
}
else {
return false;
}
}
}
示例4: getJoinType
import org.hibernate.FetchMode; //導入依賴的package包/類
@Override
protected JoinType getJoinType(
AssociationType associationType,
FetchMode config,
PropertyPath path,
String lhsTable,
String[] lhsColumns,
boolean nullable,
int currentDepth,
CascadeStyle cascadeStyle) throws MappingException {
return getJoinType(
null,
path,
-1,
associationType,
config,
cascadeStyle,
lhsTable,
lhsColumns,
nullable,
currentDepth
);
}
示例5: BaselineAttributeInformation
import org.hibernate.FetchMode; //導入依賴的package包/類
public BaselineAttributeInformation(
boolean lazy,
boolean insertable,
boolean updateable,
ValueGeneration valueGenerationStrategy,
boolean nullable,
boolean dirtyCheckable,
boolean versionable,
CascadeStyle cascadeStyle,
FetchMode fetchMode) {
this.lazy = lazy;
this.insertable = insertable;
this.updateable = updateable;
this.valueGenerationStrategy = valueGenerationStrategy;
this.nullable = nullable;
this.dirtyCheckable = dirtyCheckable;
this.versionable = versionable;
this.cascadeStyle = cascadeStyle;
this.fetchMode = fetchMode;
}
示例6: ComponentType
import org.hibernate.FetchMode; //導入依賴的package包/類
public ComponentType(TypeFactory.TypeScope typeScope, ComponentMetamodel metamodel) {
this.typeScope = typeScope;
// for now, just "re-flatten" the metamodel since this is temporary stuff anyway (HHH-1907)
this.isKey = metamodel.isKey();
this.propertySpan = metamodel.getPropertySpan();
this.propertyNames = new String[ propertySpan ];
this.propertyTypes = new Type[ propertySpan ];
this.propertyNullability = new boolean[ propertySpan ];
this.cascade = new CascadeStyle[ propertySpan ];
this.joinedFetch = new FetchMode[ propertySpan ];
for ( int i = 0; i < propertySpan; i++ ) {
StandardProperty prop = metamodel.getProperty( i );
this.propertyNames[i] = prop.getName();
this.propertyTypes[i] = prop.getType();
this.propertyNullability[i] = prop.isNullable();
this.cascade[i] = prop.getCascadeStyle();
this.joinedFetch[i] = prop.getFetchMode();
if (!prop.isNullable()) {
hasNotNullProperty = true;
}
}
this.entityMode = metamodel.getEntityMode();
this.componentTuplizer = metamodel.getComponentTuplizer();
}
示例7: createFlowsCriteria
import org.hibernate.FetchMode; //導入依賴的package包/類
private static DetachedCriteria createFlowsCriteria(FlowFinderCriteria finderCriteria) {
DetachedCriteria criteria = DetachedCriteria.forClass(Flow.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.setFetchMode("parts", FetchMode.JOIN) // eager
.add(ge("creationTime", finderCriteria.getFrom()))
.addOrder(Order.desc("identifier"));
if (finderCriteria.getApplication() != null) {
// constrain query to a certain application name
criteria.add(eq("application", finderCriteria
.getApplication()));
}
if (finderCriteria.getTo() != null) {
// there's an upper limit to creationTime property
criteria.add(Restrictions
.le("creationTime", finderCriteria.getTo()));
}
return criteria;
}
示例8: getAllIsCacheableAndReturnsDistinctResult
import org.hibernate.FetchMode; //導入依賴的package包/類
@Test
public void getAllIsCacheableAndReturnsDistinctResult() throws Exception {
List<Object> expectedResult = new ArrayList<Object>();
when(session.createCriteria(Object.class)).thenReturn(criteria);
when(criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)).thenReturn(criteria);
when(criteria.setCacheable(true)).thenReturn(criteria);
when(criteria.setFetchMode("association", FetchMode.JOIN)).thenReturn(criteria);
when(criteria.list()).thenReturn(expectedResult);
assertThat(dao.getAll("association")).isSameAs(expectedResult);
verify(sessionFactory, atLeastOnce()).getCurrentSession();
verify(criteria).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
verify(criteria).setCacheable(true);
verify(criteria).setFetchMode("association", FetchMode.JOIN);
}
示例9: execute
import org.hibernate.FetchMode; //導入依賴的package包/類
@Override
public void execute() {
try{
Transaction tx = session.beginTransaction();
// Query q = session.createQuery("from Users u where u.userId = :userid");
// q.setString("userid", userID);
// user = (Users)q.uniqueResult();
Criteria crt = session.createCriteria(Users.class).setFetchMode("signings", FetchMode.JOIN).setFetchMode("lendings", FetchMode.JOIN)
.setFetchMode("duplicates", FetchMode.JOIN).setFetchMode("picturebooks", FetchMode.JOIN).setFetchMode("lendings.warningses", FetchMode.JOIN);
crt.add( Restrictions.eq("userId", userID));
user = (Users)crt.uniqueResult();
tx.commit();
log.info("loading user: "+ userID);
}catch (Exception e){
log.error("loading user failed: " + userID);
log.error(e.getMessage());
}
}
示例10: bindUnidirectionalOneToManyInverseValues
import org.hibernate.FetchMode; //導入依賴的package包/類
/**
* @param property The property to bind
* @param manyToOne The inverse side
*/
protected void bindUnidirectionalOneToManyInverseValues(ToMany property, ManyToOne manyToOne) {
PropertyConfig config = getPropertyConfig(property);
if (config == null) {
manyToOne.setLazy(true);
} else {
manyToOne.setIgnoreNotFound(config.getIgnoreNotFound());
final FetchMode fetch = config.getFetchMode();
if(!fetch.equals(FetchMode.JOIN) && !fetch.equals(FetchMode.EAGER)) {
manyToOne.setLazy(true);
}
final Boolean lazy = config.getLazy();
if(lazy != null) {
manyToOne.setLazy(lazy);
}
}
// set referenced entity
manyToOne.setReferencedEntityName(property.getAssociatedEntity().getName());
}
示例11: bindManyToOneValues
import org.hibernate.FetchMode; //導入依賴的package包/類
/**
*/
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());
}
示例12: handleFindNextScheduledTasks
import org.hibernate.FetchMode; //導入依賴的package包/類
/**
* {@inheritDoc}
*
* @see com.communote.server.persistence.tasks.TaskDao#findNextScheduledTasks()
*/
@SuppressWarnings("unchecked")
@Override
protected Collection<Task> handleFindNextScheduledTasks(Date upperBound, int maxTasks,
Collection<Long> taskIdsToExclude) {
Criteria criteria = getSession().createCriteria(Task.class);
criteria.setFetchMode(TaskConstants.PROPERTIES, FetchMode.JOIN);
criteria.add(Restrictions.eq(TaskConstants.TASKSTATUS, TaskStatus.PENDING));
criteria.add(Restrictions.eq(TaskConstants.ACTIVE, true));
criteria.addOrder(Order.asc(TaskConstants.NEXTEXECUTION));
if (taskIdsToExclude != null && taskIdsToExclude.size() > 0) {
criteria.add(Restrictions.not(Restrictions.in(TaskConstants.ID, taskIdsToExclude)));
}
if (upperBound != null) {
criteria.add(Restrictions.lt(TaskConstants.NEXTEXECUTION, upperBound));
}
criteria.setMaxResults(maxTasks);
return criteria.list();
}
示例13: getFdTypeByDocumentTypeName
import org.hibernate.FetchMode; //導入依賴的package包/類
/**
* An API to fetch all Field types by document type name.
*
* @param docTypeName String
* @param batchInstanceIdentifier String
* @param isKVExtraction boolean
* @return List<FieldType>
*/
@Override
public List<FieldType> getFdTypeByDocumentTypeName(String docTypeName, String batchInstanceIdentifier, boolean isKVExtraction) {
LOG.info("batchInstanceID ID : " + batchInstanceIdentifier);
DetachedCriteria criteria = criteria();
criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
if (isKVExtraction) {
criteria.setFetchMode("kvExtraction", FetchMode.JOIN);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
}
DetachedCriteria subQuery = criteria(BatchInstance.class);
subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER));
return find(criteria);
}
示例14: getFdTypeAndRegexValidationByDocTypeName
import org.hibernate.FetchMode; //導入依賴的package包/類
/**
* An API to fetch all Field types by document type name.
*
* @param docTypeName String
* @param batchInstanceIdentifier String
* @return List<FieldType>
*/
@Override
public List<FieldType> getFdTypeAndRegexValidationByDocTypeName(String docTypeName, String batchInstanceIdentifier) {
LOG.info("batchInstanceID ID : " + batchInstanceIdentifier);
DetachedCriteria criteria = criteria();
criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
criteria.setFetchMode(REGEX_VALIDATION, FetchMode.JOIN);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
DetachedCriteria subQuery = criteria(BatchInstance.class);
subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER));
return find(criteria);
}
示例15: getJoinType
import org.hibernate.FetchMode; //導入依賴的package包/類
/**
* Get the join type (inner, outer, etc) or -1 if the
* association should not be joined. Override on
* subclasses.
*/
protected int getJoinType(
AssociationType type,
FetchMode config,
String path,
String lhsTable,
String[] lhsColumns,
boolean nullable,
int currentDepth,
CascadeStyle cascadeStyle)
throws MappingException {
if ( !isJoinedFetchEnabled(type, config, cascadeStyle) ) return -1;
if ( isTooDeep(currentDepth) || ( type.isCollectionType() && isTooManyCollections() ) ) return -1;
final boolean dupe = isDuplicateAssociation(lhsTable, lhsColumns, type);
if (dupe) return -1;
return getJoinType(nullable, currentDepth);
}