1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*
# PostgreSQL Database Modeler (pgModeler)
#
# (c) Copyright 2006-2026 - Raphael Araújo e Silva <raphael@pgmodeler.io>
#
# DEVELOPMENT, MAINTENANCE AND COMMERCIAL DISTRIBUTION BY:
# Nullptr Labs Software e Tecnologia LTDA <contact@nullptrlabs.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# The complete text of GPLv3 is at LICENSE file on source code root directory.
# Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
*/
#include "rule.h"
#include "utilsns.h"
Rule::Rule()
{
execution_type=ExecutionType::Null;
obj_type=ObjectType::Rule;
attributes[Attributes::EventType]="";
attributes[Attributes::Table]="";
attributes[Attributes::Condition]="";
attributes[Attributes::ExecType]="";
attributes[Attributes::Commands]="";
}
void Rule::setCommandsAttribute()
{
QString str_cmds;
unsigned i, qtd;
qtd=commands.size();
for(i=0; i < qtd; i++)
{
str_cmds+=commands[i];
if(i < (qtd-1)) str_cmds+=";";
}
attributes[Attributes::Commands]=str_cmds;
}
void Rule::setEventType(EventType type)
{
setCodeInvalidated(event_type != type);
event_type=type;
}
void Rule::setExecutionType(ExecutionType type)
{
setCodeInvalidated(execution_type != type);
execution_type=type;
}
void Rule::setConditionalExpression(const QString &expr)
{
setCodeInvalidated(conditional_expr != expr);
conditional_expr=expr;
}
void Rule::addCommand(const QString &cmd)
{
//Raises an error if the command is empty
if(cmd.isEmpty())
throw Exception(ErrorCode::InsEmptyRuleCommand,__PRETTY_FUNCTION__,__FILE__,__LINE__);
else
{
QString cmd_aux=cmd;
cmd_aux.remove(';');
commands.push_back(cmd_aux);
setCodeInvalidated(true);
}
}
EventType Rule::getEventType()
{
return event_type;
}
ExecutionType Rule::getExecutionType()
{
return execution_type;
}
QString Rule::getConditionalExpression()
{
return conditional_expr;
}
QString Rule::getCommand(unsigned cmd_idx)
{
//Raises an error if the command index is out of bound
if(cmd_idx >= commands.size())
throw Exception(ErrorCode::RefRuleCommandInvalidIndex,__PRETTY_FUNCTION__,__FILE__,__LINE__);
return commands[cmd_idx];
}
unsigned Rule::getCommandCount()
{
return commands.size();
}
void Rule::removeCommand(unsigned cmd_idx)
{
//Raises an error if the command index is out of bound
if(cmd_idx>=commands.size())
throw Exception(ErrorCode::RefRuleCommandInvalidIndex,__PRETTY_FUNCTION__,__FILE__,__LINE__);
commands.erase(commands.begin() + cmd_idx);
setCodeInvalidated(true);
}
void Rule::removeCommands()
{
commands.clear();
setCodeInvalidated(true);
}
QString Rule::getSourceCode(SchemaParser::CodeType def_type)
{
QString code_def=getCachedCode(def_type, false);
if(!code_def.isEmpty()) return code_def;
setCommandsAttribute();
attributes[Attributes::Condition]=conditional_expr;
attributes[Attributes::ExecType]=(~execution_type);
attributes[Attributes::EventType]=(~event_type);
if(getParentTable())
attributes[Attributes::Table]=getParentTable()->getName(true);
return BaseObject::__getSourceCode(def_type);
}
void Rule::generateHashCode()
{
TableObject::generateHashCode();
hash_code = UtilsNs::getStringHash(hash_code + ~execution_type + ~event_type);
}
|