Thursday, December 17, 2009

Search a date range using a date range in sql

select count(*) from tablename where (@startDate between startDate and endDate )

or (@endDate between startDate and endDate)

or (@startDate <> endDate )


If this sql returns greater than 0, that means there exists a conflict with your date interval and the db working set.

Saturday, November 14, 2009

Google Go is coming fast :)

Go is …

… simple

package main

import "fmt"

func main() {
fmt.Printf("Hello, 世界\n")
}

… fast

Go compilers produce fast code fast. Typical builds take a fraction of a second yet the resulting programs run nearly as quickly as comparable C or C++ code.

… safe

Go is type safe and memory safe. Go has pointers but no pointer arithmetic. For random access, use slices, which know their limits.

… concurrent

Go promotes writing systems and servers as sets of lightweight communicating processes, called goroutines, with strong support from the language. Run thousands of goroutines if you want—and say good-bye to stack overflows.

… fun

Go has fast builds, clean syntax, garbage collection, methods for any type, and run-time reflection. It feels like a dynamic language but has the speed and safety of a static language. It's a joy to use.

… open source

Go for it.

Thursday, June 18, 2009

Searching a string in another string

 String string = "Madam, I am Adam";

// Starts with
boolean b = string.startsWith("Mad"); // true

// Ends with
b = string.endsWith("dam"); // true

// Anywhere
b = string.indexOf("I am") > 0; // true

// To ignore case, regular expressions must be used

// Starts with
b = string.matches("(?i)mad.*");

// Ends with
b = string.matches("(?i).*adam");

// Anywhere
b = string.matches("(?i).*i am.*");

Thursday, May 28, 2009

Inversion of Control

IOC is a kind of design principle; stands for abstraction of implementations from user. For example there exists a number of implementations of Interface pizzaDelivery().
One of them makes pizza in 20 minutes and the other makes in 50 minutes but both of them makes pizza. We call the interface and never think about the implementation and wait for the process to be completed, may be an example of IOC principle. By using this, we develop our codes by not caring about other peoples code or implementation. And by this we can focus on our active work, and build up a layered architecture.

Tuesday, April 21, 2009

VALIDATION PROBLEMS WERE FOUND problem: cvc-enumeration-valid

Exception:
VALIDATION PROBLEMS WERE FOUND problem: cvc-enumeration-valid:
string value '2.4' is not a valid enumeration value for
web-app-versionType in namespace http://java.sun.com/xml/ns/javaee

Solution:
While I was deploying my project on weblogic server 10.3
I had this exception at deploy ear phase. And I have found
the solution as changing the version of my web.xml
from 2.4 to 2.5.

Wednesday, April 1, 2009

java.lang.NoSuchMethodError: com.lowagie.text.Image.getPlainWidth()F

java.lang.NoSuchMethodError: com.lowagie.text.Image.getPlainWidth()F

at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1219)

at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:675)

at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:641)

at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:536)

at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:323)


I have changed the jasperreports version to 3.5.0 and itext version from 1.3.1 to 2.1.4 then problem resolved.:)

Friday, March 13, 2009

ConcurrentModificationException

For example, it is not generally permssible for one thread to modify a Collection while another thread is iterating over it.

for(Personel personel : personelList){
if(!personel.getSelected()){
personelList.remove(personel);
}else{
personel.setParent(parent);
}
}

sun

Abstract Class-Concrete Class example :)

Abstract classes are "abstraction" of a class as the name suggests. As an example: The Human class can be an abstract class and in its concrete classes "man" and "woman", some of the functionalities are common. For example "human" can have a function "walks". Now "walks" is something that belongs to all humans. But "dances" is a function that might be different for "man" and "woman" or maybe to anyone who belongs to this class. So we over ride the "dances" functionality to provide seperate implementation to different implementors.

Wednesday, March 11, 2009

Linux copy directory

You can use;

cp -Rf source_dir/ dest_dir/

to copy one directory to another. And -R parameter means Recuresively; f means forcefully.

Wednesday, March 4, 2009

eclipse.ini

Here is my eclipse.ini file :

-vm C:\Program Files\Java\jdk1.6.0_12\jre\bin
-vmargs
-Dsun.lang.ClassLoader.allowArraySyntax=true
-Xms40m
-Xmx512m

My development environment is Eclipse 3.4.1, Weblogic 10.3 ...

We were using OC4J but now we changed the Application Server to WebLogic and the JDK version 1.5 to 1.6. Some of my friends said that, If I use bea_rockit version of the JDK the memory leak occures. So I changed the virtual machine configuration to standart Sun JDK.

-Xms40m
-Xmx512m
-->
Sets the heap space 40MB initially and a maximum of 512MB. These values can differ depending on your development environment.

Thursday, January 29, 2009

JSF Session Parameters and Redirect

Putting values in the Request map is problematic issue.
JSF navigation has 2 modes:
1) Forward
2) Redirect

The forward solution is not good. Mostly because:
The Url is not updated on the browser, causing compability problems with 3rd service companies. No bookmarking available. No possibity to send URL to some by email and all sort of side effect problems.

The redirect solution is also problematic, since redirecting to a new page is a new request. This causes the data that is put in the request map to disappear.

Sun forum

Tuesday, January 20, 2009

JPQL case insensitive search

According to the JPQL spec the pattern value following the keyword LIKE must be a string literal or a string-valued input parameter. So I assume the expression lower(:username) is the problem the OpenJPA query compiler is complaining about. As a workaround you could try "lowering" the value for the username input parameter yourself before passing it to the setParameter call. Then the JPQL would look like:

SELECT u FROM User u WHERE lower(u.username) LIKE :username

Ref:

MarkMail

Sunday, January 4, 2009

Ubuntu Oracle XE setup

1-There is an apt-get repository up on oss.oracle.com for XE. Just add:

deb http://oss.oracle.com/debian unstable main non-free
to /etc/apt/sources.list and then:
# wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle 
-O- | sudo apt-key add -
# apt-get update
# apt-get install oracle-xe

'libaio' and 'bc' are in the repository, so dependencies will pull them in if the user doesn't have them. (Note: You will need to 'sudo' or have 'root' privileges to install XE.

****If you don't know the root password then you can do this like that:

sudo” means superuser do. “sudo” will prompt for “Password:”. Please specify user password

As you have noticed during the Ubuntu installation there was no question about the root password, as you might have been used to see during other Linux distribution installation process.Because of this your root accout is inactive.

If you want to enable root account (which is not recommended) enter the following command.

$sudo passwd root

This will prompt for a new root password and once you confirm it, you can start using the root account to login.


2- You must install libaio-dev package to continue and
"sudo aptitude install libaio-dev"
should do it. And you will have glibc already, and impossible to run without it.

3-As _root_ begin installing the latest available Oracle XE:
root@Ozzy:~$ su -
root@Ozzy:~# cd /home/ozer/Desktop
root@Ozzy:/home/ozer/Desktop# ls
DapperDevStatus02-Feb-2006.pdf oracle-xe_10.2.0.1-0.060128_i386.deb trash.desktop
root@Ozzy:/home/ozer/Desktop# dpkg -i oracle-xe_10.2.0.1-0.060128_i386.deb
Selecting previously deselected package oracle-xe.
(Reading database ... 58594 files and directories currently installed.)
Unpacking oracle-xe (from oracle-xe_10.2.0.1-0.060128_i386.deb) ...
This system does not meet the minimum requirements for swap space. Based on
the amount of physical memory available on the system, Oracle Database 10g
Express Edition requires 1006 MB of swap space. This system has 799 MB
of swap space. Configure more swap space on the system and retry the installation.
dpkg: error processing oracle-xe_10.2.0.1-0.060128_i386.deb (--install):
subprocess pre-installation script returned error exit status 1
Errors were encountered while processing:
oracle-xe_10.2.0.1-0.060128_i386.deb
root@Ozzy:/home/ozer/Desktop#

Ooops we have a problem here. We must increase the swap size of our ubuntu to the
requested amount of space:

How do I add more swap?

  • Usually, people associate swap with a swap partition, maybe because they've been proposed to create a swap partition on install. In fact any file can be used as a swapping device, be it a partition or a conventional file. If you're considering responsiveness, my advice: add more RAM. Swapping to a partition or a file won't change anything.
  • We will add more swap by adding a swap file.
  • Adding more swap is a four-step process :

    • a- Creating a file the size you want.
    • b- Formatting that file to create a swapping device.
    • c- Adding the swap to the running system.
    • d- Making the change permanent.
  • We will consider (as an example) a 512 Mb swap need.

  • a- Creating a file the size you want :

    • We will create a /mnt/512Mb.swap swap file.

      sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512
      • What is important here is count=512, which means we want our file to contain 512 blocks of bs=1M, which means block size = 1 Megabyte

      • Be careful *not* to do this dd of=/mnt/512Mb.swap bs=1M seek=512 count=0

        • Though the file grows to 512Mb immediately,it will have holes that makes it unusable.
  • b- Formatting that file to create a swapping device :

    sudo mkswap /mnt/512Mb.swap
  • c- Adding the swap to the running system :

    sudo swapon /mnt/512Mb.swap
    • You can see with "cat /proc/meminfo" that your additionnal swap is now available.

  • d- Making the change permanent :

    • edit your /etc/fstab:

      gksudo gedit /etc/fstab
    • and add this line at the end of the file:

      /mnt/512Mb.swap  none  swap  sw  0 0
    • save and reboot
4-After doing all this we can continue to install oracle-xe:

root@Ozzy:/home/ozer/Desktop# dpkg -i oracle-xe_10.2.0.1-0.060128_i386.deb
(Reading database ... 62016 files and directories currently installed.)
Unpacking oracle-xe (from oracle-xe_10.2.0.1-0.060128_i386.deb) ...
Setting up oracle-xe (10.2.0.1-0.060128) ...
Oracle Database 10g Express Edition is not configured. You must run
'/etc/init.d/oracle-xe configure' as the root user to configure the database.
Executing Post-install steps...
You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.


5-After running the above code you will start to configure the database:

root@Ozzy:/home/ozer/Desktop# /etc/init.d/oracle-xe configure
Oracle Database 10g Express Edition Configuration
-------------------------------------------------

This will configure on-boot properties of Oracle Database XE. The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts. Press to accept the defaults.
Ctrl-C will abort.
Specify the HTTP port that will be used for Oracle Application Express [8080]:

Specify a port that will be used for the database listener [1521]:

Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration:

Confirm the password: (* make sure you remember this password *)

Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]: y

Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to "http://127.0.0.1:8080/apex"
root@Ozzy:/home/ozer/Desktop#