BizBlox Find/Fetch methods explained

21 01 2010

by Stephen Trembath

Just a quick summary of the DOCollection methods and how they work at the query level.

I will add to documentation eventually once I refine this a bit more, and maybe reduce the number of methods:

Take for example a CustomerCollection, comprised of Customer DataObjects. For the below examples the query will find customers with FirstName=Stephen

SetCurrentQuery
Simply sets a SqlBuilder as the query to run on the DOCollection – does not actually run any SQL.
To run the query you have to use one of the below methods. If you do not run any of the below methods, and try to access DataObjects within the collection, it will default to running the Find() method.

Find
For the current query, selects all IDs:
e.g. SELECT CustomerID FROM Customer WHERE FirstName=’Stephen’

Only when the actual Customer objects are accessed is the DataObject loaded via a new SQL query:
e.g. if you do custColl(0) it will run: SELECT Customer.* FROM Customer WHERE CustomerID = ‘……’

Iterating through a large collection, can result in a lot of queries – i.e. one to select all IDs, and one to select details of each DataObject you access.

Fetch
Retrieves all data for all matching rows in the query:
e.g. SELECT Customer.* FROM Customer WHERE FirstName=’Stephen’

This returns more data, but there is no need for follow-up queries to retrieve customer information.

FindAll
Works like a Find, but disregards the current query, and instead finds all matching IDs within the table
e.g. SELECT Customer.CustomerID FROM Customer

Should be used sparingly.

FetchAll
Works like a Fetch, but disregards the current query, and instead finds all matching IDs within the table
e.g. SELECT Customer.* FROM Customer

Should be used sparingly.

Count
If the DOCollection has been populated by a Find/Fetch etc, this will just return the number of rows from the collection itself.

If the DOCOllection has not been populated, this will do a SELECT Count(*) FROM Customer

FindRange
Returns a subset of the rows retrieved by the query. e.g. custColl.FindRange(50, 99) will skip the first 50 rows and return the following 50.

It does this by finding all IDs that match the query, while using a SELECT TOP to minimize the upper range

(e.g. SELECT TOP 100 CustomerID FROM Customer WHERE FirstName=’Stephen’)

It then manually removes in code the IDs that are not needed, e.g. the first 50 IDs in this case.

After that, accessing each DataObject will result in a SELECT Customer.* FROM Customer WHERE CustomerID = ‘……’ type query.

FetchRange
Similar to FindRange() except that it does a SELECT(*) to retrieve all data, e.g. custColl.FetchRange(50, 99) will skip the first 50 rows and return the following 50.

(e.g. SELECT TOP 100 Customer.* FROM Customer WHERE FirstName=’Stephen’)

It then manually removes in code the DataObjects that are not needed, e.g. the first 50 DataObjects in this case.

Generally not recommended.

FetchSelected
This is a new method that is still under development for general use, and needs to be defined better. It is best used where performance is crucial, and where the query is not overly complex.

It is similar to FindRange but uses SQL Server 2005′s built-in paging for efficiency, using the ROW_NUMBER function:
http://www.davidhayden.com/blog/dave/archive/2005/12/30/2652.aspx

It also only selects the columns explicitly entered in the SqlBuilder (you can still add a SELECT *)

However, with that comes a greater chance for limitations in queries, and should only be used for now where fullt tested.

The ROW_NUMBER function will only return from the database the actual rows that are required, and there is no need for manual removal in code.

e.g. Case 1:
Dim mySql as New SqlBuilder(“Customer”)
mySql.addSelect(Customer.

Columns.CustomerID)
mySql.addSelect(Customer.Columns.FirstName)
mySql.addSelect(Customer.Columns.LastName)
mysql.addWhere(Customer.Columns.FirstName, ‘Stephen’)

custColl.FetchSelected(50, 99)

The query will be similar to the following, but using the ROW_NUMBER syntax to retrieve the desired rows:
SELECT Customer.CustomerID, Customer.FirstName, Customer.LastName FROM Customer WHERE Customer.FirstName=’Stephen’

e.g. Case 2:
Dim mySql as New SqlBuilder(“Customer”)
mySql.addSelectAll()
mysql.addWhere(Customer.Columns.FirstName, ‘Stephen’)

custColl.FetchSelected(50, 99)

The query will be similar to the following, but using the ROW_NUMBER syntax:
SELECT * FROM Customer WHERE Customer.FirstName=’Stephen’





BizBlox 1.7.2 Release

10 07 2009

The latest update to BizBlox has been released today. This update has fixes for unicode support and a small issue with transaction management.

  • BizBlox used to use the local database collation settings for handling content, however this update forces unicode coalescence to comply with the way .Net handles strings (all unicode!) and makes dealing with multilingual content a no-brainer.
  • Failed transactions will no longer throw ‘null reference exception’.

Get the latest release from http://www.pixolut.com/bizblox





BizBlox 1.7: New fundamentals

6 04 2009

The BizBlox OR/M API has been in development for 5 years and is actively used in many commercial enterprise and light weight applications around the globe. The key premise of BizBlox has always been to keep databases simple. NO MAPPING, no complexity, no scripts. Its funny that layers on top of nHibernate like Fluent and even the Microsoft Linq for SQL have been trying to get this right over the last year or so – but BizBlox did it this way from the beginning. Naming parity; where classes names should match table names; property names should match column names makes perfect sense for a lot of applications and the complexities which a lot of object relational mappers introduce makes life hard for developers; both initially and especially further down the track in maintenance. Also, removing the need for special mapping scripts or weird GUI mapping tools. Just export your SQL from the enterprise manager/management studio and you’re done. Developers can just concentrate on developing business logic.

Pixoüt have just released BizBlox 1.7 on Google Code. The new version delivers greatly increased performance and flexibility, with major improvements to the DataObject caching algorithm, the addition of column attributes to the DataObject class, and the ability to handle a greater range of data types.
BizBlox 1.7 now caches information about the structure of a DataObject, including properties and column information. This information was previously loaded using reflection on every Load() and Save() of a DataObject, but it is now cached in a DOInfo object the first time an instance of that DataObject is created. While there is a minor performance penalty on the very first load of an instance of the type in the App Domain, subsequent performance will be improved as there is no locking or reflection on any object.

BizBlox 1.7 also introduces column attributes in DataObjects, including PrimaryKey(), Persists() and Identity() attributes. The PrimaryKey() attribute provides flexibility in selecting the UID column for the DataObject. The Persists() attribute allows the addition of custom properties to a class that are not saved to the database. The Identity() attribute allows the use of a SQL Server Identity (auto-incrementing) column, by excluding that column from an insert/update.

You can find out more about BizBlox by going to the BizBlox home page. BizBlox is an open source database mapping framework developed by Pixolüt Industries.





Why we moved to Google Code

29 12 2008

We have been using SourceForge for a long, long time hosting all our Open Source projects. It was a tough decision to move away from SourceForge, however as our teams and projects grew – and as time went on – we felt SourceForge had lost touch with some of the fundamentals of software development for the sake of monetization.

Over 2008 I saw SourceForge move towards a services based model to attempt to support the projects which reside on it. In and of itself this is a great idea, however the real problem was that the world of web based applications had rocketed ahead whilst the core platform of SourceForge felt like it lagged behind.

Google Code was launched way back in August 2006 and has adopted the typical Google approach to its developer platform. This approach means that adding content, code and downloads is super simple and whilst the Issue Tracker in SourceForge was turned off for all our projects since it was so cumbersome, the Google Code Issue Tracker is just a joy to work with.

Overall, we feel that the impact on development and team collaboration will be vastly improved by making the move.

The Pixolüt Industries projects on Google Code are:

BizBlox

PreNIS

xReplace





BizBlox 1.6.1 Released

12 08 2008

New version of BizBlox was put up on SourceForge this morning with some changes which have been floating around in the source tree and some production versions for a while.

Special thankyou goes out to Chris Thomas for his input and Stephen Trembath for his updates and also for getting this release live.

Updates in this release:

+: Added implicit Find() call if Find() is not previously called on a DOCollection and an attempt is made to access an Object
+: Change SqlBuilder Join methods to only add a Join to the query once, regardless of how often an attempt is made to add it.
+: AddWhereIn() overloads, accepting arrays of strings and GUIDs
+: AddWhere(), AddWhereGT(), AddWhereLT(), AddWhereGTE(), AddWhereLTE() overloads which allow comparison between columns in the query
+: Add <Assembly:AllowPartiallyTrustedCallers()> to BizBlox AssemblyInfo

http://www.pixolut.com/bizblox





New Open Source Releases

6 05 2008

xReplace is a project I was working on for a very specific need – it turned out to be a procedural text editor to define a process of text manipulation which will be performed for multiple files described using XML. xReplace also supports third party plug-ins for extra features. I developed this tool because I had to create a reproducable ‘search and replace’ style of text manipulation on thousands of content files whilst migrating a website from one CMS to another. Once I wrote the transofrmation script, I was able to rerun it over and over as the templates evolved up until the site went live. Becuase xReplace supports plugins, its also great for doing very specific yet repetitive tasks – there is an example plugin for creating ZIP files and source code to start making your own. There is extensive documentation in the installer.

BizBlox 1.6 has finally been released on SourceForge. It has been being used in production for a few months by several enterprise projects but everyone was working from the source. Thanks to Stephen Trembath for putting the new installer live on SourceForge.

 





Essential nAnt Utilities from Pixolüt

28 11 2007

Download the nAnt Utilities from here

This is a set of nAnt includes which we use in our build pipeline which I thought may be helpful to other developers using .Net and nAnt… Download them and give them a shot…

Whats included:

build.include handles .Net compilation of projects of any size and also provides build output and error management. This also allows for multiple .Net platforms to be targetted from a single nAnt script, which is something nAnt does not do natively.

ftp.include handles automated FTP of files to a server from within nAnt

prenis.include processes a Nullsoft Scriptable Install System (NSI) file using the PreNIS pre-processor.

svn.include will do most automated gets and checkouts including automated version labels on tags using SubVersion. This is a very useful incude since the current Subversion support in nAnt is rather poor.

How to use them:

These properties are used for all scripts:
<property name="include.path" value=".\InstallScripts\targets" />
<property name="nant.contrib" value="c:\nant\contrib\bin\nant.contrib.tasks.dll" />

These properties are used for the build.include
<property name="solution.config" value="debug" />
<property name="compiler.target2003" value="C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe" />
<property name="compiler.target2005" value="C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\devenv.exe" />

These properties are set for ftp.include which also needs the ftp_mostrecent.bat file as well as the other parameters defined in the actual .include file for logging in.
<property name="ftp.executable" value="${include.path}\ftp_mostrecent.bat" />

These properties are set for prenis.include
<property name="prenis.executable" value="${include.path}\prenis.exe" />

These properties are set for svn.include and also you will require a command line version of subversion and also the GetAssemblyVersion.exe file which is included in the utilities pack.
<property name="svn.executable" value="C:\Program Files (x86)\CollabNet Subversion\svn.exe" />
<property name="svn.assemblyparser" value="${include.path}\GetAssemblyVersion.exe" />
<property name="svn.versionsrc" value="${include.path}" />
<property name="svn.username" value="username" />
<property name="svn.password" value="password" />
<property name="svn.baseuri" value="svn://subversion.pixolut.com/myrepository" />

Use the following to include the include files in your build script.


<include buildfile="${include.path}\ftp.include" />
<include buildfile="${include.path}\svn.include" />
<include buildfile="${include.path}\prenis.include" />
<include buildfile="${include.path}\build.include" />





PreNIS 1.2 Released with Visual Studio 2008 support!

26 11 2007

PreNIS 1.2 has been released and it contains some minor changes so that the PreNIS engine will recognise new Visual Studio 2008 projects and handle them as it does Visual Studio 2005 projects. 
 
As the differences between VS2005 and VS2008 projects appear minimal on initial inspection, Prenis should work with both, though we will continue to monitor this.

Special thankyou to Stephen for updating the latest rev of PreNIS and getting it live so quick…





BizBlox 1.5.1 Released

23 10 2007

BizBlox 1.5.1 Released
http://www.pixolut.com/bizblox

+: Added `Launch BizBlox Builder’ to installer finish screen
x: Fixed bug with UNIQUE constraints being parsed as Primary Keys in SQL Server 2005-generated scripts
x: Updated the install script for less (!) .Net support – useless carry over
x: Fixed long standing file association bug, BBX files are now associated correctly.
x: Fixed bug with default values not working for DateTime mapping and BoundsCheck project options

Stephen has been kind enough to push his latest bug fixes to a complete release and I finally had a chance to fix the install script a little from when we migrated BizBlox Builder from being closed source and set it free!

Remember that we have started providing consulting for developers wishing to integrate BizBlox in their commercial applications (which you can since BizBlox is released under the LGPL)  through the SourceForge Services Marketplace. Its early stages, but I can see that the drive for a structured approach to integration and consulting services for the huge number of open source projects is a great opportunity.





PreNIS 1.1 Released

19 10 2007

This version of the Nullsoft Install System Pre-Processor is built for .Net framework 2.0 and all source has been migrated to build under .Net 2.0 and Visual Studio 2005

UPDATES TO THIS VERSION FROM 1.0.3

+ 1.0.3 added the ability to have recursive includes – so that all
dependant DLLs could be grabbed from all projects which are used by
the referenced one. This concept has been extended to the macro
language so that you can dynamically choose to recurse projects.

+ We have added some new arguments for the macro.bin Macros – now
you can use the following:

includeProjects = [true|false]
* this will include all DLLs which are from the project(s).

includeReferences = [true|false]
* this will include referenced DLLs

recursive = [true|false]
* this will set the recursion through all dependancies capability.

Example:

##macro.bin;
assembly = Mobux.Web.Public;
includeProjects = true;
includeReferences = false;
##
File /nonfatal "%%absfilename%%"
##
macro.end
##

+ The final thing that we did in this release was make the script language
MUCH more tolerant of white space. As you can see in the above example you
can now split macros, imports or any command across lines and have as much
white space as you desire in your scripts. You can also use any case you
like with commands.

For more information on PreNIS you should go to the following places:

1. Learn about it at http://www.pixolut.com/prenis

2. Find out about NSIS http://nsis.sourceforge.net/

3. Contribute to the project at http://www.sourceforge.net/projects/prenis/