Friday, September 14, 2012


;SQLSERVER2008 Configuration File
[SQLSERVER2008]

; Specify the Instance ID for the SQL Server features you have specified. SQL Server directory structure, registry structure, and service names will reflect the instance ID of the SQL Server instance.

INSTANCEID="MSSQLSERVER"

; Specifies a Setup work flow, like INSTALL, UNINSTALL, or UPGRADE. This is a required parameter.

ACTION="Install"

; Specifies features to install, uninstall, or upgrade. The list of top-level features include SQL, AS, RS, IS, and Tools. The SQL feature will install the database engine, replication, and full-text. The Tools feature will install Management Tools, Books online, Business Intelligence Development Studio, and other shared components.

FEATURES=SQLENGINE,REPLICATION,FULLTEXT,CONN,SSMS,ADV_SSMS,SNAC_SDK

; Displays the command line parameters usage

HELP="False"

; Specifies that the detailed Setup log should be piped to the console.

INDICATEPROGRESS="True"

; Setup will not display any user interface.

QUIET="False"

; Setup will display progress only without any user interaction.

QUIETSIMPLE="True"

; Specifies that Setup should install into WOW64. This command line argument is not supported on an IA64 or a 32-bit system.

X86="False"

; Detailed help for command line argument ENU has not been defined yet.

ENU="True"

; Parameter that controls the user interface behavior. Valid values are Normal for the full UI, and AutoAdvance for a simplied UI.

UIMODE="Normal"

; Specify if errors can be reported to Microsoft to improve future SQL Server releases. Specify 1 or True to enable and 0 or False to disable this feature.

ERRORREPORTING="False"

; Specify the root installation directory for native shared components.

INSTALLSHAREDDIR="C:\Program Files\Microsoft SQL Server"

; Specify the root installation directory for the WOW64 shared components.

INSTALLSHAREDWOWDIR="C:\Program Files (x86)\Microsoft SQL Server"

; Specify the installation directory.

INSTANCEDIR="C:\Program Files\Microsoft SQL Server"

; Specify that SQL Server feature usage data can be collected and sent to Microsoft. Specify 1 or True to enable and 0 or False to disable this feature.

SQMREPORTING="False"

; Specify a default or named instance. MSSQLSERVER is the default instance for non-Express editions and SQLExpress for Express editions. This parameter is required when installing the SQL Server Database Engine (SQL), Analysis Services (AS), or Reporting Services (RS).

INSTANCENAME="MSSQLSERVER"

; Agent account name

AGTSVCACCOUNT="NT AUTHORITY\SYSTEM"

; Auto-start service after installation.

AGTSVCSTARTUPTYPE="Automatic"

; Startup type for Integration Services.

ISSVCSTARTUPTYPE="Automatic"

; Account for Integration Services: Domain\User or system account.

ISSVCACCOUNT="NT AUTHORITY\NetworkService"

; Controls the service startup type setting after the service has been created.

ASSVCSTARTUPTYPE="Automatic"

; The collation to be used by Analysis Services.

ASCOLLATION="Latin1_General_CI_AS"

; The location for the Analysis Services data files.

ASDATADIR="Data"

; The location for the Analysis Services log files.

ASLOGDIR="Log"

; The location for the Analysis Services backup files.

ASBACKUPDIR="Backup"

; The location for the Analysis Services temporary files.

ASTEMPDIR="Temp"

; The location for the Analysis Services configuration files.

ASCONFIGDIR="Config"

; Specifies whether or not the MSOLAP provider is allowed to run in process.

ASPROVIDERMSOLAP="1"

; A port number used to connect to the SharePoint Central Administration web application.

FARMADMINPORT="0"

; Startup type for the SQL Server service.

SQLSVCSTARTUPTYPE="Automatic"

; Level to enable FILESTREAM feature at (0, 1, 2 or 3).

FILESTREAMLEVEL="0"

; Set to "1" to enable RANU for SQL Server Express.

ENABLERANU="False"

; Specifies a Windows collation or an SQL collation to use for the Database Engine.

SQLCOLLATION="SQL_Latin1_General_CP1_CI_AS"

; Account for SQL Server service: Domain\User or system account.

SQLSVCACCOUNT="NT AUTHORITY\SYSTEM"

; Windows account(s) to provision as SQL Server system administrators.

SQLSYSADMINACCOUNTS="VC-VM\Administrator"

; The default is Windows Authentication. Use "SQL" for Mixed Mode Authentication.

SECURITYMODE="SQL"

SAPWD="oplAdmin123"

; Provision current user as a Database Engine system administrator for SQL Server 2008 R2 Express.

ADDCURRENTUSERASSQLADMIN="False"

; Specify 0 to disable or 1 to enable the TCP/IP protocol.

TCPENABLED="1"

; Specify 0 to disable or 1 to enable the Named Pipes protocol.

NPENABLED="1"

; Startup type for Browser Service.

BROWSERSVCSTARTUPTYPE="Disabled"

; Specifies how the startup mode of the report server NT service.  When
; Manual - Service startup is manual mode (default).
; Automatic - Service startup is automatic mode.
; Disabled - Service is disabled

RSSVCSTARTUPTYPE="Automatic"

; Specifies which mode report server is installed in.
; Default value: “FilesOnly”

RSINSTALLMODE="FilesOnlyMode"

; Add description of input argument FTSVCACCOUNT

FTSVCACCOUNT="NT AUTHORITY\LOCAL SERVICE"

Tuesday, September 11, 2012

Locking in multiuser environment


These are methodologies used to handle multi-user issues. How does one handle the fact that 2 people want to update the same record at the same time?

1. Do Nothing
- User 1 reads a record
- User 2 reads the same record
- User 1 updates that record
- User 2 updates the same record
User 2 has now over-written the changes that User 1 made. They are completely gone, as if they never happened. This is called a 'lost update'.

2. Lock the record when it is read. Pessimistic locking
- User 1 reads a record *and locks it* by putting an exclusive lock on the record (FOR UPDATE clause)
- User 2 attempts to read *and lock* the same record, but must now wait behind User 1
- User 1 updates the record (and, of course, commits)
- User 2 can now read the record *with the changes that User 1 made*
- User 2 updates the record complete with the changes from User 1
The lost update problem is solved. The problem with this approach is concurrency. User 1 is locking a record that they might not ever update. User 2 cannot even read the record because they want an exclusive lock when reading as well. This approach requires far too much exclusive locking, and the locks live far too long (often across user control - an *absolute* no-no). This approach is almost *never* implemented.

3. Use Optimistic Locking. Optimistic locking does not use exclusive locks when reading. Instead, a check is made during the update to make sure that the record has not been changed since it was read. This can be done by checking every field in the table.
ie. UPDATE Table1 SET Col2 = x WHERE COL1=:OldCol1 AND COl2=:OldCol AND Col3=:OldCol3 AND...
There are, of course, several disadvantages to this. First, you must have already SELECTed every single column from the table. Secondly, you must build and execute this massive statement. *Most* people implement this, instead, through a single column, usually called timestamp. This column is used *for no other purpose* than implementing optimistic concurrency. It can be a number or a date. The idea is that it is given a value when the row is inserted. Whenever the record is read, the timestamp column is read as well. When an update is performed, the timestamp column is checked. If it has the same value at UPDATE time as it did when it was read, then all is well, the UPDATE is performed and *the timestamp is changed!*. If the timestamp value is different at UPDATE time, then an error is returned to the user - they must re-read the record, re-make their changes, and try to update the record again.

- User 1 reads the record, including the timestamp of 21
- User 2 reads the record, including the timestamp of 21
- User 1 attempts to update the record. The timestamp in had (21) matches the timestamp in the database(21), so the update is performed and the timestamp is update (22).
- User 2 attempts to update the record. The timestamp in hand(21) *does not* match the timestamp in the database(22), so an error is returned. User 2 must now re-read the record, including the new timestamp(22) and User 1's changes, re-apply their changes and re-attempt the update.

Sunday, March 4, 2012

Add digits stored in linklist nodes.The digits are in reverse order Eg: Add 354 and 445 L1 : ->4->5->3->null L2 : ->5->4->4->null Ans : ->9->9->7->null
 class Node{  
      public int data;  
      public Node next;  
      public Node(int n){  
           this.data = n;  
           this.next = null;  
      }  
 }  
 public class LinkList{  
      public Node addNode(Node head, int n){  
           if(head == null){  
                head = new Node(n);  
                return head;  
           }  
           Node curr = head;  
           while(curr.next != null){  
                curr = curr.next;  
           }  
           curr.next= new Node(n);  
           return head;  
      }  
      public static void printLinkList(Node head){  
           if(head == null){  
                return;  
           }  
           Node curr = head;  
           while(curr != null){  
                System.out.print("->"+curr.data);  
                curr = curr.next;  
           }  
           System.out.print("->null");  
           System.out.println();  
      }  
      public static Node addLists(Node head1, Node head2){  
           if(head1==null && head2==null){  
                return null;  
           }else if(head1 == null){  
                return head2;  
           }else if(head2 == null){  
                return head1;  
           }  
           Node newHead = null;  
           Node newCurr = null;  
           Node curr1 = head1;  
           Node curr2 = head2;  
           int carry = 0;  
           while(curr1 != null && curr2 != null){  
                int newSum = curr1.data + curr2.data + carry;  
                if(newSum >= 10){  
                     carry = 1;  
                     newSum = newSum - 10;  
                }else{  
                     carry = 0;  
                }  
                if(newHead == null){//first node  
                     newHead = new Node(newSum);  
                     newCurr = newHead;  
                }else{//subsequent nodes  
                     newCurr.next = new Node(newSum);  
                     newCurr = newCurr.next;  
                }  
                curr1= curr1.next;  
                curr2= curr2.next;  
           }  
           while(curr1 != null){  
                int newSum = curr1.data + carry;  
                if(newSum >= 10){  
                     carry = 1;  
                     newSum = newSum - 10;  
                }else{  
                     carry = 0;  
                }  
                newCurr.next = new Node(newSum);  
                newCurr = newCurr.next;  
                curr1= curr1.next;  
           }  
           while(curr2 != null){  
                int newSum = curr2.data + carry;  
                if(newSum >= 10){  
                     carry = 1;  
                     newSum = newSum - 10;  
                }else{  
                     carry = 0;  
                }  
                newCurr.next = new Node(newSum);  
                newCurr = newCurr.next;  
                curr2= curr2.next;  
           }  
           if(carry == 1){  
                newCurr.next = new Node(1);  
                newCurr = newCurr.next;  
           }  
           newCurr.next = null;  
           return newHead;  
      }  
      public static void main(String args[]){  
           LinkList l1 = new LinkList();  
           Node head1 = l1.addNode(null, 1);  
           head1 = l1.addNode(head1, 2);  
           head1 = l1.addNode(head1, 6);  
           head1 = l1.addNode(head1, 9);  
           LinkList l2 = new LinkList();  
           Node head2 = l2.addNode(null, 4);  
           head2 = l2.addNode(head2, 5);  
           head2 = l2.addNode(head2, 5);  
           LinkList.printLinkList(head1);  
           LinkList.printLinkList(head2);  
           Node head3 = LinkList.addLists(head1, head2);  
           LinkList.printLinkList(head3);  
      }  
 }  

Saturday, February 25, 2012

String compression

 public class Compress {  
      public static void compressStr(String str){  
           if(str == null || str.length() < 2){  
                return;  
           }  
           if(countCompression(str) >= str.length()){  
                System.out.println("Should not compress");  
                return;  
           }  
           char[] a = str.toCharArray();  
           int src = 1;  
           int dst = 0;  
           int count = 1;  
           while(src < a.length){  
                if(a[src-1] == a[src]){  
                     count++;  
                }else{  
                     System.out.println("The prev val is "+a[src-1]+" and next val is "+a[src]);  
                     a[dst++] = a[src-1];  
                     a[dst++] = (char) (count + '0');  
                     count = 1;  
                }  
                src++;  
           }  
           System.out.println("The src val is "+src+" and next val is "+count);  
           String compStr = new String(a, 0, dst);  
           compStr = compStr + str.charAt(a.length-1) + count;  
           System.out.println("The compressed str is "+compStr);  
      }  
      public static int countCompression(String str){  
           char[] a = str.toCharArray();  
           int src = 1;  
           int count = 1;  
           int size = 0;  
           while(src < a.length){  
                if(a[src-1] == a[src]){  
                     count++;  
                }else{  
                     size += 1 + String.valueOf(count).length();  
                     count = 1;  
                }  
                src++;  
           }  
           size += 1 + String.valueOf(count).length();  
           System.out.println("The compressed size is "+size);  
           return size;  
      }  
      public static void main(String args[]){  
           compressStr("aabbccccccc");  
      }  
 }  
This is to remove dups from a sorted int or char[]



 public class RemoveDups {  
      public static void removeDups(int[] a){  
           if(a == null || a.length < 2){  
                return;  
           }  
           int count = 1; //init to 1 to take care of last matching character  
           for(int i = 1; i < a.length; i++){  
                if(a[i-1] == a[i]){  
                     count++;  
                     if(count > a.length/2){  
                          System.out.println("The val "+a[i]);  
                          return;  
                     }  
                }else{  
                     count = 1;  
                }  
           }  
      }  
      public static void removeDupsStr(String str){  
           if(str == null || str.length() < 2){  
                return;  
           }  
           char a[] = str.toCharArray();  
           int src = 1;  
           int dst = 1;  
           while(src < a.length){  
                if(a[src-1] == a[src]){  
                     src++;  
                }else{  
                     a[dst] = a[src];  
                     dst++;  
                }  
           }  
           System.out.println("The str is "+new String(a,0,dst));  
      }  
      public static void removeDupsStringInN(String str){  
           if(str == null || str.length() < 2){  
                return;  
           }  
           char[] a= str.toCharArray();  
           boolean[] flag = new boolean[256];  
           for(int i = 0; i < flag.length; i++){  
                flag[i] = false;  
           }  
           int src = 0;  
           int dst = 0;  
           while(src < a.length){  
                if(!flag[a[src]]){  
                     a[dst] = a[src];  
                     dst++;  
                     flag[a[src]] = true;  
                }  
                src++;  
           }  
           System.out.println("The str is "+new String(a,0,dst));  
      }  
      public static void main(String args[]){  
           int a[] = { 1,1,1,1,3,3,3,3,3};  
           removeDups(a);  
           removeDupsStr("aaijsy");  
           removeDupsStringInN("sayaji");  
      }  
 }  

Wednesday, February 15, 2012

Longest Common Subsequence

 public class LCSequence {  
      public String lcs(String a, String b) {  
           int[][] lengths = new int[a.length()+1][b.length()+1];  
           // row 0 and column 0 are initialized to 0 already  
           for (int i = 0; i < a.length(); i++)  
                for (int j = 0; j < b.length(); j++)  
                     if (a.charAt(i) == b.charAt(j))  
                          lengths[i+1][j+1] = lengths[i][j] + 1;  
                     else  
                          lengths[i+1][j+1] =  
                          Math.max(lengths[i+1][j], lengths[i][j+1]);  
           // read the substring out from the matrix  
           StringBuffer sb = new StringBuffer();  
           for (int x = a.length(), y = b.length();  
                     x != 0 && y != 0; ) {  
                if (lengths[x][y] == lengths[x-1][y])  
                     x--;  
                else if (lengths[x][y] == lengths[x][y-1])  
                     y--;  
                else {  
                     if(a.charAt(x-1) == b.charAt(y-1)){  
                          sb.append(a.charAt(x-1));  
                          x--;  
                          y--;  
                     }  
                }  
           }  
           System.out.println("The DP table is: ");   
           for (int i=0; i<lengths.length; i++) {   
                for (int j=0; j<lengths[i].length; j++) {   
                     System.out.print(" " + lengths[i][j]);   
                }   
                System.out.println("");   
           }   
           return sb.reverse().toString();  
      }  
      public static void main(String args[]){   
           LCSequence m = new LCSequence();   
           System.out.println("The LCS is "+m.lcs("12","1122"));   
      }   
 }  



Sunday, February 12, 2012

Why is string immutable in Java

1) Performance (string pooling)
2) thread safety ( we can pass around strings between threads and not worry about anyone changing it)
3) Security
http://geekexplains.blogspot.com/2009/11/why-string-has-been-made-immutable-in.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+GeekExplains+%28Geek+Explains%29