Monday, 21 December 2009 14:20

"General" Search Profile -- using SQL

Written by 
Rate this item
(0 votes)

There are many situations where some specific search profile could be useful. But it's not good to create many search profiles because their list tends to be cluttered.

There is some "general" search profile that uses the power of the repository.GetElementSet function below.

When you create the following Addin-search and add the search profile to use this addin-function you can use searches using direct SQL queries like:

select Object_ID from t_object where name like 'a%'

The SQL has to return the list of object_id (see help for repository.GetElementSet)

 

Search profile (Plugin COM object is called EAPlugins)

<Search Name="Find By SQL" GUID="{371E2601-771A-4d70-9030-918A0167AAD1}" PkgGUID="-1" Type="0" LnksToObj="0" CustomSearch="1" AddinAndMethodName="EAPlugins.findBySQL"><SrchOn/><LnksTo/></Search>

Plugin code (C#):

public  Boolean findBySQL(EA.Repository rep, String searchString, out String XML)
{

            XML = @"<ReportViewData>  
       <Fields>

              <Field name=""CLASSGUID""/>
              <Field name=""CLASSTYPE""/>
               <Field name=""Name""/>            
       </Fields>
       <Rows>
";
            EA.Collection col=null;
           
            try
            {
               
                col= CommonUtils.repository.GetElementSet(searchString, 2);
                if ((col.Count == 1) && (col.GetAt(0) == null)) { }   //this temporarily solves the bug in EA where an empty Set gives Count 1
                else
                {
                    foreach (EA.Element elem in col)
                    {
                        
                        XML = XML + "<Row>\n";
                        XML = XML + "<Field name=\"CLASSGUID\" value=\"" + elem.ElementGUID + "\"/>\n";
                        XML = XML + "<Field name=\"CLASSTYPE\" value=\"" + elem.Type + "\"/>\n";
                        XML = XML + "<Field name=\"Name\" value=\"" + elem.Name + "\"/>\n";
                        XML = XML + "</Row>\n";
                    }
                }
            }
            catch (Exception) { }
            finally {
                if (col!=null)
                  System.Runtime.InteropServices.Marshal.ReleaseComObject(col);
                col = null;
            }
            ;

            XML = XML + @"</Rows>
</ReportViewData>";

            return true;
        }

Read 966 times
Lubos

Lubomír Markovič

HomeCredit a.s. (Business Analyst)
 
Experience in companies developing large banking systems as designer, analyst and methodologist. Responsible for Sparx Enterprise Architect integration into company's environment and processes.

Website: cz.linkedin.com/pub/lubomir-markovic/1/2b5/2b8

1 comment

  • Comment Link mike Sunday, 26 May 2013 05:48 posted by mike

    Hi

    Where could i get a copy of the "Plugin COM object is called EAPlugins"

    Regards

Login to post comments