Tuesday, January 18, 2011

Easy operate with database settings profile in java

The easy way to get settings from profile document from any part of your java progam.

Call "readProperties" method at the beginig of your program to read properties from profile.

The next example read one item called "isProductionDatabase". You could extend this class to read all items.

public class DatabaseProperties{
 private DatabaseProperties(){}
    private static String ProfileDatabaseSettings = 
    private final static String ITEM_IS_PRODUCTION_DATABASE = 
    private static Properties databaseProperties;

    private static void readPropertyFromDocument(
      Document profile, 
      String propertyName) throws NotesException{
       String property = profile.getItemValueString(propertyName);
     databaseProperties.setProperty(propertyName, property);   
    public static void readProperties(Database database) throws NotesException{
     databaseProperties = new Properties();
     Document profile = 
      database.getProfileDocument(ProfileDatabaseSettings, null);
     readPropertyFromDocument(profile, ITEM_IS_PRODUCTION_DATABASE);

    public static void readProperties(
      Database database, 
      String profileName) throws NotesException{
       if(profileName != null){
      ProfileDatabaseSettings = profileName;
    public static String get(String key){
     return databaseProperties.getProperty(key); 
    public static boolean isProductionDatabases(){
        String isProductionDatabase = 
        return "1".equals(isProductionDatabase);

Monday, January 17, 2011

Serialization in to doucment item

Utility function to serialize\deserialize java object in to the domino document item. This object will be possible to read with another languages like LotusScript and so on.
    public static void serializeObject(Document document, String itemName, Serializable o) 
throws IOException, NotesException{
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(bos);  
        byte[] oByte = bos.toByteArray();
        document.replaceItemValueCustomDataBytes(itemName, o.getClass().getName(), oByte);
    public static Object deSerializeObject(Document document, String itemName, String oTypeName) 
throws IOException, NotesException, ClassNotFoundException{
        byte[] oByte = document.getItemValueCustomDataBytes(itemName, oTypeName);
        ByteArrayInputStream bis = new ByteArrayInputStream(oByte);
        ObjectInput in = new ObjectInputStream(bis);
        Object o = in.readObject();

        return o;

Friday, January 14, 2011

DateTime.toJavaDate() issue

Lotus Notes DateTime.toJavaDate() function sets time part to curren time if it was avoided in the DateTime Object. So each time you call toJavaDate() on such object you will receive different time. For example
"15.01.2011" -> "15.01.2011 15:36:37"
"15.01.2011" -> "15.01.2011 15:36:41"
and so on. Code for fix this: