Big Data Working with Terabytes in SQL Server Andrew Novick .
Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2,...
-
Upload
astrid-fitzgerald -
Category
Documents
-
view
217 -
download
1
Transcript of Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2,...
Generating the .Net Business and Data Layers
Andrew Novick
Visual Basic Pro User Group
October 2, 2003
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 2
Agenda
The n-Tier Model DeKlarit Paradigm
Building the Model Generating the Code Using The Code
Demo of DeKlarit
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 3
Novick Software
Consulting Company of Andrew Novick Project Management Business Applications Design Programming Coaching Training
Technologies: SQL Server, VB, VB.Net, ASP, ASP.Net, and XML
http://www.NovickSoftware.com
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 4
The n-Tier Model
Web Server Code (ASP, ASP.Net)
Windows Client (WinForms)Browser
Business Objects
Data Services Layer
Data Storage Layer (SQL Server)
UI
Business
Data
Client
AppServer
Database
LogicalLayer
PhysicalLayer
*
*One possible configuration
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 5
DeKlarit
Modeling and code generation tool for the business and data layer of an n-Tier application.
Current Version 2.2 Price: $899 Languages: C# & VB.Net Databases: SQL Server & Oracle Business Frameworks Add-ins Create Windows and Web Forms
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 6
Alternatives
Commercial Products Freeware Shareware Write Your Own
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 7
Commercial Products
DeKlarit ($899) Lockwood Tech’s ProcBlaster ($399) IronSpeed Designer ($495…$3,500) VBeXpress.Net ($450) RapTeir (Free…$299) AlachiSoft TierDeveloper ($495-$995) LLBLGenPro (Free…$195) ORM.Net ($495)
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 8
Free/OpenSource
LLBGEN (there is a paid pro version) Olymeyrs OJB.Net (Pre-Alpha Port of a Java tool)
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 9
Write Your Own
Writing Code To Write Your Data Services Layer Presented to VB Pro, December 2001 Based on VBPJ Article:
Automate Writing Stored Procedures June 2001
Available at http://www.NovickSoftware.com/Presentations
Implementing CRUD Operations Using Stored Procedures: Part 1on www.DatabaseJournal.com 10/7/03
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 10
DeKlarit Paradigm
ModelingCode
GenerationApplication
Coding
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 11
Concepts
Business Framework Business Components
Attributes Domains Rules Formulas Code Generation
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 12
The Business Framework
An information model of a business that represents it’s behavior and structure.
A Model Consisting of A database schema DataAdapters to encapsulate business logic DataSets that will be used by UI layer
programmers.
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 13
Business Component
Similar to an Object, Entity, or Structure May have repeating groups
(de-normalized)
Contains multiple attributes
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 14
Attributes
Main elements of the Business Component Structure
Primary Element identifies the Business Component
Secondary Elements have data for the Business Component
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 15
Primary Elements- Primary keys
Identify the Business Component instance
Must be unique
May not change
Must have a value from when the instance is created
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 16
Universal Relation Assumption (URA)
One thing (attribute) has the same name everywhere.
When an attribute appears in two Business Components they are assumed to be related.
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 17
URA – This won’t work
• Name used in both tables.
• Self-reference in UnitsDefinition (UnitsCD, DerivedFromUnitCD).
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 18
URA - Subtypes
URA doesn’t always work Multiple relationships to the same component Self-references
Subtypes allow you to circumvent this restriction.
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 19
Domains
Abstract data types that allow attributes to have consistent data types.
UI makes them hard to find.
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 20
Data Types Supported
Characters Char(length). Fixed length character string. VarChar(length). Variable length character string. Length is the
maximum length. Text.
Numeric(length [, decimals]) DateTime Date Blob Boolean GUID
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 21
Subtypes – Multiple Relationships The Problem
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 22
Subtypes – Multiple Relationships The Solution
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 23
Hierarchical Business Component
* Source DeKlarit 2.2 Help
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 24
DataProviders
Extract data from the Business Framework Read-only Attributes come from existing Business
Components
Essentially a Query or View
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 25
DataProvider – Example
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 26
DataProvider Features
Parameters Conditions Ordering Distinct
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 27
Business Rules
Rules are declarative. Written in DeKlarit’s own syntax:
<Action> [IF <Condition>];
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 28
Available Rules
Error Assign Default Static Method Call Add and Subtract Serial
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 29
Error Rule
error( ExceptionName [, <StringExpr>] )
if <Condition> ;
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 30
Error Rule Example
error( NoCashException, "Not enough available cash to buy the stock") if AccountAvailableCash < 0 and TradeBuySell = -1;
UI Would have this code: try accountDataAdapter1.Update(accountDataSet1) catch (NoCashException e) Label1.Text = e.Message
end try
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 31
Assign Rule
<Attribute> = <Expression>
[ if<Condition> ];
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 32
Assign Rule Example
TradeCommission = 9.99 if insert and TradeAmount < 10000;
TradeCommission = 7.99 if and TradeAmount < 100000;
TradeCommission = 5.99 if insert and TradeAmount >= 100000;
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 33
Issues with Assign Rules
They overlap with formulas and could be replaced by formulas.
Not recalculated as formulas are
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 34
Default Rule
Default( <Attribute>, <Expression>);
Default(TradeCommission, 9.99);
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 35
Default = Assignment
Attribute> = <Expression>
if insert and <Attribute>.IsNull();
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 36
Static Method Call Rule
<StaticMethodCall> if <Condition> ;
MyNamespace.MyClass.MyStaticMethod(…) if insert;
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 37
Add and Subtract Rule
add( <Attribute1>, <Attribute2> ); subtract( <Attribute1>, <Attribute2> );
Equivalent to assignment statements
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 38
Serial Rule
Numbers an attribute
serial( <AttributeToBeNumbered>, <AttributeWhichHasTheLastValue>, <Increment> );
serial(InvoiceLineNumber, InvoiceLastLineNumber, 1);
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 39
Formulas
Equation for calculating an attribute
Types Horizontal Vertical
Built-in Methods
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 40
Horizontal Formulas
Formula = f( Att1, …, Attn);
The function may reference attributes in the table and static methods, including CLR methods such as System.Datetime.Now()
Usuall arithmentic operators Conditionals
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 41
Horizontal Formula Example
TradeCurrentValue = TradeQty * StockLastPrice * TradeBuySell * -1;
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 42
Conditionals in Horizontal Formulas
TradeNetAmount = TradeAmount – TradeCommission
if TradeBuySell = 1; (TradeAmount + TradeCommission) * -1
Otherwise;
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 43
Vertical Formulas
Aggregates a value from another level
<VerticalFormula> ::= <VerticalFunction> [Where <Condition>];
AccountStockValue = SUM(TradeCurrentValue);
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 44
Vertical Functions
SUM( <SummedAttribute>) COUNT( <CountedAttribute>) MAX( <AttributeToMaximize>
[, <ReturnedAttribute> ]) MIN( <AttributeToMinimize>
[,<ReturnedAttribute> ]) FIND( <AttributeToFind> )
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 45
Max and Min
StockHighestTradedPriceAccount = MAX(TradePrice);
Optional parameter for retrieving an attributed associated with the Min or Max
StockHighestTradedPriceAccountID = MAX(TradePrice, AccountId);
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 46
DeKlarit Project
Business Components Data Providers Tables Domains
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 47
Database Changes
DeKlarit does more than other object generators:
In includes a database conversion tool
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 48
Code Generation
When built, generates a Business Framework project
DataSet for each componentDataAdapter for each component
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 49
The FreeDB Schema
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 50
Add-In: WinForms Application
Press a button and Deklarit generates a simple data entry application for the Windows environment.
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 51
Add-In: Web Forms Application
Press a button and DeKlarit generates a simple data entry application for ASP.Net
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 52
Using the Business Framework in ASP.Net
The framework can be used in any .Net environment including ASP.Net
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 53
Software Supported
Databases SQL Server Oracle
Visual Studio 2002 2003
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 54
Issues with DeKlarit
Nonstandard modeling approach Business Rules Universal Relation Assumption
Not really n-Tier Produces a combined Business/Data Tier
No really Object Oriented Produces a data centric application
Limited support (e-mail or newsgroup)
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 55
Minor Issues with DeKlarit
C# orientation (examples, help, etc) Mangled names in generated code Rough edges running Reverse engineering
Wizard and a few other UI features. Poor English in the help and in the error
messages.
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 56
Great things about DeKlarit
Limited knowledge required to start Help is integrated with Visual Studio Code generated for you. Database change scripts written and executed
for you!
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 57
Technical Support
E-Mail (Responded within 30 minutes)
Newsgroups and limited documents on their web site.
No phone support.
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 58
DeKlarit
Be the first!
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 59
Apress Curlingstone an Imprint of Wrox Download code from the book at
www.Curlingstone.com
Andrew Novick [email protected] 978-440-8126 www.NovickSoftware.com
Consulting - Project Management – Design - Programming - Training
SQL Server 2000 XML Distilled
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 60
T-SQL UDF of the Week
Free newsletter about SQL Server User-Defined Functions
A CREATE FUNCTION script in every issue Additional information on UDFs
Find it athttp://www.NovickSoftware.com/UDFofWeek/UDFofWeek.htm
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 61
T-SQL User-Defined Functions
The Book
Coming November 2003
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 62
Novick Software
Consulting Company of Andrew Novick Project Management Business Applications Design Programming Coaching Training
Technologies: SQL Server, VB, VB.Net, ASP, ASP.Net, and XML
http://www.NovickSoftware.com Home of the T-SQL User-Defined Function of the Week
© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 63
Thanks for coming!
VB Pro Users Group