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.dialect; 019 020import java.util.List; 021 022import net.sf.hajdbc.ForeignKeyConstraint; 023import net.sf.hajdbc.ForeignKeyConstraintFactory; 024import net.sf.hajdbc.IdentifierNormalizer; 025import net.sf.hajdbc.QualifiedName; 026import net.sf.hajdbc.QualifiedNameFactory; 027 028public class StandardForeignKeyConstraintFactory implements ForeignKeyConstraintFactory 029{ 030 final QualifiedNameFactory factory; 031 032 public StandardForeignKeyConstraintFactory(QualifiedNameFactory factory) 033 { 034 this.factory = factory; 035 } 036 037 @Override 038 public QualifiedNameFactory getQualifiedNameFactory() 039 { 040 return this.factory; 041 } 042 043 @Override 044 public ForeignKeyConstraint createForeignKeyConstraint(String name, final QualifiedName table, final QualifiedName foreignTable, final int deleteRule, final int updateRule, final int deferrability) 045 { 046 IdentifierNormalizer normalizer = this.factory.getIdentifierNormalizer(); 047 return new StandardForeignKeyConstraint(normalizer.normalize(name), table, new IdentifierList(normalizer), foreignTable, new IdentifierList(normalizer), deleteRule, updateRule, deferrability); 048 } 049 050 private static class StandardForeignKeyConstraint extends AbstractConstraint<ForeignKeyConstraint> implements ForeignKeyConstraint 051 { 052 private final QualifiedName foreignTable; 053 private final List<String> foreignColumns; 054 private final int deleteRule; 055 private final int updateRule; 056 private final int deferrability; 057 058 StandardForeignKeyConstraint(String name, QualifiedName table, List<String> columns, QualifiedName foreignTable, List<String> foreignColumns, int deleteRule, int updateRule, int deferrability) 059 { 060 super(name, table, columns); 061 this.foreignTable = foreignTable; 062 this.foreignColumns = foreignColumns; 063 this.deleteRule = deleteRule; 064 this.updateRule = updateRule; 065 this.deferrability = deferrability; 066 } 067 068 @Override 069 public QualifiedName getForeignTable() 070 { 071 return this.foreignTable; 072 } 073 074 @Override 075 public List<String> getForeignColumnList() 076 { 077 return this.foreignColumns; 078 } 079 080 @Override 081 public int getDeleteRule() 082 { 083 return this.deleteRule; 084 } 085 086 @Override 087 public int getUpdateRule() 088 { 089 return this.updateRule; 090 } 091 092 @Override 093 public int getDeferrability() 094 { 095 return this.deferrability; 096 } 097 } 098}