When you first think about creating a web application, one of the most important considerations is how you are going to manage your data. How and where will you store it? How easy is it going to be to retrieve it and present it in a visually pleasing manner?
When working with Morfik you can be at ease that you will be able to store and retrieve your information without difficulty—and that you will be able to present it with style. Morfik offers native, built-in support for database programming. Morfik was in fact conceived right from the start to work with a database and to create applications that are database driven. This article and others in this documentation will provide a quick overview of all aspects of database programming with Morfik, from creating tables to accessing external, third-party databases.
It can be said that when working with Morfik, the database provides a lot of the structure of your application as it is tightly coupled with how visual elements are designed and put together. The creation of the web interface for presenting database information will, therefore, also be extensively covered in this and several other articles.
These database development articles focus on creating complex web application projects with a server side component, as this enables the use of database management systems. Only a subset of this information applies to Morfik application projects that use XML data sources and do not have a server side component.
A database is a set of records stored in a specific way to facilitate the retrieval and use of personal or business information. Databases are generally managed through the use of specialized software generally known as a Database Management Systems (DBMS).
There are several architectures that are used to store and manage databases. The most often used is known as the Relational Database and this is the one adopted by Morfik's built-in database. Read more...
Required concepts and notions
The Morfik user should be familiar with concepts such as tables and data types, indexes, primary and foreign keys as well as relationships and constraints.
A basic knowledge of SQL will make some of the text easier to understand but is not technically a requirement. You will have links to supporting topics covering the major SQL constructs that are normally used from within a Morfik XApp (Morfik-built, web-based application).
|Note:||Almost all SQL commands in this guide, except when otherwise specified, are written in the SQL dialect that is specific to the Morfik Built-in Database. Exceptions might exist when covering work with external databases and these will be clearly indicated.|
The default database
Morfik has a built-in database management system which is used by default in all new projects. It is very easy to start new projects from scratch because there is no need for formalities such as requesting database access from a database or network administrator. Of course, you still have to go through the appropriate steps in order to deploy a production application, but there is no delay in getting started.
The built-in database is a fully-featured relational database management system called Firebird. Morfik makes use of many advanced features of Firebird transparently, allowing the developer to benefit from them without having to learn how to use them directly. This allows developers to quickly go from being a novice to creating sophisticated data-driven applications.
Every Morfik web application project has an associated default database as part of the project’s structure. The default database bears the same file name as the project it belongs too, but with a different extension (.mxd). This means that you are creating a new database every time you create a new project.
Tables are the structures in which you store information in a relational database. Morfik treats tables as first class citizens within a project and they can be viewed individually, directly in the Project View.
How you store information in tables is a very important aspect of creating a web application. Morfik provides a default database for each project that is created, and it provides the means for you to directly create tables within the database using the Table Designer. Morfik also allows you to add tables from other databases to your project. They will be perceived as any other table in the project, but will not be editable. Read more...
From the Power Menu, or from the Project Ribbon when you are in Project View, you can create new tables right within the Morfik development environment without having to resort to any external tool.
The Table Designer is a specialized part of the Morfik development environment which allows you to define the structure of tables in your project's default database. Within the Table Designer you can add the fields you want to your table and choose the appropriate data type for each one of them.
Morfik's Table Designer allows you to create one or more indexes for your Table and choose their composition for enhanced performance during data retrieval operations. Read more...
A query is a precise request for information retrieval from an information storage system of some type. When working with Morfik we will be primarily referring to database queries which are generally expressed in the form of an SQL language expression. A query specifies exactly what information the user wants to retrieve from the database. This is done by specifying which fields from which tables the user needs to retrieve and under which set of conditions (parameters).
In Morfik, queries are first class citizens within your project and are independently displayed in the Project View. Within the Morfik development environment we use the Query Designer to create queries either visually or through the pass-through SQL editor which allows you to directly enter any valid SQL statements. Read more...
The Query Designer is a specialized part of the Morfik development environment which allows you to define queries for usage in your application, either visually or by writing SQL language statements.
In its Design View, the Query Designer strives to provide as easy an interface for the creation of queries as possible. In Code View, the Query Designer allows you to directly enter any SQL language statement which is valid for the target database. Read more...
Morfik was designed, from the ground up, for the creation of database driven applications and websites. Since data access is not an addition, but an integral part of the design of the product, the very manner in which you design an application or site is heavily influenced by what data is going to be shown. It is possible to create totally dynamic applications where all content comes directly from database tables and no static content is used. Again, due to how the Morfik development environment and the Morfik Framework are built, this is actually the preferred way of creating applications/websites.
It is quite simple, with Morfik, to create sophisticated data-driven applications. This makes Morfik the tool of choice for any kind of web-based application which needs to dynamically alter its layout and content.
The vast majority of work that goes into a Morfik application is in the form of visual design and configuration. This holds true for the database access parts as well. Morfik embraces a technique called Data Binding where you establish a relationship between the visual and database elements of your application and the Morfik Framework takes care of the data retrieval and its merging into the corresponding visual elements.
The combination of WYSIWYG visual designers with Data Binding lets you achieve amazing results virtually without writing a single line of code. Morfik includes visual designers for Tables, Queries and Relationships as well as Wizards for creating these objects and the visual interface elements that will be associated with them.
Of course, there will be times when a developer will need or want to write database access code for a specific purpose. Morfik makes it easy for those with the necessary skills to do so. Most of the work, however, can be accomplished through a set of visual designers and wizards.
The basis for data binding is that visual elements are directly "linked" to database elements. The first stage we need to go through in order to establish this link between the visual and database elements is to define a data source for a Form. Each Form has a data source which can be assigned through the property window/panel which is usually attached to the left side of the development environment's main window.
The property that must be set is listed as "Data Source" and when you click on the small button by the property field will cause a list of available data sources to be displayed in a dialog box, as shown in Figure 1.
|Figure 1: Select data source dialog within the Morfik development environment.|
A Form can only have one data source. This means that if you need to display information from more than one table you will need to create a query which joins information from all the necessary tables in a single data source or create smaller Forms to embed within SubForm controls. In some cases you may want to do both of these things.
Most projects built with Morfik will ultimately be a website or a Rich Internet Application, though you can use Morfik to build pure Web Service based servers. The ultimate goal of most Morfik projects is to display information in a useful and agreeable manner. Morfik's visual approach to web application development is particularly suited to allow users to create a rich web experience with very little recourse to writing code.
Once you have bound your Form to a data source, you will be able to assign specific fields to certain controls and thus map how information is going to be displayed by your application without writing code. In order to do this you must select a control you wish to use to display a certain field and set a value for its Data Field property. This property, when selected in the property window/panel, will present a drop down list of the fields available in the Form's data source.
One of the main factors in considering a company and/or website as being 'Web 2.0' is that it derives, in some way, content from its own users—thus creating value through interaction with the users. In this world, managing the content of a site is its very reason to exist, so special systems have been created to help individuals and companies get off the ground quickly. These systems are generically called Content Management Systems (CMS).
Since it can be argued that any website that allows the dynamic creation of the content it will display to user is, in fact, a content management system, several articles in this documentation use what could be considered a very simple CMS application as a basis for examples. From these articles you will get some insight into how an application which is totally dynamic can be created in the simplest of manners.
Apart from the ability to import data from other databases, Morfik allows you to create projects that access multiple databases. These can be distinct databases from the same database management system (DBMS) or from entirely different DBMSs. This can useful in many different ways such as creating a website that publishes data from a pre-existing corporate database or for distributing load amongst different servers in high concurrency, high volume on-line systems.
Every Morfik project that has a server side component has a default database, unless it is explicitly chosen otherwise. This database is in places referred to in code as the DefaultDatabaseConnection. All other databases referenced from a project are considered to be External Databases.
All access to databases other than Firebird is done through industry standard ODBC drivers or through a custom implementation of an Abstract Data Source .
Though Morfik does not enable you to run heterogeneous queries against multiple distinct databases, it does allow you to very easily retrieve related information in diverse databases and present it to the end user through a web interface.
The ability to divide the interface of your application or website into smaller parts using Forms embedded as SubForm controls in other Forms makes it quite easy to combine information from multiple databases in the same "page". This capability can be very useful when you are creating a web interface to a legacy system or extending an existing system's functionality.
There is no limitation in the number and type of databases you can combine in a Morfik project, as long as the respective DBMS has an ODBC driver or if you employ Abstract Data Sources to handle communications with the external data source. Using Abstract Data Sources you an even mix in information that is gathered from sources other than traditional database systems.
Common view and concepts
Independent of which language database you have chosen, you will work with the same concepts. Morfik presents all tables used in an application in its Project View. There is actually no notable difference between tables from external database and those from the default database. Conceptually, within the development environment, they are exactly the same and are treated so in all the Visual Designers. Stored Queries, previously mentioned here, are all created within the scope of the current project and therefore, even when they reference tables from External databases, they are considered to be regular project objects.
When working with code there will be some differences between using a Firebird database (be it the default or an external one) and all other databases.
|Figure 2: Morfik Project View showing tables and queries.|
In Figure 2 you can see a list of tables in Project View which include both normal and external tables.
- Defining data schema for your application
- Binding data to your application user interface
- Adding data editing and search functionality to your application
- Writing code for data manipulation
- Built-in Database SQL Statements - Quick Reference