public override void StartElement(XmlReader reader, IDictionary<String, String> attributes)
        {

            String localName = reader.Name;
            tempValue = new StringBuilder();

            if (localName.Equals(Constants.ENTITY_DESCRIPTOR, StringComparison.OrdinalIgnoreCase))
            {
                entityDescriptor = new EntityDescriptor();
            }
            else if (localName.Equals(Constants.ENTITY_DESCRIPTOR_PROPERTY, StringComparison.OrdinalIgnoreCase))
            {
                propertyName = attributes[Constants.ENTITY_DESCRIPTOR_NAME];
            }
            else if (localName.Equals(Constants.ENTITY_DESCRIPTOR_ATTRIBUTE, StringComparison.OrdinalIgnoreCase))
            {
                currentAttribute = new EntityDescriptor.Attribute();
                isAttribute = true;
            }
            else if (localName.Equals(Constants.ENTITY_DESCRIPTOR_INDEX, StringComparison.OrdinalIgnoreCase))
            {
                currentIndex = new EntityDescriptor.Index();
                isIndex = true;
            }
            else if (localName.Equals(Constants.ENTITY_DESCRIPTOR_RELATIONSHIP, StringComparison.OrdinalIgnoreCase))
            {
                currectRelationship = new EntityDescriptor.Relationship();
                isRelationship = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Is used to create a new index on a table in database
        /// <para>
        /// Create Index On Book table
        /// <code>
        ///        String indexName = "BOOK_INDEX_BASED_ON_AUTHOR";
        ///        boolean isUnique = true;
        ///
        ///        Collection<String> columnNames = new ArrayList<String>();
        ///        columnNames.Add("LINK");
        ///
        ///        try {
        ///            new Book().CreateIndex(indexName, columnNames.GetEnumerator(), isUnique);
        ///        } catch(DatabaseException databaseException) {
        ///            //Log It.
        ///        }
        /// </code>
        /// </para>
        /// </summary>
        /// <param name="entityDescriptor">Entity Descriptor object which defines the structure of table</param>
        /// <param name="indexName">Name of index</param>
        /// <param name="columnNames">Iterator over column names</param>
        /// <param name="isUnique">true/false whether index needs to be unique or not. (A unique index guarantees that the index key contains no duplicate values and therefore every row in the table is in some way unique</param>
        /// <exception cref="Siminov.Core.Exception.DatabaseException">If not able to create index on table</exception>
        public static void CreateIndex(EntityDescriptor entityDescriptor, String indexName, IEnumerator<String> columnNames, bool isUnique)
        {

            DatabaseDescriptor databaseDescriptor = GetDatabaseDescriptor(entityDescriptor.GetClassName());
            DatabaseBundle databaseBundle = resourceManager.GetDatabaseBundle(databaseDescriptor.GetDatabaseName());

            IDatabaseImpl database = databaseBundle.GetDatabase();
            IQueryBuilder queryBuilder = databaseBundle.GetQueryBuilder();

            if (database == null)
            {
                Log.Log.Error(typeof(DatabaseHelper).FullName, "CreateIndex", "No Database Instance Found For ENTITY-DESCRIPTOR: " + entityDescriptor.GetClassName());
                throw new DeploymentException(typeof(DatabaseHelper).FullName, "CreateIndex", "No Database Instance Found For ENTITY-DESCRIPTOR: " + entityDescriptor.GetClassName());
            }

            ICollection<String> columnNamesCollection = new List<String>();
            while (columnNames.MoveNext())
            {
                columnNamesCollection.Add(columnNames.Current);
            }



            IDictionary<String, Object> parameters = new Dictionary<String, Object>();
            parameters.Add(IQueryBuilder.FORM_CREATE_INDEX_QUERY_INDEX_NAME_PARAMETER, indexName);
            parameters.Add(IQueryBuilder.FORM_CREATE_INDEX_QUERY_TABLE_NAME_PARAMETER, entityDescriptor.GetTableName());
            parameters.Add(IQueryBuilder.FORM_CREATE_INDEX_QUERY_COLUMN_NAMES_PARAMETER, columnNamesCollection.GetEnumerator());
            parameters.Add(IQueryBuilder.FORM_CREATE_INDEX_QUERY_IS_UNIQUE_PARAMETER, isUnique);


            String query = queryBuilder.FormCreateIndexQuery(parameters);
            database.ExecuteQuery(GetDatabaseDescriptor(entityDescriptor.GetClassName()), entityDescriptor, query);

            IDatabaseEvents databaseEventHandler = resourceManager.GetDatabaseEventHandler();
            if (databaseEventHandler != null)
            {
                EntityDescriptor.Index index = new EntityDescriptor.Index();
                index.SetName(indexName);
                index.SetUnique(isUnique);

                IEnumerator<String> columnNamesIterator = columnNamesCollection.GetEnumerator();
                while (columnNamesIterator.MoveNext())
                {
                    index.AddColumn(columnNamesIterator.Current);
                }

                databaseEventHandler.OnIndexCreated(GetDatabaseDescriptor(entityDescriptor.GetClassName()), entityDescriptor, index);
            }
        }