001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc;
019
020
021/**
022 * @author Paul Ferraro
023 */
024public interface TriggerSupport
025{
026        enum TriggerEventEnum implements TriggerEvent
027        {
028                INSERT(TriggerTimeEnum.AFTER, true), UPDATE(TriggerTimeEnum.AFTER, false), DELETE(TriggerTimeEnum.BEFORE, null);
029                
030                private final TriggerTime time;
031                private final Boolean value;
032                
033                private TriggerEventEnum(TriggerTime time, Boolean value)
034                {
035                        this.time = time;
036                        this.value = value;
037                }
038
039                @Override
040                public TriggerTime getTime()
041                {
042                        return this.time;
043                }
044                
045                @Override
046                public Boolean getValue()
047                {
048                        return this.value;
049                }
050                
051                static TriggerEvent valueOf(Boolean value)
052                {
053                        for (TriggerEventEnum event: TriggerEventEnum.values())
054                        {
055                                if (((value != null) && (event.value != null)) ? value.equals(event.value) : (value == event.value))
056                                {
057                                        return event;
058                                }
059                        }
060                        
061                        throw new IllegalArgumentException();
062                }
063        }
064        
065        enum TriggerTimeEnum implements TriggerTime
066        {
067                BEFORE("OLD"), AFTER("NEW");
068                
069                private final String alias;
070                
071                private TriggerTimeEnum(String alias)
072                {
073                        this.alias = alias;
074                }
075                
076                @Override
077                public String getAlias()
078                {
079                        return this.alias;
080                }
081        }
082        
083        String getTriggerRowAlias(TriggerTime time);
084        
085        String getCreateTriggerSQL(String name, TableProperties table, TriggerEvent event, String action);
086        
087        String getDropTriggerSQL(String name, TableProperties table);
088}