Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 20 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
20
Dung lượng
0,95 MB
Nội dung
CHAPTER 4 INTRODUCTION TO QUADRANT
101
In this case, I’ll click the As Original option, and a check mark will appear next to the value in the
Original column, indicating this is the selected value for resolving the conflict (see Figure 4-29).
Figure 4-29. After selecting As Original to resolve the conflict
The exclamation point (!) next to the Shock Absorbers entity has now changed to an asterisk (*), and
if you close the Changes view, you will see the same indication in the CarComponents Explorer. The data
conflict has been resolved, but the change has not yet been committed. You can take this last step of
committing this change by using Ctrl+S or the File
Save Changes menu option, which will make the
data consistent again.
Finally, there can be situations where the local copy of the data can become stale because
something has changed in the database, but the local copy of the data hasn’t refreshed since the
database change. Suppose the suspension engineering team has decided to go with two shock absorbers
per wheel rather than one, and they have just changed the Description value for Shock Absorbers to Two
for Each Wheel and the corresponding Quantity value from 4 to 8 in the database. This would mean the
local copy of the data displayed by Quadrant is stale and no longer matches what is in the database.
Figure 4-30 shows the resulting Quadrant view.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
102
Figure 4-30. Stale data in Quadrant after a recent change in the database
This situation is resolved by simply refreshing the data from the data store using the F5 refresh key.
Figure 4-31 shows the result.
Figure 4-31. After using F5 to refresh stale data
Using the Quadrant Explorer Query Bar
The area immediately above the column titles and below the menu bar in the Explorer window is called
the Query Bar. The default entry normally displayed in the Query Bar is the name of the extent, or table,
that is displayed in the Explorer window; in the case of this example, it is Car.Model.CarComponents.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
103
You can enter any SQL query in this bar to filter what is being displayed in the Explorer pane. For
instance, if you wanted to see the top-level subsystem in the model, you could enter the following query
in the Query Bar:
Car.Model.CarComponents where value.PartOfComponent.Name == "My Car"
The query is executed by pressing the Enter key with the cursor in the Query Bar. Figure 4-32 shows
the result of this query, which is exactly what you would expect: The query returns all of the top-level
subsystems. SQL keywords such as where and value are automatically bolded as the query is entered.
Figure 4-32. Using the Query Bar to find the top-level subsystems
Another example of a query you could perform would be to find all subsystems that have a quantity
greater than 1. Figure 4-33 shows the results of such a query. To make the display more useful, you can
click the Quantity column label to sort by ascending or descending quantities, as indicated by an up or
down arrow to the right of the column label.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
104
Figure 4-33. Using the Query Bar to find the components with a quantity greater than 1
As a last example, you can add .Count to any query to return the number of records found by the
query. This is useful with very large tables with hundreds or thousands of records. Figures 4-34 and 4-35
show two examples.
Figure 4-34. Getting a count of records for a query
Figure 4-35. Getting a count of all items in the extent
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
105
To return to the normal table display after executing a query, click on the title bar of the Query pane
to make sure the pane is active, press the Esc key to restore the default query, and then press the Enter
key.
If you are not using the Query Bar in an Explorer workpad, you can remove it by right-clicking the
title bar of the workpad, and clicking the Query Bar option in the context menu.
More on Customizing the View
“Know Your Audience” is an important credo in designing user interfaces, and it is just as important
when designing a simple table view as it is for developing an entire application interface. A database
administrator or a power user (one who is experienced in SQL and generating ad hoc queries) is usually
going to want to see the data in a different format than a manager or an end user who is not conversant
in SQL.
You can customize Explorer workpad views in a number of ways to give the user a more productive
and convenient viewing experience. Here are a number of ways you could improve the table view of the
car model for a user who is primarily interested in the domain data rather than running queries or other
more technical aspects:
• Remove the Id column, since this is typically not meaningful information to the
user.
• Move the PartOfComponent column to the right of the Name column, since this is
probably the most significant data after the Name.
• Change the PartOfComponent label to Part Of, since this is a little more user
friendly.
• Move the Level column to the right of the Description column.
• Remove the Query Bar, since this is a feature only power users would need.
Based on these requirements, the sequence of visible columns would be as follows:
• Name
• Part Of
• Description
• Level
• Quantity
To remove the Id column, right-click on any column heading, select the Column Settings option,
and uncheck the Id column by clicking that menu item (see Figure 4-36). (You could also make this
column visible by modifying the generated source for the view, as you will see shortly.)
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
106
Figure 4-36. Hiding the Id column
Making the other changes you’ve decided on will require some simple modifications to the
generated M source code for the view. To do this, bring up the source by invoking the context-sensitive
menu: Right-click in the title bar of the Explorer window, and click the View Source option, as shown in
Figure 4-37.
Figure 4-37. Setting up to view the source code for the table view
Figure 4-38 shows the portion of the source code you’re interested in—the part where the positions
and other properties of the data columns are defined. Note that you are in a Quadrant session now (as
shown in the lower-right corner of the window), rather than the CarModel session, because you are
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
107
changing the source code for several Quadrant modules. Once the modified source for the workpad view
is deployed, you will be back in the CarModel session.
Figure 4-38. Viewing the source code for the Table view
Looking at this code, you can see there is a collection named TableColumns. Each item in this
collection corresponds to the properties of a column in the table and has the following four attributes:
DisplayName, IsVisible, Position, and PropertyName. It’s a simple matter to modify these four attributes
to provide the view you’re after. The IsVisible property of the Id column is set to false because of the
earlier Column Settings change, as you would expect.
To get the table as you would like it to appear, you will need to change the column positions for each
of the column properties, as well as the DisplayName property for two of the columns: PartOfComponent
and Quantity. The code fragment in Listing 4-1 reflects the code changes:
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
108
Listing 4-1. Modified Column Properties to Customize the Table View
M
TableColumns =>
{
{
DisplayName => "Id",
IsVisible => false,
Position => 0,
PropertyName => "Id",
},
{
DisplayName => "Name",
IsVisible => true,
Position => 1,
PropertyName => "Name",
},
{
DisplayName => "Level",
IsVisible => true,
Position => 5,
PropertyName => "Level",
},
{
DisplayName => "Description",
IsVisible => true,
Position => 3,
PropertyName => "Description",
},
{
DisplayName => "Quantity",
IsVisible => true,
Position => 4,
PropertyName => "No.",
},
{
DisplayName => "CarComponents_PartOfComponent",
IsVisible => false,
Position => 5,
PropertyName => "CarComponents_PartOfComponent",
},
{
DisplayName => "PartOfComponent",
IsVisible => true,
Position => 2,
PropertyName => "PartOf",
},
}
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
109
To change the name of the view, locate the portion of the code in the Microsoft.Quadrant module
where the table is defined, and change the DisplayName property from "Table" to "System Designer
Table", as Figure 4-39 illustrates. If you are doing this exercise on your own computer, note that the Name
property of the table (shown in the figure as "Table_0", may be different in the generated code on your
computer. These are system-assigned names, so don’t be concerned if you see these kinds of differences
between your system and what is shown here in the text.
Figure 4-39. Changing the Table view name
To deploy your customized code for the CarModel view, right click in the source code window and
select the Deploy option, as shown in Figure 4-40. An alternative way of doing this is to press Ctrl+F5.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
110
Figure 4-40. Deploying the source for the modified view
This will bring up a Deploy dialog box (see Figure 4-41) to allow you to select which database
session to use for deployment. Accept the default Use Existing Database Session and click the Deploy
button.
Figure 4-41. Select the existing database session to deploy.
Download from Wow! eBook <www.wowebook.com>
[...]... covered in this chapter: • Writing and saving model code in an M file • Creating types and extents (tables) of types • Deploying your model to the database • Viewing and editing the model in SQL Server using SQLServer Management Studio • Adding new entities and records using Quadrant Explorer views • Using Quadrant Explorer views to view and edit the model • Customizing an Explorer view • Managing... learning another language? M is an integrated part of Microsoft SQLServer Modeling, and is the language “glue” of this framework If you’re going to undertake data modeling using this environment, then developing a knowledge of M is essential The primary tools of the framework—Quadrant and Intellipad—are “Maware.” M and, more broadly, the SQL Server Modeling framework, provide an environment for creating... talk briefly about modules, the fundamental namespaces of the M language Then I’ll cover each of the four basic constructs in M: types, extents (which define storage locations—ultimately, these map to SQL Server tables), computed values, and languages (used for building DSLs) Finally, I’ll return to modules in the context of import and export directives The latter have to do with making certain aspects... entities that can occur and the constraints over the sets of values that comprise the type • Extents: These specify storage locations, usually for instances of types They typically map to tables in SQL Server • Computed values: These specify parameterized queries and can be thought of as functions with zero or more parameters • Languages: These define the tokens and syntax rules for domain-specific... module can contain any or all of the type declarations, extent declarations and initializations, computed values (aka functions), or language declarations I’ve already touched on types, extents (storage or SQL tables), and languages (i.e., domain-specific languages) in the previous chapters I haven’t yet talked about computed values, but will do so in this chapter The simplest possible module declaration... declaration (Remember, the double-forward slash designates a comment line in the code, and is ignored by the compiler.) This module declaration would be accepted by the M compiler, but it would result in no SQL being generated by the compiler because there is absolutely nothing to compile within the scope of the module In M, the module is a top-level namespace containing some M code Modules cannot be nested... Server Modeling framework, provide an environment for creating and deploying domain-specific languages, or DSLs M is a more congenial language for developing, maintaining, and deploying data models than TSQL By “congenial,” I mean that M is more user-friendly and less error prone You’ll have an opportunity to compare the expressiveness and brevity of M for the purpose of building and maintaining model-driven... requires that if a derived type (Car in this context) includes another derived type as a value (such as Engine), the included type must have a unique identity • If the type is used to define an extent (→ SQL table), the type should provide a unique identity that can map to the primary key of the table The AutoNumber() function provides a way of establishing a unique identity for any type instance With . Deploying your model to the database
• Viewing and editing the model in SQL Server using SQL Server Management
Studio
• Adding new entities and records using. time in learning another
language?
M is an integrated part of Microsoft SQL Server Modeling, and is the language “glue” of this
framework. If you’re