2008-06-17 16:27:32 +00:00
/* -------------------------------------------------------------------------- */
2009-01-26 18:25:15 +00:00
/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad */
2008-06-17 16:27:32 +00:00
/* Complutense de Madrid (dsa-research.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
# ifndef TEMPLATE_SQL_H_
# define TEMPLATE_SQL_H_
# include <iostream>
# include <map>
# include <vector>
# include "Template.h"
# include "SqliteDB.h"
# include "ObjectSQL.h"
using namespace std ;
/**
* SQL Template class , it provides DB support for template objects
*/
class TemplateSQL : public Template , public ObjectSQL
{
public :
TemplateSQL (
const char * _table ,
int template_id = - 1 ,
2008-06-18 15:58:44 +00:00
bool replace = false ,
2009-02-14 22:32:21 +00:00
const char separator = ' = ' ,
const char * xml_root = " TEMPLATE " ) :
Template ( replace , separator , xml_root ) , table ( _table ) , id ( template_id )
2008-06-17 16:27:32 +00:00
{ } ;
virtual ~ TemplateSQL ( ) { } ;
2009-03-06 12:10:15 +00:00
2008-06-17 16:27:32 +00:00
protected :
//Database implementation variables
2009-03-06 12:10:15 +00:00
2008-06-17 16:27:32 +00:00
const char * table ;
static const char * db_names ;
2009-03-06 12:10:15 +00:00
2008-06-17 16:27:32 +00:00
//Template attributes
2009-03-06 12:10:15 +00:00
2008-06-17 16:27:32 +00:00
/**
* Template unique identification .
*/
int id ;
2009-03-06 12:10:15 +00:00
2008-06-17 16:27:32 +00:00
/**
* Writes the template in the DB
* @ param db pointer to the database .
* @ return 0 on success .
*/
int insert ( SqliteDB * db ) ;
2009-03-06 12:10:15 +00:00
2008-06-17 16:27:32 +00:00
/**
* Updates the template in the DB
* @ param db pointer to the database .
* @ return 0 on success .
*/
int update ( SqliteDB * db ) ;
/**
* Reads the template ( identified by its id ) from the DB
* @ param db pointer to the database .
* @ return 0 on success .
*/
int select ( SqliteDB * db ) ;
/**
* Removes the template from the DB
* @ param db pointer to the database .
*/
2008-07-20 22:41:20 +00:00
int drop ( SqliteDB * db ) ;
/**
2009-03-06 12:10:15 +00:00
* Removes a template attribute from the DB . If there are multiple
* attributes with the same name , only one will be replaced . The attribute
* MUST be allocated in the heap .
* @ param db pointer to the database .
* @ param attribute pointer to the new attribute .
*/
int replace_attribute ( SqliteDB * db , Attribute * attribute ) ;
/**
* Insert a given attribute ( MUST be allocated in the heap ) in the template
* and updates the DB .
2008-07-20 22:41:20 +00:00
* @ param db pointer to the database .
2009-03-06 12:10:15 +00:00
* @ param attribute pointer to the new attribute
2008-07-20 22:41:20 +00:00
*/
2009-03-06 12:10:15 +00:00
int insert_attribute ( SqliteDB * db , Attribute * attribute ) ;
2008-06-17 16:27:32 +00:00
} ;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
# endif /*TEMPLATE_SQL_H_*/