Wednesday, June 25, 2014

Make the table smaller for test and restore it back

Scenario:
There's a huge table with 40 million records or more and now for test purpose need limit the records to the latest 5 days records. After the test, need
restore the table.
Resolution:
Delete would be very, very slow. It may need 24 hours or even longer. The best way is to rename the table and create the new table.

Thursday, June 12, 2014

gradle note

1.
The left shift operator << is a shortcut for the action doLast.
task helloWorld {
doLast {
println 'Hello world!'
}
}
equals to
task helloWorld << {
println 'Hello world!'
}

2.
gradle -q tasks
gradle -q tasks --all
gradle -q helloWorld -> gradle -q hW
gradle -b ... Use this option to execute a build script with a different name other then build.gradle

3.
http://www.gradle.org/docs/current/dsl/index.html
jar{
exclude('**/*.properties')
}

4.
mavenLocal()
mavenCentral()
From http://www.gradle.org/docs/current/javadoc/index.html
DependencyHandler
   //declaring arbitrary files as dependencies
   compile files('hibernate.jar', 'libs/spring.jar')

   //putting all jars from 'libs' onto compile classpath
   compile fileTree('libs')
maven { url "http://cptrasv01:8081/nexus/content/groups/public/" }
    compile group: 'com.tdsecurities.stars.mdm', name: 'midas_common', version:'1.0.1-SNAPSHOT'

5. gradle plugin application does not work for inteactive console application even the below is added into the build.gradle
run{
    standardInput = System.in
}

6. Changing the project default layout
sourceSets {
main {
java {
srcDirs = ['src']
}
}
test {
java {
srcDirs = ['test']
}
}
}
buildDir = 'out'

7.
Using the wrapper is considered best practice and should be mandatory for every Gradle
project. Gradle scripts backed by the wrapper are perfectly prepared to run as part of
automated release processes like continuous integration and delivery.

drop table

default drop table does not free the table space, while truncate table will free the table space.
The fastest way to unload and load data from/to oracle is to use some pro*c to "flatten out" the data to a flat file and sqlldr
with direct path mode to reload it. (By Tom)
My test shows that it needs 5 minutes to unload 50 millions data from the database (4G csv file)

Monday, June 2, 2014

SLF4J, logback and groovy

logback.groovy does not support
<configuration debug="true"> in logback.xml.
statusListener(OnConsoleStatusListener) may help.
Or add the below to the source:
LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);

HelloWorld.java
package log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;

public class HelloWorld {
public static void main(String[] args) {
LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);
Logger logger = LoggerFactory.getLogger(HelloWorld.class);
logger.info("Hello World!");
}
}


logback.xml

<configuration debug="true">

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>myApp.log</file>
    <encoder>
      <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{yyyyMMdd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="debug">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
  </root>
  
</configuration>

logback.groovy

statusListener(OnConsoleStatusListener)

appender("FILE", FileAppender) {
  file = "myApp.log"
  encoder(PatternLayoutEncoder) {
    pattern = "%date %level [%thread] %logger{10} [%file:%line] %msg%n"
  }
}

appender("STDOUT", ConsoleAppender) {
  encoder(PatternLayoutEncoder) {
    pattern = "%d{yyyyMMdd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
  }
}

root(DEBUG, ["FILE","STDOUT"])

Sunday, June 1, 2014

The elephant and the ant

http://books.google.ca/books?id=sNF5PxD0SV4C&printsec=frontcover&dq=the+ant+and+the+elephant&hl=en&sa=X&ei=n9uLU6_wKoKe8gHZuYDwDQ&ved=0CDoQ6AEwAA#v=onepage&q=the%20ant%20and%20the%20elephant&f=false
1. Just when it seemed he would be swept downstream and gone forever, the ant grabbed onto a snag and scrambled to safety.
2. The ant remained stranded wondering what he would do, ...
3. called the ant in his wee, small voice.
4. I've had my swim for today, and besides, if I went racing about helping everyone who was in trouble I'd have no time left to relax.
5. Then the turtle tottered on his way to ...
6. Suddenly he went toppling backward and landed upside down.
7. "Blast it all, " he muttered. "Dad blame it! " And he began thrashing out with his legs.
8. As he stretched his stringy neck looking about for help, the turtle spied a hornhill roosting on her nest high on a tree limb.
9. As she leaned down to say more, the hornbill tipped the nest and her one big egg rolled out to go tumbling all the way to the ground. Luckily it landed in a clump of fluff-twuff weeds without so much as a crack.
10. Still she kept on furiously thrashing the air until her wings worn to a frazzle.
11. a giraffe came striding along
12. He flopped down with such a whump! it upset a huge boulder which was all set to topple. 
13. With a furious roar he leaped to his feet, tugging frantically to free himself.
14. he went lumbering off the trees
15. "Out of my way, you stupid stump!" He snorted. And with a furious lunge he tried to knock over the stump. This drove the horn still deeper. Then with a mighty tug he tried pulling himself free, but the stump refused to let go. At last the rhino realized he was hopelessly stuck.
16. That would have been that if a jolly big somebody hadn't decided to take a stroll through the jungle that day.
17. Then without a word of thanks the old codger went tottering away down the bank to disappear in the river.
18. The elephant didn't suspect there was a deep ravine just ahead. It was too well hidden by scatter-flat ferns.
19. He waited for hours, staring up at the sky until it faded into evening and a deep stillness settled over the jungle.