Smelly Database

0 comments

1. multipurpose column
ex: a column used to store either someone's birth date if he/she is a customer or the start date if he/she is an employee.

2. multipurpose table
ex: a generic Customer table that is used to store information about both people and corporations.

3. redundant data
when data is stored in more than one places.

4. table with too many columns
indicate that the table is lack of cohesion and it needs to be normalized.

5. table with too many rows
it can cause performance problems and it needs to be splitted horizontally, or vertically.

6. smart columns
if first four digits of the client's ID indicate the client's home branch, then it's a smart column.

7. fear of change
is a good indicator that you have a serious technical risk on your hands, one that will get worse over time.


from 'Refactoring Databases' - a Martin Fowler signature series

Script to Drop All Index Keys of a MySQL Database Except Primary Key

1 comments

This script will produce the scripts to drop all index keys of a database:

#!/bin/sh

db=$3
user=$1
pswd=$2

mysql -u$user -p$pswd -e "show tables from $db"| awk '{if(NR>1) print "show index from "$1";"}'| mysql -u$user -p$pswd $db| awk '{if($3 !~ /Key_name/ && $3 !~ /PRIMARY/) print $1" "$3}'| awk '{print "alter table "$1" drop index "$2";"}'

Save the script as a shell script file and then execute by submitting 3 parameters:
1. Username
2. Password
3. Database name

Later, copy and paste the alter scripts via the MySQL client.

ConcurrentModificationException

0 comments

Getting this error ?

java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:449)
at java.util.AbstractList$Itr.next(AbstractList.java:420)
This exception might be happened because of:

1. Doing an iteration over a collection that is being modified during the loop. For example:
for (Object object: list) {
list.remove(object);
}
2. Modifying the list at the same time (because List isn't thread safe). It can only happen either when the list object was declared static or singleton, or it's owned by a static or singleton object.