• R/O
  • SSH
  • HTTPS

ea2ddl: コミット


コミットメタ情報

リビジョン136 (tree)
日時2011-09-21 09:51:06
作者taktos9

ログメッセージ

ColumnModelの実装終了

変更サマリ

差分

--- trunk/ea2ddl.net/ea2ddl.net/Model/ColumnModel.cs (revision 135)
+++ trunk/ea2ddl.net/ea2ddl.net/Model/ColumnModel.cs (revision 136)
@@ -8,6 +8,7 @@
88 */
99 using System;
1010 using System.Collections.Generic;
11+using System.Text.RegularExpressions;
1112 using EA;
1213
1314 namespace ea2ddl.net.Model
@@ -35,11 +36,40 @@
3536 public ColumnModel(EA.Attribute columnDef, Dictionary<string, string> domainDictionary) {
3637 Name = columnDef.Name;
3738 Alias = columnDef.Style;
39+ InitType(columnDef, domainDictionary);
3840 Note = columnDef.Notes;
3941 Nullable = !columnDef.AllowDuplicates;
4042 VendorExt = new Dictionary<string, string>();
4143 }
42-
44+
45+ private void InitType(EA.Attribute columnDef, Dictionary<string, string> domainDictionary) {
46+ string domain = domainDictionary[columnDef.Type];
47+ if (String.IsNullOrEmpty(domain)) {
48+ Type = columnDef.Type;
49+ if (String.IsNullOrEmpty(columnDef.Length)) {
50+ Precision = int.Parse(columnDef.Length);
51+ } else if (String.IsNullOrEmpty(columnDef.Precision)) {
52+ Precision = int.Parse(columnDef.Precision);
53+ if (String.IsNullOrEmpty(columnDef.Scale)) {
54+ Scale = int.Parse(columnDef.Scale);
55+ }
56+ }
57+ } else {
58+ Regex regex = new Regex("^(\\w+)\\s*(\\((\\d+)(,\\s*(\\d+))?\\))?.*", RegexOptions.IgnoreCase);
59+ Match m = regex.Match(domain);
60+ if (m.Success) {
61+ Type = m.Groups[1].Value;
62+ if (m.Groups[3].Success) {
63+ Precision = int.Parse(m.Groups[3].Value);
64+ }
65+ if (m.Groups[5].Success) {
66+ Scale = int.Parse(m.Groups[5].Value);
67+ }
68+ }
69+ }
70+
71+ }
72+
4373 private void InitializeVendorExt(EA.Attribute columnDef) {
4474 foreach (TaggedValue tag in columnDef.TaggedValuesEx) {
4575 VendorExt.Add(tag.Name, tag.Value);
--- trunk/ea2ddl.net/ea2ddl.net/Model/DatabaseModel.cs (revision 135)
+++ trunk/ea2ddl.net/ea2ddl.net/Model/DatabaseModel.cs (revision 136)
@@ -22,7 +22,7 @@
2222 {
2323 Tables = new List<TableModel>();
2424 }
25-
25+
2626 public void AddTable(TableModel table) {
2727 Tables.Add(table);
2828 }
--- trunk/ea2ddl.net/ea2ddl.net.Test/RegexTest.cs (nonexistent)
+++ trunk/ea2ddl.net/ea2ddl.net.Test/RegexTest.cs (revision 136)
@@ -0,0 +1,49 @@
1+/*
2+ * Created by SharpDevelop.
3+ * User: takiguchi
4+ * Date: 2011/09/21
5+ * Time: 9:25
6+ *
7+ * To change this template use Tools | Options | Coding | Edit Standard Headers.
8+ */
9+using System;
10+using System.Text.RegularExpressions;
11+using NUnit.Framework;
12+
13+namespace ea2ddl.net.Test
14+{
15+ [TestFixture]
16+ public class RegexTest
17+ {
18+ [Test]
19+ public void TestSimple()
20+ {
21+ Regex regex = new Regex("^(\\w+)\\s*(\\((\\d+)(,\\s*(\\d+))?\\))?.*", RegexOptions.IgnoreCase);
22+ Match m = regex.Match("INTEGER");
23+ Assert.True(m.Success);
24+ Assert.AreEqual("INTEGER", m.Groups[1].Value);
25+ Assert.False(m.Groups[3].Success);
26+ }
27+
28+ [Test]
29+ public void TestLength()
30+ {
31+ Regex regex = new Regex("^(\\w+)\\s*(\\((\\d+)(,\\s*(\\d+))?\\))?.*", RegexOptions.IgnoreCase);
32+ Match m = regex.Match("VARCHAR(10)");
33+ Assert.True(m.Success);
34+ Assert.AreEqual("VARCHAR", m.Groups[1].Value);
35+ Assert.AreEqual("10", m.Groups[3].Value);
36+ Assert.False(m.Groups[5].Success);
37+ }
38+
39+ [Test]
40+ public void TestScaleRegex() {
41+ Regex regex = new Regex("^(\\w+)\\s*(\\((\\d+)(,\\s*(\\d+))?\\))?.*", RegexOptions.IgnoreCase);
42+ Match m = regex.Match("DECIMAL(20, 4)");
43+ Assert.True(m.Success);
44+ Assert.AreEqual("DECIMAL", m.Groups[1].Value);
45+ Assert.AreEqual("20", m.Groups[3].Value);
46+ Assert.AreEqual("4", m.Groups[5].Value);
47+ }
48+ }
49+}
旧リポジトリブラウザで表示