Thursday, April 12, 2012

Design Patterns (JAVA)

Singleton - A singleton is an object that cannot be instantiated.

pattern:
 
public class SingletonObject
{
    private SingletonObject(){}; // Private constructor so the object cannot be 
                                 // instantiated outside of this class

    public static SingletonObject getSingletonObject() // Allow a method to create a 
    {                                                  // local copy if the object is
      if (ref == null)                                 // not yet created. And return
          // it's ok, we can call this constructor     // that object
          ref = new SingletonObject();
      return ref;
    }

    private static SingletonObject ref;                // provide a local reference
}


source: http://www.javacoffeebreak.com/articles/designpatterns/index.html

Sunday, April 8, 2012

Beginning MySQL

Useful MySQL commands:
SHOW DATABASES - list databases on the server


Creating a user:
login locally as root
mysql -u root -p
Then,
mysql> create user 'username'@'%' IDENTIFIED BY 'password';
mysql>  grant CREATE,INSERT,DELETE,UPDATE,SELECT on <~DB~>.<~OBJECTS~> to username@location;


This assumes the database is already created;


Designing a mysql database with MySQL Workbench:
  Good walkthrough: http://net.tutsplus.com/tutorials/databases/visual-database-creation-with-mysql-workbench/