public static AssociationStorageStrategy getInstance(AssociationKeyMetadata keyMetadata, AssociationStorageType associationStorage, AssociationDocumentStorageType associationDocumentStorage) { if ( keyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE || keyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION || associationStorage == AssociationStorageType.IN_ENTITY ) { return IN_ENTITY; } else if ( associationDocumentStorage == AssociationDocumentStorageType.COLLECTION_PER_ASSOCIATION ) { return COLLECTION_PER_ASSOCIATION; } else { return GLOBAL_COLLECTION; } } }
public static AssociationStorageStrategy getInstance(AssociationKeyMetadata keyMetadata, AssociationStorageType associationStorage, AssociationDocumentStorageType associationDocumentStorage) { if ( keyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE || keyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION || associationStorage == AssociationStorageType.IN_ENTITY ) { return IN_ENTITY; } else if ( associationDocumentStorage == AssociationDocumentStorageType.COLLECTION_PER_ASSOCIATION ) { return COLLECTION_PER_ASSOCIATION; } else { return GLOBAL_COLLECTION; } } }
/** * @param associationMetadata * @return index column name for indexed embedded collections or null for collections without index */ private String findIndexColumnName(AssociationKeyMetadata associationMetadata) { String indexColumnName = null; if ( associationMetadata.getAssociationType() == AssociationType.SET || associationMetadata.getAssociationType() == AssociationType.BAG ) { // String cols[] = associationMetadata.getColumnsWithoutKeyColumns( // Arrays.asList( associationMetadata.getRowKeyColumnNames() ) // ); } else { if ( associationMetadata.getRowKeyIndexColumnNames().length > 1 ) { throw new UnsupportedOperationException( "Multiple index columns not implemented yet" ); } indexColumnName = associationMetadata.getRowKeyIndexColumnNames()[0]; } return indexColumnName; }
/** * Transform {@code toManyValue} into association rows * @param toManyValue an object, {@link Collection} or a {@link Map}, can be {@literal null} * @param associationKey the association key * @return collection of association rows. Empty list if {@code toManyValue} is null */ public static Collection<?> getRows( Object toManyValue, AssociationKey associationKey) { Collection<?> rows = null; if ( associationKey.getMetadata().getAssociationType() == AssociationType.ONE_TO_ONE ) { Object oneToOneValue = toManyValue; if ( oneToOneValue != null ) { rows = Collections.singletonList( oneToOneValue ); } } // list of rows if ( toManyValue instanceof Collection ) { rows = (Collection<?>) toManyValue; } // a map-typed association, rows are organized by row key else if ( toManyValue instanceof Map ) { rows = getRowsFromMapAssociation( associationKey, (Map) toManyValue ); } return rows != null ? rows : Collections.emptyList(); }
@Override public boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext) { AssociationStorageType associationStorage = associationTypeContext .getOptionsContext() .getUnique( AssociationStorageOption.class ); return associationKeyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE || associationKeyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION || associationStorage == AssociationStorageType.IN_ENTITY; }
@Override @SuppressWarnings("unchecked") public Object getRows() { Object rows; Object fieldValue = DotPatternMapHelpers.getValueOrNull( getEntity().getPropertiesAsHierarchy(), associationKeyMetadata.getCollectionRole() ); if ( fieldValue == null ) { rows = Collections.emptyList(); } else if ( associationKeyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE ) { rows = fieldValue; } else { rows = fieldValue; } return rows; }
@Override public void setRows(Object rows) { EntityDocument entity = getEntity(); if ( isEmpty( rows ) ) { entity.unset( associationKeyMetadata.getCollectionRole() ); } else { entity.unset( associationKeyMetadata.getCollectionRole() ); if ( associationKeyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE && rows instanceof Collection ) { Object value = ( (Collection<?>) rows ).iterator().next(); entity.set( associationKeyMetadata.getCollectionRole(), value ); } else { entity.set( associationKeyMetadata.getCollectionRole(), rows ); } } }
private static Collection<?> getRows(Document document, AssociationKey associationKey, AssociationStorageStrategy storageStrategy) { Collection<?> rows = null; if ( associationKey.getMetadata().getAssociationType() == AssociationType.ONE_TO_ONE ) { Object oneToOneValue = getValueOrNull( document, associationKey.getMetadata().getCollectionRole(), Object.class ); if ( oneToOneValue != null ) { rows = Collections.singletonList( oneToOneValue ); } } else { Object toManyValue; if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) { toManyValue = getValueOrNull( document, associationKey.getMetadata().getCollectionRole() ); } else { toManyValue = document.get( MongoDBDialect.ROWS_FIELDNAME ); } // list of rows if ( toManyValue instanceof Collection ) { rows = (Collection<?>) toManyValue; } // a map-typed association, rows are organized by row key else if ( toManyValue instanceof Document ) { rows = getRowsFromMapAssociation( associationKey, (Document) toManyValue ); } } return rows != null ? rows : Collections.emptyList(); }
private static Collection<?> getRows(Document document, AssociationKey associationKey, AssociationStorageStrategy storageStrategy) { Collection<?> rows = null; if ( associationKey.getMetadata().getAssociationType() == AssociationType.ONE_TO_ONE ) { Object oneToOneValue = getValueOrNull( document, associationKey.getMetadata().getCollectionRole(), Object.class ); if ( oneToOneValue != null ) { rows = Collections.singletonList( oneToOneValue ); } } else { Object toManyValue; if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) { toManyValue = getValueOrNull( document, associationKey.getMetadata().getCollectionRole() ); } else { toManyValue = document.get( MongoDBDialect.ROWS_FIELDNAME ); } // list of rows if ( toManyValue instanceof Collection ) { rows = (Collection<?>) toManyValue; } // a map-typed association, rows are organized by row key else if ( toManyValue instanceof Document ) { rows = getRowsFromMapAssociation( associationKey, (Document) toManyValue ); } } return rows != null ? rows : Collections.emptyList(); }
Object toStore = associationKey.getMetadata().getAssociationType() == AssociationType.ONE_TO_ONE ? ( (List<?>) rows ).get( 0 ) : rows;
Object toStore = associationKey.getMetadata().getAssociationType() == AssociationType.ONE_TO_ONE ? ( (List<?>) rows ).get( 0 ) : rows;