Trends in Database Development: XML, .NET, WinFS

download Trends in Database Development: XML, .NET, WinFS

of 106

  • date post

    05-Jan-2016
  • Category

    Documents

  • view

    23
  • download

    0

Embed Size (px)

description

Trends in Database Development: XML, .NET, WinFS. Alexander Vaschillo Microsoft. SQL Server Stores Everything. Overall direction: Storing stuff whatever this stuff is Different data models Relational Hierarchical (XML) Object (Graphs) Files. Latest in SQL Server. XML - PowerPoint PPT Presentation

Transcript of Trends in Database Development: XML, .NET, WinFS

  • Trends in Database Development: XML, .NET, WinFSAlexander VaschilloMicrosoft

  • SQL Server Stores EverythingOverall direction: Storing stuff whatever this stuff isDifferent data modelsRelationalHierarchical (XML)Object (Graphs)Files

  • Latest in SQL ServerXMLMapping to relational (SQLXML)Native (XML Datatype)ObjectsMapping to relational (ObjectSpaces)Native (CLR UDT).NET integrationServerClientUsing all of the aboveWinFS

  • The Two WorldsSQLServerRowSetSQLRelational worldLanguageData storageData output

  • XSD Mapping Example

  • Three WorldsSQLServerRowSetSQLRelational worldXML worldXMLFilesXPathXQueryXML/HTMLMapMemoryObjectC#,C++,VBObject worldMap

  • New MappingCustomerNameProductPartNumCustomerNameProductPartNumPurchaseRData Model GraphData Model GraphMapping

  • Native XML StoreXML Data TypeXML data typeNative SQL typeUse for column, variable or parameter CREATE TABLE docs (id INT PRIMARY KEY, xDoc XML NOT NULL)Store un-typed or typed XML instancesWell-formed and validation checksOptional XML Schema enforcementXML instances stored as LOB (2GB)Efficient binary representation

  • Native XML StoreXML IndexCreate XML index on XML columnCREATE XML INDEX idx_1 ON docs (xDoc)Creates indexes on tags, values & pathsSpeeds up queriesEntire query is optimizedSame industry leading cost based optimizerIndexes are used as available

  • XML QueryXQuery: query XML documents and dataStandards-based: W3CIn document 123, return section heading of section 3 and laterSELECT id, xDoc::query('for $s in /doc[@id = 123]//sec[@num >= 3] return {data($s/heading)}') FROM docs

  • XML View: Unification ModelSQL Server Yukon XML data typeUse XQueryRelational columnsUse SQLXML View hides representationUse XQuery against any dataXML ViewCustomer Table

    CustomerIDContactNameStreetCityXML data type

  • .NET IntegrationServer side: SQLCLR.NET hosted inside the databaseWrite stored procedures in C#Use ADO programming model on the server the same way as on the client sideCreate UDTsClient sideWeb ServicesDatasetObjectspaces

  • SQLCLRComponent reuseMainstream development experienceFamiliar choice of programming languages and constructsLeverage existing libraries and componentsSeamless debugging and deploymentDeep integration with the engine

  • SQLCLR DevelopmentVS .NET ProjectRuntime hosted inside SQL

  • Web Services OverviewNatural client side programming modelTurn your existing Stored Procedures into web ServicesMessaging done according to SOAP 1.1 standardChoose how to model resultsXMLObjectsDatasetCan run on database server or mid-tierIntegrated with Visual Studio

  • Easy Programming ModelSQLXML generates WSDL automaticallyVisual Studio.NET recognizes a DatasetRetrieve results of a Stored Procedure and load into a Dataset in 1 line of code!

    Dim Service As New MyHost.MyWebService()Dim retval As IntegerDataSet ds = Service.GetCustomer(Name)

  • Web Services Decoupled ArchitectureSQL ServerSQLXMLApplicationMethod callSQL queryRowsetXmlReaderClientMid-TierServer

  • Universal StorageSQL server Abstracts data model from the userAbstracts data access programming model from the userAbstracts its existence from the userCan it replace file system?

  • User FilesUnstructured dataNot really unstructured proprietary structureData broken into filesOne level of granularity (HTML, Powerpoint)Easy manipulation?Proprietary formatsNeed particular application to interpret filesNo Sharing (Import/Export)No relationshipsDuplication of DataCompatibility of data (Emails, Contacts,)

  • WinFSDatabaseReliability, Concurrency, Speed, query optimizationUnderstanding schemasUniform SearchNew APIsSQLObjectsOld APIsWill be supportedOld files still workWant to enable richer integration provide translations mechanisms

  • WinFS SchemasUnification on some levelBase schemas shipped with WindowsPlay by the rules all applications will be enabled with your dataUse extensions for your proprietary dataConvenient programming modelShell supports librariesNavigation (relationships)Integration (Email body is a document)

  • The Windows SchemasAudio Videos Images Games. . . Principals LocationsCalendar EventsCoreMessage (Email)WinFSTypesMeta BaseFile SyncShellSubscriptions. . .System Tasks Explorer Config NaturalUI Programs Services SecurityHelp Device. . .SystemUser DataDocumentsAnnotationsMedia NotesPerson TasksInfrastructure

  • WinFs Data ModelCommon data modelSimple but richCommon programming model for all applicationsUnified store - unified accessSubsume relational conceptsRich object abstraction for dataSemantic relationshipsAlign with CLR

  • Common Data ModelMap to CLR - frameworkMap to SQL add some abstractionsExpress data in XMLCombine SQL 99, CLR, XSD, UMLNested tablesRelationshipsScalar typesProvide mapping to other data models

  • SQL 99 Data ModelToo implementation specific not a good application level abstractionTables, not types are first classIdentityOperational semantics (copy, etc.)Integrate SQL with Programming language rather than map from objects to DBNo high-level relationship supportCan use low-level concepts (foreign keys)

  • CLR Data ModelFramework on topConstrainEnhance with additional functionalityNot designed for persistenceReferences are not durableForeign keys can be persistedNo setoriented query capabilitiesNo high-level relationship conceptsCan use collections to implement someNo support for BLOBs

  • XML/XSD Data ModelUse XML syntax, but not semanticsNo Relationships in XSD Data ModelToo many concepts not useful for us and hard to map to CLR and SQLDifferent set of scalar typesComplex mechanisms for type extensionNot compatible with CLR

  • WinFS Data ModelItems (Entities)Scalar typesInline TypesInheritanceExtensionsRelationships

  • ItemsHave identitySmallest referenceable unitHave Properties and Behaviors (methods)Can exist independently, can be copied, etc.Person, Message, Document, Audio,...

  • Scalar TypesUsed for properties on an Item (Relatonship)Carefully chosen subset of SQL and CLR typesString, Boolean, Binary, Byte, Int16, Int32, Int64, Single, Double, Decimal, DateTime, Guid, XML, Stream.Enumeration

    Arrays and Sets

  • Inline typeA structure without identityNot referenceableHas to be contained in an Entity (or Relationship)Example: Address

    ...

  • InheritanceSingle inheritance (Items, Inline types)Substitutability

  • Inheritance Hierarchy

    Item

    Document

    Contact

    Message

    Person

    Organization

    Email

    Fax

    Voice

  • ExtensionsNon-invasively adds more structures to an existing ItemMultiple extensions can be added independentlyMust be attached to an Item and live with it

  • RelationshipsDocument-Author, Message-Participant, Album-RecordAssociation and CompositionRelate two ItemsMay have propertiesSupport cardinalities (1:1, m:1, 1:m, m:m)May control lifetimeBased on common values or identity

  • Relationship Example ...

    ...

  • Relationship Example

    DocumentRole.Author = ContactRole.Name

  • Data Model MappingA WinFS schema is mapped to a SQL schema Types are mapped to CRL classes in the storage (UDT), and CLR API classesClasses are automatically created based on type definitionViews are generated for each typeRelationships: UDT vs. metadataSchema becomes a namespace in the API

  • WinFS APINatural programming modelLanguage integrationCollections vs. SQL QueriesDatabase operations are hidden from a developer

  • Querying WinFS

    StorageContext sc = new StorageContext();

    StorageSearcher searcher =sc.Items.FilterByType().Filter(Exists(Names[LastName=Smith]);

    PersonItem p1 = searcher.GetFirst();orforeach (PersonItem p in searcher){ ...}

  • Query CompositionStorageSearcher messages =sc.Items.FilterByType().Filter("Subject LIKE '%Academic Days%'");

    StorageSearcher myMessages= messages.Project("Subject, Size ").Sort(Size desc);

    foreach( StorageRecord m in myMessages){ string s = m[Subject]; int size = m[Size];}

  • Item CreationItem root = sc.GetRootItem();

    PersonItem person = new PersonItem();person.DateOfBirth = 11/01/1960";

    FullName fullName = new FullName();fullName.FirstName = John;fullName.LastName = Smith;person.Names.Add(fullName);

    root.Children.Add(person);sc.SaveChanges();

  • Relationship NavigationStorageSearcher organizations =sc.Items.WithType().Filter("Keywords[Value=Financial']");

    StorageSearcher employees = EmploymentRelation.GetEmployees(organizations);

    StorageSearcher documents = DocumentAuthorRelation.GetDocuments(employees);

    foreach( DocumentItem document in documents){ ...}

  • NotificationsPersonItem person = sc.Items.FilterByType().Filter(Exists(Names[LastName=Smith]).GetFirst();

    StoreWatcherOptions Opts=new StoreWatcherOptions();Opts.NotifyModified = true;

    StoreWatcher w = person.GetWatcher( Opts );w.StoreObjectChanged += new StoreEventHandler( MyHandler );

    void MyHandler( Object sender, StoreEventArgs e ){}

  • Creating API for a SchemaCreate WinFS schema in XML formatSchema compiler generates API assemblyYou can add your own helper membersThe assemblies are installed into a WinFS store WinFS types are registered as UDTsViews and other database objects are createdWinFSSchemaCLR ComplierCode for Helper MembersWinFSSchemaCompilerCode for Standard APIAPIClassesCLR ComplierSchemaAssembliesC# code for UDTs

  • WinFS Message Schema (Example)Body PreferenceMessageSubject-Time sent-Type