1 package com.daffodilwoods.daffodildb.server.sql99.ddl.revoke; 2 3 import java.util.*; 4 7 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 8 import com.daffodilwoods.daffodildb.server.serversystem.*; 9 import com.daffodilwoods.daffodildb.server.sql99.*; 10 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*; 11 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 12 import com.daffodilwoods.database.resource.*; 13 14 public class AbandonedTableConstraints { 15 ArrayList abandonedColumnConstraint; 16 ArrayList abandonedDomainConstraint; 17 _ServerSession serverSession; 18 AbandonedObjectHandler abanObjHan; 19 20 public AbandonedTableConstraints(AbandonedObjectHandler temp, _ServerSession serversession) throws DException { 21 serverSession = serversession; 22 abanObjHan = temp; 23 abandonedColumnConstraint = new ArrayList(); 24 abandonedDomainConstraint = new ArrayList(); 25 } 26 27 public void calculate(ColumnPrivilegeDescriptor cpd, _ServerSession currentSession) throws DException { 28 ArrayList userNSchema = abanObjHan.getUserNSchema(); 29 if (userNSchema == null) { 30 return; 31 } 32 calculateAbandonedTableConstraints_Referencetial(cpd, userNSchema, currentSession); 33 calculateAbandonedTableConstraint_Check(cpd, userNSchema, currentSession); 34 calculateAbandonedColumnConstraint_Check(cpd, userNSchema, currentSession); 35 calculateAbandonedDomainConstraint(cpd, userNSchema, currentSession); 36 } 37 38 public void process() throws DException { 39 for (int i = 0, size = abandonedColumnConstraint.size(); i < size; i++) { 40 TableConstraintDescriptor temp = (TableConstraintDescriptor) abandonedColumnConstraint.get(i); 41 temp.delete(serverSession); 42 serverSession.refreshConstraint(temp.getQualifiedTable()); 43 } 44 for (int i = 0, size = abandonedDomainConstraint.size(); i < size; i++) { 45 DomainConstraintDescriptor temp = (DomainConstraintDescriptor) abandonedDomainConstraint.get(i); 46 temp.delete(serverSession); 47 } 48 } 49 50 private void calculateAbandonedTableConstraints_Referencetial(ColumnPrivilegeDescriptor cpd, ArrayList userNSchema, _ServerSession currentSession) throws DException { 51 _Executer executerPrimaryKeyConstraint = ( (DataDictionary) currentSession.getDataDictionary()).getPreparedStatementGetter().getPrimaryConstraintExecuter(); 52 _SelectQueryIterator iter = (_SelectQueryIterator) executerPrimaryKeyConstraint.execute(new Object [] {cpd.object_catalog, cpd.object_schema, cpd.object_name, cpd.column_name}); 53 if (iter.first()) { 54 do { 55 TableConstraintDescriptor tableConstraintDes = new TableConstraintDescriptor(); 56 tableConstraintDes.loadDataFromRecord(iter, serverSession); 57 ArrayList foreignConstraint = tableConstraintDes.getReferentialConstraints(serverSession); 58 for (int i = 0, size = foreignConstraint.size(); i < size; i++) { 59 TableConstraintDescriptor temp = (TableConstraintDescriptor) foreignConstraint.get(i); 60 for (int j = 0, tempsize = userNSchema.size(); j < tempsize; j++) { 61 Object [] obj = (Object []) userNSchema.get(j); 62 if (cpd.getGrantee().equalsIgnoreCase( (String ) obj[0]) 63 && (temp.constraint_schema.equalsIgnoreCase( (String ) obj[1]) 64 && temp.constraint_catalog.equalsIgnoreCase( (String ) obj[2]))) { 65 addInList(temp); 66 } 67 } 68 } 69 } while (iter.next()); 70 } 71 } 72 73 private void calculateAbandonedTableConstraint_Check(ColumnPrivilegeDescriptor cpd, ArrayList userNSchema, _ServerSession currentSession) throws DException { 74 _Executer executerCheckTableConstraint = ( (DataDictionary) currentSession.getDataDictionary()).getPreparedStatementGetter().getCheckTableConstraintExecuter(); 75 _SelectQueryIterator iter = (_SelectQueryIterator) executerCheckTableConstraint.execute(new Object [] {cpd.object_catalog, cpd.object_schema, cpd.object_name}); 76 int listSize=abandonedColumnConstraint.size(); 77 if ( listSize > 0) { 78 for (int i = 0; i < listSize; i++) { 79 TableConstraintDescriptor tmp = (TableConstraintDescriptor) abandonedColumnConstraint.get(i); 80 if (! (tmp.table_catalog.equalsIgnoreCase(cpd.object_catalog) && tmp.table_schema.equalsIgnoreCase(cpd.object_schema) && 81 tmp.table_name.equalsIgnoreCase(cpd.object_name))) { 82 addAbandonedTableCheckConstraintInList(cpd, iter, serverSession, userNSchema); 83 } 84 } 85 } else { 86 addAbandonedTableCheckConstraintInList(cpd, iter, serverSession, userNSchema); 87 } 88 } 89 90 private void addAbandonedTableCheckConstraintInList(ColumnPrivilegeDescriptor cpd, _SelectQueryIterator iter, _ServerSession serverSession, ArrayList userNSchema) throws DException { 91 if (iter.first()) { 92 do { 93 TableConstraintDescriptor temp = new TableConstraintDescriptor(); 94 temp.loadDataFromRecord(iter, serverSession); 95 for (int j = 0, tempsize = userNSchema.size(); j < tempsize; j++) { 96 Object [] obj = (Object []) userNSchema.get(j); 97 if (cpd.getGrantee().equalsIgnoreCase( (String ) obj[0]) && (temp.constraint_schema.equalsIgnoreCase( (String ) obj[1]) && temp.constraint_catalog.equalsIgnoreCase( (String ) obj[2]))) { 98 addInList(temp); 99 } 100 } 101 } while (iter.next()); 102 } 103 104 } 105 106 private void calculateAbandonedColumnConstraint_Check(ColumnPrivilegeDescriptor cpd, ArrayList userNSchema, _ServerSession currentSession) throws DException { 107 _Executer executerCheckColumnConstraint = ( (DataDictionary) currentSession.getDataDictionary()).getPreparedStatementGetter().getCheckColumnConstraintExecuter(); 108 _SelectQueryIterator iter = (_SelectQueryIterator) executerCheckColumnConstraint.execute(new Object [] {cpd.object_catalog, cpd.object_schema, cpd.object_name, cpd.column_name}); 109 if (iter.first()) { 110 do { 111 TableConstraintDescriptor temp = new TableConstraintDescriptor(); 112 temp.loadDataFromRecord(iter, serverSession); 113 for (int j = 0, tempsize = userNSchema.size(); j < tempsize; j++) { 114 Object [] obj = (Object []) userNSchema.get(j); 115 if (cpd.getGrantee().equalsIgnoreCase( (String ) obj[0]) && (temp.constraint_schema.equalsIgnoreCase( (String ) obj[1]) && temp.constraint_catalog.equalsIgnoreCase( (String ) obj[2]))) { 116 addInList(temp); 117 } 118 } 119 } while (iter.next()); 120 } 121 } 122 123 private void calculateAbandonedDomainConstraint(ColumnPrivilegeDescriptor cpd, ArrayList userNSchema, _ServerSession currentSession) throws DException { 124 _Executer executerCheckDomainConstraint = ( (DataDictionary) currentSession.getDataDictionary()).getPreparedStatementGetter().getCheckConstraintForDomainExecuter(); 125 _SelectQueryIterator iter = (_SelectQueryIterator) executerCheckDomainConstraint.execute(new Object [] {cpd.object_catalog, cpd.object_schema, cpd.object_name, cpd.column_name}); 126 if (iter.first()) { 127 do { 128 DomainConstraintDescriptor temp = new DomainConstraintDescriptor(); 129 temp.loadDataFromRecord(serverSession, iter); 130 for (int j = 0, tempsize = userNSchema.size(); j < tempsize; j++) { 131 Object [] obj = (Object []) userNSchema.get(j); 132 if (cpd.getGrantee().equalsIgnoreCase( (String ) obj[0]) 133 && (temp.constraint_schema.equalsIgnoreCase( (String ) obj[1]) 134 && temp.constraint_catalog.equalsIgnoreCase( (String ) obj[2])) 135 && (!abandonedDomainConstraint.contains(temp))) { 136 abandonedDomainConstraint.add(temp); 137 } 138 } 139 } while (iter.next()); 140 } 141 } 142 143 private void addInList(TableConstraintDescriptor tcd) { 144 if (!abandonedColumnConstraint.contains(tcd)) { 145 abandonedColumnConstraint.add(tcd); 146 } 147 } 148 149 public void print_abandoned() { 150 } 151 } 152 | Popular Tags |