Category Archives: Java

Audit Master Table by Trigger

Misal Nama Table yang kita mau audit adalah table M_PRICE dan kita mau mengaudit setiap ada activity Add, Update and Delete terhadadap table ini.
Kita perlu 2 table untuk mengaudit, satu untuk mencatat data2 yang diubah (tracking), satu table lagi digunakan untuk mencatat summary sudah berapa kali berubah master table tersebut.

M_PRICE ==> master table

M_PRICE_A ==> Audit table

M_PRICE_C ==> tracking berapa kali berubah

Dan berikut Triger yang bisa kita buat dengan nama M_PRICE_T

 

create or replace
TRIGGER M_PRICE_T BEFORE INSERT OR DELETE OR UPDATE ON M_PRICE FOR EACH ROW
DECLARE
l_change_num NUMBER;
BEGIN
— Increment the change_num for this table and keep the new value
UPDATE M_PRICE_C set change_num = change_num+1 returning change_num into l_change_num;

– Insert appropriate audit row(s)
IF INSERTING THEN
INSERT INTO M_PRICE_A(PRICE_ID, PRICE_NAME, change_num, aud_action, aud_timestamp) VALUES(:new.PRICE_ID, :new.PRICE_NAME, l_change_num, ‘I’, SYSDATE);
ELSIF UPDATING THEN
INSERT INTO M_PRICE_A(PRICE_ID, PRICE_NAME, change_num, aud_action, aud_timestamp) VALUES(:new.PRICE_ID, :new.PRICE_NAME, l_change_num, ‘AU’, SYSDATE);
INSERT INTO M_PRICE_A(PRICE_ID, PRICE_NAME, change_num, aud_action, aud_timestamp) VALUES(:old.PRICE_ID, : old.PRICE_NAME, l_change_num, ‘BU’, SYSDATE);
ELSE
INSERT INTO M_PRICE_A(PRICE_ID, PRICE_NAME, change_num, aud_action, aud_timestamp) VALUES(:old.PRICE_ID, : old.PRICE_NAME, l_change_num, ‘D’, SYSDATE);
END IF;
END M_PRICE_T;

In Oracle how to Check is there any table got locked?

Here is the query

SELECT a.sid,a.serial#, a.username,c.os_user_name,a.terminal,
b.object_id,substr(b.object_name,1,40) object_name
from v$session a, dba_objects b, v$locked_object c
where a.sid = c.session_id
and b.object_id = c.object_id

Deleting files older than 30 days automatically

1. create the script to find files older than 30 days and delete the files, suppose the script file name is deletefile

can use this

find  /home/mujoko/archive/  -mtime +30    -exec rm {} \;  // find files the older than 30 days in /home/mujoko/archive/  folder, make sure there is space after rm and before {}

or

find  /home/mujoko/archive/ -mtime +30 |xarsg rm // using this script its possible we face error too many parameters if the files is to many to delete

2. Login as root

3. Configure crontab by execute

crontab -e mujoko  //replace mujoko by your own username

4. Edit crontab by adding

30 1 * * * /home/mujoko/deletefile    //deletefile is the file you create at step 1

5. Save your crontab.

Walaaaa, your file within /home/mujoko/archive will be deleted when the files is older than 30 days.

 

 

 

 

 

What is the difference between a HashMap and a Hashtable in Java?

There are several differences between HashMap and Hashtable in Java:

  1. Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
  2. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
  3. One of HashMap’s subclasses is LinkedHashMap, so in the event that you’d want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn’t be as easy if you were using Hashtable.

 

source

http://stackoverflow.com/questions/40471/differences-between-hashmap-and-hashtable

Eclipse hot key

Edit

  • Ctrl+1 — Quick Fix: press while cursor is positioned at member variable, parameter, selection, warnings, errors, …
  • Ctrl+Space — Context Assist: press after a ., or to use macros (forwhilesysout, …). Press in class-scope to automatically create method declarations.
  • Ctrl+Shift+O — Organize Imports
  • Ctrl+Shift+F — Reformat source
  • Alt+Shift+T — Show Refactor Quick Menu

Navigation

  • Ctrl+J — Incremental Search
  • Ctrl+Shift+T — Search a type, with search on typing. You can use only the upcase letters (e.g. type “MIL” to find MouseInputListener)
  • Ctrl+F6 — Switch between last used files
  • F3 — Open declaration
  • Ctrl+Alt+H — Open Call Hierarchy

Commenting

  •  Ctrl+Shift+/ – Toggling comment

Show all Hot Key

Ctrl+Shift+L

To maintain connection to MySQL while idle in hibernate.

Add this in hibernate configuratuion.

<property name=“hibernate.c3p0.preferredTestQuery”>select 1;</property>

Git Cheatsheet

Create new branch and push to remote
$ git branch name -> create local branch
$ git push origin name -> push local branch to remote

pulling code from a remote branch and create a new local branch
$ git checkout -b [local branch name] [remote branch name]

delete remote branch
$ git push origin :name

list branch in remote repo
$ git branch -r

Switch to a master branch
$ git checkout master

merging code from other branch to master (–no-ff is to always create commit object to avoid losing
info about historical existence of another branch and groups together all commits
$ git merge –no-ff [other branch name]

delete local branch
$ git branch -d name

tag a commit for future reference (can be used for the purpose of versioning)
$ git tag -a [tag name] -m “[some description]“

To see how many commits created since the last tag or given tag
$ git describe –tags

push all tags to remote
$ git push –tags

push one tag to remote
$ git push origin [tag name]

list existing tags
$ git tag -l

checkout a tagged revision and create a branch
$ git checkout -b name tags/[tag name]

Update on 08th May 2o12

Delete Branch at Remote:
$ git push origin –delete name

To remove a tag on the remote server:
$ git push origin :refs/tags/[tag name]

Resource:

http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

About Killing Session at Oracle

Get The session ID by this query:

 

select * from v$session
where program like 'sqlplus@s61cj185%'</pre>
set feedback off
 set serveroutput on size 9999
 column username format a20
 column sql_text format a55 word_wrapped
 begin
 for x in
 (select username||'('||sid||','||serial#||') ospid = '|| process ||
 ' program = ' || program username,
 to_char(LOGON_TIME,' Day HH24:MI') logon_time,
 to_char(sysdate,' Day HH24:MI') current_time,
 sql_address,
 sql_hash_value
 from v$session
 where status = 'ACTIVE'
 and rawtohex(sql_address) <> '00'
 and username is not null ) loop
 for y in (select sql_text
 from v$sqlarea
 where address = x.sql_address ) loop
 if ( y.sql_text not like '%listener.get_cmd%' and
 y.sql_text not like '%RAWTOHEX(SQL_ADDRESS)%' ) then
 dbms_output.put_line( '--------------------' );
 dbms_output.put_line( x.username );
 dbms_output.put_line( x.logon_time || ' ' || x.current_time || ' SQL#=' || x.sql_hash_value);
 dbms_output.put_line( substr( y.sql_text, 1, 250 ) );
 end if;
 end loop;
 end loop;
 end;
 /

And kill using this query:

ALTER SYSTEM DISCONNECT SESSION ’7,36875′ IMMEDIATE;

or
ALTER SYSTEM KILL SESSION ‘sid,serial#’ IMMEDIATE

Unlock user account for Oracle

Steps to unlock User

sqlplus /nolog;
conn / as sysdba;
alter user <usernme> account unlock;

IPhone bookmark

1. Objective C

2.Iphone Dev

3. http://cocoadevcentral.com/d/learn_objectivec/

4. http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-1/

Follow

Get every new post delivered to your Inbox.