You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Ryan Brown <ry...@gmail.com> on 2009/12/01 23:21:32 UTC
Finding sprocs referenced in mapper files (ibatis.NET)
Does anybody know of a way to get a list of all the stored procedures used
in a given codebase? We have a ton that are no longer used and I would like
to get a list of those that are used to help with cleaning this up and
verifying deployments.
Any help would be greatly appreciated
*Ryan Brown*
--
-rb
--
-rb
Re: Finding sprocs referenced in mapper files (ibatis.NET)
Posted by Ron Grabowski <ro...@yahoo.com>.
The attached file contains some code I wrote to parse .xml mapper files. It extracts embedded resources:
Assembly assembly = Assembly.Load("...");
string[] resourceNames = assembly.GetManifestResourceNames();
List<SqlMapInfo> items = new List<SqlMapInfo>();
foreach (string resourceName in resourceNames)
{
if (resourceName.EndsWith("xml"))
{
var searcher = new SqlMapSearcher(assembly, resourceName);
items.AddRange(searcher.Extract());
}
}
and stores information about them:
class SqlMapInfo
{
public string Id { get; set; }
public string Statement { get; set; }
public string Filename { get; set; }
}
I must have really been liking LINQ when I wrote my inspection code:
// http://stackoverflow.com/questions/442425/nested-group-by-in-linq
var statementGroups =
from item in items
where item.Statement == "insert" || item.Statement == "update"
group item by item.Statement
into byStatements
select new
{
Statement = byStatements.Key,
Ids = from item in byStatements
group item by item.Id into byIds
where byIds.Count() > 1
select new
{
Id = byIds.Key,
Filenames = from item in byIds select item.Filename
}
};
The output:
foreach (var statementGroup in statementGroups)
{
Console.WriteLine(statementGroup.Statement);
foreach (var id in statementGroup.Ids)
{
Console.WriteLine("\t{0} {1}", id.Id, id.Filenames.Count());
foreach (var filename in id.Filenames)
{
string[] parts = filename.Split('.');
Console.WriteLine("\t\t{0}", parts[parts.Length -2] + ".xml");
}
}
}
told me that some of my <insert id="..."> statements had ids of SaveNew instead of the more common Insert:
insert
Insert: 43
InsertWithIdentity: 10
SaveNew: 15
update
Delete: 2
Save: 14
Update: 44
Is that what you were looking for? You could change the LINQ query to filer just for <procedure> nodes and focus on how those were being used.
________________________________
From: Ryan Brown <ry...@gmail.com>
To: user-cs@ibatis.apache.org
Sent: Tue, December 1, 2009 5:21:32 PM
Subject: Finding sprocs referenced in mapper files (ibatis.NET)
Does anybody know of a way to get a list of all the stored procedures used in a given codebase? We have a ton that are no longer used and I would like to get a list of those that are used to help with cleaning this up and verifying deployments.
Any help would be greatly appreciated
Ryan Brown
--
-rb
--
-rb