#include <cookBook.hpp>

Public Member Functions | |
| CookBook (DatabasePtr _database, const std::string &inputXSLFileName, const std::string &outputXSLFileName, bool performVersionCheck=true) throw (Error) | |
| CompilerPtr | getXMLLayer (void) const |
| DatabasePtr | getDatabase (void) const |
| int | getVersion (void) const throw (Error) |
| Query database version. | |
| void | update (void) throw (Error) |
| Update database version. | |
Static Protected Member Functions | |
| static CompilerPtr | createXMLLayer (DatabasePtr _database, const std::string &inputXSLFileName, const std::string &outputXSLFileName) |
Protected Attributes | |
| DatabasePtr | database |
| Database. | |
| CompilerPtr | xmlLayer |
| Compiler-chain. | |
Use transactions.
Definition at line 31 of file cookBook.hpp.
| CookBook::CookBook | ( | DatabasePtr | _database, | |
| const std::string & | inputXSLFileName, | |||
| const std::string & | outputXSLFileName, | |||
| bool | performVersionCheck = true | |||
| ) | throw (Error) |
Constructor.
| _database | Database holding the recipes. | |
| inputXSLFileName | Filename of XSL-script translating XML-queries to the SQL-dialec of the database. | |
| outputXSLFileName | Filename of XSL-script adapting the structure of the output generated by the XSU-utility. | |
| performVersionCheck | This boolean has to be set to false, if the database is empty (no tables have been created yet). |
| CompilerPtr CookBook::getXMLLayer | ( | void | ) | const [inline] |
Get compiler-chain for accessing database. The returned compiler-chain is an XSU-utility with two XSL-scripts for pre- and postprocessing. The XSL-scripts are providing an abstraction- layer to hide the SQL-dialect of the database.
The following picture illustrates, how the compiler-chain is being used to extract a recipe for example:
Example for using compiler-chain
Definition at line 57 of file cookBook.hpp.
References xmlLayer.
00057 { return xmlLayer; }
| DatabasePtr CookBook::getDatabase | ( | void | ) | const [inline] |
Get direct access to database.
Definition at line 60 of file cookBook.hpp.
References database.
00060 { return database; }
| int CookBook::getVersion | ( | void | ) | const throw (Error) |
Query database version.
Definition at line 56 of file cookBook.cpp.
References XMLDocument::fromString(), XMLDocument::getDocumentElement(), and xmlLayer.
Referenced by update().
00057 { 00058 XMLDocument xmlDocument( "" ); 00059 xmlDocument.fromString 00060 ( xmlLayer->translate 00061 ( "<?xml version='1.0' encoding='UTF-8'?><version/>" ) ); 00062 int 00063 version = atoi( xmlDocument.getDocumentElement().selectNode( "version" ). 00064 getNodeText().c_str() ); 00065 return version; 00066 }
| void CookBook::update | ( | void | ) | throw (Error) |
Update database version.
Definition at line 68 of file cookBook.cpp.
References ERRORMACRO, getVersion(), versionText(), and xmlLayer.
00069 { 00070 // Read version number. 00071 int version = getVersion(); 00072 00073 // Check for minimum version requirement. 00074 ERRORMACRO( version >= 13, Error, , 00075 i18n( "Update for database versions 0.1 to 0.12 is not " 00076 "supported." ) ); 00077 00078 // Check against maximum version constraint. 00079 ERRORMACRO( version <= DATABASEVERSION, Error, , 00080 i18n( "Recipe database is of version %1. This software can " 00081 "only handle databases up to version %2. You need to " 00082 "update AnyMeal to access this database." ). 00083 arg( versionText( version ) ). 00084 arg( versionText( DATABASEVERSION ) ) ); 00085 00086 // Update database. 00087 stringstream query; 00088 query << "<?xml version='1.0' encoding='UTF-8'?>" << endl 00089 << "<update><version>" << version << "</version></update>" 00090 << endl; 00091 ofstream nullDevice( "/dev/null" ); 00092 xmlLayer->translate( query, nullDevice ); 00093 }
| static CompilerPtr CookBook::createXMLLayer | ( | DatabasePtr | _database, | |
| const std::string & | inputXSLFileName, | |||
| const std::string & | outputXSLFileName | |||
| ) | [static, protected] |
DatabasePtr CookBook::database [protected] |
CompilerPtr CookBook::xmlLayer [protected] |
Compiler-chain.
Definition at line 73 of file cookBook.hpp.
Referenced by getVersion(), getXMLLayer(), and update().