Execution thru Act, Learn, Build

   Posted by: Tom Salonek

In the book Just Start: Take Action, Embrace Uncertainty, Create the Future (see earlier post for citation), the authors’ state most entrepreneurs “allow opportunities to emerge.” They also share most entrepreneurs try to limit loss and find “good enough” solutions. I agree.

Most entrepreneurs I know are risk averse, focus on practical decisions, and don’t make big gambles.  This is the opposite of common thinking.  Instead of large endeavors, most entrepreneurs take small steps, learn what works and what doesn’t, and then choose to continue or cancel. 

Saras D. Sarasvathy from the University of Virginia’s Darden School of Business, states “act-learn-build” is effective for launching new endeavors.  It’s simply: 

Act: Take a step

Learn: Evaluate

Build: Continue until goal achievement or cancellation

Act-Learn-Build is something we’ve been doing at Intertech since our inception.  In subsequent posts, I’ll share what’s worked and what hasn’t.

 

Code Snippets using VS 11 Part 2

   Posted by: Andrew Troelsen

The the last post, I gave a review of the role of code snippets in Visual Studio.  Here, I’ll pick it up with some information about how to build custom snippets.

First of all, why might you build custom snippets?  The short answer is that if you notice you are authoring the same boiler plate code, time and time again, you could help simplify your days by automating this task via a snippet.

Before we build our own, let’s examine the details of one of the built in snippets: the class snippet (see previous blog post for details regarding how to locate the default snippet files):

   1:  <?xml version="1.0" encoding="utf-8" ?>
   2:  <CodeSnippet Format="1.0.0">
   3:    <Header>
   4:      <Title>class</Title>
   5:      <Shortcut>class</Shortcut>
   6:      <Description>Expansion snippet for class</Description>
   7:      <SnippetTypes>
   8:        <SnippetType>Expansion</SnippetType>
   9:        <SnippetType>SurroundsWith</SnippetType>
  10:      </SnippetTypes>
  11:    </Header>
  12:    <Snippet>
  13:      <Declarations>
  14:        <Literal default="true">
  15:          <ID>name</ID>
  16:          <ToolTip>Class name</ToolTip>
  17:          <Default>MyClass</Default>
  18:        </Literal>
  19:      </Declarations>
  20:     <Code Language="csharp" Format="CData">
  21:      <![CDATA[class $name$
  22:      {
  23:        $selected$$end$
  24:      }]]>
  25:     </Code>
  26:    </Snippet>
  27:  </CodeSnippet>

The root element for any code snippet is appropriately named <CodeSnippet>. Within this element scope are two key sub-elements: <Header> and <Snippet>. The <Header> element is used to describe the basic characteristics of the code snippet itself. The following table documents the key sub-elements of <Header>:

image

The <Snippet> sub-element is a bit more complex than <Header>, given that this is where the real action happens. In a nutshell, the <Snippet> element defines the following information:

  • The set of 'variables' to be generated by the expansion. These are the yellow-highlighted-Tab-key-navigated tokens explained earlier in the article.
  • The C# skeleton code to be generated once the expansion is activated.

The <Snippet> element uses the <Declarations> element to account for the expansion variables, each of which is represented by unique <Literal> element. Consider again the class.xml code snippet. This expansion needs only a single <Literal> to represent the class name:

   1:  <Declarations>
   2:    <Literal default="true">
   3:      <ID>name</ID>
   4:      <ToolTip>Class name</ToolTip>
   5:      <Default>MyClass</Default>
   6:    </Literal>
   7:  </Declarations>

Finally, we need to address the role of the <Code> sub-element defined within <Snippet>. This element is used to define the code to be inserted, represented by a CDATA section (recall that CDATA sections are used to defined data that is not well-formed XML, but still required by the XML document). Here is the <Code> element for the class.xml code snippet:

   1:  <Code Language="csharp" Format="CData">
   2:    <![CDATA[class $name$
   3:    {
   4:      $selected$$end$
   5:    }]]>
   6:  </Code>

Notice the various names sandwiched by $ tokens (such as $name$). This syntax is used to reference the variables defined within a <Literal> element, as well as predefined literals understood by Visual Studio (such as $selected$).

Also note that the $name$ token is referring to the name <Literal> defined in the <Declarations> section of the class.xml document. The $selected$ token represents the code statements selected within the IDE before the expansion was activated. As you would guess, $end$ is used to mark where the user's cursor will be placed after the snippet has expanded.

If you are an XML superstar, the previous section should be about all you need to define your custom code snippets. However, for those of you wish to see a concrete example, we will build a code snippet, newobj, which is responsible for generating the following C# statement (shown in pseudo-code):

[typeName] [varName] = new [typeName]();

The [typeName] placeholder will be controlled by a <Literal> aptly named typename and will have a default value of object. The [varName] placeholder will be controlled by another <Literal> named varname, which has the default value of 'obj'. Create a new XML document (newobj.xml) and enter the following:

   1:  <?xml version="1.0" encoding="utf-8" ?>
   2:  <CodeSnippet Format="1.0.0">
   3:    <Header>
   4:      <Title>new object</Title>
   5:      <Shortcut>newobj</Shortcut>
   6:      <Description>Expansion snippet to allocate a new type
   7:      </Description>
   8:      <SnippetTypes>
   9:        <SnippetType>Expansion</SnippetType>
  10:      </SnippetTypes>
  11:    </Header>
  12:    <Snippet>
  13:      <Declarations>
  14:        <Literal>
  15:          <ID>typename</ID>
  16:          <ToolTip>type name</ToolTip>
  17:          <Default>object</Default>
  18:        </Literal>
  19:        <Literal>
  20:          <ID>varname</ID>
  21:          <ToolTip>variable name</ToolTip>
  22:          <Default>obj</Default>
  23:        </Literal> 
  24:      </Declarations>
  25:        <Code Language="csharp" Format="CData">
  26:          <![CDATA[$typename$ $varname$ = new $typename$ ($end$);]]>
  27:        </Code>
  28:    </Snippet>
  29:  </CodeSnippet>

The current version of newobj.xml generates code that triggers the type's default (no argument) constructor. One enhancement you could make is to add a third <Literal> that represents a C-style code comment:

   1:  <Literal>
   2:    <ID>ctorArgs</ID>
   3:    <ToolTip>Type in your ctor args</ToolTip>
   4:    <Default>/* Type Args Here */</Default>
   5:  </Literal>

We could then update our CDATA section as so:

   1:  <Code Language="csharp" Format="CData">
   2:    <![CDATA[$typename$ $varname$ = new $typename$ ($ctorArgs$ $end$);]]>
   3:  </Code>

The end result is that we have provided a Tab-reachable placeholder where constructor arguments can be manually entered like the one shown here:

image

At this point, you can register the location of your new *snippet file with the Code Snippet manager.  When you wish to activate your snippet, simply type in the registered short cut name like you would do for any of the built in VS snippet.

Happy coding.

Working with Code Snippets using Visual Studio 11 (Part 1)

   Posted by: Andrew Troelsen

When I teach foundational .NET courses at Intertech, I make sure to point out useful features of the IDE, one of which is code snippet technology. In this blog post, I’ll talk about the basics of using snippets with Visual Studio 11 (which is really no different from using them with VS 2010).  However, in part 2 of this post, I’ll talk about building custom snippets.

Code snippets have been a very useful feature of VS since the release of 2005 (if memory serves). As you may know, “code snippets” are a feature of the IDE which allow you to insert bodies of predefined, commonly used code, once the snippet is activated.

Each code snippet has a registered name (such as foreach, exception, and so forth).  Thus, if you happen to know the name of the snippet you are interested in, simply type in the name within a C# code editor and press the TAB key twice (the first TAB will auto-complete the snippet name, the second TAB will insert the associated code). For example, if you start to type foreach you would find:

image

And once you perform the TAB-TAB operation, you end up with:

image

Most code snippets have built in “placeholders” which you are expected to update.  Here, we see that the IEnumerable in the foreach loop is simply named “collection”, which would be a compiler error at the moment.  To fill in the placeholders once you have activated a snippet, just keep pressing the TAB key to cycle through each placeholder.  Once you are all done, press the ESC key to return to normal code editing mode.

If you don’t happen to know all the snippets built into VS, you can see a list of all snippets via a mouse right-click.  For example, if you were to right click in a C# code editor, you will see an Insert Snippet option.  From here, you can drill into various sub-categories and tinker away:

image

In addition to the Insert Snippet option, you will also notice a “Surround with” option. The difference is that these snippets will encase the current selection in the code editor.  For example, if you wished to wrap up the current foreach loop into a "#region / #endregion section, you would first select the code, right click, and pick the following:

image

You should also be aware of the “Code Snippet Manager” tool which can be opened via the Tools menu. Here, you will be able to see each registered code snippet on your machine, the associated short name, category and location in your directory structure:

image

If you were to navigate to the directory containing a given snippet, you’ll notice these instructions are packaged in into *.snippet files, which contain XML definitions of the snippet (no surprise there…what isn’t described in XML these days?)

image

If you open any of these snippets into your text editor of choice, you’ll get some insight as to how the snippets do their work.

In the next part of this blog post, I’ll talk about the process of building and registering custom snippets.

Happy coding.

Creating the Future in Business thru Execution

   Posted by: Tom Salonek

Nike’s “Just Do It!” is more than just a slogan.  This is a fact CEOs understand.

In a survey, when asked to name the main reason for the success of their companies, 75% of the CEOs leading Inc. magazine’s top 500 companies said “superior execution in a mundane business.” In my book “Building a Winning Business,” takeaway #37 is titled “Just Do It!” In this brief chapter, I share “It’s better to take action than to procrastinate while obsessing about perfection.” This position is backed by a recent Harvard Business Review book called Just Start: Take Action, Embrace Uncertainty, Create the Future.

The book is authored by educators Leonard A. Schlesinger, Charles F. Kiefer and Paul B. Brown.  They spent years studying entrepreneurs and how they create new products and offerings (in situations where analyzing data or forecasting wouldn’t work).  Their findings?  “Successful entrepreneurs don’t just ‘think different,’ they translate that thinking into immediate action… Rather than predict the future, they try to create it.”

 

Engagement and Employee Feedback

   Posted by: Tom Salonek

This is the last in series of posts on engagement. 

Feedback is one of the top areas for engagement. As cited earlier, Gretchen Spreitzer, professor of management and organizations at the University of Michigan’s Ross School of Business, and Christine Porath, assistant professor at Georgetown University’s McDonough School of Business, in “Creating Sustainable Performance” (HBR Jan/Feb. 2012) stated:

“Feedback creates opportunities for learning and the energy so critical for a culture of thriving. By resolving feelings of uncertainty, feedback keeps people’s work-related activities focused on personal and organizational goals. The quicker and more direct the feedback, the more useful it is.”

To support feedback, we do a series of things at Intertech:

  • A performance review.  This is the least effective way feedback.  Reviews look backward…  “We never can should have.”
  • Key Result Areas (KRA’s).  KRA’s are a Dale Carnegie concept to goal setting and feedback.  Because KRA’s are focused on the future, it’s much more effective than a review.
  • Yammer.  Yammer is a business social media tool.  Throughout the day, our team posts updates, questions, and kudos.
  • Peer recognition.  We’ve implemented a program called “ACE.” ACE is a way for one employee to recognize another. 

Finally, as it relates to feedback, I’m a big believer in hand written notes.  This is backed by research.  Data states a handwritten note is 2X+ more meaningful than a face-to-face conversation.  The data goes on to state a face-to-face conversation is 2X+ more meaningful than an email.

IE9 (Internet Explorer 9) Changes Developers Should Know About

   Posted by: Rich Franzmeier

Intro

The ASP.NET project I am on currently has spanned 5 years and has undergone many upgrades.  The latest upgrade was made necessary by the Internet Explorer 9 (IE9) push by Microsoft in Windows Update.  Our users started getting it and things that used to work started breaking.  I was given the task to find and repair these issues.  This post details my findings.  I am posting the two that I felt would be most relevant to developers.  Note that one of the issues (the second one) is related to ASP.NET alone but the first one is important for all web developers.

Content (or custom) Attribute Changes

Before IE9, content attributes could be get or set using JavaScript object DOM ‘expando’ properties.  With the introduction of IE9, that is no longer the case.  A content attribute is an attribute that is specified in the HTML source or, with ASP.NET, in the server side Control.Attributes collection.  There are pre-defined HTML content attributes like ‘value’ or ‘id’.  There are also user-defined content attributes (I call them ‘custom’ attributes), and that’s what I’ll be talking about in this post.  Expando properties are defined from MSDN as follows:  All objects in JavaScript support "expando" properties, or properties that can be added and removed dynamically at run time. (See http://msdn.microsoft.com/en-us/library/89t1khd2(v=vs.94).aspx)

Before IE9 the custom attributes were implied with the same name expando properties (i.e. javaObject.customAttr was valid in JavaScript.)  With IE9, that is no longer the case.  Note that the pre-defined content attributes will still be available as expando properties.

FIX -- The fix is to use the getAttribute and setAttribute functions of the JavaScript object instead of the expando properties.

See the MSDN explanation of this IE9 change here:  http://msdn.microsoft.com/en-us/library/ie/gg622931(v=vs.85).aspx

Example 1  – Content Attribute As HTML Source

This example will show what happens in IE9 and compatibility mode when we set a custom attribute in the HTML source.

Here is the ASP.NET code:

<asp:Button ID="ContentAttrBtn" runat="server" Text="Get Custom Content Attribute" 
    OnClientClick="attrAsContentAttribute(); return false;" />
<asp:TextBox ID="TextBox2" runat="server" helloWorld="content attribute!" />
If you aren’t familiar with ASP.NET, this is the HTML that is generated:
<input type="submit" name="ctl00$MainContent$ContentAttrBtn" 
  value="Get Custom Content Attribute" onclick="attrAsContentAttribute(); return false;"
  id="MainContent_ContentAttrBtn" />
<input name="ctl00$MainContent$TextBox2" type="text" id="MainContent_TextBox2" 
  helloWorld="content attribute!" />

Here is the JavaScript:

function attrAsContentAttribute() {
    var txt = document.getElementById('<%= TextBox2.ClientID %>');
    alert('TextBox2 helloWorld attribute (expando) = ' + txt.helloWorld);
    alert('TextBox2 value attribute (expando) = ' + txt.value);
    alert('TextBox2 helloWorld attribute (getAttribute) = ' + txt.getAttribute("helloWorld"));
}

When this is run in IE9, we get the following alert boxes:

image …Note that this is undefined in IE9 now.

image …I entered “textbox value” into the textbox.

image …works with getAttribute.

When this is run in IE9 Compatibility Mode, the following alert box changes (the 1st one):

image …works in compatibility mode.

Example 2 – Content Attribute Added in ASP.NET Code Behind (on server)

This example will show what happens in IE9 and compatibility mode when we set a custom attribute in the ASP.NET code behind.

Here is the ASP.NET code:

<asp:Button ID="ServerAttrBtn" runat="server" Text="Get Custom Server Attribute" 
    OnClientClick="attrSetOnServer(); return false;" />
<asp:TextBox ID="TextBox1" runat="server" />
If you aren’t familiar with ASP.NET, this is the HTML that is generated:
<input type="submit" name="ctl00$MainContent$ServerAttrBtn" 
  value="Get Custom Server Attribute" onclick="attrSetOnServer(); return false;" 
  id="MainContent_ServerAttrBtn" />
<input name="ctl00$MainContent$TextBox1" type="text" id="MainContent_TextBox1" 
  helloWorld="hello from server!" />

This is the code-behind to the page where I am setting the helloWorld attribute:

TextBox1.Attributes.Add("helloWorld", "hello from server!");

Here is the JavaScript:

function attrSetOnServer() {
    var txt = document.getElementById('<%= TextBox1.ClientID %>');
    alert('TextBox1 helloWorld attribute (expando) = ' + txt.helloWorld);
    alert('TextBox1 id attribute (expando) = ' + txt.id);
    alert('TextBox1 helloWorld attribute (getAttribute) = ' + txt.getAttribute("helloWorld"));
}

When this is run in IE9, we get the following alert boxes:

image …Note that this is undefined in IE9 now.

image …id of the TextBox or input element.

image …works with getAttribute.

When this is run in IE9 Compatibility Mode, the following alert box changes (the 1st one):

image …works in compatibility mode.

AjaxControlToolkit CalendarExtender

This issue is more specific to ASP.NET applications that are using the AjaxControlToolkit (November 2011 Release).  I noticed in my app that when I selected a date using the calendar extender (the calendar image that allows you to choose a date from a visual calendar), and the date had one digit in the month and/or day, it was formatted in the TextBox as follows:  4/9/2012

It should have formatted it this way:  04/09/2012

Note that I never set the CalendarExtender.Format value.  I just took the default.

Why do I care, you may ask?  Because the validation in the control doesn’t work correctly when it is formatted without leading zeroes.  What I noticed in my app was that I would get a “Date required” error message when a date was already in the TextBox control.

FIX -- The fix is to set the CalendarExtender.Format explicitly to "MM/dd/yyyy".

I logged this bug as an issue on CodePlex and you can follow it if you are interested here:  http://ajaxcontroltoolkit.codeplex.com/workitem/27137

The Revolutionary/Evolutionary Database Projects (and Dev11)

   Posted by: Dave Zimmerman

I have been working with database projects since the 2006 CTP “Data Dude” days through its 1.0 release as Visual Studio Team Edition for Database Professionals; Its realized vision -- of organizing our database artifacts/schema into a solution; checking changes into source control (TFS) surrounded with descriptive meta data (work items) documenting the motivations for those changes; and empowering us to automate the build, deployment, and test of those changes through our staged environments – has truly been revolutionary for this aspect of software development for those who have persevered in the new discipline.  Those of you who have been using this for a while also know that tools and best practices surrounding database projects has been very evolutionary as well with each release of Visual Studio, not to mention each release of SQL Server.  The Dev 11/SQL 2012 release is no exception here.

The latest release of Visual Studio (Dev 11 at the time of this post) will upgrade your databases project (.dbproj) to a database project (.ssdt) which stands for SQL Server Developer Tools.  This is a major rework by the tools team which is now fully aligned with the various SQL server cleints with the aim of providing a unified toolset for all SQL Server Development whether you are working in SQL Server Management Studio (SSMS), Business Intelligence Design Studio (BIDS), or Visual Studio (VS).  We have been reading about this effort and/or playing with these features in Community Technology Previews (CTPs) which began integrating with Visual Studio 2010 Premium SP1 in CTP3.  The Visual Studio Dev11 Beta shipped with the release candidate 0 (RC0) of the SSDT tools.  The SSDT tools have since been released to manufacturing (RTM).  Thus, if you want to play with these tools in Dev11, a good place to start is to either download and install the Feature Pack for 2012, or just install the required VS components for the VS dev-build-deploy cycle.  Specifically for me, this consists of 64-bit DACFramework.msi, SqlSystemClrTypes.msi, SQLDOM.msi, and SQLLS.msi.  Those of you installing on 32-bit build machines, would want to install the 32-bit versions of those downloads.

Dev11 Bug Alert: If you are getting the following error on your Dev11 64-bit build machines when you go to build your .ssdt projects:

clip_image002[6]C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets (381): The "SqlModelResolutionTask" task could not be loaded from the assembly C:\Program Files\Microsoft SQL Server\110\DAC\Bin\Microsoft.Data.Tools.Schema.Tasks.Sql.11.dll. Could not load file or assembly 'file:///C:\Program Files\Microsoft SQL Server\110\DAC\Bin\Microsoft.Data.Tools.Schema.Tasks.Sql.11.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

Workaround: This is due to a bug in the Dev11 build targets.  The workaround is to copy your DAC files from the (x86) Program files directory to a 64-bit location, for example:

C:\Program Files (x86)\Microsoft SQL Server\110\DAC\Bin\

gets copied to

C:\Program Files\Microsoft SQL Server\110\DAC\Bin\

Not So Fast On that Uninstall

Great strides have been made with SSDT projects.  Just to name a few, developers working offline in declarative mode using LocalDB or online interacting with a shared database both get a greatly improved Transact-SQL Debugging and testing experience; one database project is used for all versions of SQL Server and the organization of database artifacts is much friendlier/more intuitive than the previous .dbproj.  On the other hand, while there are many great new features, not all the old features of database projects you may be taking advantage of have made it into the SSDT code rewrite (See SQL Server Data Tools CTP4 vs. VS2010 Database Projects ) and conversions aren’t no-brainers for all database projects (See Top VSDB->SSDT Project Conversion Issues)  [As an aside, our upgrade team was not impressed with the upgrade logic used by the database project conversion wizard.  If you don’t mind not losing your seamless history of artifact changes in your .dbproj, I recommend just pointing at a database and recreating your solution as an SSDT rather than the really odd arrangement of new and old scripts you acquire over time while working with a converted .dbproj file.  However, for those who do want to keep this history, manually upgraded, e.g moving artifacts to the appropriate folders and deleting others is a tedious option.] 

SNAGHTML155916c

Example of “upgraded” database project which preserves the .dbproj artifact organization.  Unfortunately when new artifacts get added, the solution places them in the new .ssdt folder organization.  (Now we have 2 “Production folders” – and a solution which is in neither the .dbproj nor .ssdt canonical form,  Worse yet, you may start getting compiler errors after synching table changes because with .ssdt projects index scripts are stored in the table definition itself for readability (Nice!), But it does not clean up the .dbproj’s pattern of storing index scripts as separate files.   

So in your exuberance over the new features, don’t be too hasty clicking Uninstall on your dev machine and build machine VS2010 installations, especially if you want to continue using features, like for example, the data generation/compare tools.  But keep a stiff upper lip as well, Microsoft is already narrowing the gap with out-of-band power tools that integrate with the 2012 tools (See  SSDT PowerTools which at the time of this writing has re-integrated the Schema Explorer with .ssdt projects) 

Incivility in the Workplace Makes for Wasted Time and Money

   Posted by: Tom Salonek

Incivility is bad for business.

A culture that tolerates uncivil prima donnas because of who they are or what they deliver goes against findings in a recent Harvard Business Review article.  The article, by Pearson and Porath, is based on seven years of research.  They share, when one co-worker is abusive to another, the abused will:

  • Decrease effort (by 50%)
  • Intentionally decrease work quality (by 33% or more)
  • Waste time by actively avoiding the offender (by 66%)

At Intertech, incivility isn’t tolerated from employees, customers, or partners.  For the uncivil, our solution is simple… end the relationship.  This may seem extreme.  But, data on human development states people are about 98% defined as a person by their mid-20’s. For me, this means it’s pointless to be in the “human change business.”

Last thing to note, if uncivil are permitted to have their own operating guidelines and stay, it’s a matter of time before the abused, who are civil and deliver good work, choose to leave. 

Spring Transactions and the Element

   Posted by: Jim White

This week, I had a wonderful group of people from the IT department of one of Minnesota's great counties in my classroom to learn Spring 3.  It's always nice to see a group of people that seem to get along well in the classroom.  My guess is they also get along well at work and that usually bodes well for software projects.  Teams that work together usually find solutions together.

A couple of very good questions from class this week centered on the schema-based (XML) configuration of Spring transactions.

Spring Transactions in XML

In general, when using Spring's declarative schema-based transactions, you need to define three elements in the XML metadata along with the beans that need transactions (unless these are defined with annotations and component scans).  The XML below is an example of defining a few beans and the three elements needed to apply Spring's schema-based AOP transactions.

<!-- A couple of business beans that need transactions -->
<bean id="contactDao" class="com.intertech.service.ContactDaoJDBCImpl"
    destroy-method="dispose" autowire="byType">
</bean>
<bean id="contactService" class="com.intertech.service.ContactServiceImpl"
    autowire="byType">
</bean>
<!-- A transaction manager bean -->
<bean id="txManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="basicDS" />
</bean>
<!-- The transaction advice - setting attributes for transactions -->
<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        <tx:method name="get*" read-only="true" />
        <tx:method name="add*" propagation="REQUIRED" />
        <tx:method name="update*" propagation="REQUIRED" isolation="SERIALIZABLE" />
        <tx:method name="remove*" propagation="REQUIRED" isolation="SERIALIZABLE" />
        <tx:method name="*" />
    </tx:attributes>
</tx:advice>
<!-- Establish the AOP transaction cross cutting concern and define which classes/methods are transactional  -->
<aop:config>
    <aop:pointcut id="serviceOperations"
        expression="execution(* com.intertech.service.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperations" />
</aop:config>

Beyond the two beans (id's of contactDao and contactService) that will be provided transactions, the txManager bean defines the transaction manager to be used.  Spring provides several transaction manager beans which act as facades to the actual technology-specific transaction implementations.  The transaction manager beans must implement org.springframework.transaction.PlatformTransactionManager, which allows custom and new transaction managers to facilitate transactions in Spring without developers having to learn and understand that manager directly.  In the case above, I am just using Spring's DataSourceTransactionManager bean that wraps the transaction manager capability provided via JDBC and the available data source.  See here for more information on defining transaction managers.

Next is the all important transaction advice element.  This element sets the transaction manager to use for transactions (as defined by the previous transaction manager bean in this case), and then establishes the transaction attributes for various transactional methods.  This is the portion of the configuration I want to focus on in this post.  More on this in just a bit.

The last of the 3 elements defining schema-based transactions in Spring is the the AOP configuration element.  As Spring's declarative transactions are performed by AOP, this element defines the points of execution for transactions (and other cross cutting concerns) across the application.  In this example, the AOP transaction advisor and associated pointcut expression say that transactions are to be applied to any method in any class in the com.intertech.service package (regardless of return type, method name, method parameters, etc.).  See here for more information on AOP configuration definitions.

Transaction Attributes

Back to the transaction advice element, you will note that the <tx:attributes> element contains any number of child <tx:method> elements.  These elements lead to a great deal of confusion.

<tx:attributes>
    <tx:method name="get*" read-only="true" />
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" isolation="SERIALIZABLE" />
    <tx:method name="remove*" propagation="REQUIRED" isolation="SERIALIZABLE" />
    <tx:method name="*" />
</tx:attributes>

How do these elements relate to the pointcut defined in the AOP configuration?  How do the wildcards and matches work on these elements?  Does the name="*" containing element always have to be there?

AOP Configuration Pointcut and <tx:method>

First off, those classes and methods captured by the AOP configuration element and its associated pointcut for the transaction advisor define which methods in all the methods of the Spring beans may have transactions applied to them.  If you will, this represents a potentially large set of methods, but smaller than the original set provided by all beans in the application.  Importantly, however, this does not mean that the methods captured by the AOP pointcut are going to have transactions yet.

image

Next, the transaction advice element with its transactional attributes (and nested transactional method elements) determine which methods will indeed be transactional and how the transactions on those methods will operate.  In the example above, there are several <tx:method> elements that select subsets of the AOP pointcut methods.  The methods captured by the wild card matches (all methods in this group that start with "get", start with "add", start with "remove", etc....) as shown in the yellow ovals in the diagram below become transactional.

image

Wildcards and Order of <tx:method>

The order of the <tx:method> elements is not important.  What is important is the name pattern!  Spring attempts to match the most specific name patterns first.  So, for example, say you had just three <tx:method> elements as shown below.

<tx:method name="add*" propagation="SUPPORTS" read-only="true" />
<tx:method name="addC*" propagation="REQUIRED" timeout="30"/>
<tx:method name="*" />
Then also assume you had a method called addContact( ) and another called addRate( ) that fell under the methods of the AOP pointcut.  In this case, the second <tx:method> element above would be applied to addContact( ) method and the first <tx:method> would apply to the addRate( ) method.  That is because more specific addC* pattern matches addContact but not addRate.  Further, even though the "*" pattern would capture both the addContact( ) and addRate( ) methods, it is more general and less specific than either of the "add*" or "addC*" names.  The name="*" pattern is important, however, to capture all methods selected by the AOP pointcut, but not by a more specific <tx:method> name.  In this example, a method like foo( ) that was captured by the pointcut would not be captured by either add* or addC* patterns.

The Attributes

Remember, the <tx:method> elements determine what is transactional, but also determine what attributes are applied to the transactions of those methods captured in the pattern match.  More information can be found on the transaction attributes here.  However, below is a table listing the attributes and their default values.  When your <tx:method> element does not specify the attribute, the method's transaction uses the default value.  In the example above, the catch-all <tx:method name="*"/> element abides by all defaults.

Transaction attribute

Purpose

Default setting

propagation

What should happen if a transaction already exists?

REQUIRED

isolation

Set the isolation level of the transaction.

DEFAULT

read-only

Specify if data can be modified or only read in the transaction.

False (allowing for reads and writes)

timeout

Length of time in seconds that the transaction can run before timing out.

-1

rollback-for

What triggers a rollback of a transaction?

RuntimeException

no-rollback-for

What does not trigger a rollback of a transaction?

Any checked exception

Wrap Up

I want to thank Kevin and Bryan from my class this week for raising the good questions which led to the material for this post.  I had a lot of good questions to choose from this week as everyone in my class was engaging and thoughtful.  It makes class a lot of fun for everyone - students and instructor alike.  If you are looking to learn more about Spring 3, contact Dan McCabe at Intertech, Inc. to enroll in a class today.  You can find more information about our Complete Spring 3 Framework class here.

Financial Transparency and a Stake in the Outcome

   Posted by: Tom Salonek

The employee sustainability study by Spreiter and Porath, in the Harvard Business Review, January-February 2012, states “sharing information” makes for happy and productive employees. 

In the study, they state “Doing your job in an information vacuum is tedious and uninspiring: there’s no reason to look for innovative solutions if you can’t see the impact. People can contribute more effectively when they understand how their work fits with the organization’s mission and strategy.”

I agree. 

At Intertech, we have open book management where every month we share:

  • Sales
  • Cost of Goods Sold (COGS)
  • Gross Profit
  • SG&A
  • Post-tax Profit

Along with sharing the numbers, our CFO does a great job telling the story behind the numbers.  Along with financials, we share progress on strategic goals, new customers and initiatives, and updates on our non-profit, the Intertech Foundation. 

We give everyone a stake in the outcome.  Our consultants can earn 2X their year-end bonus based on Intertech’s profitability.  This is the Intertech Profit Participation Program (PPP).  In 2011, consultants received 50 percent additional year-end bonus.  This year, we’re targeting 75 percent.

In addition to our PPP, we have an Equity Participation Program (EPP).  The EPP, essentially, grants free options annually to all employees.

Between the PPP and EPP, company-wide we’re focused on the two big drivers of firm value:  Profit and share growth.

Find Us
Contact Us 651-288-7000 1-800-866-9884
Home | Training | Curriculum | Course Finder | Schedule | Enroll | Twin Cities Java User Group | Consulting | Foundation | Jobs | About Us | Our Story | Press Room | Instructors | President | Map & Directions | Sitemap

Java Training | JSF / Struts / Spring / Hibernate Training | Java Power Tools Training | .NET 4.0 & Visual Studio 2010 Training | Microsoft Web Development Training | Prism / MVVM / MEF Training | .NET 3.5 and Visual Studio 2008 Training | .NET 2.0 and Visual Studio 2003 Training | Cloud Computing Training | Ajax / Web Services / XML Training | Groovy and Grails Training | SQL Server 2012 Training | SQL Server 2008 Training | SQL Server 2005 Training | Mobile Development Training | SharePoint 2010 Training | SharePoint 2007 Training | Agile, Process, Analysis & Design Training | Arch/Design Patterns Training | Microsoft Official Curriculum Training | Web Development Training | Ruby Training | Rational Application Developer (RAD) Training | WebSphere Application Server Training | WebSphere Portal Training | WebLogic Training | Boot Camp Training | Project Management Training | C / C++ Training | Metro / WinRT / Windows 8 Development Training | Retired

Intertech delivers training on-site and virtually serving cities including Phoenix, AZ | San Francisco, CA | Los Angeles, CA | San Diego, CA | San Jose, CA | Washington, DC | Chicago, IL | Orlando, FL | Boston, MA | Duluth, MN | Minneapolis St. Paul, MN | Rochester, MN | Raleigh-Durham, NC | New York, NY | Philadelphia, PA | Austin, TX | Dallas, TX | Houston, TX | Seattle, WA.