| 1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors; 2 3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 7 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.parser.*; 9 import com.daffodilwoods.database.general.*; 10 import com.daffodilwoods.database.resource.*; 11 12 public class DomainConstraintDescriptor extends ConstraintDescriptor { 13 14 17 18 public String constraint_catalog; 19 public String constraint_schema; 20 public String constraint_name; 21 public String domain_catalog; 22 public String domain_schema; 23 public String domain_name; 24 public CheckConstraintDescriptor checkConsDes; 25 public DomainDescriptor domainDes; 26 27 public DomainConstraintDescriptor() throws DException { 28 } 29 30 public void save(_ServerSession serverSession) throws DException { 31 try { 32 SqlSchemaConstants.insert(serverSession, SqlSchemaConstants.domain_constraints_TableName, null, 33 new Object [] { 34 constraint_catalog, 35 constraint_schema, 36 constraint_name, 37 domain_catalog, 38 domain_schema, 39 domain_name, 40 is_deferrable, 41 initially_deferred 42 }); 43 } catch (PrimaryConstraintException de) { 44 DException tde = new DException("DSE1145", new Object [] {getName()}); 45 throw tde; 46 } catch (SizeMisMatchException de) { 47 if (de.getDseCode().equals("DSE773")) { 48 DException tde = new DException("DSE8103", null); 49 throw tde; 50 } 51 } catch (DException de) { 52 if (de.getDseCode().equals("DSE1255")) { 53 DException tde = new DException("DSE1145", new Object [] {getName()}); 54 throw tde; 55 } 56 if (de.getDseCode().equals("DSE773")) { 57 DException tde = new DException("DSE8103", null); 58 throw tde; 59 } 60 throw de; 61 } 62 } 63 64 public void load(_ServerSession serverSession) throws DException { 65 DataDictionary dd = (DataDictionary) serverSession.getDataDictionary(); 66 67 _SelectQueryIterator domain_constraint_iterator = (_SelectQueryIterator) dd.getPreparedStatementGetter().getDomainConstraintsTableExecuter().executeForFresh(new Object [] {constraint_catalog, constraint_schema, constraint_name}); 68 if (!domain_constraint_iterator.first()) { 69 throw new DException("DSE339", new Object [] {constraint_catalog, constraint_schema, constraint_name}); 70 } 71 loadDataFromRecord(domain_constraint_iterator); 72 } 73 74 public void setDomainDescriptor(DomainDescriptor domainDescriptor) throws 75 DException { 76 domainDes = domainDescriptor; 77 domain_catalog = domainDescriptor.catalog_name; 78 domain_schema = domainDescriptor.schema_name; 79 domain_name = domainDescriptor.domain_name; 80 } 81 82 public void delete(_ServerSession serverSession) throws DException { 83 String bve = "CONSTRAINT_CATALOG=? and CONSTRAINT_SCHEMA=? and CONSTRAINT_NAME=?"; 84 _ServerSession globalSession = serverSession.getGlobalSession(); 85 booleanvalueexpression condition = ConditionParser.parseCondition(bve, globalSession, SqlSchemaConstants.domain_constraints_TableName); 86 super.delete(serverSession, SqlSchemaConstants.domain_constraints_TableName, condition, new Object [] {constraint_catalog, constraint_schema, constraint_name}); 87 deleteConstraints(serverSession); 88 } 89 90 private void deleteConstraints(_ServerSession serverSession) throws DException { 91 loadConstraint(serverSession); 92 checkConsDes.delete(serverSession); 93 } 94 95 private void loadConstraint(_ServerSession serverSession) throws DException { 96 if (checkConsDes == null) { 97 checkConsDes = new CheckConstraintDescriptor(); 98 checkConsDes.constraint_catalog = constraint_catalog; 99 checkConsDes.constraint_schema = constraint_schema; 100 checkConsDes.constraint_name = constraint_name; 101 checkConsDes.load(serverSession); 102 checkConsDes.domainConstraintDescriptor = this; 103 } 104 } 105 106 public void loadDataFromRecord(_SelectQueryIterator iter) throws DException { 107 Object [] obj = (Object []) iter.getObject(); 108 constraint_catalog = (String ) obj[SystemTablesFields. 109 domainConstraint_constraint_catalog]; 110 constraint_schema = (String ) obj[SystemTablesFields. 111 domainConstraint_constraint_schema]; 112 constraint_name = (String ) obj[SystemTablesFields. 113 domainConstraint_constraint_name]; 114 domain_catalog = (String ) obj[SystemTablesFields. 115 domainConstraint_domain_catalog]; 116 domain_schema = (String ) obj[SystemTablesFields. 117 domainConstraint_domain_schema]; 118 domain_name = (String ) obj[SystemTablesFields.domainConstraint_domain_name]; 119 is_deferrable = (String ) obj[SystemTablesFields. 120 domainConstraint_is_deferrable]; 121 initially_deferred = (String ) obj[SystemTablesFields. 122 domainConstraint_initially_deferred]; 123 } 124 125 public void loadDataFromRecord(_ServerSession serverSession, _SelectQueryIterator iter) throws 126 DException { 127 loadDataFromRecord(iter); 128 loadConstraint(serverSession); 129 } 130 131 private String getName() throws DException { 132 return new StringBuffer ().append(constraint_catalog).append(".").append( 133 constraint_schema).append(".").append(constraint_name).toString(); 134 } 135 136 public boolean equals(Object parm1) { 137 if (! (parm1 instanceof DomainConstraintDescriptor)) { 138 return false; 139 } 140 DomainConstraintDescriptor des = (DomainConstraintDescriptor) parm1; 141 return constraint_catalog.equalsIgnoreCase(des.constraint_catalog) 142 && constraint_schema.equalsIgnoreCase(des.constraint_schema) 143 && constraint_name.equalsIgnoreCase(des.constraint_name); 144 } 145 146 public int getDescriptorType() { 147 return DOMAIN_CONSTRAINT_DESCRIPTOR; 148 } 149 150 public void setGeneratedConstraintName(_ServerSession serverSession) throws 151 DException { 152 constraint_catalog = domain_catalog; 153 constraint_schema = domain_schema; 154 constraint_name = serverSession.getDataDictionary(). 155 generateDomianConstraintName(); 156 } 157 158 public boolean isDeffered() { 159 return is_deferrable.equalsIgnoreCase(SqlSchemaConstants.YES) && 160 initially_deferred.endsWith(SqlSchemaConstants.YES); 161 } 162 } 163 | Popular Tags |