JavaScript what is “this”
“this” in js functions
I am getting deeper into the JS rabbit hole and as a programmer with more experience with strongly typed languages I find some things hard to grasp in languages where functions are first class elements (learn more here). One thing that is not tricky but interesting is the different values for “this” in a function. What “this” is in a function depends on how it is used. These are my brief notes about functions and “this”, feel free to comment if you see something incorrect.
As a global function: honk();
- this = global context(window object)
As a method: myCar.honk()
- this = object that method belongs to
As a constructor: new Car()
- A new empty object is passed to function as this parameter
- This happens because of the new keyword is used before the function call
Function called with honk.apply(…) or honk.call(…)
- Here you can decide what “this” is, because it is passed into the call to apply and call
- apply(object(will be this), [array of params]);
- call(object(will be this), param, param….);
Examples with console output
Console output for above code
Track every Build Number with Maven
Problem
You need to differentiate between build numbers. For example, you’ve just redeployed your application and need to ensure that the new version is what you are viewing. Or, you need to keep track of how many times you build. There could be many reasons why you want to know the build number that you are on. I use it for reporting bugs against specific builds.
Solution
maven-buildnumber-plugin. This Maven2 plugin will generate a unique build number each time your build your project. You can even configure which maven phase triggers the increment of the number. This plugin can also fetch data from SVN to ensure that a team of developers all get unique build numbers.
As a bonus, it generates a buildNumber.properties file so that you can read in this build number from anywhere in your project. Here is how I use the plugin.
First, update your pom.xml. You need to setup the build trigger.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>false</doUpdate>
<format>${version}.{0,number}</format>
<items>
<item>buildNumber0</item>
</items>
</configuration>
</plugin>
</plugins>
</build>

Now, you’ll need the build number and append it to your artifact’s final name. Add this to your pom.xml
<build>
<finalName>
${project.artifactId}-${project.version}.{buildNumber}
</finalName>
</build>
Now you’re package goal will output a file named
projectname-1.0.1.war
This is a great start and now you can differentiate each and every build. However, I need to take this a step further.
I need to see the version on my application’s index page. To do this, I use an ant filter to write the version and timestamp to a version.html file, and then copy it to my project’ web app directory. Add this to your pom.xm.
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<!-- versioning -->
<echo message="[build version]"/>
<delete file="target/projectname/version.html"/>
<tstamp>
<format property="rightNow" pattern="d MMM yyyy" locale="en"/>
</tstamp>
<copy todir="target/projectname">
<fileset dir="src/main/webapp">
<include name="version.html"/>
</fileset>
<filterset>
<filter token="VERSION" value="${buildNumber}"/>
<filter token="BUILTON" value="${rightNow}"/>
</filterset>
</copy>
<echo message=" version is ${buildNumber}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Version.html is simple.
<p class="version">Version: @VERSION@</p> <p class="built">Built on: @BUILTON@</p>
Finally, in my index page…
<jsp:include page="/version.html"/>
Almost everything you want to know about this plugin can be found on the plugin’s site: http://mojo.codehaus.org/buildnumber-maven-plugin/
Alternatives
As an alternative to writing and importing version.html, you can read buildNumber.properties in an MVC controller and put the version in your page model. This is what I for my login pages. I use a java class to read the build number, format it, and cache it. I start the first build number at 00100, then format that to 0.1.0. So the next build is 00101 which gets displayed as 0.1.1.
Update:Tips
Here is a usage tip. You can move the create goal into a build profile so that the build number only increments in specific situations. I use a profile for my Continuous Integration builds so that our version increments only when Hudson builds our apps. This also makes it possible to synchronize our Hudson build numbers to our module versions.
Feedback
What do you use to track build numbers? How do your format it?
.Net Data Provider Overview
Summary
This is a high level summary of the basic .Net API’s for interacting with a database. This includes a short description of each and how they relate to each other. As a developer with mainly a Java and PHP background I was unclear about how ADO.Net related to OleDb and I had no idea what was meant by the term “.Net Data Provider”. I created this because the msdn documentation is HEAVILY focused on ADO.Net and does not give a clear picture of how the many namespaces, interfaces, and classes interact. Please add comments to correct or enlighten. Note at this time the relation of .Net Providers to Nhiberante, LINQ to SQL, and Entity Framework is not covered in this post.
.Net Data Provider
- http://msdn.microsoft.com/en-us/library/a6cd7c08(v=VS.71).aspx
- A .NET Framework data provider is used for connecting to a database, executing commands, and retrieving results. Those results are either processed directly, or placed in an ADO.NET DataSet.
What that actually means is that a .Net Data Provider implements the interfaces defined in the System.Data namespace. - A .Net Data Provider is similar to a JDBC driver in Java
- http://en.wikipedia.org/wiki/Java_Database_Connectivity
System.Data
- http://msdn.microsoft.com/en-us/library/system.data.aspx
- This page contains text that makes you believe that ADO.Net is the CORE part of .Net data access, however the reality is that ADO.Net is the highest level of data access and is built upon the .Net Data Providers that implement the interfaces in the System.Data.
- In my opinion it almost seems like microsoft is trying to hide how database connections work, so that users are trapped using controls provided by visual studio.
- This namesapce contains the Interfaces that need to be defined by ALL .Net Data Providers
- Core Interfaces
- IDbConnection
- IDbCommand
- IDataAdapter
- IDataReader
Four examples of System.Data Implementations
- The below namespaces include classes that implement the core “.Net Data Provider” interfaces defined in System.Data
|
System.Data.SqlClient |
System.Data.OleDb |
System.Data.Odbc |
IBM.Data.DB2.iSeries |
|
|
http://msdn.microsoft.com/en-us/library/system.data.oledb.aspx |
http://msdn.microsoft.com/en-us/library/system.data.odbc.aspx |
http://www-03.ibm.com/systems/i/software/access/windows/dotnet/index.html |
|
Core Classes
|
Core Classes
|
Core Classes
|
Core Classes
|
ADO.Net
- http://msdn.microsoft.com/en-us/library/27y4ybxw(v=VS.71).aspx
- ADO.Net is a database query and manipulation API built on top of the basic .Net Data Provider classes. ADO.Net focuses on disconnected, multi-tier database interaction. In my opinion the core ADO.Net classes should be in a separate namespace like System.Data.ADO just for the sake of clarity.
- Core Classes
- DataSet
- DataTable
- DataColumn
- DataRelation