|
"Wiring" The Prototype A type.properties file that fits with the example MySQL database addressbook looks like this: _db = myDataSource _table = PERSON _id = ID firstname = FIRSTNAME lastname = LASTNAME email = EMAILWhat exactly happens here? The two lines at the beginning tell Helma to map the prototype Person and all its HopObjects derived from it to the table PERSON (please note the different case!) found via the database connection established with myDataSource the MySQL connector as defined before. So, _db defines the database connection (or: data source) and _table the database table to be used. What's missing are the details of how the relational table columns should be mapped to the object-oriented database. Most important is the mapping of the table's primary key index to the object-oriented database index: this key is necessary to provide a unique identifier for both, each entry in the relational database and each HopObject. And in consequence, _id maps the two to each other. Btw. _db, _table and _id are internal Helma properties. That's why they start with an underscore for not getting in the way of your custom properties. However, they are mandatory for each type.properties file. The five following lines assign each column of the relational table to a property of the HopObject. E.g. the data that is contained in the column FIRSTNAME of the table, becomes the value of the property firstname of the HopObject, the column LASTNAME is being mapped to the property lastname and so on. A recommended naming convention is to use lowercase (resp. mixed case) letters for HopObject properties and uppercase letters for database columns resp. table names. So, you achieved to represent the figure of HopObjects from the prior step with a few lines in type.properties. Save the type.properties in the folder of the corresponding HopObject - in this case in the Person folder. To generate the corresponding table in your database, you should be able to use an SQL statement such as the following. CREATE TABLE `PERSON` ( `ID` int(11) NOT NULL default '0', `FIRSTNAME` varchar(128) NOT NULL default '', `LASTNAME` varchar(128) NOT NULL default '', `EMAIL` varchar(128) NOT NULL default '', PRIMARY KEY (`ID`) );As a side remark, be aware of what names to choose for your HopObject's properties. Just as the database columns can be made up of any name as long as they do not conflict with MySQL keywords, you are restricted to use property names that do not represent reserved HopObject or ECMAScript keywords. A look in this documentation's reference section might help if you are in doubt.
... comment
|
navigation
Download
Community
Weblog
Mailing Lists
IRC Channel
Documentation
Introductions
Tools
Reference
Project
Roadmap
Bug Reporting
Source
Wiki
Tags
Updates
Related Projects
search
|
||||