alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.mdr.persistence.jdbcimpl;

import org.netbeans.mdr.persistence.*;

import java.sql.*;
import java.util.*;

/**
 * JdbcStorageFactory implements the StorageFactory interface by
 * creating instances of JdbcStorage.
 *
 * @author John V. Sichi
 * @version $Id: JdbcStorageFactory.java,v 1.2 2004/02/05 04:35:31 jsichi Exp $
 */
public class JdbcStorageFactory implements StorageFactory
{
    // NOTE: Property names are defined here without the MDRStorageProperty
    // prefix; user code should prepend that prefix, which will be stripped off
    // by MDR before createStorage is called.
    
    public static final String PROPERTY_PREFIX =
    "org.netbeans.mdr.persistence.jdbcimpl.";
    
    public static final String STORAGE_URL =
    PROPERTY_PREFIX + "url";
    
    public static final String STORAGE_SCHEMA_NAME =
    PROPERTY_PREFIX + "schemaName";

    public static final String STORAGE_USER_NAME =
    PROPERTY_PREFIX + "userName";

    public static final String STORAGE_PASSWORD =
    PROPERTY_PREFIX + "password";

    public static final String STORAGE_DRIVER_CLASS_NAME =
    PROPERTY_PREFIX + "driverClassName";

    public static final String STORAGE_DATATYPE_MOFID =
    PROPERTY_PREFIX + "datatype.mofid";

    public static final String STORAGE_DATATYPE_STREAMABLE =
    PROPERTY_PREFIX + "datatype.streamable";

    public static final String STORAGE_DATATYPE_STRING =
    PROPERTY_PREFIX + "datatype.string";

    public static final String STORAGE_DATATYPE_INT =
    PROPERTY_PREFIX + "datatype.int";

    // ripped from memoryimpl
    private static final String NULL_STORAGE_ID = ".";
    private static final MOFID NULL_MOFID = new MOFID(0, NULL_STORAGE_ID);
    
    // implement StorageFactory
    public Storage createStorage(Map map) throws StorageException
    {
        Properties properties = new Properties();
        Iterator iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            if (!(entry.getKey() instanceof String)) {
                continue;
            }
            if (entry.getValue() == null) {
                continue;
            }
            if (!(entry.getValue() instanceof String)) {
                continue;
            }
            properties.put(entry.getKey(),entry.getValue());
        }
        String url = properties.getProperty(STORAGE_URL);
        String schemaName = properties.getProperty(STORAGE_SCHEMA_NAME);
        String driverClassName =
            properties.getProperty(STORAGE_DRIVER_CLASS_NAME);
        if (url == null || schemaName == null) {
            throw new StorageBadRequestException(
                "JdbcStorageFactory requires parameters "
                + STORAGE_URL + " and " + STORAGE_SCHEMA_NAME);
        }
        if (driverClassName != null) {
            try {
                Class.forName(driverClassName);
            } catch (ClassNotFoundException ex) {
                // let driver manager report "no suitable driver" when
                // the connection is attempted
            }
        }
        return new JdbcStorage(properties,NULL_STORAGE_ID);
    }
    
    // implement StorageFactory
    public MOFID createNullMOFID() throws StorageException
    {
        return NULL_MOFID;
    }
}

// End JdbcStorageFactory.java
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.