The Tours Sample Application and Sample Database,
Page 1 of 1
|

|
 Documentation Top

Global Index
Top of Demos |
The Tours Sample Application and Sample Database
Overview and Getting Started
The toursDB sample database is the foundation for most of the examples in the Cloudscape documentation. This database comes prebuilt in your installation under /demo/databases. Getting Started with Cloudscape offers instructions on the simplest way to connect to this database with Cloudscapes GUI tool, Cloudview.
This database also comes with a sample application, called JBMSTours, which you can run to see how a simple application interacts with the database. For example, the class CreateToursDB in the application builds the database. It creates the schema and inserts data into the database. The application includes other classes that you will want to look at.
You can also build the database using one of the main entry points in the application. Learning Cloudscape: The Tutorial takes you through all the steps of building and using the application and the sample database.
NOTE: This database and the accompanying application make heavy use of Cloudscapes object-relational features in order to show you how to use them. In practice, your database would probably make much greater use of the standard SQL-92 data types.
In addition, the javadoc for the package provides basic information for using the application.
Running the Application
Full information on working with the database and the application is provided in Learning Cloudscape: The Tutorial. These instructions provide a quick cheat sheet.
Before you begin, determine which environment you want to run in:
Embedded Environment
In an embedded environment, an instance of Cloudscape will run in same JVM as the application when the application starts. No network access is involved. Only one instance can access a database at a time.
|
In an embedded environment, an application starts up an instance of Cloudscape.
To run any of the applications in an embedded environment, or to access any of the object data in the database, the following libraries must be in your class path:
-
the main Cloudscape library for your product (since the application will start up an instance of Cloudscape)
-
the license library (license.jar), if you are working with the 30-day evaluation product
-
%CLOUDSCAPE_INSTALL%/demo/programs/tours (the library for these applications)
For users not working with Cloudscape synchronization, the main Cloudscape library is called cloudscape.jar and is found in the %CLOUDSCAPE_INSTALL%/lib directory. These users would set the class path as follows (Windows):
%CLOUDSCAPE_INSTALL%/lib/cloudscape.jar;
%CLOUDSCAPE_INSTALL%/demo/programs/tours;
For users who are working with Cloudscape synchronization, the main Cloudscape library is called cloudsync.jar. It is found in the %CLOUDSCAPE_INSTALL%/lib directory.
If you want to just build the database and run all the main programs in the application, run them in this order:
JBMSTours.CreateToursDB
Builds the database. java JBMSTours.CreateToursDB
JBMSTours.BuildATour (run it up to four times)
Builds a customer tour to two cities. java JBMSTours.BuildATour
JBMSTours.GenerateReport
Generates a report about data in the database. java JBMSTours.GenerateReport
JBMSTours.RunTime
Prints out runtime statistics for some queries. java JBMSTours.RunTime
JBMSTours.ArchiveData
Moves some old data to a database called History. java JBMSTours.ArchiveData
JBMSTours.CreateScript
Helps you create an SQL script you can use to rebuild a clean database. java JBMSTours.CreateScript
JBMSTours.AdminHelper
Shows you how to perform some administrative tasks such as backing up a database, running the consistency checker, turning on user authentication, and the like. java JBMSTours.AdminHelper legalargument
Or you could run all but the first one against the pre-built version. The easiest way to do that would be to run all the applications from the %CLOUDSCAPE_INSTALL%/demo/databases directory.
Client/Server Environment
In a client/server environment, Cloudscape is already running inside a server framework. The client application simply connects to it.
|
You can also run any of the applications with main methods as client applications that connect to Cloudscape running inside a connectivity (server) framework. This application supports the following frameworks:
-
Cloudconnector
-
RmiJdbc Server framework (provided with Cloudscape)
For quick-start information on starting one of these frameworks, see the simple demo. Follow those instructions, with the following addition: Before starting the server, add %CLOUDSCAPE_INSTALL%/demo/programs/tours to the class path.
To run any of the applications in a client environment, or to access any of the object data in the database, the following libraries must be in your class path:
-
The Cloudscape client library (%CLOUDSCAPE_INSTALL%/lib/client.jar), since the application will need the client driver
-
The server framework client libraries, /frameworks/cloudconnect/classes/, /frameworks/cloudconnect/lib/weblogicaux.jar, and /frameworks/cloudconnect/lib/license for Cloudconnector (WebLogic) or %CLOUDSCAPE_INSTALL%/frameworks/RmiJdbc/classes/RmiJdbc.jar for RmiJdbc
-
%CLOUDSCAPE_INSTALL%/demo/programs/tours (the library for these applications)
For example, you would set the class path to the following (Windows):
%CLOUDSCAPE_INSTALL%/lib/client.jar;
%CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/classes;
%CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/lib/
weblogicaux.jar;
%CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/license;
%CLOUDSCAPE_INSTALL%/demo/programs/tours;
You can run the same applications as you would in embedded environment (see Embedded Environment). To run the applications as client applications, you must provide two or three arguments when invoking them:
-
The host name of the server
-
The port number of the server
-
Add the single letter r as a final (third) argument if you are using the RmiJdbc framework.
-
If the program takes any other arguments, put those at the end.
For example, to run JBMSTours.CreateToursDB in a client environment when your framework is Cloudconnector, which is running on your own machine in the default port, you would type:
java JBMSTours.CreateToursDB localhost 7001
To run JBMSTours.CreateToursDB in client environment when your framework is RmiJdbc, which is running on your own machine in the default port, you would type:
java JBMSTours.CreateToursDB localhost 1099 r
Run the CreateToursDB application before running any of the others, so that you have a database to work with.
To run JBMSTours.AdminHelper with the argument back_up in the RmiJdbc framework, you would type:
java JBMSTours.AdminHelper localhost 1099 r back_up
What You Can Learn
The JBMSTours application provides examples of several different things you can do with an application using Cloudscape as a data manager. Here are some of the highlights:
-
Connecting to a database (see ApplicationMode javadoc source)
-
Creating tables and indexes (see CreateSchema javadoc source)
-
Creating and executing SQL statements (several classes)
-
Storing SQL-92 data types in the database (see InsertFlights javadoc source)
-
Storing Java data types in the database (see InsertCities javadoc source)
-
Creating stored prepared statements (see CreateSchema javadoc source)
-
Using stored prepared statements (see FlightBuilder javadoc source)
-
Simple queries (see InsertCountries javadoc source)
-
Complex queries (see FlightBuilder javadoc source))
-
Using PreparedStatements for performance (many classes, (see InsertCountries javadoc source))
-
Using the databases object-relational features (Java-SQL integration) (several classes, but see especially City javadoc source)
-
Using java.io.Serializable and java.io.Externalizable for storing Java data types (several classes)
-
Analyzing the performance of queries (see RunTime javadoc source))
-
Using SQL Aggregates, which are useful in reports (see GenerateReport javadoc source)
-
Using complex Database-side methods (see ArchiveData javadoc source)
-
Storing images (see InsertMaps javadoc source))
-
Using multiple connections from a single application (see HotelStay javadoc source)
-
Using a VTI class in a query (see HotelStay javadoc source)
-
Running in an embedded or client/server environment (see ApplicationMode javadoc source)
Fun Queries to Try
The savvy user will want to get straight to the heart of the matter. Queries!
To use the tool ij, add %CLOUDSCAPE_INSTALL%/lib/tools.jar to your class path. Once you start ij, you can connect to toursDB like this:
Connect 'jdbc:cloudscape:toursDB';
Or, if youre in a client/server environment, like this:
Connect 'jdbc:cloudscape:weblogic:toursDB';
Try out some of these queries (from the tutorial):
SELECT * FROM Flights
WHERE orig_airport = 'JFK'
AND flying_time > 5;
SELECT Country, City FROM Countries JOIN Cities
USING (country_ISO_code);
SELECT Flights.flight_id, Flights.segment_number, flight_date,
economy_seats_taken, business_seats_taken,
firstclass_seats_taken
FROM Flights JOIN FlightAvailability
USING (flight_id, segment_number);
SELECT city.getName() AS CITY, hotel_name
AS HOTEL, booking_date, rooms_taken
FROM Cities, Hotels, HotelAvailability
WHERE Cities.city_id = Hotels.city_id
AND Hotels.hotel_id = HotelAvailability.hotel_id;
SELECT NEW JGroup(group_id, number_kids, number_adults,
number_people, main_person, number_rooms, city_id, address,
phone, tour_level, budget,
running_total).toString(getCurrentConnection()) FROM Groups;
SELECT customized_tour.toString()
FROM CustomizedTours;
SELECT city->language FROM Cities;
SELECT city.getName(), city.getDistanceFrom(
(SELECT city FROM Cities WHERE city_id = 35))
AS MILES_FROM_PARIS FROM cities;
SELECT city.getName(),
city.getTimeDifference(getCurrentConnection(),
CURRENT_DATE, 'JFK')
AS CurrentTimeDifFromNewYork
FROM Cities
WHERE city_id = 35;
VALUES (findcity(GETCURRENTCONNECTION(),
'Amsterdam', 'Netherlands').toString());
VALUES (findcity(GETCURRENTCONNECTION(), 'AMS').toString());
CALL cleanOutFlightAvailability(GETCURRENTCONNECTION());
CREATE STATEMENT findRoomsTaken
AS SELECT rooms_taken
FROM HotelAvailability
WHERE hotel_id = ? AND booking_date = ?;
EXECUTE STATEMENT findRoomsTaken
USING VALUES (5, current_date);
VALUES FlightBuilder.
returnAnyFlight(getCurrentConnection() ,
'SFO','MAD').toString();
VALUES FlightBuilder.returnAnyFlight(
getCurrentConnection(), 'JFK','CAI').toString();
SELECT color, food
FROM
(VALUES ('orange', 'orange'), ('apple', 'red'),
('banana', 'yellow'))
AS Fruits_And_Colors(fruit, color)
JOIN
(VALUES ('orange', 'orange juice'), ('apple', 'pie'), ('apple',
'muffins'),('banana', 'bread'),
('banana', 'meringue pie'))
AS Fruits_And_Foods(fruit, food)
USING (fruit);
SELECT AVG(customized_tour.getTotalMilesTraveled())
FROM CustomizedTours;
SELECT MIN(miles)
FROM Flights
WHERE orig_airport = 'SFO';
SELECT MAX(city.showTemperature()), Region
FROM Cities JOIN Countries USING (country_ISO_code)
GROUP BY Region;
INSERT INTO people
VALUES (26, NEW Person('Your', 'Name'));
SELECT (CAST (person AS Adult)).getPassportNumber()
FROM People
WHERE person INSTANCEOF Adult;
Pictures in the Database
To see some pictures stored in the database, go straight to that section in the tutorial.
Whats New in the Version 3.0 Database and Application?
Changes in Pre-Built Database
-
A jar file is stored in the database.
Changes to Database Schema
-
Class aliases
-
More method aliases
-
Triggers
-
Table for storing next values for pseudo-auto-increment columns
-
A new view, Locks (which queries the new LockTable VTI)
-
More stored prepared statements
-
Default values for some tables
Changes to Classes in JBMSTours package
-
The JBMSTours package structure has been changed. Now there are several subpackages such as JBMSTours.aggregates, JBMSTours.triggeractions, JBMSTours.serializabletypes, and the like. For example, the class City has been moved into the serializabletypes subpackage. It is now JBMSTours.serializabletypes.City.
-
Improved static methods for working with dates and times in JBMSTours.JCalendar
-
The application now includes servlets, applets, vtis, and aggregates.
-
New class with main methods: JBMSTours.AdminHelper
-
Reorganization of the JBMSTours.CreateSchema class.
-
JBMSTours.ApplicationMode uses new RmiJdbc driver and protocol.
-
JBMSTours.serializabletypes.City, JBMSTours.serializabletypes.Location, and JBMSTours.serializabletypes.TimeZones provide a compareTo method and are thus orderable Java data types. That means that you can use <, =, and > comparison operators on them within SQL-J statements and create indexes on them.
|