+ All Categories
Home > Documents > Genexus x Episodio 1 2da Edicion En

Genexus x Episodio 1 2da Edicion En

Date post: 03-Jun-2018
Category:
Upload: jaimicolaza
View: 234 times
Download: 0 times
Share this document with a friend

of 136

Transcript
  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    1/136

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    2/136

    2

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    3/136

    3

    GeneXus X Episode One

    Cecilia Fernndez Daniel Mrquez Lisboa

    Cover design: Fiorella Franzini

    Artistic participation by Mara Ins Carriquiry

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    4/136

    4

    Preface to the 2nd Edition

    Everyone at Artech has worked hard on the X version of GeneXus. This is not

    just another version. It represents a great leap forward in many ways and particularly in its capability for integration and extensions, be them by Artech

    itself or by the GeneXus Community.

    The Community has enthusiastically participated in the testing of CTP

    versions and is currently adopting the first released version of this product. It has

    put it in to work, in many cases including extensions. For the XIX GeneXus

    Meeting we look forward to sharing many significant experiences in this sense.

    In 2007 we asked Daniel Mrquez Lisboa (the author of GeneXus, Desarrollo

    Basado en el Conocimiento Gua Prctica (Practical Guide to Knowledge

    Based GeneXus Development),published by Magr in 2006) and Cecilia

    Fernndez, an expert trainer in our courses, to write an introductory book on the

    GeneXus Rocha Version. Now that the X version has turned into an undeniable

    and significant reality, we once again have turned to Daniel y Cecilia for a second

    edition of the book, with updates of that first story told as the version was under

    development, to reflect the present where the X version is in full operations.

    As I stated back then: "I have to admit that, at first, the books casual style took

    me by surprise. Having read it attentively, I now find that the "casual style" is yet

    another great idea that the authors have had" And two years later I reconfirm

    my statement.

    I expect this second edition to be a success, and invite all to freely access the

    book, by making use of the modern technology available to us all these days, at

    www.genexus.com/genexus/libroepisodio1ed2 . And to the authors, my

    congratulations on their work and my sincere wish for continued success.

    Breogn Gonda

    Artech President

    http://www.genexus.com/genexus/libroepisodio1ed2http://www.genexus.com/genexus/libroepisodio1ed2http://www.genexus.com/genexus/libroepisodio1ed2
  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    5/136

    5

    Dear Readers,

    Prior to the XVII GeneXus International Meeting for users held in September

    2007, we were asked to write an easily readable book on the GeneXus version that

    was undergoing continuous development: the Rocha version today renamed X

    -, which actually turned out to be a true re-founding of the product.

    Since then, the X has been greatly enhanced, with improved and added

    functionalities. Such significant advances call for the n eed to adapt our works

    initial edition GeneXus Rocha Episode One for it to continue aimed at its

    original purpose: to disclose GeneXus to those new in the discipline who may be

    willing to discover this unique tool, and also to others who, having experienced

    previous versions, might want to rediscover it in this new and promising stage. So

    here is an updated second edition of our work. It is based on Upgrade 4 of

    GeneXus X.

    Artech is currently working towards the release, in just a few short months, of

    GeneXus X Evolution 1, which includes novel functionalities of significance that

    allow, for example, the generation of Win applications in addition to Web

    applications.

    We wish you enjoy reading these pages as much as we have enjoyed writing

    them, and hope everyone may have the possibility of adapting their individual

    pace and needs as they go through the story. Certain chapters are a little more

    technical than others, particularly Chapter 3, dealing with Patterns. We finally

    gave in to the temptation of revealing its full power and such enthusiasm drove us

    to increasingly reveal more and more about the topic. Those of you eager to learn

    more will surely read it in depth from beginning to end. Others with an interest not

    as strong will probably go through it in a more superficial way. But both areoptions that each reader should feel free to take. It was based on that possibility

    that we unleashed our eagerness to write the story. The last chapters are probably

    the ones most enjoyable to read.

    To better understand the explanations, we suggest you follow the characters

    steps by working yourselves on the GeneXus trial version available at

    www.genexus.com/trial . Though it is possible to apply the generator and DBMS

    of your choice, we recommend everyone who is new at GeneXus to select thedefault ones, which coincidently are those used in the examples of the story. We

    http://www.genexus.com/trialhttp://www.genexus.com/trialhttp://www.genexus.com/trial
  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    6/136

    6

    invite you to access our Download Center

    (www.gxtechnical.com/genexus/libroepisodio1ed2/zip ), where you may obtain a

    free zip with the finished contents of the fully-developed project. Based on that

    you will be able to create another project (KB) and import it. That will prove

    useful in comparing the steps you follow against the already implemented

    application.

    Throughout the book you will find numerous quotes from a white paper by

    Breogn Gonda and Nicols Jodal, titled Desarrollo basado en conocimiento.

    Filosofa y fundamentos tericos de GeneXus (Knowledge -based Development.

    Philosophy and Theoretical Foundation of GeneXus"), and published in May

    2007.

    Once again, we would like to mention our gratitude to all who contributed to

    our work, each in their own personal way, during the first edition. Thank you all!

    Now Mary, Diego, Mike and Julia are anxiously waiting to go on stage, so,

    enjoy your reading!

    The Authors

    Montevideo, May 2009

    http://www.gxtechnical.com/genexus/libroepisodio1ed2/ziphttp://www.gxtechnical.com/genexus/libroepisodio1ed2/ziphttp://www.gxtechnical.com/genexus/libroepisodio1ed2/ziphttp://www.gxtechnical.com/genexus/libroepisodio1ed2/zip
  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    7/136

    7

    Abstract

    Chapter 1: The Encounter. After many years, Diego and Mary meet again andembark on a story of encounters along with GeneXus.

    Chapter 2: Once Upon a Time... There Was a Project. Julia, Mike and Diegodefine and start the analysis and development of a system for a travel agency,while Diego guides Mary, as the share coffee, through her first experience withIDE and the creation of the projects first objects.

    Chapter 3: Machine-made, Hand-finished. As Julia achieves great productivitythanks to GeneXus patterns , Diego unleashes his creativity, and shows thatcustomer demands don't always translate to insurmountable obstacles.

    Chapter 4: Flight to the World of Subtypes. Working at high speed, Diegoshows Mary, not at the bar but in the office this time, why Subtypes are the bestsolution to problems that might arise in a data model, as he defines the final formof the last transactions.

    Chapter 5: When the "What" Is Not Enough. Mary's interest seemed to be onthe rise, as meetings, at both the office and the bar, became more frequent. Anumber of questions still remained to be answered: transactions allowdeclarations, but what about batch processes? GeneXus Procedures. After,more declarations: Business Components. And H ow to issue pdf r eports? Invitingattractions and attractive invitations. A potential dinner. And what about, dynami c

    queri es, for instance?

    Chapter 6: More declarations . Data Providers to allow loading and give back astructured output, by just a declaration of intention, instead of programming.Diego declares his intention and must send an xml to the airline.

    Chapter 7: Winds of Change. At her place, he was getting increasingly agitated,as they shared wine, music and more GeneXus. Though everything necessarilyhas to come to an end, Diego was barely suspecting that this could be just the

    beginning of something else.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    8/136

    8

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    9/136

    9

    Chapter 1

    The Encounter

    A man and a lady happened to ran into each other while waiting in line at the bank. They hadnt seen each other in many years and appeared happy to meetagain. Maybe old college friends?

    "Hello Mary. I ts nice to see you again!! How are things going? You stillworking at the same place?" asked the man in a deep, projected voice as he staredat her with a seducing attitude.

    "Hi Diego! How are you? Im doing fine, after long years in the company I w as

    promoted and have been working as Developer Team Manager for the past twoyears, answered the lady, looking somewhat tired.

    "Then I guess I should congratulate you! But, why do you look so down?Trouble at the office? I've heard that your systems are quite trustworthy inaddition to their large scale ..."

    "They are indeed, but they are also very difficult to maintain!" Mary said,obviously upset. "I feel Im going to end up getting sick, Diego. I havent beenable to sleep well lately, and my responsibilities are far too many, not to mentionthe long hours, lack of leisure time. I have this oppression in my chest..."

    "Believe me, I understand" added Diego, as his right hand gently touched herleft arm. "What is your work method? Which tools do you apply?"

    "Well, a bit of this and bit of that... In the end, they're all the same," Maryanswered, seemingly unaware of how close Diego was. "I have this large teamworking on maintenance and development, but we can't keep up."

    "Uh mm... Not all of them are the same! After were done her, would you liketo go for a cup of coffee with me so you can tell me more?" asked Diego, bothhappy and embarrassed.

    GeneXus?

    At the coffee shop, Diego listened attentively to the problems that distressedMary. He remembered how strong and driven she used to be, and felt an almostselfish pleasure in being now the one to help her out.

    So as to generate an atmosphere of confidence, Diego started by asking her:"How many projects are you working on right now?"

    "Currently we have a single project in progress that involves mainlymaintenance tasks. Our clients keep asking for new things, and we are finding it

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    10/136

    10

    hard to meet their new requirements. Besides, maintenance is really expensive andI can't justify hiring more people. It'd imply excessive overhead costs."

    "Maybe the systems you use are too old, technology wise I mean... Have youthought about reengineering everything?" he asked frivolously.

    "That would be ideal, and I have suggested it actually, but we're on a reallytight schedule. And, as I said, we may have already exceeded our budget. I reallydon't know what to do Diego... I'm so exhausted that I cant seem to find a wayout of this."

    "I know exactly what you mean! Do you have an idea of the number of peoplewho are in the same situation as you? I've seen it a million times. Applications areincreasingly complex, and the manual tools we are used to do not enabledevelopments, or whats worse: the maintenance of s uch systems. They are gettingout of hand. But dont despair Mary! Theres still hope for possible solutions. Thealternative now is to automate the work done by humans, so that we can focus onnew complexities instead of coding, a task that can be accomplished by means of a

    program. For instance, at my company, we're handling several large projects atonce, quite easily and without many inconveniences so far. Have you ever heardof GeneXus?"

    "GeneXus?... Oh, yes! Ive heard about it, but haven't had the time to look intoit in detail. Do you use this tool? Theyve told me that its non -technical users are

    becoming more and more frequent, and that is something Ive been wonderingabout."

    "In fact, I'm not saying that GeneXus is the solution, bu t I do know that itsolves many of the problems that your company is facing. It's a program thatmakes programs. It automates the creation and maintenance of your applicationsand your database. Of course, as you can imagine, it's in a more abstract level thanother tools. Tell me, if you had a program that allowed you to do thisautomatically, would you use it?"

    "Absolutely!" she replied as she sat up straight. "Indeed, that's exactly our problem, we have to do almost everything manually."

    In Diegos opinion, the problems at Marys company were very common.They find it impossible to take on new projects due to the time implied by themaintenance of the current systems, based on traditional technologies. For asoftware development company, this is a red flag alert.

    And as for you, dear reader, by now you are probably wondering how it allworks, right?

    "How does it work?" asked Mary enthusiastically.

    "Wouldn't it reasonable to think that, given a set of views on data," interrupted

    Diego with certain malice, "there's only one single minimum relational model forit?"

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    11/136

    11

    "Hmmm Maybe, I'm not sure. But how is that related to my maintenance problems?"

    "And if that were true," Diego continued, as he ignored her hesitation, "don't

    you think it's possible for a reverse engineering process based on those views tocreate the scheme of that minimum relational database? If you need to see it to

    believe it... let's make a bet, for old times' sake. Believe me, you're going to lose!"

    A Bet

    GeneXus is a tool that, starting from users' views, captures their knowledgeand systematizes it in a Knowledge Base . Using this Knowledge Base, GeneXusautomatically designs, generates and maintains the database structure and theapplication programs; that is: the programs necessary for users to operate based ontheir own views.

    "GeneXus stores in a Knowledge Base all the elements needed for building theapplication, and then uses the KB for developing the system, as it automatically

    builds the normalized data model, also using any desired programming languageand database. This way, you can achieve a project with the company'sknowledge..."

    "Oh, okay! So that all ows for"

    The objective of GeneXus is [by describing users' views] to achieve high-qualityautomated management of business systems knowledge.

    Breogn Gonda & Nicols Jodal

    GeneXus works with pure knowledge whose validity is totallyindependent from current technologies.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    12/136

    12

    "Yes!" Diego interrupted eagerly in order to complete her thought, It providesyou with something very valuable, the future portability of your application. Allthat knowledge business rules, dialogs, controls, reports- that is currentlyexpressed in specific programming languages could be perfectly translated intoother languages without the need to commence at the start line. This means that

    knowledge is reused because the Knowledge Base implies knowledge that isindependent from the platform."

    Following two quick blinks, and before anything else was said, Mary orderedanother round of coffee.

    Knowledge Base and External and Relational Models

    As the two friends went on with their conversation at the coffee shop, Mary became more and more interested in this specific software tool and Diego in...

    "On one hand, you have the Relational Model, which - as you know is meantfor obtaining an accurate representation of data in a database, upon compliancewith certain conditions that are quite desirable."

    "Right!" she exclaimed, "Like eliminating redundancies and introducing asmall set of rules to avoid the most significant sources of inconsistent data."

    "Exactly, rules that verify uniqueness and referential integrity, apart from providing a set of operators for quality data management," added Diego,enthusiastic about the complicity growing between them.

    "Of course, that's why everyone uses them! Doesn't GeneXus?"

    "Yep, Im getting there Remember the External Mo del where external viewsare represented? GeneXus focuses on this model because that's where the actualknowledge is; it's the most important model for users and developers. It includesexternal knowledge and everything else, such as other auxiliary models that might

    be useful, and can be automatically inferred from the External Model."

    "I see... So the External Model... cannot contain physical or internal elements

    like files, tables, entities, entity relationships or indexes... right?"

    "Exactly! Nor any other element that can be automatically inferred," repliedDiego, eager to continue his explanation to her. "The External Model will be usedto obtain and store knowledge. It aims at representing reality in the most directand objective way possible."

    "Sure! Its a way to independence from implementation, for you have a high -level system description that won't change unless user views are modified. Am Iright?" Mary asked.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    13/136

    13

    "Absolutely! That's why we take the views of the various users to be stored inthe model. Then, all the knowledge contained in them is captured andsystematized to maximize its inference capabilities."

    "Actually, I find that hard

    to believe. It sounds purelytheoretical. Do you mean totell me that a meredescription subjected to a

    program will magicallycreate the application?" Maryasked skeptically as sheexpected Diego to convinceher with his passionatereasoning.

    "Well, I wouldn't call it magic; after all, we ARE talking about software here.And you actually do have a bit of programming to do, but it's minimal. InGeneXus you'll have certain procedural codes, but you will not be writing in thelanguage that you are used to. Here, you won't need to name tables, indexes or anyother physical elements in a database."

    "But then... I don't understand where the Relational Model comes in," said Marysomewhat confused.

    "It's the one used to represent and handle data, the internal or physical modelthat in this case you will not be creating. It will be inferred by GeneXus by meansof its reverse engineering procedure. Mine was actually a tricky bet."

    "And how do you describe users' views, the External Model, to allow reverseengineering to be applied to them in order to obtain everything you mentioned?The description must be accurate and formal enough to avoid ambiguities andallow a program to infer all those things that still have to do manually."

    "And so it is." Diego assured her. "Descriptions are made through certainGeneXus objec t types that represent the what.' Through them, GeneXus finds thehow. That's why, in order to learn to use GeneXus, you need to learn to describe

    and use these object types. In fact, no profound technical knowledge is required."Diego went on talki ng to fill in the reduced spaces between Marys words.

    Though they hadn't seen each other for long years, he remembered Mary verywell. He was familiar with her thoughtful expression that meant he could go onwith the conversation. He couldn't believe his good luck. Thanks GeneXus! hethought, as he continued in a slow and confidential tone, and controlling pauses soas to achieve the desired effect.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    14/136

    14

    "To make all this possible,GeneXus has a Knowledge Baseinitially associated with a set ofinference mechanisms andcertain general rules to ensure

    consistency for instance(referential integrity rules).When the GeneXus analystdescribes reality by creatingobjects, these descriptions theExternal Model- are automatically systematized and stored in the KnowledgeBase. Also, from this knowledge it obtains a set of results that enhance theaccuracy of further inferences."

    "It's an inference machine!" exclaimed Mary.

    "Thats right! For example, given a view of the data, it can automatically inferthe program needed for handling it."

    "Diego, I will have to get going now, but I would sure like to know more aboutall this. What do you say we meet again next week? Same time, same place?

    "Of course," he replied, trying to sound calm and controlled.

    GeneXus always works based on the Knowledge Base . All the knowledge in theKnowledge Base is equivalent to the contents of the External Model (a subgroup of theKnowledge Base), for it consists of the External Model itself, plus independent rulesand inference mechanisms, and a set of other elements automatically inferred from it.

    The developer can change the External Model by modifying objects in the user's reality.Such modifications will be automatically transmitted to all elements where they arenecessary: other elements of the Knowledge Base, database and application programs.

    Likewise, the developer may not directly change any elements that do not belong to theExternal Model.

    ALL the knowledge is in the External Model and this gives the possibility of latersupporting the Knowledge Base in a completely different way, while our customers'knowledge would continue to be usable with no problems whatsoever.

    Breo n Gonda & Nicols Jodal

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    15/136

    15

    Chapter 2Once Upon a Time, There Was a Project

    Travel Agency & Co., a new tourism operator, has decided to hire the servicesof the software firm ACME Business Software Solutions to develop a Web. Theidea is to provide clients the possibility of searching for destinations, flights anddifferent services, book flights, make other travel reservations, and obtain tickets(front-end). The project will also include the creation of a back-end system forrelated data maintenance.

    The ACME Company has been applying the various versions of GeneXus forquite some time, and has several IT specialists among its staff. The team membersselected for this project are Julia, Diego and Mike. Diego and Mike are GeneXus

    Analysts who work on any project assigned to them. Diego is the one specificallyin charge of developing applications and Mike takes care of the testing. Julia,though not a GeneXus specialist, has been responsible for gathering requirementsfor numerous projects, but her specific area of expertise is to document and leadworkgroup's meetings as benchmarks are achieved. In this team, every member isentitled to express opinions and to participate in decision-making.

    The preliminary tasks are done by Julia and Diego, while Mike continuestesting other applications under development for other ACME clients.

    It has always been Julias method to use text processing in documenting the

    work done. But in large-scale projects, it becomes quite complicated for her toeasily manage dozens of folders that imply hundreds of files, to share them withthe developers and to coordinate team discussions, among other tasks. No wondershe was thrilled to find out that GeneXus X provided an embedded documentationfeature that would make her life easier.

    Time is of the Essence

    A short while ago, the companys board of directors and the developmentteam agreed on a short-term project that would take around three weeks. Basedon GeneXus X's well known usability and productivity features, they haddecided to reduce the time frame agreed with clients to half of the time periodsregularly scheduled.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    16/136

    16

    Luckily for the development team, Travel Agency & Co.'s internal operationswere quite efficient and well documented. So, Julia, Diego and Mike decidedthat they would meet with people from the different company areas in order togather their particular views.

    They wanted to start representing the company's reality as soon as possible.Among other things, they learned that Travel Agency & Co. focused on leisuretravel to a variety of destinations worldwide. What did this mean? First of all,since destinations were tourist attractions in cities around the world, they neededa place to store this data.

    The whole team had a meeting to exchange notes and ideas, and decided thatJulia would be in charge of describing the first guidelines obtained. Meanwhile,the others especially Diego would use GeneXus to represent the most clearlydescribed user views.

    The IDE at a Glance

    It's time to go into the GeneXus X development environment. If you like, youcan follow Julia's steps to get to know the elements that make up this environment.That way, you'll create the project Knowledge Base and the first Transaction typeobject.

    Commonly known by its acronym (IDE), this Integrated Development Environment goes way beyond its name. And that's because an IDE is anenvironment that offers a high level of comfort, windows from where to selectelements, windows for writing codes, toolboxes, and source codes, among otherthings. In this case, the functionality of GeneXus Xs IDE exceeds basicrequirements.

    Julia opens a session in GeneXus X and sees a start page similar to the one below:

    Every user ha s one or multiple views of the data he/she uses on a daily basis.Among these views, we can identify a first group with the views used to

    handle data (with restricted permits to add, modify, delete and view data).These user views, the first GeneXus object type, are called Transactions."Breogn Gonda & Nicols Jodal

    "A drastic increase in productivity [system development] is still needed.However, the productivity of programming languages has already reacheda plateau. ... So, how can we achieve this necessary increase inproductivity? With developments based on knowledge instead of onprogramming. The solution is to describe instead of program!"

    Breogn Gonda & Nicols Jodal

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    17/136

    17

    Initially, we can see two clearly defined content areas. On the left is the KnowledgeBase Navigator, offering various views. It's made up of an area (now blank) that will display a tree with the elements of the Knowledge Base that isopen, and a set of horizontal panels with the names of other views.

    On the right is a main window (that's how we will refer to it, as we'll do mostof our tasks there). It is basically another item with multiple functions. In the topleft corner of the main window is the Start Page tab, which is the first open itemin the main window. As you work, new tabs will indicate other work spacescontaining project elements such as navigation reports, diagrams, transactionstructures, and so on.

    Now, let's look at the only tab we have, which includes other sectionscontaining information. For example, Recent Knowledge Bases displays a list ofrecently opened Knowledge Bases with the dates of the latest updates, and

    provides links to create new Knowledge Bases or to open existing ones.Below is an Extensions section with tools developed by Artech or third parties.

    They are free to be installed and used, and enable an increased tool power in alldirections.

    The section labeled GeneXus Community displays an RSS feed of Communitynews, with "More..." links to read the complete stories.

    The Address cell allows you to search the Web or your file system withoutleaving the IDE.

    Panels

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    18/136

    18

    New Project and New Knowledge Base

    The first task in developing an application with GeneXus is to create theKnowledge Base.

    At their following meeting at the coffee shop, Mary - still with a concernedlook on her face asked Diego:

    "You said that GeneXus enables the automated creation of databases and programs, but how does it know in which environment and language is should build the programs? For example, if you had to develop an application in Java andanother application, or the same one, in (.Net)..."

    "Lets see... When you create the Knowledge Base we usually call it KBfor short you can set the project to be generated in Java. As we said, the KB is

    platform-independent: if you generate the application in Java, you can later reusethis knowledge to generate it in .Net. You don't have to describe the objects fromreality again, and you only have to associate this knowledge with anotherenvironment. When you associate an environment, you'll find a place to seteverything related to it. For example, in Java, youll have to set the location of theclasses in the webapp, something that makes no sense in .Net. This means thatdepending on the selected environment, the program displays the propertiesneeded to set it. Thats how GeneXus can make your application come true andimplement it as you asked."

    Coincidently, as Diego and Mary exchanged words and looks at the coffeeshop, Julia followed the same steps that you can see below.

    1. On the File menu, click New, and then click Knowledge Base (or click the New Knowledge Base link in the Start Page ). The following dialog box will be displayed.

    TravelAgency

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    19/136

    19

    From here, the project is associated with an implementationenvironment. Leave "C# Environment," which is the default option. Also notethat English is associated as the default language of the application. Allmessages, buttons, etc. will be then in English. But you will be able to latergenerate the same application in another language, in both static and dynamic

    form (in running time, the user selects the language to be used in theapplication), at a minimum cost.

    It should also be noted that the KB will be stored in a database whose defaultname will be GX_KB_name in the same installation of your local SQLServer.If you do not have one you may use one from the net. By pressing the[Advanced] button you can change the values.

    2. Click [Create]. GeneXus will create an empty Knowledge Base. The screendisplayed should be similar to the one below.

    As you will see, part of the content has changed. There's a tree in the FolderView panel; the parent node is the Knowledge Base (with the name that you

    gave it) and the children are the elements that make it up: Domains, Tables, Customization, Documentation, Objects , etc.

    A new section called Knowledge Navigator has been added to the Start Page .It has shortcuts to the most common tasks that you mostcommonly do after creating or opening a Knowledge Base.

    This Knowledge Base will also be used by the rest of the team. Julia is nowready to start documenting the project.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    20/136

    20

    Documenting from the Inside

    Documents, notes and task lists are just examples of the documentationimplied in any software development process. Documentation, when it's up-to-date and easily accessible, is an important part in every application.

    And thats why GeneXus' documentation features are built into the KB.Documents, files, diagrams, and objects can all be linked, and easily accessible toevery team member, so we say that it's active, integrated documentation thatconstitutes an actual wiki.

    Files

    The department managers had emailed Julia several documents describingtheir system requirements, priorities and descriptions of their areas, some processflows, etc.

    Because these documents were created by the end users, she decided to addthem, unchanged, to the Knowledge Base, for future reference. The actual wordsof users were important to consider here.

    So, she expanded the Documentation tree node and double-clicked Files . Inthe new Files tab that was displayed in the main window, she clicked Add New

    File . A window was displayed to search her file system and choose each file to beadded to the KB. Below is the resulting Files tab.

    Images

    She had also received the company's logo, so she accessed the Customization node of the Folder View tree, double-clicked on the Images tab and imported the

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    21/136

    21

    Logo.bmp file, which she saved in the KB. Later, it would be used as a header forthe application's pages. In the same email, she received dozens of image files oftourist attractions that later would be stored in the database. She temporarily savedthem here as well, to have them centralized in the KB.

    The M ain Document

    Now, Julia gets ready to write the main page of the KB's wiki. Note that belowthe Documentation node is a Main Document object. Every development team hasa different approach to documentation. At ACME, this main page is used todescribe an overview of the system being developed, and to access documentationelements.

    They could as well create the project's Master Plan here instead of inserting itas a file. But you and your development team are free to use this page as youconsider most convenient.

    Julia opens Main Document and a new tab called Document: Main is displayedin the main window. Since she wants to start writing, she clicks the Edit selectorin the lower menu bar and enters the text shown below with a format. Next, sheclicks Preview and obtains a normalized view of the text. Finally, she saves thechanges (Preview changes to Browse).

    Note she formatted the text through the formatting toolbar.

    Julia changed the font type and size, and set the topic title in bold.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    22/136

    22

    In addition, she needed to add links to the documents she has received and justsaved in the KB, which is crucial for an integrated documentation. To do so, shedragged the Table item from the toolbox 1 to the page. After inserting the table, shewrote the following en each row.

    She wanted a preview so she clicked the Preview selector. Satisfied with herwork, she saved it and the following window was displayed.

    Note that due to the symbols she used in the table's second column, thedocuments are now underlined: they are links to the stored files.

    As a result, the documentation is very dynamic and actively integrated to the project through the KB.

    The GeneXus documentation editor uses two opening square brackets ([[) andtwo closing brackets (]]) in the text to create links.

    If you're following this example, you may have noticed that right after typingthe second opening bracket, the editor prompted a list of valid objects to choosefrom, as shown in the figure below.

    1 The GeneXus IDE provides dockable function panels that stick to any side of the window. Also, theycan be automatically hidden when the focus shifts so that they don't take up space in the main window. Toactivate them, open the View menu and choose Other Tool Windows.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    23/136

    23

    Julia selected File , and after typing a period (.) the list of available files wasdisplayed (she could also have dragged the File object from the toolbox , obtainingthe same result as by writing "[[File.").

    Next, she selected each desired file and pressed . The text was endedwith two closing square brackets.

    Creating the First Transaction: Attraction

    Back at the coffee shop, while talking to Mary, Diego thinks that he shouldenter the first views obtained by interviewing staff from the Tourist InformationSection at Travel Agency & Co. That department in the company is responsiblefor finding information to be added and for removing the necessary destinationsand itineraries offered to customers. He thinks that, as soon as he gets back towork, he should create the Attraction transaction, when Mary suddenly interruptshis thoughts:

    "You know, Diego, I don't understand how you can accurately describe users'views to avoid ambiguities and to automatically infer everything."

    "Remember the new project we're working on? Well, I've been meeting withusers who handle data on tourist attractions in every country and city, in order tooffer them to customers. They use the attraction's name, such as "CentenarioStadium," "Roman Coliseum" or "Disney World," and the name of the countryand city where the attraction is located, with images of each attraction. They alsotold me that attractions are grouped in categories. For example, the CentenarioStadium belongs to a Great Monuments category, and Disney World toEntertainment. These are their views on the data."

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    24/136

    24

    "I see... And how can you objectively describe those views?"

    "With attributes... and with Transaction type objects. Let me explain .

    Attributes are the reference framework for other descriptions. It's not exactly thesame as a relational model attribute. Here, attributes are the basic semanticelement. Precise, unique semantics are assigned to their names, and that's whyattributes are so important in GeneXus."

    Diego scribbled a few names on a paper napkin: AttractionName ,CountryName , CityName , AttractionImage, AttractionCategoryDescription , andcontinued his explanation:

    "These attribute names have clear semantic content that anyone can understandwithout the need for any context at all. They are not just 'Name' or 'Description.'Theres a strong relationship between an attributes name and its meaning. Thatname, in turn, is a sequence of characters, something syntactic, unique, with whichany program can work without ambiguity. If I write or speak of

    AttractionCategoryDescription anywhere, we both know it's a description of theattraction category. And GeneXus knows this too, because of the syntax."

    "So," she cut in, "you can't use the same attribute name to refer to other data,

    because that would cause confusion and ambiguity."

    "Exactly. An attribute must have the same name everywhere it's used, and therewon't be two different attributes with different meanings sharing the samename. That's the basic concept. But there's one exception, though. Anyway, I don'twant to get you all confused at this point. These views described by users are usedto handle data (add, edit, delete, view it) and are represented in GeneXus throughthe Transaction object type. Every transaction has a set of elements: structure,rules, formulas, display elements. In other words, in one object we're killing

    several birds with one stone : when you set the information that will be used,you're also designing the screen that the end user will work with, and you're alsodefining the necessary data behavior as it is entered, among other things."

    Diego grabbed the same napkin and added the following:

    AttractionId* AttractionName AttractionCategoryId AttractionCategoryDescription AttractionImageCountryIdCountryName

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    25/136

    25

    CityIdCityName

    Then he said: "Data is displayed according to a structure that must beaccurately represented. This would be the structure of the Attraction transaction.

    The asterisk next to AttractionId stands for uniqueness: there's only one AttractionId . That is, it's an identifier that makes an attraction unique. All theinformation has to be identifiable, so an attraction must be identified through oneor more attributes."

    "But wait Diego, I have some questions here!... Are you talking about theconcept of primary key of a table in a relational model? Will the attributes youlisted be columns in a physical table that will store this information? In the end,aren't you designing a table with this transaction?"

    "Well, indirectly I am. But also no, because I'm not concerned aboutdesigning a physical table of the relational model. I've only specified theattributes that the end user will interact with to enter attractions into the system.I've specified a user view, not a table. Heres where the reverse engineering andthe Relational Model inferred by GeneXus come into the picture. If this were theonly transaction in the KB then GeneXus would infer a physical tablecontaining exactly every listed attribute. But things are not quite that way whenother transactions share some of the attributes mentioned. Those cases would callfor a "normalizatio n, but I don't want to rush things now, Ill come back to thatlater, ok?"

    "I think I'm getting your point. But I still wonder why in the transactionstructure you added attributes without saying that they were mentioned by theusers. All the ones ending in Id And also, why didn't you use the attraction'sname as identifier?"

    "And what if the same attraction name is used to describe attractions indifferent countries and cities, like Disney World in Paris, or in Miami, or LasVegas, or Disney World in Orlando. In these cases we need an attribute providinguniqueness to the set of data elements that make up an attraction. Everytransaction structure should have one or more attributes to identify each instance.In this transaction, it will match the inferred table's primary key, but that's notalways the case. Later, you'll see it in a two-level transaction; but forget about thatfor the moment. Now, we can tell GeneXus that AttractionId will be a numericattribute and set it as Autonumber."

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    26/136

    26

    "And what about the AttractionCategoryId , CountryId , and CityId attributes?Are they identifiers too?"

    "Yep, they'll be identifiers in other transactions. Countries, cities, and attraction

    categories belong to entities that are independent from tourist attractions. Forexample, we haven't discussed this with the customer yet, but flights will alsohave arrival and departure cities. Obviously, we'll have to create a transaction torepresent and enter data about countries and cities, as well as existing attractioncategories. As it happens, these identifiers you mentioned will identify each one oftheir details (instances)."

    "Let me get this right: once you define the other transactions, GeneXus willinfer tables to store their data, and will know that the attributes you added to the

    Attraction transaction structure ( AttractionCategoryId , CountryId and CityId ) will be turned into foreign keys in the associated relational table."

    "Bright as always Mary!" exclaimed Diego with an admiring look.

    "But then, why are CountryName , CityName , and AttractionCategoryDescription in that structure too? In a normalized relationalmodel, they could never be in that table."

    "In fact, they won't be in it. That's why I mentioned that a transaction structuredoesn't exactly match that of the associated physical table. I'll come to that lateron, in more detail. Next time, I'll bring my notebook along. There will be a nexttime, right?" he asked a bit shyly, "That way I could show you..."

    The following day at work, Diego created the transaction using the GeneXusIDE. These were the steps he followed:

    He first clicked the New Object link in the Start Page and a dialog box for

    creating objects in the KB was displayed. He then clicked Transaction in theSelect a Type dialog box containing the GeneXus objects available, and typedAttraction in the Name field. Following is the screen displayed.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    27/136

    27

    Lastly he clicked [Create] and the transaction was opened. Note that in the following figure a new tab with the transaction name has been

    added to the main window. What's being edited? The transaction's structure .

    The structure edit window features a set of columns to create attributes, namethem, and set their data types and descriptions.

    Objects opened in the IDE's main window are displayed as tabs. Only the activeone is displayed in the middle of the screen. The opened object can have severalelements or sections, only one of which will be active each time. At the bottom ofthe window there is a bar to select other sections of the active object.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    28/136

    28

    In GeneXus, the structure Diego drew on a paper napkin is represented as shownabove. He named the attributes according to the GIK ( GeneXus Incremental

    Knowledge ) naming convention, a standard created by Artech and adopted by theCommunity. Its purpose is to give each attribute a unique name that clearlyconveys its concept, or semantic meaning.

    As you may have noticed, in the Type column you can give each attribute aGeneXus-supported data type.

    The Blob data type allows a wide range of data (videos, worksheets, all kindsof documents, audio files, digital images, etc.) to be stored in the database. The

    purpose of the AttractionImage attribute is to store an image of the attraction in.bmp, .jpg, or any other format.

    In the Description column, you can enter an extended description of theattribute. For the moment, we'll leave the suggestions provided by GeneXus basedon the attribute name.

    To add more attributes, press after completing a definition and repeatthe process.

    Selectors

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    29/136

    29

    Key Attributes: In his drawing on a napkin, Diego marked the key attribute withan asterisk. In GeneXus, key attributes are marked with a key icon.

    As Diego assigned the data type for the AttractionName attribute in the Type

    column, he thought it convenient to create a Name domain for all attributes thatnamed "something", and an ID one for all those that were numerical identifiers.

    You are probably used to working with Domains. If not, go on to the next paragraph to have an insight on the topic.

    Domains?

    It is common for applications to have attributes sharing definitions of the dataand size types, and certain other characteristics. For instance, in the Attractiontransaction there are several attributes that are ID (AttractionId,AttractionCategoryId, CityId, and CountryId). Diego created a domain called Id,with all the characteristics of identifiers, which he will apply to all attributeswhose function is to represent a non-existent value that is necessary to achieveuniqueness.

    Defining Domains

    Diego double-clicked the Domains node in the Folder View tree, and the tabfor displaying and editing domains was opened in the main window. There, heentered the Id and Name domains. The process is similar to that of creatingtransaction attributes.

    Some domains are automatically created by GeneXus together with the KB.

    After Diego defined the first domains, he returned to the transaction and as hesubstituted domains he realized that he still needed to define a Description domain

    Each domain is a set of unique features that may be shared by severalattributes. This allows for consistency and easy maintenance, since changinga domain feature will transmit the change to all the attributes based on thatdomain.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    30/136

    30

    for AttractionCategoryDescription. Instead of returning to the Domains windowwe went to the Type column of the attribute and wroteDescription=Character(20) 2. As he left that field the domain was automaticallycreated. Upon saving, he had the following:

    Note that the asterisk next to the transaction name in the tab is no longer there(the asterisk indicates that changes made have not been saved yet) and that theStructure selector changed colors.

    Descriptor Attribute: What does the magnifying glass icon in front of the AttractionName attribute mean? It indicates, in the case of having to keep only one

    attribute that best described the entity (with more semantic meaning), this would be the one. This information will be used by automation tools, so we won't dealwith it right now.

    The ATTRACTION Table

    By default, GeneXus names the tables it defines after the transactions they are based on. 3 At any time, you can view the table's design (structure, indexes, etc.) byopening the Tables node of the tree in the Folder View panel and double-clicking

    on the table's name. For ATTRACTION it will be:

    2 GeneXus generally offers several ways to do this in a simple way.3 From now on, table names will be written in uppercase to tell them apart from transaction names.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    31/136

    31

    Given the transaction structure, GeneXus will also design a form for it. Thiswill be the screen that end users will use to enter attractions when the transactionis turned into an executable program. It can be seen by clicking the WebForm 4 selector in the access bar.

    This form can be customized by moving controls around, by adding, changing,or deleting them, or by changing their appearance, for example.

    4 With GeneXus X you can exclusively generate Web 2.0 applications. To generate a Win applicationyou can resort to GeneXus X Evolution 1, where the transaction will also include a WinForm.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    32/136

    32

    Satisfied with his work, Diego remembered that he hadn't documented thetransaction. As a rule, ACMEs team members create documentation as they moveforward, especially regarding entities such as the Attraction transaction.

    So, he opened the Main Document , inserted a new table called Objects, and in

    the first row he added a link to the newly created transaction (just like Julia did afew pages back when she added links to the documents) with a brief description.

    We can see that Attraction is a link. What will happen when Diego clicks it? Anew documentation tab will be opened for the transaction, where he will be able toedit or even open the transaction.

    Suppose that you need to open the transaction to view its structure beforedocumenting it. You can do so by clicking the Open Transaction: Attraction link.Then, to open the documentation edit window you can click the Documentation

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    33/136

    33

    selector. As you can see, dear reader, in GeneXus it's also true that many roadslead to Rome .

    Creating the Second Transaction: Country

    Next, Diego created the transaction that would contain data on countries andcities. Its structure was drawn on the paper napkin that he had kept in his pocketsince his last meeting with Mary:

    CountryId*CountryNameCountryFullNameCountryWorldRegionCountryDetailsCountryFlag

    (CityId*

    CityNameCityInformation)

    Since he had already opened Main Document, he started from there. He added anew link in the table, this time to the Country transaction. But he hadn't created it

    yet! Note that the link displayed has a question mark ( ? ) next to it.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    34/136

    34

    Upon clicking on the ? , Diego will automatically create the transaction, whichwill appear opened in the structure, ready for him to enter attributes. The link willnow be defined in Main Document . (Once again: remember that about the roads toRome?)

    Country: A Two-Level Transaction

    It is a well known fact that countries have cities, so reality leads to determinethat there are n cities per country. GeneXus can easily represent this reality withtwo-level transactions.

    That's why the Country transaction has two levels. The first level, also knownas prolog or just header, is implicit so it does not need to be identified. In this case,the header's attributes imply that there's only one instance for each country.

    But because there are several cities for one country, the method used torepresent it (on paper: a set of brackets proceeded by a name for the level)

    determines a set of attributes that are repeated in the header: it is known as "body"or second level.

    Note that both levels (header and body) have their own identifiers: theCountryId attribute is the first level identifier, and CityId is the second levelidentifier. This means that for any given country ( CountryId ), a city ( CityId ) can't

    be used more than once.Based on this structure, GeneXus creates two tables: COUNTRY and

    COUNTRYCITY. The primary key of the first table is CountryId , and the primarykey of the second table is made up by CountryId and CityId .

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    35/136

    35

    The following figure shows the structure that Diego entered. 5

    Because CountryId and CityId already exist in the KB (they were created whenthe Attraction transaction was saved), when typing the first characters of each,GeneXus wi ll open a list with the KBs attributes that show the same start, fromwhere the corresponding one can be selected. This saves time of further typing.The same goes for CityId and CityName.

    Database Normalization

    When the Country transaction was created there were certain changes ofsignificance. More precisely, the contents of the ATTRACTION table havechanged because GeneXus has normalized it according to the new functionaldependencies added. Following are the new table structures.

    Remember that functional dependence X Y is a restriction between twosets of attributes of the database that determines that: if for 2 records the X values match, then the Y values must also match. This means that the valuesof Y attributes in any record depend on the X attributes or are defined bythem.

    5 Note that new domains have appeared. We assume that Diego created them either before or as heentered those attributes. For example, when entering CountryFullName , in the Type column he could

    have entered: LongName = Character(50) with the same result. In the event that Diego had alreadydefined a Details domain as VarChar(500,200), it's worth noting that when he enters the CountryDetails attribute, GeneXus will infer the Details domain as its data type (because it's in the last part of its name).

    To add a second level to a transaction, click the preceding attribute and press (in this case, click the CountryFlag attribute). Continue with the restof the attributes as usual. You can also do this by right-clicking the attribute and

    displaying a context menu to add a new level, move the attribute, etc.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    36/136

    36

    Can you spot the differences? By creating the Country transaction and settingthe CountryId and CityId attributes as identifiers of their levels you're definingthat:

    1. Every country will be (uniquely) identified by a CountryId value; this valuewill be associated with (determine) only one CountryName, CountryFullName,etc. (these functional dependencies are established). In a normalized RelationalModel, this results in a physical table with the CountryId primary key to storethis data while preserving uniqueness.

    2. Every city will be assigned to a country ( CountryId ) through the CityId value.Therefore, the ( CountryId, CityId ) pair will determine a CityName andCityInformation . Thus, there must be a physical table with the {CountryId,CityId} primary key to store data about each city. 6

    So, what does GeneXus do with attributes having the same name in differenttransactions?

    Remember the two most important statements of the GeneXus philosophy:

    Identical concepts must have identical attribute names, andDifferent concepts must not have the same attribute names.

    6 Note that GeneXus names the table by concatenating the transaction name to the level name:COUNTRYCITY.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    37/136

    37

    Considering the above, when attributes of the same name are found in differenttransactions, it means that they are exactly the same! So, what can GeneXus do tomaintain a normalized inferred database? Transform the CountryId and CityId attributes in the ATTRACTION table to foreign keys and remove the

    CountryName and CityName attributes from that table (they are then inferablethrough the previous ones. If they remained there then there would be redundantinformation).

    Stored Attributes and Inferred Attributes

    Here comes the question that Mary asked Diego about the CountryName andCityName attributes referenced in the Attraction transaction structure. Since theywont be included in the associated physical table... why did Diego add them toAttraction?

    If you look at the transaction form a few pages back, youll find thoseattributes. Why?

    That's because the transaction will be turned into a program that end users willaccess through their browsers. In a screen designed as the WebForm Editor, userswill be able to add attractions (new records in the underlying ATTRACTIONtable).

    When end users type a country identifier in the CountryId field and a cityidentifier in CityId , they should be able to view the country's name(CountryName ) and the city's name ( CityName ). This means that CountryName and CityName are invoked, at execution time, from the COUNTRY andCOUNTRYCITY tables through the combined { CountryId , CityId } foreign key.In order to be added to the form, attributes accessed through foreign keys must bein the structure, inferred .

    What would happen if the user entered nonexistent values for CountryId ,CityId ? What if, through the Country transaction, the user tried to delete a citywith attractions? If we were allowed to do that, we'd be breaking one of the mostimportant data consistency rules of relational models: referential integrity. In fact,GeneXus will automatically add in transactions the code necessary for thesecontrols.

    Referential Integrity

    Diego told Julia that he had defined the first two transactions. In order toconfirm that the model accurately reflected reality, she drew a Bachman Diagram (a diagram of relations between tables) of the tables inferred by GeneXus based onthe transactions.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    38/136

    38

    To do so, she expanded the Tables node in Folder View and then, from anytable she right clicked to open the context menu and selected New Object ,following which, in the displayed Create New Object window, she selected the

    Diagrams object and clicked [Create]. Next, she selected all three tables at once

    and dragged them to the blank page to obtain the following result:

    In this diagram, the single arrow head indicates that there s one instance of the pointed table for each instance of the first table; that is to say, for each city theresonly one country, and for each tourist attraction theres only one city. Likewise,the double arrow head indicates several instances of the pointed table for eachinstance of the first table; that is to say, for each country there are many relatedcities, and for each city there are many attractions.

    This allows determining the relationships between them. For example, therelationship between COUNTRY and COUNTRYCITY is 1 to n (one to many);the opposite is n to 1 (many to one). COUNTRYCITY and ATTRACTION alsohave a 1 to n relationship.

    When adding or editing a record in the ATTRACTION table, theCOUNTRYCITY table must have a related record to ensure referential integrity.When a record is deleted from the COUNTRYCITY table, there mustn't be anyrelated records in the ATTRACTION table. GeneXus automatically solves this byadding this logic to the Attraction and Country transactions in a way thatstransparent for developers. Similar considerations can be made regarding controls

    performed on the related COUNTRY and COUNTRYCITY tables.

    Base Table and Extended Table

    While Julia confirmed that everything was correct, Diego remembered passages of his last conversation with Mary at the coffee shop:

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    39/136

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    40/136

    40

    Remember that the environment had already been selected when the KB wascreated. Therefore, several properties were already set; 7 for example SQL Server,the default DBMS. But something is missing to implement the system. Anassistant (wizard) will ask Diego for the DBMS server and database details only

    once. The DBMS is Microsoft SQL Server 2005 Express, installed in theDevelopeSrv server in the net. Diego will name the database asTravelAgencyTest:

    If the database is still to be created, it can be done by pressing [Editconnection] followed by the Create database link. If this is left for later on, thenGeneXus will do it automatically a few steps ahead.

    GeneXus will then go on to generate and execute the Developer Menu, 8 so thatdevelopers can immediately test the applications. Once the environment is fullyset, every time is pressed GeneXus will carry out all the steps pending andnecessary to execute the application. Diego expected to see what's shown in the

    following figure: the first Impact Analysis of this Knowledge Base.

    7 To change one of them, just select the Preferences panel in the KnowledgeBase Navigator and find the preference to be set; for example, the associated DBMS, the implementation language, etc. Then, access

    its properties by pressing (in the window that is opened).8 A simple prototyping menu created by GeneXus (it's an xml file containing links to the variousGeneXus objects created, in order to invoke them quickly and easily as we'll explain shortly).

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    41/136

    41

    This I mpact A nalysis Report (IAR) told him that GeneXus would createthe tables shown on the left. Their structures and other details such as indexes,etc., 9 are displayed on the right.

    What's an Impact Analysis Report ? GeneXus uses the Knowledge Base todesign the database. The existing objects can be changed at any time, and newobjects may be added to modify the KB. The IAR is obtained from an analysis

    performed by GeneXus of the impact of new definitions or changes to the KB onthe associated physical database. Through this analysis, the developer knowsabout the structural changes that GeneXus will make on the database to update itand make it consistent with the KB.

    Diego agreed with the IAR and clicked [Create] to reorganize the database. 10 Since the database didn't exist yet, it would be created in this first step. Later on, itwill be reorganized after being changed and restructured. When are programsgenerated? Right now, ready for testing! Barely a minute went by since Diego

    pressed and entered the platform details that were missing (name of BD andserver) until a browser window was displayed with the ready-to-run DeveloperMenu. He carefully analyzed some reports previously displayed by GeneXus tomake sure that he was going in the right direction.... But don't rush, dear reader,

    because we'll come back to this later and Mike is anxious to step in.

    Mike 007... With a License to Kill

    It was his turn. He had to destroy them; the transactions, of course.

    9 Below are the SQL sentences that will be used to reorganize (in this case, create ) that table.10 The term reorganize means to make physical changes.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    42/136

    42

    Looking steadily at the Developer Menu displayed in the browser containinglinks to the transactions, Mike clasped his hands together and cracked hisknuckles. Then he paused. Here we go , he said to himself.

    The idea was to start the testing immediately by entering data into thedatabase that GeneXus had just created and check the transactions' behavior.

    He clicked Country and the screen displayed was similar to the followingfigure.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    43/136

    43

    This is the Country transaction at execution time.Soon, he noticed that the CountryId attribute should be autonumbered. This

    means that the user shouldn't have to worry about assigning it a specific value because CountryId doesn't represent an object from reality. It's just a number that

    makes new records unique.Likewise, when he found CountryWorldRegion , a one-digit attribute, he didn't

    know which numeric value belonged to each world region (how could theyindicate whether a country is in Africa, North America, Europe, etc.?). We have to

    show the end user the names of regions and continents to choose from! he thought.So, he decided to start a conversation with Diego to discuss the issue; so that

    they could all agree with his suggestion. He returned to the KB, where he selectedCountry and accessed the documentation section.

    Making Conversation

    Upon opening the documentation, Talk is one of the selectors provided. Itallows us to create a space for dialogs with other users about the object at hand.

    Note that the title at the top indicates a Talk document for the transaction. Itends with a question mark, which means that there isn't a Talk page for this objectyet and that it should be created before writing. When Mike saves this space, a

    page will be generated with its content.Upon clicking the question mark, the view switched to edit mode. Next, he

    entered the text, saved it and viewed it:

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    44/136

    44

    Setting an Identifier Attribute as Autonumber

    Later that day, Diego read what Mike had written and replied positively in theCountry transaction's Talk area. He accepted Mike's suggestion, and proceeded todo the changes.

    He wanted to automatically number the CountryId attribute, a numericidentifier, through the Autonumber feature of the DBMSs that support it.

    All GeneXus objects have properties that affect both their look and feel.

    So, Diego selected the CountryId attribute and pressed in the structure ofthe Country transaction.

    Every object's or attribute's properties can be edited at any time by pressing to display them in a floating window.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    45/136

    45

    First, he changed the Autonumber property to True, and set the propertiesshown in the figure above.

    An attribute undergoes cosmetic surgery

    To complete Mike's following request in the Talk, Diego went to thetransaction's WebForm, selected the CountryWorldRegion attribute control and

    pressed (Diegos properties window is AutoHide so now the Propertieswindow shifted out). Inside the control properties window, he set theControlType property to Combo Box. Next, he selected the Values property toopen the Values Editor window and entered the values for the attribute. That wasall.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    46/136

    46

    If, instead of doing this in the CountryWorldRegion control properties inthe form, he had done it in the CountryWorldRegion attribute properties in thestructure , the scalpel would have cut deeper: it would mean that every time thisattribute was added to a form, by default it would be displayed as a Combo Boxwith the indication established, and not as an Edit control. When he realized hismistake, Diego made this definition at the structure level. This is a good example

    of how knowledge is inferred in the Knowledge Base and reused.At that point he admits that whats more convenient rather, is to create a

    numbered domain to be used by any attribute that will represent regions in theworld, particularly CountryWorldRegion . So he edits the domains and creates anew one, WorldRegion, of the Numeric (1.0) type, and in the properties window() he selects the Enum values property and presses the button to open thewindow and enter the values to be taken up by the numbered domain:

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    47/136

    47

    This way he avoids having to recall, in the application, that value 8corresponded to South America in the system. So, from there on, when that valueis to be referred he can write WorldRegion.SouthA, certainly much easier toremember than 8.

    So, he edits the properties of the CountryWorldRegion attribute (for example, by going to that attribute in the Country structure and pressing ) and changesthe data type for it to be now in the WorldRegion domain.

    The value of the ControlType property will immediately change to become

    Combo box, and its values are that of the numbered one.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    48/136

    48

    Reorganizing ( reorg )

    Diego has changed some properties of two Country transaction attributes. Willthis indirectly trigger any changes in the physical table? Following is the Impact

    Analysis Report displayed after Diego pressed .

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    49/136

    49

    Yes, GeneXus found that a table needs to be reorganized . Note the wordAutonumber to the right of the CountryId attribute data type. The reorganization will have to activate this property at the DBMS level. But, what happened with theother change, the one to CountryWorldRegion? Nothing! It's not a database

    change, only the KB was affected: the WorldRegion domain is still of the Numeric(1.0) type, so the type of the CountryWorldRegion attribute remains unchanged atthe database level. The main change will be a cosmetic one, and indicates that inall forms where this attribute is shown, it will be displayed as a Combo Box, withthe values of the numbered domain.

    This proves that not all changes done to a GeneXus object necessarily causethe database to be reorganized . We'll give another example when we explain thetransaction's rules.

    Diego can have GeneXus do the reported changes ([Reorganize]) or cancel the

    reorganization . If he cancels it, the IAR will be redone the next time he presses. He chooses to reorganize .

    When rereading the Talk to reply that everything has been done, Diego realizesthat Mike suggested autonumbering all transaction Ids by default. (His confusionwas caused by Mike documenting this in the Country transaction Talk, instead ofdoing it in the Main Document Talk). To implement this, would he have to changethe attribute properties one by one? No! He remembered that those attributes were

    based on the Id domain. So he only had to edit the domain properties and set theAutonumber property at the domain level, just as it was done for CountryId . All

    current and future attributes based on that domain will automatically inherit this property!

    But... Here's a problem! Diego thought. CityId is not a single primary key. To be set as autonumber, attributes must be a single primary key. CityId is part ofCOUNTRYCITY's primary key. 11

    How can he prevent this attribute from taking the Autonumber True propertyfrom its Id domain? 12 Simply by editing the CityId attribute properties (as withCountryId ) and changing the Autonumber property to False. In this way, thedomain's default behavior is changed for this attribute.

    The same applies to the AttractionCategoryId attribute which currently belongs to Attraction and is not a primary key. However, it will soon become a primary key when Diego creates the new AttractionCategory transaction. For thisreason, Diego decided not to change the Id domain definition for the moment (toactivate the Autonumber ). He'll do it later, when he creates the new transaction(he documented this "To-Do Diego", which was saved in Orphan Documents after

    being created by selecting the Document object from the New Object window).

    11 To assign consecutive values to this attribute, Diego will have to use the Serial rule. We suggest thatyou read about it after you see the following introduction to rules.12

    GeneXus is aware of this restriction. So, even if Diego hadn't spotted the problem, the system wouldhave acted intelligently: it wouldn't have defined the attribute as autonumber in the database. Forlearnings sake we preferred to put Diego to work.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    50/136

    50

    Transactions: Not just a pretty face; they also have personality

    Diego added to the transactions the behavior described by users regarding datamanagement.

    "An attraction must neve r be entered into the system if it doesnt have aname." Thus, he opened the Attraction transaction, clicked the Rules selector andtyped the following rule:

    Error ( 'Attraction must have a name' )if AttractionName.IsEmpty();

    If users don't complete the AttractionName field, the previous message will bedisplayed at execution time, and the control wont let them move on to another

    field. Saving the record in the corresponding table won't be allowed, either.

    "A country must never be entered into the system without a name and fullname. The country's details can be left blank, but a warning message should bedisplayed to the user in case they were overlooked." So, he clicked the Rulesselector in the Country transaction and typed these three rules, in random order:

    Error ( 'Country must have a name' )if CountryName.IsEmpty();

    Error ( 'Country must be in full' )if CountryFullName.IsEmpty();

    Msg ( 'No country details were provided. Do you want to continue? )if CountryDetails.IsEmpty();

    The third rule also triggers a message, but unlike the Error rule, it allows theuser to move on to the next field and save the record.

    Many other rules can be used to program the transaction's specific behavior. Note that they are written in declarative style and, with few exceptions, the orderin which they are added is not relevant. In our case, they will be triggered

    depending on the order of the CountryName , CountryFullName andCountryDetails attributes in the form.

    In a two-level transaction, the records of two tables are being handled.Therefore, when the user enters a new country and its n cities through the Countrytransaction form, n+1 records will be added: 1 in the COUNTRY table and n inthe COUNTRYCITY table. They will be added following the same order used toenter them into the form. A rule may be triggered immediately before or after oneof these saving operations. To this end, rules can be conditioned not only throughif clauses as shown above, but also through trigger events such as BeforeInsert or

    AfterInsert .

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    51/136

    51

    After saving the transaction's n+1 records (1 header and n lines) a Commit isautomatically performed. It can be disabled by the GeneXus analyst through atransaction property. In addition, rule triggering events capture the momentimmediately before or after the Commit operation. For example, to get a list of the

    newly entered country and its cities, you can invoke another type of GeneXusobject: Procedure. You must invoke it after entering the n+1 records, by sendingthe newly entered country Id by parameter. To obtain it before the Commitoperation, write the following rule in the rules section:

    PrintCountry. call (CountryId) on BeforeComplete ; 13

    If you want it after the Commit operation, use the following rule:

    PrintCountry. call ( CountryId ) on AfterComplete ;

    Diego documents the changes already made. Think about the changes made tothe KB since pressing the previous .

    What's hiding behind ?

    1. When you press , GeneXus first makes an impact analysis of the KBchanges on the database. When there's an impact, it will display the Impact

    Analysis Report , which can be confirmed to physically reorganize the

    database. As we've seen, it can also be cancelled.

    Diego knows that the only changes he made since he last pressed wasadd rules to both transactions, that's why he doesn't expect a reorganization thenext time he presses . However, he knows that the following steps will becarried out.

    2. GeneXus steps into the specification stage, which is an analysis of everythingdefined in the elements making up the objects that you have changed, be they

    structures, forms, new rules, etc. This task results in a navigation report whereGeneXus shows the logic interpreted for each object that has been changedsince the last , together with warnings and errors, if any.In our friends example two objects have changed: Country and Attraction, so

    Diego will see the following after pressing :

    13 The Call , a common invocation method in GeneXus, is being used as a rule. Note that the invokedobject's name appears before the call ; in this case it is a Procedure, another GeneXus object. Lastly, notethat trigger events are identified in the syntax of a rule:

    Rule if condition on Event Condition is a Boolean condition and Event is a valid trigger event. In the product's documentation you

    can read more about other trigger events such as AfterValidate , BeforeInsert , BeforeUpdate , BeforeDelete , AfterInsert , AfterUpdate , AfterDelete , BeforeComplete , AfterComplete , etc.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    52/136

    52

    There weren't any warnings or errors. Note that, upon selecting Country on theleft, it shows the tables where the saving will be done, and the referential integritychecks that will be performed when deletion of a country or city is tried throughthis transaction.

    3. After the specification stage comes the generation of the object(s) that

    GeneXus deems necessary to completely perform the execution. (If there areobjects that haven't been changed and were generated in a previous , whydo it again?) The generation entails writing lines of code to implement the

    programming of objects in your chosen language for the developmentenvironment (for each transaction of the two that Diego has, a .cs file will begenerated among other things. Dont forget that he chose C# as thedevelopment language). Also, while the developer does not create his ownmain object, an xml will be created: the Developer Menu which will containlinks to all programs (objects) generated.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    53/136

    53

    4. Lastly, GeneXus compiles the programs and executes (while a main object inthe execution is not created) the Developer Menu in the browser installed inthat computer.

    This whole process is fully automated. You'll never have to specify and/or generate an object explicitly, because GeneXus is intelligent enough to determinewhich actions to trigger at each time.

    That's how, upon D iegos warning and previously opening the D eveloperMenu, Mike executed Country, where he added, updated and deleted a fewrecords. Finally, he documented the results in the transaction's Documentation,changing its status to OK.

    Note what happened when, accidentally, with country 1, Argentina, beingedited he erased the name and exited the filed Remember that shortly before

    Diego had programmed an Error rule with that same message?

    He still hadn't tested Attraction (he had found things to change in Country, sohe had decided to put it on hold for a while) when he read in the Talk that Diegohad asked him to delay the test until he created the related transaction that camenext.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    54/136

    54

    Creating the AttractionCategory Transaction

    Diego added the attribute pair AttractionCategoryId and AttractionCategoryDescription to the Attraction transaction, even though he knew

    that later he'd create an AttractionCategory transaction to contain them.

    This transaction categorizes the attractions of each country's cities:"Buildings/Structures," "Nightlife," "Relaxation," "Adventure," "Gastronomy,""Safaris," "Business," etc.

    With the Attraction and AttractionCategory transaction structures we'reimplying that an attraction belongs to only one category, while a category cancontain n attractions.

    The following Diagram shows the new existing relation between the tablesinvolved up to now in the project.

    The next time is pressed, GeneXus will have to reorganize the database by creating the new ATTRACTIONCATEGORY table and removing the AttractionCategoryDescription attribute from the ATTRACTION table. Fromnow on, this attribute will be inferred from the new foreign key

    AttractionCategoryId. Before pressing , Diego remembered to set the Id domain as

    Autonumber (he had left a note to do it when he created the AttractionCategorytransaction.)

    Finally, he pressed and read the corresponding Impact Analysis Reports .

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    55/136

    55

    Note how changes made in Attraction are informed. And forAttractionCategory it informs that the table is new and must be created. It alsoincludes a warning 14:

    After clicking [Reorganize] Diego obtained a new database and the newlygenerated programs. He closed the browser because Mike would be in charge oftesting, and documented the new transaction and Autonumber settings.

    Mike read Diego's notes, prototyped all transactions and again pressed ...

    14 What if Mike had previously tested the Attraction transaction and had entered records prior to thisreorganization ? Suppose he entered an attraction with Category 1 Id and a description NightlifeWhat would happen then in the reorganization upon creating the ATTRACTIONCATEGORY table and

    AttractionCategoryId becoming a foreign key in ATTRACTION and after AttractionCategoryDescription being inferred? What will happen to the pre-existing record inATTRACTION? For a consistent database, a record will have to be created in

    ATTRACTIONCATEGORY, with Id 1 and described as Nightlife. T he reorganization program willdo this on its own. What would happen if there were two or more attractions with the same category Idand different descriptions? This is what the warning informs. Find out what it is.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    56/136

    56

    While testing the Attraction transaction, Mike tried to enter the attractioncategory of the Eiffel Tower but couldn't remember the code of the correspondingBuildings/Structures attraction category. So, he pressed the icon next to thecategory Id field. A category selection list , automatically created by GeneXus,was displayed as shown in the following figure.

    Mike will select the first option on the list, Buildings/Structures, and thecontrol will return to the Attraction transaction. The AttractionCategoryId fieldwill display the value 1; the focus will be there and the user will be able to moveon to the next field (in this case, country Id, for which the process can berepeated).

    To free end users from memorizing foreign key codes, GeneXus automaticallycreates objects called Prompts, which are invoked through the icon displayednext to all foreign key fields at execution time. They are selection li sts that showthe entire data of the referenced table for the user to choose from.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    57/136

    57

    To confirm that the referential integrity checks were being made, he entered anonexistent category value in AttractionCategoryId. At execution time, heobtained an error message about it. 15

    GeneXus can "disguise" an attribute for it to appear as another attribute atexecution time, so that end users don't have to open these selection lists every timethey enter foreign key values. Mike suggested this and Diego implemented it bychanging two properties of the AttractionCategoryId attribute. As a result, to enterthe Buildings/Structures category, now Mike only needs to remember and type thefirst letters, and they will be autocompleted.

    The attribute where the end user will enter the description is actually the AttractionCategoryId foreign key disguised" as AttractionCategoryDescription .This way, though the end user enters descriptions, the corresponding Id isretrieved from the table and stored in a transparent way.

    They still had to improve the project's usability and appearance, so they wroteabout the need to use other GeneXus tools, such as GXpatterns . Maybe theycould all meet and discuss whether to put a part of the application in production in

    15 Seconds later, he would try to delete a category with related attractions from the AttractionCategory

    transaction. He expected it to fail in order to ensure referential integrity. Dear reader, you can also try thisfor yourself.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    58/136

    58

    the agency's tourism section. This would allow them to test it, enter countries andcities, and send any feedback obtained.

    Given GeneXus' features, anything can be tested at any time. And particularly,it is possible to prototype each object at the time most convenient for it. This is acrucial capability that stems directly from the GeneXus theory, more specificallyfrom the automatic propagation of changes.

    Prototyping is a great resource which, if used properly, will avoid an overlysignificant dependency on the final test, or even on deployment (D-Day, wheneverything happens and Murphy's Law especially applies) .

    Breogn Gonda & Nicols Jodal

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    59/136

    59

    Chapter 3Machine-made, Hand-finished

    Immediate Plans

    The Travel Agency & Co. project is well under way, enough to move several parts to pre-production. Now the time has come for tests to be done by end usersas the system is further developed.

    Problem: A Pretty Plain Application

    Julia meets with the end users to get their first impressions and address possible sidetracks. They like the controls and data input method when entering

    data through the transactions, but would prefer queries with more sophisticatedviews and increased functionality. For example, they want to work with countries in a more visual and user-friendly way, and the possibility to view all existingcountries on a grid and select one to update or delete it, or even view the country's

    full details , including cities and any other related data .

    Solution: An Appealing Application, Only 3 Clicks Away

    Patterns: here we come! Julia said to herself without hesitation. With the

    Country transaction in Edit view, three clicks and one , she asked the endusers, "Is this what you have in mind?"

    The end users view a new link in the Developer Menu: Work With Country,which, when clicked, opens a new object in the browser: WWCountry, which notonly displays a grid with the systems existing countries - sorted by name, theirmost meaningful attribute 16 -, but also allows filtering by name in that same grid(as the end user enters data in the filter variable, it is automatically filtered in thegrid). In addition, it provides automatic paging of the grid 17:

    16 See Chapter 2, page 27. When entering attributes in a transaction structure, the first attribute ofCharacter or VarChar type entered is marked as the descriptor . You can change descriptors by right-clicking the new descriptor in the structure and clicking the Toggle Description Attribute option in the

    displayed context menu. But, as we'll see soon, Julia will have another option to do it.17 The default value is 10 records per page (that is, it loads 10 grid lines). We've changed it down to 3 in acentralized location of the Work With pattern that we'll see further ahead.

  • 8/11/2019 Genexus x Episodio 1 2da Edicion En

    60/136

    60

    In addition, it allows performing the following tasks:

    Insert a ne


Recommended