public CollectionService( ICollectionInitializer initializer, ICollectionResolver <TContext> resolver, IDatabaseCollectionProvider <TContext> provider) { _initializer = initializer ?? throw new ArgumentNullException(nameof(initializer)); _resolver = resolver ?? throw new ArgumentNullException(nameof(resolver)); _provider = provider ?? throw new ArgumentNullException(nameof(provider)); }
public TransactionService( ICollectionInitializer initializer, ICollectionResolver <TContext> resolver, IDatabaseTransactionManager <TContext> transactionManager) { _initializer = initializer ?? throw new ArgumentNullException(nameof(initializer)); _resolver = resolver ?? throw new ArgumentNullException(nameof(resolver)); _transactionManager = transactionManager ?? throw new ArgumentNullException(nameof(transactionManager)); }
private static void ReadElements(IReadContext context, ICollectionInitializer initializer, ITypeHandler4 elementHandler) { int elementCount = context.ReadInt(); for (int i = 0; i < elementCount; i++) { initializer.Add(context.ReadObject(elementHandler)); } }
public virtual void Write(IWriteContext context, object obj) { ICollectionInitializer initializer = CollectionInitializer.For(obj); IEnumerable enumerable = (IEnumerable)obj; ClassMetadata elementType = DetectElementTypeErasingNullables(Container(context), enumerable); WriteElementTypeHandlerId(context, elementType); WriteElementCount(context, initializer); WriteElements(context, enumerable, elementType.TypeHandler()); }
private static ICollectionInitializer GetInitializer(object destination, Type initializerType, Type collElementType) { ICollectionInitializer initializer = null; if (collElementType != null) { Type genericProtocolType = initializerType.MakeGenericType(collElementType); initializer = InstantiateInitializer(destination, genericProtocolType); } return(initializer); }
public virtual void Activate(IReferenceActivationContext context) { object collection = context.PersistentObject(); ICollectionInitializer initializer = CollectionInitializer.For(collection); initializer.Clear(); ReadElements(context, initializer, ReadElementTypeHandler(context, context)); initializer.FinishAdding(); }
public object NewItem(object element) { object item = NewItem(); ICollectionInitializer initializer = CollectionInitializer.For(CollectionFor(item)); initializer.Add(element); initializer.FinishAdding(); return(item); }
private static void Fill(ICollection collection, IEnumerable <T> elements) { ICollectionInitializer initializer = CollectionInitializer.For(collection); foreach (T item in elements) { initializer.Add(item); } initializer.FinishAdding(); }
public static void CopyCollectionState(object original, object destination, ICounterpartFinder counterpartFinder) { IEnumerable originalCollection = (IEnumerable )original; ICollectionInitializer destinationCollection = CollectionInitializer.For(destination); destinationCollection.Clear(); foreach (object element in originalCollection) { object counterpart = counterpartFinder.FindCounterpart(element); destinationCollection.Add(counterpart); } }
public void Test() { object list = new LinkedList <int>(); ICollectionInitializer initializer = CollectionInitializer.For(list); Assert.IsNotNull(initializer); foreach (object item in Values) { initializer.Add(item); } initializer.FinishAdding(); Iterator4Assert.AreEqual(Values, ((IEnumerable)list).GetEnumerator()); }
public AbstractCollectionPersister(Mapping.Collection collection, ISessionFactoryImplementor factory) { this.factory = factory; dialect = factory.Dialect; //sqlExceptionConverter = factory.SQLExceptionConverter; collectionType = collection.CollectionType; role = collection.Role; ownerClass = collection.OwnerClass; Alias alias = new Alias("__"); sqlOrderByString = collection.OrderBy; hasOrder = sqlOrderByString != null; sqlOrderByStringTemplate = hasOrder ? Template.RenderOrderByStringTemplate(sqlOrderByString, dialect) : null; sqlWhereString = collection.Where; hasWhere = sqlWhereString != null; sqlWhereStringTemplate = hasWhere ? Template.RenderWhereStringTemplate(sqlWhereString, dialect) : null; hasOrphanDelete = collection.OrphanDelete; batchSize = collection.BatchSize; cache = collection.Cache; keyType = collection.Key.Type; int keySpan = collection.Key.ColumnSpan; keyColumnNames = new string[keySpan]; string[] keyAliases = new string[keySpan]; int k = 0; foreach (Column col in collection.Key.ColumnCollection) { keyColumnNames[k] = col.GetQuotedName(dialect); keyAliases[k] = col.Alias(dialect); k++; } keyColumnAliases = alias.ToAliasStrings(keyAliases, dialect); //unquotedKeyColumnNames = StringHelper.Unquote( keyColumnAliases ); ISet distinctColumns = new HashedSet(); CheckColumnDuplication(distinctColumns, collection.Key.ColumnCollection); //isSet = collection.IsSet; //isSorted = collection.IsSorted; primitiveArray = collection.IsPrimitiveArray; array = collection.IsArray; IValue element = collection.Element; int elementSpan = element.ColumnSpan; ICollection iter = element.ColumnCollection; Table table = collection.CollectionTable; enableJoinedFetch = element.OuterJoinFetchSetting; elementType = element.Type; if (!collection.IsOneToMany) { CheckColumnDuplication(distinctColumns, element.ColumnCollection); } if (elementType.IsEntityType) { elementPersister = factory.GetPersister((( EntityType )elementType).AssociatedClass); } else { elementPersister = null; } qualifiedTableName = table.GetQualifiedName(dialect, factory.DefaultSchema); string[] aliases = new string[elementSpan]; elementColumnNames = new string[elementSpan]; int j = 0; foreach (Column col in iter) { elementColumnNames[j] = col.GetQuotedName(dialect); aliases[j] = col.Alias(dialect); j++; } elementColumnAliases = alias.ToAliasStrings(aliases, dialect); IType selectColumns; string[] selectType; hasIndex = collection.IsIndexed; if (hasIndex) { IndexedCollection indexedCollection = ( IndexedCollection )collection; indexType = indexedCollection.Index.Type; int indexSpan = indexedCollection.Index.ColumnSpan; indexColumnNames = new string[indexSpan]; string[] indexAliases = new string[indexSpan]; int i = 0; foreach (Column indexCol in indexedCollection.Index.ColumnCollection) { indexAliases[i] = indexCol.Alias(dialect); indexColumnNames[i] = indexCol.GetQuotedName(dialect); i++; } selectType = indexColumnNames; selectColumns = indexType; indexColumnAliases = alias.ToAliasStrings(indexAliases, dialect); CheckColumnDuplication(distinctColumns, indexedCollection.Index.ColumnCollection); } else { indexType = null; indexColumnNames = null; indexColumnAliases = null; selectType = elementColumnNames; selectColumns = elementType; } hasIdentifier = collection.IsIdentified; if (hasIdentifier) { if (collection.IsOneToMany) { throw new MappingException("one-to-many collections with identifiers are not supported."); } IdentifierCollection idColl = ( IdentifierCollection )collection; identifierType = idColl.Identifier.Type; Column col = null; foreach (Column column in idColl.Identifier.ColumnCollection) { col = column; break; } identifierColumnName = col.GetQuotedName(dialect); selectType = new string[] { identifierColumnName }; selectColumns = identifierType; identifierColumnAlias = alias.ToAliasString(col.Alias(dialect), dialect); unquotedIdentifierColumnName = identifierColumnAlias; identifierGenerator = idColl.Identifier.CreateIdentifierGenerator(dialect); CheckColumnDuplication(distinctColumns, idColl.Identifier.ColumnCollection); } else { identifierType = null; identifierColumnName = null; identifierColumnAlias = null; unquotedIdentifierColumnName = null; identifierGenerator = null; } rowSelectColumnNames = selectType; rowSelectType = selectColumns; sqlDeleteString = GenerateDeleteString(); sqlInsertRowString = GenerateInsertRowString(); sqlUpdateRowString = GenerateUpdateRowString(); sqlDeleteRowString = GenerateDeleteRowString(); isLazy = collection.IsLazy; isInverse = collection.IsInverse; if (collection.IsArray) { elementClass = (( Array )collection).ElementClass; } else { // for non-arrays, we don't need to know the element class elementClass = null; } initializer = CreateCollectionInitializer(factory); if (elementType.IsComponentType) { elementPropertyMapping = new CompositeElementPropertyMapping(elementColumnNames, ( IAbstractComponentType )elementType, factory); } else if (!elementType.IsEntityType) { elementPropertyMapping = new ElementPropertyMapping(elementColumnNames, elementType); } else { IClassPersister persister = factory.GetPersister((( EntityType )elementType).AssociatedClass); // Not all classpersisters implement IPropertyMapping! if (persister is IPropertyMapping) { elementPropertyMapping = ( IPropertyMapping )persister; } else { elementPropertyMapping = new ElementPropertyMapping(elementColumnNames, elementType); } } }
private static void WriteElementCount(IWriteBuffer context, ICollectionInitializer initializer) { context.WriteInt(initializer.Count()); }
public void PostInstantiate() { initializer = queryLoaderName == null ? CreateCollectionInitializer(new CollectionHelper.EmptyMapClass<string, IFilter>()) : new NamedQueryCollectionInitializer(queryLoaderName, this); }
public AbstractCollectionPersister( Mapping.Collection collection, ISessionFactoryImplementor factory ) { this.factory = factory; dialect = factory.Dialect; //sqlExceptionConverter = factory.SQLExceptionConverter; collectionType = collection.CollectionType; role = collection.Role; ownerClass = collection.OwnerClass; Alias alias = new Alias( "__" ); sqlOrderByString = collection.OrderBy; hasOrder = sqlOrderByString != null; sqlOrderByStringTemplate = hasOrder ? Template.RenderOrderByStringTemplate( sqlOrderByString, dialect ) : null; sqlWhereString = collection.Where; hasWhere = sqlWhereString != null; sqlWhereStringTemplate = hasWhere ? Template.RenderWhereStringTemplate( sqlWhereString, dialect ) : null; hasOrphanDelete = collection.OrphanDelete; batchSize = collection.BatchSize; cache = collection.Cache; keyType = collection.Key.Type; int keySpan = collection.Key.ColumnSpan; keyColumnNames = new string[keySpan]; string[ ] keyAliases = new string[keySpan]; int k = 0; foreach( Column col in collection.Key.ColumnCollection ) { keyColumnNames[ k ] = col.GetQuotedName( dialect ); keyAliases[ k ] = col.Alias( dialect ); k++; } keyColumnAliases = alias.ToAliasStrings( keyAliases, dialect ); //unquotedKeyColumnNames = StringHelper.Unquote( keyColumnAliases ); ISet distinctColumns = new HashedSet(); CheckColumnDuplication( distinctColumns, collection.Key.ColumnCollection ); //isSet = collection.IsSet; //isSorted = collection.IsSorted; primitiveArray = collection.IsPrimitiveArray; array = collection.IsArray; IValue element = collection.Element; int elementSpan = element.ColumnSpan; ICollection iter = element.ColumnCollection; Table table = collection.CollectionTable; enableJoinedFetch = element.OuterJoinFetchSetting; elementType = element.Type; if( !collection.IsOneToMany ) { CheckColumnDuplication( distinctColumns, element.ColumnCollection ); } if( elementType.IsEntityType ) { elementPersister = factory.GetPersister( ( ( EntityType ) elementType ).AssociatedClass ); } else { elementPersister = null; } qualifiedTableName = table.GetQualifiedName( dialect, factory.DefaultSchema ); string[ ] aliases = new string[elementSpan]; elementColumnNames = new string[elementSpan]; int j = 0; foreach( Column col in iter ) { elementColumnNames[ j ] = col.GetQuotedName( dialect ); aliases[ j ] = col.Alias( dialect ); j++; } elementColumnAliases = alias.ToAliasStrings( aliases, dialect ); IType selectColumns; string[ ] selectType; hasIndex = collection.IsIndexed; if( hasIndex ) { IndexedCollection indexedCollection = ( IndexedCollection ) collection; indexType = indexedCollection.Index.Type; int indexSpan = indexedCollection.Index.ColumnSpan; indexColumnNames = new string[indexSpan]; string[ ] indexAliases = new string[indexSpan]; int i = 0; foreach( Column indexCol in indexedCollection.Index.ColumnCollection ) { indexAliases[ i ] = indexCol.Alias( dialect ); indexColumnNames[ i ] = indexCol.GetQuotedName( dialect ); i++; } selectType = indexColumnNames; selectColumns = indexType; indexColumnAliases = alias.ToAliasStrings( indexAliases, dialect ); CheckColumnDuplication( distinctColumns, indexedCollection.Index.ColumnCollection ); } else { indexType = null; indexColumnNames = null; indexColumnAliases = null; selectType = elementColumnNames; selectColumns = elementType; } hasIdentifier = collection.IsIdentified; if( hasIdentifier ) { if( collection.IsOneToMany ) { throw new MappingException( "one-to-many collections with identifiers are not supported." ); } IdentifierCollection idColl = ( IdentifierCollection ) collection; identifierType = idColl.Identifier.Type; Column col = null; foreach( Column column in idColl.Identifier.ColumnCollection ) { col = column; break; } identifierColumnName = col.GetQuotedName( dialect ); selectType = new string[ ] {identifierColumnName}; selectColumns = identifierType; identifierColumnAlias = alias.ToAliasString( col.Alias( dialect ), dialect ); unquotedIdentifierColumnName = identifierColumnAlias; identifierGenerator = idColl.Identifier.CreateIdentifierGenerator( dialect ); CheckColumnDuplication( distinctColumns, idColl.Identifier.ColumnCollection ); } else { identifierType = null; identifierColumnName = null; identifierColumnAlias = null; unquotedIdentifierColumnName = null; identifierGenerator = null; } rowSelectColumnNames = selectType; rowSelectType = selectColumns; sqlDeleteString = GenerateDeleteString(); sqlInsertRowString = GenerateInsertRowString(); sqlUpdateRowString = GenerateUpdateRowString(); sqlDeleteRowString = GenerateDeleteRowString(); isLazy = collection.IsLazy; isInverse = collection.IsInverse; if( collection.IsArray ) { elementClass = ( ( Array ) collection ).ElementClass; } else { // for non-arrays, we don't need to know the element class elementClass = null; } initializer = CreateCollectionInitializer( factory ); if( elementType.IsComponentType ) { elementPropertyMapping = new CompositeElementPropertyMapping( elementColumnNames, ( IAbstractComponentType ) elementType, factory ); } else if( !elementType.IsEntityType ) { elementPropertyMapping = new ElementPropertyMapping( elementColumnNames, elementType ); } else { IClassPersister persister = factory.GetPersister( ( ( EntityType ) elementType ).AssociatedClass ); // Not all classpersisters implement IPropertyMapping! if( persister is IPropertyMapping ) { elementPropertyMapping = ( IPropertyMapping ) persister; } else { elementPropertyMapping = new ElementPropertyMapping( elementColumnNames, elementType ); } } }
public void PostInstantiate() { initializer = queryLoaderName == null ? CreateCollectionInitializer(CollectionHelper.EmptyMap) : new NamedQueryCollectionInitializer(queryLoaderName, this); }