Thursday, April 24, 2014

Creating Projections in GetEventStore

Why do you need to create projections? Well currently Im trying to debug a problem and need to find out everything that happened to an order that was placed. I know the Id of the order and want to search the entire GetEventStore and find out everything about it.

GetEventStore: Projections Tab
Note: To be able to access this, you must turn on runProjections=true in the GES config file.

Step 1: Click on New Projection

Delete the code in the Source. Add your Javascript. For Example, I had to go through the entire GES to search for an event where Id == 69864709-5991-49CF-8283-65E99AB343A2 (Guid)


fromStream('Test-events') 
    .when({
        $init: function () {
            return { count: 0, }; // initial state
        },
      
        OrderModified: function(s, e) {
            if(e.body.OrderId.toString() == 'a88b484d-e208-44c4-afd0-2ea1d76838cd'){
                linkTo('OrderId-a88b484d', e);
            }
        },
    }); 

2 Click on Emit Enable
3 Post. Now your Projection shows up in the Streams for analysis.

Saturday, April 12, 2014

Design Patterns - Part 1

Lately I realized that the more new stuff I am learning the more I'm forgetting to apply the basic design principles in the code. The more there is to learn the more there is remember. This only makes things complex. This blog is just a quick brush up on the design patterns we see and use in our code on a day to day basis. 

Decorator Pattern: Sean Chambers has written a good article here on the decorator pattern. There is a free chapter in the OReilly book available here. In a nutshell, this pattern comes handy if you want to extend classes at runtime instead of compile time using a form of object composition. By dynamically composing objects, we are making sure the Open Close principle is not violated. Meaning, new functionality is added without modifying base class. The pattern does what Inheritance will help accomplish just its more powerful and is executed at runtime. C# example is IO operations using streams. File Streams, Memory Streams, Buffered steams and the like.

Courtesy: MSDN


Adapter Pattern: The Adapter pattern lets you adapter one interface to another. This is the best way to deal with that legacy monster that is hard to test. Create an interface and it will hide the ugliness and help test the code too! It is different than the decorator pattern in the sense that in Decorator Pattern the interface of the objects you are composing is the same while in Adapter you change the interfaces. Adapters also have a definite sequence to them; the Adaptee must be contained by the Adapter.

Composite Design Pattern: Ray Houston from LosTechies has a good article here. In a gist: Its best for handing tree like structures where the parent and leaf nodes does not have to be dealt differently.

Friday, July 26, 2013

NHibernate.TransientObjectException : object references an unsaved transient instance - save the transient instance before flushing.

I came across this error recently and found the following on nhforge:

When a transaction is committed, the session is flushed to the database. That just means data changes are written to the database. This exception is telling us we’re trying to save an object, which is referenced another object that isn’t saved. We can infer that this means cascading is turned off for this relationship. 

Reference: http://nhforge.org/blogs/nhibernate/archive/2009/08/23/part-5-fixing-the-broken-stuff.aspx

Thursday, March 7, 2013

GroupBy Multiple Columns in LINQ

How do you  GroupBy Multiple Columns in LINQ? 

The solultion is pretty simple:
Given a collection of Books where each book has an Author and a Name, if you have group group by all authors then by the name of the book, you can do


Books.GroupBy(book => new { book.Author, book.Name });

Wednesday, May 9, 2012

Changing Subversion Username/Password

I found out that one of my colleagues was using another developers machine and was using his credentials to checkin. This really works if you dont want to be blamed.... but in real life this should not happen. Anyway to work around this problem all we had to do was to go to

C:\Users\[Username]\AppData\Roaming\Subversion\auth\svn.simple
Delete the hexa file in the folder. This will force you to re-enter your credentials the next time you check in.

Hope this helps.

Monday, September 12, 2011

Creating a branch from a previous commit.

How many times have we found ourselves not tagging a particular build and passing it on the some client. When defects are found the question that is asked everytime is "Can we fix it for that build please?" or "We cant take the risk with the current code, need to fix it for that build only". Well subversion has an update to revision and revert options what about git?


I have to fix a defect in a commit made 2 weeks ago. I have on me a SHA, what can I do? I decided to checkout that SHA so I did

bmansharamani@BINDIYA-PC /d/Ent6 (develop)
$ git checkout ddb0a72586c6b64f3d433dfe823f0156e7c5463a
Note: moving to 'ddb0a72586c6b64f3d433dfe823f0156e7c5463a' which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b
HEAD is now at ddb0a72... testing fix of repo size issue


bmansharamani@BINDIYA-PC /d/Ent6 ((ddb0a72...))
$ git checkout -b TestBranch
Switched to a new branch 'TestBranch'


Fixed the issue and whoa! the problem solved.


Saturday, May 21, 2011

Rownum Oracle

Today when creating a view I kept getting the following error:
SQL Error: ORA-00998: must name this expression with a column alias


My view was something like this:

CREATE OR REPLACE VIEW PROTOCOL_SEGMENT_INFO_VIEW AS 
SELECT ROWNUM, T.SEGMENT_ID, T.PROTOCOL_NUMBER, T.PROTOCOL_ID_PREFIX, T.PROTOCOL_ID_SUFFIX, T.MODIFIED_DATE FROM
(
SELECT ANIMAL_REQ_ORDER.SEGMENT_ID,
    PROTOCOL.PROTOCOL_NUMBER,
    PROTOCOL.PROTOCOL_ID_PREFIX,
    PROTOCOL.PROTOCOL_ID_SUFFIX,
    ANIMAL_SHIPMENT.RECEIVED_DATE MODIFIED_DATE
  FROM ANIMAL_SHIPMENT
  JOIN ANIMAL_DELIVERY ON ANIMAL_DELIVERY.ANIMAL_DELIVERY_ID = ANIMAL_SHIPMENT.ANIMAL_DELIVERY_ID
  JOIN ANIMAL_REQ_ORDER ON ANIMAL_REQ_ORDER.ANIMAL_REQ_ORDER_ID = ANIMAL_DELIVERY.ANIMAL_REQ_ORDER_ID
  JOIN SEGMENT ON SEGMENT.SEGMENT_ID = ANIMAL_REQ_ORDER.SEGMENT_ID
  JOIN EFFECTIVE_PROTOCOL_VIEW EPV ON EPV.PROTOCOL_ID = SEGMENT.PROTOCOL_ID
  JOIN PROTOCOL ON PROTOCOL.PROTOCOL_ID = EPV.EFFECTIVE_PROTOCOL_ID
UNION 
SELECT  CENSUS_TRANSACTION.SEGMENT_ID,
    PROTOCOL.PROTOCOL_NUMBER,
    PROTOCOL.PROTOCOL_ID_PREFIX,
    PROTOCOL.PROTOCOL_ID_SUFFIX,
    CENSUS_TRANSACTION.CENSUS_DATETIME MODIFIED_DATE
  FROM CENSUS_TRANSACTION
 JOIN SEGMENT ON SEGMENT.SEGMENT_ID = CENSUS_TRANSACTION.SEGMENT_ID
  JOIN EFFECTIVE_PROTOCOL_VIEW EPV ON EPV.PROTOCOL_ID = SEGMENT.PROTOCOL_ID
  JOIN PROTOCOL ON PROTOCOL.PROTOCOL_ID = EPV.EFFECTIVE_PROTOCOL_ID
UNION
SELECT SEGMENT.SEGMENT_ID,
    PROTOCOL.PROTOCOL_NUMBER,
    PROTOCOL.PROTOCOL_ID_PREFIX,
    PROTOCOL.PROTOCOL_ID_SUFFIX,
    PROTOCOL_ACCOUNT.CREATED_DATETIME MODIFIED_DATE
FROM PROTOCOL_ACCOUNT
JOIN EFFECTIVE_PROTOCOL_VIEW EPV ON EPV.PROTOCOL_ID = PROTOCOL_ACCOUNT.PROTOCOL_ID
JOIN PROTOCOL ON PROTOCOL.PROTOCOL_ID = EPV.EFFECTIVE_PROTOCOL_ID
JOIN SEGMENT ON SEGMENT.PROTOCOL_ID = PROTOCOL.PROTOCOL_ID
  ) T;


well after a lot of playing around, I realized that it was really the rownum within the view that was missing an alias. So here is what it really should have been:



CREATE OR REPLACE VIEW PROTOCOL_SEGMENT_INFO_VIEW AS 
SELECT ROWNUM ROWNUMBER, T.SEGMENT_ID, T.PROTOCOL_NUMBER, T.PROTOCOL_ID_PREFIX, T.PROTOCOL_ID_SUFFIX, T.MODIFIED_DATE FROM
(
SELECT ANIMAL_REQ_ORDER.SEGMENT_ID,
    PROTOCOL.PROTOCOL_NUMBER,
    PROTOCOL.PROTOCOL_ID_PREFIX,
    PROTOCOL.PROTOCOL_ID_SUFFIX,
    ANIMAL_SHIPMENT.RECEIVED_DATE MODIFIED_DATE
  FROM ANIMAL_SHIPMENT
  JOIN ANIMAL_DELIVERY ON ANIMAL_DELIVERY.ANIMAL_DELIVERY_ID = ANIMAL_SHIPMENT.ANIMAL_DELIVERY_ID
  JOIN ANIMAL_REQ_ORDER ON ANIMAL_REQ_ORDER.ANIMAL_REQ_ORDER_ID = ANIMAL_DELIVERY.ANIMAL_REQ_ORDER_ID
  JOIN SEGMENT ON SEGMENT.SEGMENT_ID = ANIMAL_REQ_ORDER.SEGMENT_ID
  JOIN EFFECTIVE_PROTOCOL_VIEW EPV ON EPV.PROTOCOL_ID = SEGMENT.PROTOCOL_ID
  JOIN PROTOCOL ON PROTOCOL.PROTOCOL_ID = EPV.EFFECTIVE_PROTOCOL_ID
UNION 
SELECT  CENSUS_TRANSACTION.SEGMENT_ID,
    PROTOCOL.PROTOCOL_NUMBER,
    PROTOCOL.PROTOCOL_ID_PREFIX,
    PROTOCOL.PROTOCOL_ID_SUFFIX,
    CENSUS_TRANSACTION.CENSUS_DATETIME MODIFIED_DATE
  FROM CENSUS_TRANSACTION
 JOIN SEGMENT ON SEGMENT.SEGMENT_ID = CENSUS_TRANSACTION.SEGMENT_ID
  JOIN EFFECTIVE_PROTOCOL_VIEW EPV ON EPV.PROTOCOL_ID = SEGMENT.PROTOCOL_ID
  JOIN PROTOCOL ON PROTOCOL.PROTOCOL_ID = EPV.EFFECTIVE_PROTOCOL_ID
UNION
SELECT SEGMENT.SEGMENT_ID,
    PROTOCOL.PROTOCOL_NUMBER,
    PROTOCOL.PROTOCOL_ID_PREFIX,
    PROTOCOL.PROTOCOL_ID_SUFFIX,
    PROTOCOL_ACCOUNT.CREATED_DATETIME MODIFIED_DATE
FROM PROTOCOL_ACCOUNT
JOIN EFFECTIVE_PROTOCOL_VIEW EPV ON EPV.PROTOCOL_ID = PROTOCOL_ACCOUNT.PROTOCOL_ID
JOIN PROTOCOL ON PROTOCOL.PROTOCOL_ID = EPV.EFFECTIVE_PROTOCOL_ID
JOIN SEGMENT ON SEGMENT.PROTOCOL_ID = PROTOCOL.PROTOCOL_ID
  ) T;