Wednesday, February 29, 2012

Netbean Maven project include WS client code

Maven project in netbeans that include some webserivce client code reference to generated java code,but those code is not in classpath,so it cause error in IDE,but command clean package is OK.
put following code in pom.xml build-plugins

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-ws-source</id>
<phase>gernated-source</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java-gen</source>
</sources>
</configuration>
</execution>
</executions>
<configuration>
</configuration>
</plugin>

Tuesday, February 28, 2012

access other user's table from sqldeveloper

while using sqldeveloper,we can only see the table belongs to the user logged in,
if you want access other user's table,you can use following method

1) right click the connection,then schema browser,so so can see other user's table
2)clik on "other users" below the connection,then user,then tables you want access

Wednesday, February 15, 2012

python code that crumble data for test

following code that read big data(fixed length) file,and scruble the specified columns data to create new data to test.

from random import randint

fa = open ('a.bbb','r')
fb = open ('b.txt','w')
i = 0
for line in fa:
i= i + 1
if(i!=1):
s = list(line)
if(len(s)>500 and s[300]!=' ' and s[300]!= ''):
print s[300] + s[301]
delta = str(int(s[300]+s[301]) + i/5000 + 1)
if (len(delta)>2):
delta = str(randint(10, 99))
x = list(delta)
if (len(delta)<2):
s[300]='0'
s[301]=x[0]
else:
s[300]=x[0]
s[301]=x[1]
print ' ---> ' + s[300] + s[301]
fb.write("".join(s))
else:
fb.write(line)
fa.close()
fb.close()

Python code that find the wrong data in huge data file

following code go though big data file find the line that data startwith letter "T"

fa = open ('a.bbb','r')
i = 0
for line in fa:
i= i + 1
if line.startswith('T'):
print i;
fa.close()

python code that separate 150000 records into 15 small files

fa = open ('b150000.txt','r')
n = 1
fb = open ('b-1.txt','w')
i = 0
for line in fa:
# 1 to 10000 for first 10001 to 20000 for second
if((i/10000 +1)!=n):
n=i/10000 + 1
fb.close()
fb = open('b-'+str(n)+'.txt','w')
fb.write(line)
i = i + 1
fa.close()
fb.close()

comments in ibatis sqlmap files

if you want put some comments in ibatis sqlmap file,you can not just like you did in sql -- two dash with comment.
you have to put all comments line this /*multiline comments */

Java 7 Diamond operator

List<String> strList = new ArrayList<>();
List<Map<String, List<String>> strList = new ArrayList<>();

Java 7 String switch

public class Test{
public static void main(String[] args){
System.out.println(monthNameToDays("March",2012));
}
public static int monthNameToDays(String s, int year) {
switch(s) {
case "April": case "June":
case "September": case "November":
return 30;
case "January": case "March":
case "May": case "July":
case "August": case "December":
return 31;
case "February":
return 28;
default:
return 0;
}
}
}

Colorful Cygwin Terminal

change Cygwin.bat to
 @echo off  C:  chdir C:\cygwin\bin  set EDITOR=vi  set VISUAL=vi  set CYGWIN=codepage:oem tty binmode title  rxvt -sr -sl 10000 -fg white -bg black -fn fixedsys -fb fixedsys -tn cygwin -e bash --login -i

Thursday, February 2, 2012

add webservice generated classes to project classpath in NetBeans

check out project from cvs, it was created by eclipse,netBeans managed classpath did not contains the classes that generated by WSDL2Java,I use following code in pom.xml to include the classes.
inside build.plugins


<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-ws-source</id>
<phase>gernated-source</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java-gen</source>
</sources>
</configuration>
</execution>
</executions>
<configuration>
</configuration>
</plugin>