Showing posts with label DevTips. Show all posts
Showing posts with label DevTips. Show all posts

Tuesday, January 20, 2015

[Oracle] How to get raw counts of all tables at once


SQL Query : 

select
      table_name,
      to_number(
        extractvalue(
          xmltype(dbms_xmlgen.getxml('select count(*) c from '||table_name))
          ,'/ROWSET/ROW/C')
          )
          count
    from user_tables 
/



Saturday, May 17, 2014

Tip: Find and Replace a string in multiple files at onces by avoiding LTS (Leaning toothpick syndrome)

Linux Command:

$ grep -lR "oldString" -r | xargs sed -i 's/oldString/newString/g'


How to avoid LST.

If your oldString or newString contains character "/" (the delimiter), then Delimiter collision occurs, which cause to LST.  To avoid that, select another delimiter such as # or ? in sed command.

examples:

sed -i 's#oldString#newString#g'
sed -i 's?oldString?newString?g'




Thursday, April 25, 2013

Tips - Some useful parameters for starting a WSO2 server

Before you start, first go to <CarbonHOME>/bin . Where <CarbonHOME> is the directory of the carbon server.


Start a carbon server with 1 port offset

(Useful when you need to start multiple servers (ESB, BPS, AS etc) at same time)

$ ./wso2server.sh -DportOffset=1



Start a Carbon server with remote-debug mode on port 5005


$ ./wso2server.sh debug 5005


 

Tips - Remote Debug with Maven 3 - Plug-in Debug

How to Debug a Maven Plug-in at Build time.

1) Open maven plug-in source code using your favorite IDE ( Eclipse, InterlliJ IDEA etc) and set break points in codes that you are going to debug.

2) Start build project using following command.

$ mvnDebug clean install 
 
3) maven starts to Listen on port 8000 till a remote debugger connects.

$ mvnDebug clean install
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000

 
4) Start remote debug on port 8000 using your IDE. It will trigger the build process with remote debug.

Tips - Remote Debug with Maven 3 - Test-cases

How To Debug Test-cases with Maven at maven run time

1) Open your Project with your favorite IDE ( eclipse, intellij IDEA etc) and set break points that you are going to debug.

2) Build the project using following parameters

$mvn clean install -Dmaven.surefire.debug

3) It starts to build your project and it will stop at test cases.

[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ org.wso2.bps.integration.tests ---
[INFO] Compiling 41 source files to /data/source/branch/carbon410/platform/products/bps/3.0.2/modules/integration/org.wso2.bps.integration.tests/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12:test (default-test) @ org.wso2.bps.integration.tests ---
[INFO] Surefire report directory: /data/source/branch/carbon410/platform/products/bps/3.0.2/modules/integration/org.wso2.bps.integration.tests/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Listening for transport dt_socket at address: 5005



4) Start remote debug on port 5005 using your IDE. It will trigger the build process with remote debug.


Source : http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html

Sunday, February 3, 2013

Limit the scope of the SVN Checkout - Example


Assume We want to checkout WSO2 Carbon branch 4.0.0 source code from [1]. But our target branch source is located under following sub locations.  
  1. https://svn.wso2.org/repos/wso2/carbon/kernel/branches/4.0.0/
  2. https://svn.wso2.org/repos/wso2/carbon/orbit/branches/4.0.0/
  3. https://svn.wso2.org/repos/wso2/carbon/platform/branches/4.0.0/
To give you a better idea, above three svn locations are represented in tree view in the following diagram. 

carbon/
├── kernel
│   ├── branches
│   │   └── 4.0.0
│   ├── graduated
│   ├── tags
│   └── trunk
├── orbit
│   ├── branches
│   │   └── 4.0.0
│   ├── graduated
│   ├── tags
│   └── trunk
└── platform
    ├── branches
    │   └── 4.0.0
    ├── graduated
    ├── tags
    └── trunk


Possible Methods of SVN checkouts for our problem


We can either use following options.

  1. checkout entire Carbon platform ( including trunk, branches, etc.) (  $svn co https://svn.wso2.org/repos/wso2/carbon  )
  2. checkout each above svn code locations separately. ( $svn co https://svn.wso2.org/repos/wso2/carbon/kernel/branches/4.0.0/  . Similarly other two locations.  )

But first method is too time consuming, because it checkout entire Carbon Platform. So second method seems to be a good choice, but is also have some (minor) negative points.
Since codes are not in same svn structure (as in the first method) in file system, maintaining can be a little bit hard. Also If you need to checkout another location ( for example let's say carbon/platform/trunk ), again you need to checkout it separately.
So it is better to have some mechanism to narrow down the svn scope when checkout the code. There are some reference articles in end of this post. Refer them to get more information about this technique. Let's see how we can do this.

Limit the Scope of the SVN checkout


( Here I am using the subversion client which come with Ubuntu )

Let's try to checkout only following structure. 

carbon/
├── kernel
│   └── branches
│       └── 4.0.0
├── orbit
│   └── branches
│       └── 4.0.0
└── platform
    └── branches
        └── 4.0.0



Step 1 - Making svn structure up to 1 level depth. 


type following commands in terminal ( instructions are in bold letters.)

~/wso2 $ svn co https://svn.wso2.org/repos/wso2/carbon --depth immediates
A    carbon/orbit
A    carbon/kernel
A    carbon/platform
Checked out revision 160720.
~/wso2 $ 

this will create following svn structure on the file system.

carbon/
├── kernel
├── orbit
└── platform



Step 2 - Making path kernel/branches/4.0.0


type following commands in terminal ( instructions are in bold letters.)


~/wso2 $ cd carbon/kernel/
~/wso2/carbon/kernel $ svn up --set-depth empty branches
Updating 'branches':
A    branches
Updated to revision 160722. 
~/wso2/carbon/kernel $ cd branches/
~/wso2/carbon/kernel/branches $ svn up --set-depth empty 4.0.0
Updating '4.0.0':
A    4.0.0
Updated to revision 160722.
~/wso2/carbon/kernel/branches $

now we have created following svn structure.
carbon/
├── kernel
│   └── branches
│       └── 4.0.0
├── orbit
└── platform
 But still kernel/branches/4.0.0 doesn't contain any file. So let's update kernel/branches/4.0.0.

move to 4.0.0 directory using 

~/wso2/carbon/kernel/branches $ cd 4.0.0
Then type
~/wso2/carbon/kernel/branches/4.0.0 $ svn up --set-depth infinity
this will update all files located under https://svn.wso2.org/repos/wso2/carbon/kernel/branches/4.0.0/.

Step 3 - Repeat step 2 for other two locations ( for orbit and platform ).




Advantages:

  • All three locations are under some svn tree.
  • Quick.
  • Limits the scope and skips unnecessary locations. 
  • Taking svn up at svn root directory ( in this example carbon ) will update only above three locations which we made using this examples. other will not update.
  • Easy Maintenance.


Reference

  1. http://svnbook.red-bean.com/en/1.7/svn.ref.svn.html
  2. http://svnbook.red-bean.com/en/1.6/svn.advanced.sparsedirs.html

Sunday, February 19, 2012

[TIP] Use Linux Pipelines and Make your life easier

Suppose you want to get the history of your terminal (commands, that you have typed  in the terminal) and find out a command that you have used log time ago.

So you can simply use history command to list down command history and find it.

$ history

( By default Linux store only last 1000 history of your command line. you can find the history file and size of history by typing following command. you can change these values changing global profile value of the terminal. )

$ echo $HISTFILE 
$ echo $HISTSIZE

But if your list is bigger one you may need to do a search to find your command. 
for example you can use grep command to find it. See following command set.

$ history > history.txt 
$ grep -i "dpkg" history.txt
 1761  dpkg -s jflex
 1974  dpkg -s cup
$ rm history.txt

In first command it writes history into a text file. In the second line, it search for "dpkg" with ignoring the case in the history.txt and it shows the results in next two lines. After that in the 5th line it removes the history.txt file.

But we can do this easily using Linux pipelines. It generates no intermediate files and can obtain result using one line. here is the command.

$ history | grep -i "dpkg" 
 1761  dpkg -s jflex
 1974  dpkg -s cup 

This is a simple example that use Linux pipelines. You can use this for very complex stuffs.  Read this Wikipedia page to learn more on Linux pipelines.

Here is another example that use pipeline.

$ find . -name .svn | xargs rm -fr

this command removes all .svn directories in current path.( Also you can use non pipeline solution to do this. see following command )

find . -name .svn -exec rm -rf {} \;

Tuesday, September 6, 2011

Remote debugging problem (Tomcat): "Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options"


 Hi all,

Today I tried to remotely debug the Apache ODE source using Apache Tomcat 7 and Intellij IDEA. If you are interested in remotely debug,  follow this tutorial http://isharapremadasa.blogspot.com/2011/09/how-to-debug-apache-ode-with-apache.html.

Problem:

I tried it in windows 7. But i was unable to halt the Tomcat's the catalina script at ODE deployment. So i tried to set following windows environment variables (given by IDEA, and modified as suspend=y) for JAVA_OPTS using, 

set JAVA_OPTS=%JAVA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000

and then tried to run catalina script by running,

catalina.bat jpda run

Then I got this;

ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.
Error occurred during initialization of VM
agent library failed to init: jdwp

Why ? and Solution

Then I googled about this problem and found the error: when i am going to define both JPDA and environment variables at ones, it cause to generate two instance of debugger and that is not possible. By removing one of them will solve the problem.

So I tried it again removing jpda parameter, and finally I was able to halt the catalina script without ODE deployment.


Notes:


JPDA stands for The Java Platform Debugger Architecture. which is a collection of APIs to debug Java code. (see http://en.wikipedia.org/wiki/JPDA )