Wednesday, August 26, 2009

Automatically generating database applications

For information about creating server projects in which you can create database applications, see Working with Projects.
Generating a PHP database application
You can generate an application that uses PHP and a MySQL database. To generate this type of application, you must have a local PHP server and access to a target MySQL database table.
Generate PHP application code
If you have not already done so, create a Flex project that specifies PHP as its application server type.
Select Data > Create Application from Database.
From the Project list, select the PHP project to use.
From the Connection list, select a database connection profile. To create and use a new connection profile, click the New button and complete the text boxes. For more information, see Directory structure and deployment considerations for PHP.
From the Table list, select the database table to use.
From the Primary Key list, select the primary key of the database table if it is not already selected.
Click Next.
Specify a Main Source Folder and a Main Application File, or accept the default values. You can generate the PHP files in the bin-debug folder, which is the default location, or in the src folder. If you want to export the project after using the data wizard, you must generate the PHP files in the src folder; otherwise, the project is exported without the PHP files and does not function.
Click Next.
Deselect any database columns that you do not want to appear in the DataGrid that the wizard generates.
Choose a database filter column, or accept the default value.
Click Finish.
Select Run > External Tools > Run As > Run on Server.
Select Run > Run to run the application on the server.
Directory structure and deployment considerations for PHP
When you use the data wizard to generate a PHP application, the default location of the generated files is the [web_server_root]\[project_name]_debug directory. The directory includes a PEAR subdirectory that contains the PEAR XML parsing utility, and a history subdirectory that contains files for Flex history management.
The main deployment directory contains tablename.php, databasenameconn.php, functionsinc.php, and XmlSerializer.class.php PHP files. It also contains a SWF file named tablename.swf and an HTML wrapper named tablename.html.
The project src directory contains the following files: tablename.mxml, tablenameconfig.as, and tablenamescript.as.
Deploy an application to a remote server
Set up the host:
Create a new database. Typically, the host has a naming convention like sitename_dbname.
Create a web user with a password (for example, name: bigryans_webuser, pw: webuser). Give the web user the following privileges: insert, update, delete, and select.
Create the database table or tables (you can export the SQL and run it in your MySQL administrator application, or you can create it manually); for example: CREATE TABLE users (
userid int(10) unsigned NOT NULL auto_increment,
username varchar(255) collate latin1_general_ci NOT NULL,
emailaddress varchar(255) collate latin1_general_ci NOT NULL,
PRIMARY KEY (userid)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
Edit the Flexphpconn.php file. This file creates the connection to the database for your Flex application users:$hostname_conn = "localhost"; // If your database and Flex app are on the same server $database_conn = "bigryans_flexphp"; // name you gave it in step 1 $username_conn = "bigryans_webuser"; // name you created in step 1 $password_conn = "webuser"; // password you gave it in step 1
Upload the files. You need the following subset of the files that the wizard outputs:
/history directory (if you want to support history management/deep linking)
/PEAR directory
AC_OETags.js
Flexphpconn.php
functions.inc.php
playerProdInstall.swf (if you want to support express installation)
Flex application files:
users.html (HTML wrapper)
users.swf (Flex application)
users.php (PHP functions for the Flex application)
XMLSerializer.class.php
You do not need to upload the xxx-profile.swf files, the projectname.swf file, or the projectname.html file.
Generating a J2EE database application
You can generate an application that uses Java and a SQL database. To generate this type of application, you must have a local Java application server and access to a target SQL database table. You can generate an application that uses a Java servlet to access a database and return data to the Flex application; or if you have LiveCycle Data Services ES, you can choose to generate an application that uses the data management service to access a database and dynamically distribute data to and from clients.
Generate J2EE application code
If you have not already done so, create a new Flex project that specifies Java 2 Enterprise Edition (J2EE) as the application server type.
Select Data > Create Application from Database.
From the Project list, select the J2EE project to use.
From the Connection list, select a database connection profile. To create and use a new connection profile, click the New button and complete the text boxes.
From the Table list, select the database table to use.
From the Primary Key list, select the primary key of the database table.
Click Next.
To use a specific Java package for the Java classes that will be generated, enter the package name in the Java Package text box.
By default, the names of the generated Java classes are prefixed with the name of the selected database table. To use a different prefix, enter it in the Class Name Prefix text box.
If your project uses LiveCycle Data Services ES, select whether to use LiveCycle Data Services ES or XML over HTTP for communication between the client and the server. If you select LiveCycle Data Services ES, the Data Management Service is used. If you select XML over HTTP, a servlet passes XML between the client and the server.
Click Next.
(Optional) Deselect any of the listed table fields to exclude them from the generated Flex DataGrid control.
Click Finish.
Select Run > External Tools > Run As > Run on Server.
Select Run > Run to run the application on the server.
Directory structure and deployment considerations for J2EE
The Flex Builder project's WebContent directory contains directories to be deployed into the root directory of the web application. Depending on the type of Java application server, the web application is deployed as a WAR file or, as is the case with Tomcat, as a linked web application directory. The Flex Builder project's src directory contains Java source files for classes that are deployed to the WEB-INF/classes directory of the web application. For projects that are compiled with Flex Builder, the contents of the Flex Builder project's bin and flex_src directories are included in the list of files that are deployed to the web application; however, the compiled SWF files are deployed rather than the corresponding MXML files that are in the flex_src directory. All of the files in those folders are deployed to the root of the web application.
Generating an ASP .NET database application
You can generate an application that uses ASP .NET and a Microsoft SQL Server database. To generate this type of application, you must have a local .NET installation and access to a target Microsoft SQL Server database table. You can generate an application that uses an ASP .NET page to access a database and return data to the Flex application.
Generate ASP .NET application code
If you have not already done so, create a new Flex project that specifies ASP .NET as the application server type. You can deploy the application to the Visual Studio Development Server or the Internet Information Server (IIS) web server that comes with Windows. If you use IIS, the deployment directory specified in the New Flex Project wizard must be defined in the IIS administration console as an ASP Application.
Select Data > Create Application from Database.
From the Project list, select the ASP .NET project to use.
From the Connection list, select a database connection profile. To create and use a new connection profile, click the New button and complete the text boxes.
From the Table list, select the database table to use.
From the Primary Key list, select the primary key of the database table.
Click Next.
Specify a .NET class name, or accept the default value.
Choose either C# with Web Services or VB with Web Services as the server language.
Click Next.
(Optional) Deselect any of the listed table fields to exclude them from the generated Flex DataGrid control.
Click Finish.
Select Run > External Tools > Run As > Run on Server.
Select Run > Run to run the application on the server.
Directory structure and deployment considerations for ASP .NET
When you run Project > Export Release Build, files are saved in the project bin_release directory and the optimized application runs from that location.
Creating a database connection profile
To generate a database application, you must have a database connection profile that provides information about the database that you want to use.
Create a connection profile
If the Create Application from Database dialog box is not already open, select Data > Create Application from Database.
Click the New button to the right of the Connection text box.
In the Create Connection Profile dialog box, enter a connection name in the Name text box. You can also complete the optional Description text box.
(Optional) When the wizard is finished or when the Data Source Explorer is opened, select the Autoconnect option to connect to the database.
Click New.
Complete the database connection text boxes. The fields vary depending on the type of database connection you choose. For PHP projects, you use MySQL. For ASP.NET projects, you use Microsoft SQL Server. For J2EE projects, you can select from a list of choices, but MySQL and Microsoft SQL Server are supported.
Click Test Connection to make sure that the connection is valid.
Click Next.
Click Finish.

No comments:

Post a Comment