PageRenderTime 5640ms CodeModel.GetById 31ms RepoModel.GetById 2ms app.codeStats 0ms

/EffiProz-CF/Core/Schema.cs

#
C# | 316 lines | 206 code | 75 blank | 35 comment | 4 complexity | 17803cdc48adddcb4c8b93ade6798d09 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. //
  2. // (C) Copyright 2009 Irantha Suwandarathna (iranthas@hotmail.com)
  3. // All rights reserved.
  4. //
  5. /* Copyright (c) 2001-2008, The HSQL Development Group
  6. * All rights reserved.
  7. *
  8. * Redistribution and use _in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * Redistributions of source code must retain the above copyright notice, this
  12. * list of conditions and the following disclaimer.
  13. *
  14. * Redistributions _in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer _in the documentation
  16. * and/or other materials provided with the distribution.
  17. *
  18. * Neither the name of the HSQL Development Group nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
  26. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  30. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. using System;
  35. using System.Collections.Generic;
  36. using System.Linq;
  37. using System.Text;
  38. using EffiProz.Core.Rights;
  39. using EffiProz.Core.Lib;
  40. using EffiProz.Core.Errors;
  41. namespace EffiProz.Core
  42. {
  43. public class Schema : SchemaObject
  44. {
  45. public QNameManager.QName name;
  46. public SchemaObjectSet triggerLookup;
  47. public SchemaObjectSet constraintLookup;
  48. public SchemaObjectSet indexLookup;
  49. public SchemaObjectSet tableLookup;
  50. public SchemaObjectSet sequenceLookup;
  51. public SchemaObjectSet typeLookup;
  52. public SchemaObjectSet charsetLookup;
  53. public SchemaObjectSet collationLookup;
  54. public SchemaObjectSet procedureLookup;
  55. public SchemaObjectSet functionLookup;
  56. public SchemaObjectSet specificRoutineLookup;
  57. public SchemaObjectSet assertionLookup;
  58. public HashMappedList tableList;
  59. public HashMappedList sequenceList;
  60. public Grantee owner;
  61. public Schema(QNameManager.QName name, Grantee owner)
  62. {
  63. this.name = name;
  64. triggerLookup = new SchemaObjectSet(SchemaObjectTypes.TRIGGER);
  65. indexLookup = new SchemaObjectSet(SchemaObjectTypes.INDEX);
  66. constraintLookup = new SchemaObjectSet(SchemaObjectTypes.CONSTRAINT);
  67. tableLookup = new SchemaObjectSet(SchemaObjectTypes.TABLE);
  68. sequenceLookup = new SchemaObjectSet(SchemaObjectTypes.SEQUENCE);
  69. typeLookup = new SchemaObjectSet(SchemaObjectTypes.TYPE);
  70. charsetLookup = new SchemaObjectSet(SchemaObjectTypes.CHARSET);
  71. collationLookup = new SchemaObjectSet(SchemaObjectTypes.COLLATION);
  72. procedureLookup = new SchemaObjectSet(SchemaObjectTypes.PROCEDURE);
  73. functionLookup = new SchemaObjectSet(SchemaObjectTypes.FUNCTION);
  74. specificRoutineLookup = new SchemaObjectSet(SchemaObjectTypes.SPECIFIC_ROUTINE);
  75. assertionLookup = new SchemaObjectSet(SchemaObjectTypes.ASSERTION);
  76. tableList = (HashMappedList)tableLookup.map;
  77. sequenceList = (HashMappedList)sequenceLookup.map;
  78. this.owner = owner;
  79. name.owner = owner;
  80. }
  81. public int getType()
  82. {
  83. return SchemaObjectTypes.SCHEMA;
  84. }
  85. public QNameManager.QName getName()
  86. {
  87. return name;
  88. }
  89. public QNameManager.QName getSchemaName()
  90. {
  91. return null;
  92. }
  93. public QNameManager.QName getCatalogName()
  94. {
  95. return null;
  96. }
  97. public Grantee getOwner()
  98. {
  99. return owner;
  100. }
  101. public OrderedHashSet getReferences()
  102. {
  103. return new OrderedHashSet();
  104. }
  105. public OrderedHashSet getComponents()
  106. {
  107. return null;
  108. }
  109. public void compile(Session session, SchemaObject parentObject) { }
  110. public String getSQL()
  111. {
  112. StringBuilder sb = new StringBuilder(128);
  113. sb.Append(Tokens.T_CREATE).Append(' ');
  114. sb.Append(Tokens.T_SCHEMA).Append(' ');
  115. sb.Append(name.statementName).Append(' ');
  116. sb.Append(Tokens.T_AUTHORIZATION).Append(' ');
  117. sb.Append(owner.getStatementName());
  118. return sb.ToString();
  119. }
  120. public String[] getSQLArray(OrderedHashSet resolved,
  121. OrderedHashSet unresolved)
  122. {
  123. EfzArrayList list = new EfzArrayList();
  124. StringBuilder sb = new StringBuilder(128);
  125. sb.Append(Tokens.T_CREATE).Append(' ');
  126. sb.Append(Tokens.T_SCHEMA).Append(' ');
  127. sb.Append(name.statementName).Append(' ');
  128. sb.Append(Tokens.T_AUTHORIZATION).Append(' ');
  129. sb.Append(owner.getStatementName());
  130. list.add(sb.ToString());
  131. sb.Length = (0);
  132. sb.Append(Tokens.T_SET).Append(' ');
  133. sb.Append(Tokens.T_SCHEMA).Append(' ');
  134. sb.Append(name.statementName);
  135. list.add(sb.ToString());
  136. //
  137. String[] subList;
  138. subList = charsetLookup.getSQL(resolved, unresolved);
  139. list.addAll(subList);
  140. subList = collationLookup.getSQL(resolved, unresolved);
  141. list.addAll(subList);
  142. subList = typeLookup.getSQL(resolved, unresolved);
  143. list.addAll(subList);
  144. subList = sequenceLookup.getSQL(resolved, unresolved);
  145. list.addAll(subList);
  146. subList = tableLookup.getSQL(resolved, unresolved);
  147. list.addAll(subList);
  148. subList = functionLookup.getSQL(resolved, unresolved);
  149. list.addAll(subList);
  150. subList = procedureLookup.getSQL(resolved, unresolved);
  151. list.addAll(subList);
  152. subList = assertionLookup.getSQL(resolved, unresolved);
  153. list.addAll(subList);
  154. //
  155. String[] array = new String[list.size()];
  156. list.toArray(array);
  157. return array;
  158. }
  159. public String[] getSequenceRestartSQL()
  160. {
  161. EfzArrayList list = new EfzArrayList();
  162. Iterator it = sequenceLookup.map.values().iterator();
  163. while (it.hasNext())
  164. {
  165. NumberSequence sequence = (NumberSequence)it.next();
  166. String ddl = sequence.getRestartSQL();
  167. list.add(ddl);
  168. }
  169. String[] array = new String[list.size()];
  170. list.toArray(array);
  171. return array;
  172. }
  173. public String[] getTriggerSQL()
  174. {
  175. EfzArrayList list = new EfzArrayList();
  176. Iterator it = tableLookup.map.values().iterator();
  177. while (it.hasNext())
  178. {
  179. Table table = (Table)it.next();
  180. String[] ddl = table.getTriggerSQL();
  181. list.addAll(ddl);
  182. }
  183. String[] array = new String[list.size()];
  184. list.toArray(array);
  185. return array;
  186. }
  187. public bool isEmpty()
  188. {
  189. return sequenceList.isEmpty() && tableList.isEmpty();
  190. }
  191. public Iterator schemaObjectIterator(int type)
  192. {
  193. switch (type)
  194. {
  195. case SchemaObjectTypes.SEQUENCE:
  196. return sequenceLookup.map.values().iterator();
  197. case SchemaObjectTypes.TABLE:
  198. case SchemaObjectTypes.VIEW:
  199. return tableLookup.map.values().iterator();
  200. case SchemaObjectTypes.CHARSET:
  201. return charsetLookup.map.values().iterator();
  202. case SchemaObjectTypes.COLLATION:
  203. return collationLookup.map.values().iterator();
  204. case SchemaObjectTypes.PROCEDURE:
  205. return procedureLookup.map.values().iterator();
  206. case SchemaObjectTypes.FUNCTION:
  207. return functionLookup.map.values().iterator();
  208. case SchemaObjectTypes.ROUTINE:
  209. Iterator functions = functionLookup.map.values().iterator();
  210. return new WrapperIterator(
  211. functions, procedureLookup.map.values().iterator());
  212. case SchemaObjectTypes.DOMAIN:
  213. case SchemaObjectTypes.TYPE:
  214. return typeLookup.map.values().iterator();
  215. case SchemaObjectTypes.ASSERTION:
  216. return assertionLookup.map.values().iterator();
  217. case SchemaObjectTypes.TRIGGER:
  218. return triggerLookup.map.values().iterator();
  219. case SchemaObjectTypes.INDEX:
  220. return indexLookup.map.values().iterator();
  221. case SchemaObjectTypes.CONSTRAINT:
  222. return constraintLookup.map.values().iterator();
  223. default:
  224. throw Error.runtimeError(ErrorCode.U_S0500, "Schema");
  225. }
  226. }
  227. public void clearStructures()
  228. {
  229. tableList.clear();
  230. sequenceList.clear();
  231. triggerLookup = null;
  232. indexLookup = null;
  233. constraintLookup = null;
  234. procedureLookup = null;
  235. functionLookup = null;
  236. sequenceLookup = null;
  237. tableLookup = null;
  238. typeLookup = null;
  239. }
  240. }
  241. }