Thursday, March 20, 2014

Eclipse - Specified VM install not found: type Standard VM, name XXX

Solution 1

- suppose the path of workspace of eclipse is 'D:\eclipse\workspace'
- then, go to  'D:\eclipse\workspace\.metadata\.plugins\org.eclipse.debug.core\.launches'
- find 'projectName build.xml.launch' file and delete it

Solution 2

- Right Click on build.xml
- Go to "Run As" >> "External Tools Configurations..."
- It shall open new window
- Go to JRE tab
- Select proper JRE if missing

MongoDB 2.4 - Java (Fail over)

import java.net.UnknownHostException;
import java.util.Arrays;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.MongoException;
import com.mongodb.ServerAddress;

public class MongoDB {

public static void main(String[] args) throws UnknownHostException,
InterruptedException {
MongoClient client = new MongoClient(Arrays.asList(new ServerAddress(
"localhost", 27017), new ServerAddress("localhost", 27018),
new ServerAddress("localhost", 27019)));
DBCollection test = client.getDB("database")
.getCollection("collection");

test.drop();

for (int i = 0; i < Integer.MAX_VALUE; i++) {
for (int retries = 0; retries < 3; retries++) {
try {
test.insert(new BasicDBObject("_id", i));
System.out.println("Inserted document: " + i);
break;
} catch (MongoException.DuplicateKey e) {
System.out.println("Document already inserted " + i);
} catch (MongoException e) {
System.out.println(e.getMessage());
System.out.println("Retrying");
Thread.sleep(5000);
}
}

Thread.sleep(500);
}
}
}

MongoDB 2.4 - Java (connecting to a replica set)

import java.net.UnknownHostException;
import java.util.Arrays;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;

public class MongoDB {

public static void main(String[] args) throws UnknownHostException,
InterruptedException {
MongoClient client = new MongoClient(Arrays.asList(new ServerAddress(
"localhost", 27017), new ServerAddress("localhost", 27018),
new ServerAddress("localhost", 27019)));
DBCollection test = client.getDB("database")
.getCollection("collection");

test.drop();

for (int i = 0; i < Integer.MAX_VALUE; i++) {
test.insert(new BasicDBObject("_id", i));
System.out.println("Inserted document: " + i);
Thread.sleep(500);
}
}
}

Wednesday, March 19, 2014

Ubuntu 12.04 - link /var/lib/postgresql to another partition's directory

- sudo service postgresql stop
- sudo cp -rf /var/lib/postgresql /anotherPartition/postgresql
- sudo chwon -R postgres:postgres /anotherPartition/postgresql
- sudo service postgresql start