4.3. Project structure
This is roughly what the structure passed to the generator looks like:
<?xml version="1.0" encoding="utf-8"?>
<Project Software="OrmFactory.com" Name="0f">
<Database Name="Schemas">
<Schema Name="0f">
<Table Name="ReleaseFiles" ClassName="ReleaseFile"
RepositoryName="ReleaseFiles">
<Column Name="Id" DatabaseType="int(11)"
FieldName="Id"
PrimaryKey="true"
AutoIncrement="true" />
<Column Name="VersionId" DatabaseType="int(11)"
FieldName="VersionId" />
<Column Name="ChannelId" DatabaseType="int(11)"
FieldName="ChannelId" />
<Column Name="Checksum" DatabaseType="tinytext"
FieldName="Checksum" />
<Column Name="FileSize" DatabaseType="int(11)"
FieldName="FileSize" />
<Column Name="Filename" DatabaseType="tinytext"
FieldName="Filename" />
<Column Name="CreatedDate" DatabaseType="datetime"
FieldName="CreatedDate"
Default="current_timestamp()" />
<Column Name="FileType" DatabaseType="int(11)"
FieldName="FileType" Default="0" />
<ForeignKey Name="FK_VersionId_Versions_Id"
FieldName="Version"
ToFieldName="Id"
ToClassName="Version"
FromColumn="VersionId"
FromFieldName="VersionId"
ToColumn="Versions.Id" />
<ForeignKey Name="FK_ChannelId_ReleaseChannels_Id"
FieldName="Channel"
ToFieldName="Id"
ToClassName="ReleaseChannel"
FromColumn="ChannelId"
FromFieldName="ChannelId"
ToColumn="ReleaseChannels.Id" />
<ReverseKey Name="FK_ReleaseFileId_ReleaseFiles_Id"
FieldName="ReleaseFile_DownloadLogs"
ToFieldName="ReleaseFileId"
ToClassName="DownloadLog"
FromColumn="Id"
FromFieldName="ID"
ToColumn="DownloadLog.ReleaseFileId" />
</Table>
</Schema>
</Database>
</Project>
This structure is similar to the project structure, but has a few differences. There are no connections, generators, layouts, only the hierarchical structure of the DBMS.
The structure itself is supplemented with new fields generated by the application for the convenience of code generation. The Table element now has ClassName and RepositoryName tags. The Column element has a FieldName tag.
These tags undergo name conversion in accordance with the generator settings, and the first two are also singularized and pluralized accordingly.
The table name and column name remains as is. Here's an example of the same table with the SCREAMING_SNAKE_CASE
setting applied (data types are omitted for brevity):
<Table Name="ReleaseFiles" ClassName="RELEASE_FILE"
RepositoryName="RELEASE_FILES">
<Column Name="Id" FieldName="ID"
PrimaryKey="true" AutoIncrement="true" />
<Column Name="VersionId" FieldName="VERSION_ID" />
<Column Name="ChannelId" FieldName="CHANNEL_ID" />
<Column Name="Checksum" FieldName="CHECKSUM" />
<Column Name="FileSize" FieldName="FILE_SIZE" />
<Column Name="Filename" FieldName="FILENAME" />
<Column Name="CreatedDate" FieldName="CREATED_DATE"
Default="current_timestamp()" />
<Column Name="FileType" FieldName="FILE_TYPE" Default="0" />
<ForeignKey Name="FK_VersionId_Versions_Id"
FieldName="VERSION"
ToFieldName="ID"
ToClassName="VERSION"
FromColumn="VersionId"
FromFieldName="VERSION_ID"
ToColumn="Versions.Id" />
<ForeignKey Name="FK_ChannelId_ReleaseChannels_Id"
FieldName="CHANNEL"
ToFieldName="ID"
ToClassName="RELEASE_CHANNEL"
FromColumn="ChannelId"
FromFieldName="CHANNEL_ID"
ToColumn="ReleaseChannels.Id" />
<ReverseKey Name="FK_ReleaseFileId_ReleaseFiles_Id"
FieldName="RELEASE_FILE_DOWNLOAD_LOGS"
ToFieldName="RELEASE_FILE_ID"
ToClassName="DOWNLOAD_LOG"
FromColumn="Id"
FromFieldName="ID"
ToColumn="DownloadLog.ReleaseFileId" />
</Table>
In addition to the foreign key element, which is needed to create accessors from other tables (many-to-one), you may see a "reverse key" element. It represents a foreign key located in another table that references the current entity. This is done to make it easier to generate one-to-many accessors.
How to parse structure
We recommend using Python’s built-in ElementTree
library.
This simple script will output your project structure to the output window:
import sys
import xml.etree.ElementTree as ET
xmlFile = sys.argv[1]
root = ET.parse(xmlFile).getroot()
for db in root.findall('Database'):
print(db.attrib["Name"])
for schema in db.findall('Schema'):
print("| ", schema.attrib["Name"])
for table in schema.findall('Table'):
print("| | ", table.attrib["Name"])
for column in table.findall('Column'):
print("| | | ", column.attrib["Name"])
The output will look something like this:
Schemas
| 0f
| | ReleaseChannels
| | | Id
| | | OS
| | | Architecture
| | | IsSelfContained
| | | CreatedDate
| | ReleaseFiles
| | | Id
| | | VersionId
| | | ChannelId
| | | Checksum
| | | FileSize
| | | Filename
| | | CreatedDate
| | | FileType
| | Versions
| | | Id
| | | VersionName
| | | ReleaseDate
| | | WhatsNew
| | | CreatedDate
For more complex examples, see the section 4.4. Generator examples