/// <summary>
        /// Perform parameter validation.  Used prior to executing the encapsulated query.
        /// </summary>
        /// <param name="reserveFirstParameter">
        /// if true, the first ? will not be verified since
        /// its needed for e.g. callable statements returning a out parameter
        /// </param>
        protected internal virtual void VerifyParameters(bool reserveFirstParameter)
        {
            if (parameterMetadata.NamedParameterNames.Count != namedParameters.Count + namedParameterLists.Count)
            {
                var missingParams = new HashedSet <string>(parameterMetadata.NamedParameterNames);
                missingParams.RemoveAll(namedParameterLists.Keys);
                missingParams.RemoveAll(namedParameters.Keys);
                throw new QueryException("Not all named parameters have been set: " + CollectionPrinter.ToString(missingParams), QueryString);
            }

            int positionalValueSpan = 0;

            for (int i = 0; i < values.Count; i++)
            {
                object obj = types[i];
                if (values[i] == UNSET_PARAMETER || obj == UNSET_TYPE)
                {
                    if (reserveFirstParameter && i == 0)
                    {
                        continue;
                    }
                    else
                    {
                        throw new QueryException("Unset positional parameter at position: " + i, QueryString);
                    }
                }
                positionalValueSpan += ((IType)obj).GetColumnSpan(session.Factory);
            }

            if (parameterMetadata.OrdinalParameterCount != positionalValueSpan)
            {
                if (reserveFirstParameter && parameterMetadata.OrdinalParameterCount - 1 != positionalValueSpan)
                {
                    throw new QueryException(
                              "Expected positional parameter count: " + (parameterMetadata.OrdinalParameterCount - 1) + ", actual parameters: "
                              + CollectionPrinter.ToString(values), QueryString);
                }
                else if (!reserveFirstParameter)
                {
                    throw new QueryException(
                              "Expected positional parameter count: " + parameterMetadata.OrdinalParameterCount + ", actual parameters: "
                              + CollectionPrinter.ToString(values), QueryString);
                }
            }
        }
Example #2
0
        public IList <PersistentCollectionChangeData> MapCollectionChanges(String referencingPropertyName,
                                                                           IPersistentCollection newColl,
                                                                           object oldColl, object id)
        {
            if (!commonCollectionMapperData.CollectionReferencingPropertyData.Name
                .Equals(referencingPropertyName))
            {
                return(null);
            }

            IList <PersistentCollectionChangeData> collectionChanges = new List <PersistentCollectionChangeData>();

            // Comparing new and old collection content.
            ICollection <object> newCollection = GetNewCollectionContent(newColl);
            ICollection <object> oldCollection = GetOldCollectionContent(oldColl);

            ISet <Object> added = new HashedSet <Object>();

            if (newColl != null)
            {
                added.AddAll(newCollection);
            }
            // Re-hashing the old collection as the hash codes of the elements there may have changed, and the
            // removeAll in AbstractSet has an implementation that is hashcode-change sensitive (as opposed to addAll).
            if (oldColl != null)
            {
                added.RemoveAll(new HashedSet <object>(oldCollection));
            }

            addCollectionChanges(collectionChanges, added, RevisionType.ADD, id);

            Set <Object> deleted = new HashedSet <Object>();

            if (oldColl != null)
            {
                deleted.AddAll(oldCollection);
            }
            // The same as above - re-hashing new collection.
            if (newColl != null)
            {
                deleted.RemoveAll(new HashedSet <object>(newCollection));
            }

            addCollectionChanges(collectionChanges, deleted, RevisionType.DEL, id);

            return(collectionChanges);
        }
Example #3
0
        internal String ShowDiff(ILOG.J2CsMapping.Collections.ISet a, ILOG.J2CsMapping.Collections.ISet b)
        {
            ILOG.J2CsMapping.Collections.ISet temp = new HashedSet();
            ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(a, temp);
            temp.RemoveAll(b);
            if (temp.Count == 0)
            {
                return("");
            }
            StringBuilder buffer = new StringBuilder();
            IIterator     it     = new ILOG.J2CsMapping.Collections.IteratorAdapter(temp.GetEnumerator());

            while (it.HasNext())
            {
                if (buffer.Length != 0)
                {
                    buffer.Append(", ");
                }
                buffer.Append(it.Next().ToString());
            }
            return(buffer.ToString());
        }
        private Assembly CreateTypeLibWrapper(string typeLibFileName)
        {
            if (_remoteObj == null)
            {
                return null;
            }

            typeLibFileName = new FileInfo(typeLibFileName).FullName;

            FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(typeLibFileName);

            byte[] publicKey;

            if (KeyPair == null)
            {
                publicKey = null;
            }
            else
            {
                publicKey = KeyPair.PublicKey;
            }

            bool hasOutputDirectory = !string.IsNullOrEmpty(OutputDirectory);
            string previousCurrentDirectory;

            if (hasOutputDirectory)
            {
                if (!Directory.Exists(OutputDirectory))
                {
                    Directory.CreateDirectory(OutputDirectory);
                }

                previousCurrentDirectory = Environment.CurrentDirectory;
                Environment.CurrentDirectory = OutputDirectory;
            }
            else
            {
                previousCurrentDirectory = null;
            }

            try
            {
                ICollection existingLibraries = new ArrayList(_alreadyImportedLibraries.Keys);
                _runMethod.Invoke(_remoteObj, new object[]
                                                  {
                                                      typeLibFileName,
                                                      null,
                                                      null,
                                                      OutputDirectory,
                                                      publicKey,
                                                      KeyPair,
                                                      null,
                                                      null,
                                                      new Version(versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart, versionInfo.ProductPrivatePart),
                                                      TypeLibImporterFlags.ReflectionOnlyLoading,
                                                      true,
                                                      true,
                                                      false,
                                                      false,
                                                      false,
                                                      false
                                                  });
                ISet newLibraries = new HashedSet(_alreadyImportedLibraries.Keys);
                newLibraries.RemoveAll(existingLibraries);

                foreach (Guid newLibraryID in newLibraries)
                {
                    Assembly libraryAssembly = (Assembly) _alreadyImportedLibraries[newLibraryID];
                    ImportedFileNames[libraryAssembly.FullName] = libraryAssembly.GetName().Name + ".dll";
                }

                string assemblyFileName = (string) _assemblyNameField.GetValue(_optionsField.GetValue(null));
                Assembly assembly = Assembly.LoadFrom(hasOutputDirectory
                                                          ? Path.Combine(OutputDirectory, assemblyFileName)
                                                          : assemblyFileName);
                ImportedFileNames[assembly.FullName] = assemblyFileName;
                return assembly;
            }
            finally
            {
                if (previousCurrentDirectory != null)
                {
                    Environment.CurrentDirectory = previousCurrentDirectory;
                }
            }
        }
        public IList<PersistentCollectionChangeData> MapCollectionChanges(string referencingPropertyName,
																			IPersistentCollection newColl,
																			object oldColl, 
																			object id)
        {
            if (!CommonCollectionMapperData.CollectionReferencingPropertyData.Name.Equals(referencingPropertyName))
            {
                return null;
            }

            var collectionChanges = new List<PersistentCollectionChangeData>();

            // Comparing new and old collection content.
            var newCollection = GetNewCollectionContent(newColl);
            var oldCollection = GetOldCollectionContent(oldColl);

            var added = new HashedSet();
            if (newColl != null)
            {
                foreach (var item in newCollection)
                {
                    added.Add(item);
                }
            }
            // Re-hashing the old collection as the hash codes of the elements there may have changed, and the
            // removeAll in AbstractSet has an implementation that is hashcode-change sensitive (as opposed to addAll).
            if (oldColl != null)
            {
                var itemsToRemove = new HashedSet();
                foreach (var item in oldCollection)
                {
                    itemsToRemove.Add(item);
                }
                added.RemoveAll(itemsToRemove);
            }

            addCollectionChanges(collectionChanges, added, RevisionType.Added, id);

            var deleted = new HashedSet();
            if (oldColl != null)
            {
                foreach (var item in oldCollection)
                {
                    deleted.Add(item);
                }
            }
            // The same as above - re-hashing new collection.
            if (newColl != null)
            {
                var itemsToRemove = new HashedSet();
                foreach (var item in newCollection)
                {
                    itemsToRemove.Add(item);
                }
                deleted.RemoveAll(itemsToRemove);
            }

            addCollectionChanges(collectionChanges, deleted, RevisionType.Deleted, id);

            return collectionChanges;
        }