프로젝트

일반

사용자정보

개정판 ddc223b4

IDddc223b491b78b3fba4eedde3b00cb9fee3f4d37
상위 3fb3351b
하위 d85fc490

GeunHo Song 이(가) 약 2년 전에 추가함

issue #000 DocPage Function 테스트 완료.

Change-Id: I1f9128df416de25cb26f0d333d54763badf398ae

차이점 보기:

ConvertService/ServiceBase/Markus.Service.DataBase.Dapper/Repositories/BaseRepository.cs
12 12
{
13 13
    public class BaseRepository : IDisposable
14 14
    {
15
        private readonly IDbConnection Connection;
15
        public readonly IDbConnection Connection;
16 16
        public readonly DbConnectionStringBuilder dbConnectionString;
17 17
        public readonly DBMSType DBMS;
18 18

  
......
130 130
            {
131 131
                Connection.Open();
132 132
            }
133
            
133 134

  
134 135
            return await Connection.ExecuteAsync(SQL, parameters, transaction, commandType: commandType);
135 136
        }
137

  
138

  
139
        public async Task<int> ExecuteAsync1(string SQL, SqlMapper.IDynamicParameters parameters, IDbTransaction transaction, CommandType commandType)
140
        {
141
            if (Connection.State != System.Data.ConnectionState.Open)
142
            {
143
                Connection.Open();
144
            }
145

  
146

  
147
            return await Connection.ExecuteAsync(SQL, parameters, transaction, commandType: commandType);
148
        }
149

  
136 150
    }
137 151
}
ConvertService/ServiceBase/Markus.Service.DataBase.Dapper/Repositories/DOCPAGERepository.cs
9 9
using Markus.Service.DataBase.RepositoriesInterfaces;
10 10
using Markus.Service.DataBase.Repositories;
11 11
using DapperParameters;
12
using NpgsqlTypes;
13
using Npgsql;
14
using Npgsql.NameTranslation;
15
using System.Xml.Linq;
16
using System.Data.Common;
12 17
/*
13 18
---------------- IMPORTANT ----------------
14 19
- You need to add the System.Data.SqlClient package. You can download it from https://www.nuget.org/packages/System.Data.SqlClient
......
16 21
*/
17 22
namespace Markus.Service.DataBase.Repositories
18 23
{
19
    public class DOCPAGERepository : BaseRepository, IDOCPAGERepository
24
	public class DOCPAGERepository : BaseRepository, IDOCPAGERepository
20 25
	{
21 26
		public DOCPAGERepository(string connectionString, DBMSType DBMS) : base(connectionString, DBMS)
22 27
		{
28
			
23 29
		}
24 30

  
25 31
		public async Task<bool> CreateAsync(IEnumerable<DOCPAGE> docPages)
......
28 34

  
29 35
			try
30 36
			{
31
				var tran = BeginTransaction();
32
				var parameter = new DynamicParameters();
37
				if (this.DBMS == DBMSType.MSSQL)
38
				{
39
					var tran = BeginTransaction();
33 40

  
34
				var items = docPages.Select(x => new InsertDocPage { DOCINFO_ID = x.DOCINFO_ID,PAGE_NUMBER = x.PAGE_NUMBER, PAGE_ANGLE = x.PAGE_ANGLE, PAGE_HEIGHT = x.PAGE_HEIGHT, PAGE_WIDTH = x.PAGE_WIDTH }).ToList();
41
					var parameter = new DynamicParameters();
35 42

  
43
					var items = docPages.Select(x => new InsertDocPage { docinfo_id = x.DOCINFO_ID, page_number = x.PAGE_NUMBER, page_angle = x.PAGE_ANGLE, page_height = x.PAGE_HEIGHT, page_width = x.PAGE_WIDTH }).ToList();
36 44

  
37
				parameter.AddTable("DOCPAGES", "TYPE_INSERT_DOCPAGE", items);
45
					parameter.AddTable("DOCPAGES", "TYPE_INSERT_DOCPAGE", items);
38 46

  
39
				var id = await base.ExecuteAsync("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure);
47
					var id = await base.ExecuteAsync("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure);
40 48

  
41
				tran.Commit();
49
					tran.Commit();
42 50

  
43
				result = true;
51
					result = true;
52
				}
53
				else if (this.DBMS == DBMSType.POSTGRESQL)
54
				{
55
                    if (NpgsqlConnection.GlobalTypeMapper.Mappings.Where(f => f.PgTypeName == "type_insert_docpage").Count() == 0)
56
                        NpgsqlConnection.GlobalTypeMapper.MapComposite<InsertDocPage>("type_insert_docpage");
57

  
58
                    InsertDocPage[] items = docPages.Select(x => new InsertDocPage {docinfo_id = x.DOCINFO_ID, 
59
                                                                                    page_number = x.PAGE_NUMBER, 
60
                                                                                    page_angle = x.PAGE_ANGLE,
61
                                                                                    page_height = x.PAGE_HEIGHT, 
62
                                                                                    page_width = x.PAGE_WIDTH }).ToArray();
63

  
64
                    var tran = BeginTransaction();
65
                    NpgsqlCommand command = new NpgsqlCommand("convert_insert_docpage", (NpgsqlConnection)this.Connection);
66
                    command.CommandType = CommandType.StoredProcedure;
67
                    var cmdParam = command.CreateParameter();
68
                    cmdParam.ParameterName = "docpages";
69
                    cmdParam.DbType = DbType.Object;
70
                    cmdParam.Value = items;
71
                    cmdParam.DataTypeName = "type_insert_docpage[]";
72
                    command.Parameters.Add(cmdParam);
73
                    await command.ExecuteNonQueryAsync();
74
                    tran.Commit();
75
                    result = true;
76
                }
77
				else
78
				{
79

  
80
				}
44 81
			}
45 82
			catch (Exception ex)
46
            {
83
			{
47 84
				throw new Exception("DOCPAGERepository CreateAsync error.", ex);
48
            }
85
			}
49 86

  
50 87
			return result;
51 88
		}
52 89

  
53
		private class InsertDocPage
90
        // call stored procedure at data access layer for example StudentDAL.cs
91
        public void CallStoredResultSet<T>(InsertDocPage[] inputParameters) where T : class
92
        {
93
            //var conn = _GetOpenConnection();
94
            //var tran = _BeginTransaction(conn);
95
            
96
            var tran = BeginTransaction();
97
            NpgsqlCommand command = new NpgsqlCommand("convert_insert_docpage_arr", (NpgsqlConnection)this.Connection );
98
            command.CommandType = CommandType.StoredProcedure;
99
            var cmdParam = command.CreateParameter();
100
            cmdParam.ParameterName = "docpages";
101
            cmdParam.DbType = DbType.Object;
102
            cmdParam.Value = inputParameters;
103
            cmdParam.DataTypeName = "type_insert_docpage[]";
104

  
105
            command.Parameters.Add(cmdParam);
106

  
107
            // throw exception here
108
            // Can't write CLR type Web.API.Models.UdtSpParameter[] with handler type MappedCompositeHandler`1
109
            command.ExecuteNonQueryAsync();
110
			tran.Commit();
111
            //this.Connection.Close();
112

  
113
            
114
        }
115

  
116
        public class InsertDocPage
54 117
		{
55
			public string DOCINFO_ID { get; set; }
56
			public int PAGE_NUMBER { get; set; }
57
			public string PAGE_WIDTH { get; set; }
58
			public string PAGE_HEIGHT { get; set; }
59
			public int PAGE_ANGLE { get; set; }
60
		}
61
    }
62
}
118
            [PgName("docinfo_id")]
119
            public string docinfo_id { get; set; }
120
            [PgName("page_number")]
121
            public int page_number { get; set; }
122
            [PgName("page_width")]
123
            public string page_width { get; set; }
124
            [PgName("page_height")]
125
            public string page_height { get; set; }
126
            [PgName("page_angle")]
127
            public int page_angle { get; set; }
128
            public InsertDocPage() { }
129
        }
63 130

  
131
	}
132
}
ConvertService/ServiceBase/Markus.Service.DataBase.Test/DataBaseDocPage.cs
6 6
{
7 7
    public class DataBaseDocPage : TestBaseMSSQL
8 8
    {
9
        //[Test, Description("")]
9
        [Test, Description("DocPageInsert")]
10 10
        public void DocPageInsert()
11 11
        {
12
            using (Markus.Service.DataBase.Repositories.DOCPAGERepository repository = new Repositories.DOCPAGERepository(ConnectionStr, dbtype))
12
            string newConvertDocID = string.Empty;
13
            string newDocInfo = string.Empty;
14
            using (Markus.Service.DataBase.Repositories.ConvertDocRepository repository = new Repositories.ConvertDocRepository(ConnectionStr, dbtype))
13 15
            {
14
                List<Entities.DOCPAGE> pages = new List<Entities.DOCPAGE>();
16
                newConvertDocID = repository.CreateAsync(ProjectNo, docUri, "111111").GetAwaiter().GetResult();
17
                Console.WriteLine($"new id : {newConvertDocID}");
18
            }
15 19

  
16
                for (int i = 0; i < 150000; i++)
20
            if (!string.IsNullOrEmpty(newConvertDocID))
21
            {
22
                using (Markus.Service.DataBase.Repositories.DOCINFORepository repository = new Repositories.DOCINFORepository(ConnectionStr, dbtype))
17 23
                {
18
                    pages.Add(new Entities.DOCPAGE { DOCINFO_ID = "a764548c-9f44-4c4d-4597-f7ac43d2b7c1", PAGE_NUMBER = i+1, PAGE_WIDTH = "1210", PAGE_HEIGHT = "1210", PAGE_ANGLE = 0 });
24
                    newDocInfo = repository.CreateAsync(newConvertDocID, 10).GetAwaiter().GetResult();
25

  
26
                    Console.WriteLine($"new id : {newDocInfo}");
19 27
                }
20 28

  
21
                var result = repository.CreateAsync(pages).GetAwaiter().GetResult();
22 29

  
23
                Console.WriteLine($"new id : {result}");
30
                if (!string.IsNullOrEmpty(newDocInfo))
31
                {
32
                    using (Markus.Service.DataBase.Repositories.DOCPAGERepository repository = new Repositories.DOCPAGERepository(ConnectionStr, dbtype))
33
                    {
34
                        List<Entities.DOCPAGE> pages = new List<Entities.DOCPAGE>();
35

  
36
                        for (int i = 0; i < 1000; i++)
37
                        {
38
                            pages.Add(new Entities.DOCPAGE { DOCINFO_ID = newDocInfo, PAGE_NUMBER = i + 1, PAGE_WIDTH = "1210", PAGE_HEIGHT = "1210", PAGE_ANGLE = 0 });
39
                        }
40

  
41
                        var result = repository.CreateAsync(pages).GetAwaiter().GetResult();
42

  
43
                        Console.WriteLine($"new id : {result}");
44
                    }
45
                }
24 46
            }
47

  
25 48
        }
26 49
    }
27 50
}
ConvertService/ServiceBase/Markus.Service.DataBase.Test/DataBaseDocPagePG.cs
1 1
using NUnit.Framework;
2 2
using System;
3 3
using System.Collections.Generic;
4
using System.Diagnostics;
4 5

  
5 6
namespace Markus.Service.DataBase.Test
6 7
{
7 8
    public class DataBaseDocPagePG : TestBasePG
8 9
    {
9
        //[Test, Description("")]
10
        [Test, Description("DocPageInsert")]
10 11
        public void DocPageInsert()
11 12
        {
12
            using (Markus.Service.DataBase.Repositories.DOCPAGERepository repository = new Repositories.DOCPAGERepository(ConnectionStr, dbtype))
13
            string newConvertDocID = string.Empty;
14
            string newDocInfo = string.Empty;
15
            using (Markus.Service.DataBase.Repositories.ConvertDocRepository repository = new Repositories.ConvertDocRepository(ConnectionStr, dbtype))
13 16
            {
14
                List<Entities.DOCPAGE> pages = new List<Entities.DOCPAGE>();
17
                newConvertDocID = repository.CreateAsync(ProjectNo, docUri, "111111").GetAwaiter().GetResult();
18
                Console.WriteLine($"new id : {newConvertDocID}");
19
            }
15 20

  
16
                for (int i = 0; i < 150000; i++)
21
            if (!string.IsNullOrEmpty(newConvertDocID))
22
            {
23
                using (Markus.Service.DataBase.Repositories.DOCINFORepository repository = new Repositories.DOCINFORepository(ConnectionStr, dbtype))
17 24
                {
18
                    pages.Add(new Entities.DOCPAGE { DOCINFO_ID = "a764548c-9f44-4c4d-4597-f7ac43d2b7c1", PAGE_NUMBER = i+1, PAGE_WIDTH = "1210", PAGE_HEIGHT = "1210", PAGE_ANGLE = 0 });
25
                    newDocInfo = repository.CreateAsync(newConvertDocID, 10).GetAwaiter().GetResult();
26

  
27
                    Console.WriteLine($"new id : {newDocInfo}");
19 28
                }
20 29

  
21
                var result = repository.CreateAsync(pages).GetAwaiter().GetResult();
22 30

  
23
                Console.WriteLine($"new id : {result}");
31
                if (!string.IsNullOrEmpty(newDocInfo))
32
                {
33
                    using (Markus.Service.DataBase.Repositories.DOCPAGERepository repository = new Repositories.DOCPAGERepository(ConnectionStr, dbtype))
34
                    {
35
                        List<Entities.DOCPAGE> pages = new List<Entities.DOCPAGE>();
36

  
37
                        for (int i = 0; i < 20000; i++)
38
                        {
39
                            pages.Add(new Entities.DOCPAGE { DOCINFO_ID = newDocInfo, PAGE_NUMBER = i + 1, PAGE_WIDTH = "1210", PAGE_HEIGHT = "1210", PAGE_ANGLE = 0 });
40
                        }
41

  
42
                        Stopwatch sw = new Stopwatch();
43

  
44
                        sw.Start();
45

  
46
                        var result = repository.CreateAsync(pages).GetAwaiter().GetResult();
47

  
48
                        
49
                        sw.Stop();
50

  
51
                        Console.WriteLine($"End Milliseconds id : {sw.ElapsedMilliseconds}");
52

  
53
                    }
54
                }
24 55
            }
56

  
25 57
        }
26 58
    }
27 59
}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)