/// <summary>
 /// Creates a new Update Query object which is ready to use. Only 'changed' EntityFieldCore are included in the update query.
 /// Primary Key fields are never updated.
 /// </summary>
 /// <param name="fields">Array of EntityFieldCore objects to use to build the insert query</param>
 /// <param name="fieldsPersistenceInfo">Array of IFieldPersistenceInfo objects to use to build the update query</param>
 /// <param name="query">The query object to fill.</param>
 /// <param name="updateFilter">A complete IPredicate implementing object which contains the filter for the rows to update</param>
 /// <param name="relationsToWalk">list of EntityRelation objects, which will be used to formulate a FROM clause with INNER JOINs.</param>
 /// <exception cref="System.ArgumentNullException">When fields is null or when updateFilter is null or
 /// when relationsToWalk is null or when fieldsPersistence is null</exception>
 /// <exception cref="System.ArgumentException">When fields contains no EntityFieldCore instances or fieldsPersistenceInfo is empty.</exception>
 protected override void CreateSingleTargetUpdateDQ(IEntityFieldCore[] fields, IFieldPersistenceInfo[] fieldsPersistenceInfo,
                                                    IActionQuery query, IPredicate updateFilter, IRelationCollection relationsToWalk)
 {
     this.CreateSingleTargetUpdateDQUsingFromClause(fields, fieldsPersistenceInfo, query, updateFilter, relationsToWalk);
     // ASA doesn't support named parameters, anonymize them
     MakeParametersAnonymous(query.Command);
 }
 /// <summary>
 /// Creates a new Update Query object which is ready to use. Only 'changed' EntityFieldCore fields are included in the update query.
 /// Primary Key fields are never updated.
 /// </summary>
 /// <param name="fields">EntityFieldCore array to use to build the update query.</param>
 /// <param name="fieldsPersistenceInfo">Array of IFieldPersistenceInfo objects to use to build the update query</param>
 /// <param name="query">The query object to fill.</param>
 /// <param name="updateFilter">A complete IPredicate implementing object which contains the filter for the rows to update</param>
 /// <exception cref="System.ArgumentNullException">When fields is null or fieldsPersistenceInfo is null</exception>
 /// <exception cref="System.ArgumentException">When fields contains no EntityFieldCore instances or fieldsPersistenceInfo is empty.</exception>
 protected override void CreateSingleTargetUpdateDQ(IEntityFieldCore[] fields, IFieldPersistenceInfo[] fieldsPersistenceInfo,
                                                    IActionQuery query, IPredicate updateFilter)
 {
     base.CreateSingleTargetUpdateDQ(fields, fieldsPersistenceInfo, query, updateFilter);
     // ASA doesn't support named parameters, anonymize them
     MakeParametersAnonymous(query.Command);
 }
        /// <summary>
        /// Creates a new Insert Query object which is ready to use.
        /// </summary>
        /// <param name="fields">Array of EntityFieldCore objects to use to build the insert query</param>
        /// <param name="fieldsPersistenceInfo">Array of IFieldPersistenceInfo objects to use to build the insert query</param>
        /// <param name="query">The query object to fill.</param>
        /// <param name="fieldToParameter">Hashtable which will contain after the call for each field the parameter which contains or will contain the field's value.</param>
        /// <remarks>Generic version.</remarks>
        /// <exception cref="System.ArgumentNullException">When fields is null or fieldsPersistenceInfo is null</exception>
        /// <exception cref="System.ArgumentException">When fields contains no EntityFieldCore instances or fieldsPersistenceInfo is empty.</exception>
        /// <exception cref="ORMQueryConstructionException">When there are no fields to insert in the fields list. This exception is to prevent
        /// INSERT INTO table () VALUES () style queries.</exception>
        protected override void CreateSingleTargetInsertDQ(IEntityFieldCore[] fields, IFieldPersistenceInfo[] fieldsPersistenceInfo,
                                                           IActionQuery query, Dictionary <IEntityFieldCore, DbParameter> fieldToParameter)
        {
            TraceHelper.WriteLineIf(Switch.TraceInfo, "CreateSingleTargetInsertDQ", "Method Enter");
            QueryFragments fragments = new QueryFragments();

            fragments.AddFormatted("INSERT INTO {0}", this.Creator.CreateObjectName(fieldsPersistenceInfo[0]));
            DelimitedStringList fieldNames = fragments.AddCommaFragmentList(true);

            fragments.AddFragment("VALUES");
            DelimitedStringList valueFragments = fragments.AddCommaFragmentList(true);

            DbParameter newParameter;
            bool        hasIdentity = false;

            for (int i = 0; i < fields.Length; i++)
            {
                IEntityFieldCore      field           = fields[i];
                IFieldPersistenceInfo persistenceInfo = fieldsPersistenceInfo[i];

                if (string.IsNullOrEmpty(persistenceInfo.IdentityValueSequenceName))
                {
                    if (!CheckIfFieldNeedsInsertAction(field))
                    {
                        continue;
                    }
                    fieldNames.Add(this.Creator.CreateFieldNameSimple(persistenceInfo, field.Name));
                    AppendFieldToValueFragmentsForInsert(query, fieldToParameter, valueFragments, field, persistenceInfo);
                }
                else
                {
                    newParameter = this.Creator.CreateParameter(field, persistenceInfo, ParameterDirection.InputOutput);
                    query.AddParameterFieldRelation(field, newParameter, persistenceInfo.TypeConverterToUse, parameterValueCanBeNull: false);
                    query.AddSequenceRetrievalQuery(CreateCommand("SELECT @@IDENTITY", query.Connection), false).AddSequenceParameter(newParameter);
                    hasIdentity = true;
                    fieldToParameter.Add(field, newParameter);
                }
            }
            if (fieldNames.Count <= 0)
            {
                if (hasIdentity)
                {
                    // a table with just 1 identity field, use a special case query: INSERT INTO table values ()
                    fieldNames.Clear();
                    valueFragments.Clear();
                    fragments.AddFragment("()");
                }
                else
                {
                    throw new ORMQueryConstructionException("The insert query doesn't contain any fields.");
                }
            }
            query.SetCommandText(MakeParametersAnonymous(fragments.ToString(), query.Parameters));

            TraceHelper.WriteIf(Switch.TraceVerbose, query, "Generated Sql query");
            TraceHelper.WriteLineIf(Switch.TraceInfo, "CreateSingleTargetInsertDQ", "Method Exit");
        }
        protected override void OnSaveEntityComplete(IActionQuery saveQuery, IEntity2 entityToSave)
        {
            if (!(entityToSave is AuditInfoEntity) &&
                !(entityToSave is ErrorEntity))
            {
                if (entityToSave.IsNew)
                {
                    AuditInfo(entityToSave, AuditInfoActionTypeEnum.Insert);
                }
                else
                {
                    AuditInfo(entityToSave, AuditInfoActionTypeEnum.Update);
                }
            }

            base.OnSaveEntityComplete(saveQuery, entityToSave);
        }
Esempio n. 5
0
        private static void DumpActionQueryCore(StringBuilder sb, IActionQuery query)
        {
            DumpParameters(sb, query);

            var text = query.Command.CommandText;

            text = ReplaceAllWholeKeywords(text, "\r\n", "", "INSERT INTO", "DELETE");
            text = ReplaceAllWholeKeywords(text, "\r\n", "\r\n ", CommonKeywords);
            text = ReplaceAllKeywords(text, "", "\r\n ", ",");

            sb.Append(text);
            sb.Append("\r\n");
            var part = 1;

            foreach (var sequenceRetrievalQuery in query.SequenceRetrievalQueries)
            {
                sb.Append("\r\n Sequence Retrieval Query #" + part++ + ":\r\n" + sequenceRetrievalQuery.SequenceRetrievalCommand.CommandText);
            }
        }
 protected override void OnDeleteEntityComplete(IActionQuery deleteQuery, IEntity2 entityToDelete)
 {
     AuditInfo(entityToDelete, AuditInfoActionTypeEnum.Delete);
     base.OnDeleteEntityComplete(deleteQuery, entityToDelete);
 }
 /// <summary>
 /// Throws exception 'cos AuditInfo can't be implemented this way.
 /// </summary>
 protected override void OnUpdateEntitiesDirectly(IActionQuery updateQuery)
 {
     throw new NotImplementedException("Audit info se ne može implementirati ovim načinom (ne prosljeđuje se entitet).");
     //base.OnUpdateEntitiesDirectly(updateQuery);
 }
 protected override void OnDeleteEntityComplete(IActionQuery deleteQuery, IEntity2 entityToDelete)
 {
     AuditInfo(entityToDelete, NinjaSoftware.Enio.CoolJ.Enums.AuditInfoActionTypeEnum.Delete);
     base.OnDeleteEntityComplete(deleteQuery, entityToDelete);
 }
        protected override void OnSaveEntityComplete(IActionQuery saveQuery, IEntity2 entityToSave)
        {
            if (!(entityToSave is NinjaSoftware.Enio.CoolJ.EntityClasses.AuditInfoEntity) &&
                !(entityToSave is NinjaSoftware.Enio.CoolJ.EntityClasses.ErrorEntity))
            {
                if (entityToSave.IsNew)
                {
                    AuditInfo(entityToSave, NinjaSoftware.Enio.CoolJ.Enums.AuditInfoActionTypeEnum.Insert);
                }
                else
                {
                    AuditInfo(entityToSave, NinjaSoftware.Enio.CoolJ.Enums.AuditInfoActionTypeEnum.Update);
                }
            }

            base.OnSaveEntityComplete(saveQuery, entityToSave);
        }
 /// <summary>
 /// Throws exception 'cos AuditInfo can't be implemented this way.
 /// </summary>
 protected override void OnUpdateEntitiesDirectly(IActionQuery updateQuery)
 {
     throw new NotImplementedException("Audit info se ne može implementirati ovim načinom (ne prosljeđuje se entitet).");
     //base.OnUpdateEntitiesDirectly(updateQuery);
 }
Esempio n. 11
0
        protected override void OnSaveEntityComplete(IActionQuery saveQuery, IEntity2 entityToSave)
        {
            if (!(entityToSave is AuditInfoEntity) &&
                !(entityToSave is ErrorEntity))
            {
                if (entityToSave.IsNew)
                {
                    AuditInfo(entityToSave, AuditInfoActionTypeEnum.Insert);
                }
                else
                {
                    AuditInfo(entityToSave, AuditInfoActionTypeEnum.Update);
                }
            }

            base.OnSaveEntityComplete(saveQuery, entityToSave);
        }
Esempio n. 12
0
 protected override void OnDeleteEntityComplete(IActionQuery deleteQuery, IEntity2 entityToDelete)
 {
     AuditInfo(entityToDelete, AuditInfoActionTypeEnum.Delete);
     base.OnDeleteEntityComplete(deleteQuery, entityToDelete);
 }
 /// <summary>
 /// Creates a new Delete Query object which is ready to use.
 /// </summary>
 /// <param name="fieldsPersistenceInfo">Array of IFieldPersistenceInfo objects to use to build the delete query</param>
 /// <param name="query">The query object to fill.</param>
 /// <param name="deleteFilter">A complete IPredicate implementing object which contains the filter for the rows to delete</param>
 /// <param name="relationsToWalk">list of EntityRelation objects, which will be used to formulate a second FROM clause with INNER JOINs.</param>
 /// <remarks>Generic version</remarks>
 /// <exception cref="System.ArgumentNullException">When persistenceInfo is null or when deleteFilter is null or when relationsToWalk is null</exception>
 protected override void CreateSingleTargetDeleteDQ(IFieldPersistenceInfo[] fieldsPersistenceInfo, IActionQuery query, IPredicate deleteFilter,
                                                    IRelationCollection relationsToWalk)
 {
     this.CreateSingleTargetDeleteDQUsingKeywordClause(fieldsPersistenceInfo, query, deleteFilter, relationsToWalk, "FROM");
     // ASA doesn't support named parameters, anonymize them
     MakeParametersAnonymous(query.Command);
 }
Esempio n. 14
0
 private static void DumpActionQuery(StringBuilder sb, IActionQuery query)
 {
     DumpActionQueryCore(sb, query);
 }