Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Oliver Haag www.ohcon.de

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

IdGenerator in java

// IdGenerator

public class IdGenerator {
	
	private long maxId; 
	
	public IdGenerator(long start) {
		maxId = start;
	}
	
	public long getNextId () {
		return ++maxId;
	}

} // IdGenerator

save Data with db4o

// save Data with db4o

import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.query.Query;
...

public class DbUtil {

  /**
  * save someObject to DB
  */
  public static void saveData(SomeClass someObject, String DbFilename) {
    ObjectContainer db=Db4o.openFile(DbFilename);
    try {
      db.set(idGenerator);
    }
    finally {
      db.close();
    }
  } //saveData(SomeClass ..)

  ..

} //DbUtil
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS