-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.vb
79 lines (69 loc) · 2.43 KB
/
Program.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Imports DevExpress.Data.Filtering
Imports DevExpress.Xpo
Imports DevExpress.Xpo.Helpers
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Namespace DevExpress.Sample
Friend Class Program
Shared Sub Main(ByVal args() As String)
TestPass()
TestFail()
Console.ReadLine()
End Sub
Private Shared Sub TestPass()
Dim dal As IDataLayer = CreateDataLayer()
Dim helper = New SampleXpoImportHelper(dal, 100)
helper.Import(Enumerable.Range(1, 10000))
Report(dal)
End Sub
Private Shared Sub TestFail()
Dim dal As IDataLayer = CreateDataLayer()
Dim helper = New SampleXpoImportHelper(dal, 100)
Try
helper.Import(Enumerable.Range(1, 10000).Select(Function(x)If(x < 1234, x, x - 1))) 'a duplicated entry
Catch ex As Exception
Console.WriteLine(ex.GetType().Name)
End Try
Report(dal)
End Sub
Private Shared Function CreateDataLayer() As IDataLayer
Dim dict = New DevExpress.Xpo.Metadata.ReflectionDictionary()
Dim classes = dict.CollectClassInfos(GetType(SampleObject).Assembly)
Dim provider = XpoDefault.GetConnectionProvider(DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("localhost", "XpoImportHelperTest"), Xpo.DB.AutoCreateOption.DatabaseAndSchema)
Dim dal = New SimpleDataLayer(dict, provider)
DirectCast(dal, IDataLayerForTests).ClearDatabase()
dal.UpdateSchema(False, classes)
Return dal
End Function
Private Shared Sub Report(ByVal dal As IDataLayer)
Using uow = New UnitOfWork(dal)
Dim count = uow.Evaluate(GetType(SampleObject), CriteriaOperator.Parse("Count()"), Nothing)
Console.WriteLine("Imported {0} objects", count)
End Using
End Sub
End Class
Public Class SampleObject
Inherits XPObject
Public Sub New(ByVal s As Session)
MyBase.New(s)
End Sub
Public Property Name() As String
<Indexed(Unique := True)>
Public Property Rank() As Integer
End Class
Public Class SampleXpoImportHelper
Inherits XpoImportHelper
Public Sub New(ByVal dataLayer As IDataLayer, ByVal batchSize As Integer)
MyBase.New(dataLayer, batchSize)
End Sub
Protected Overrides Function CreatePersistentObject(ByVal session As Session, ByVal sourceObject As Object) As Object
Dim obj = New SampleObject(session)
obj.Name = String.Format("sample{0:d5}", DirectCast(sourceObject, Integer))
obj.Rank = DirectCast(sourceObject, Integer)
Return obj
End Function
End Class
End Namespace