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-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.db.explorer;

import java.util.*;

import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.Repository;
import org.openide.options.SystemOption;

import org.netbeans.modules.db.DatabaseException;
import org.netbeans.modules.db.explorer.driver.JDBCDriver;
import org.netbeans.modules.db.explorer.driver.JDBCDriverManager;
import org.netbeans.modules.db.explorer.infos.RootNodeInfo;

public class PointbasePlus {

    /** The name of the Pointbase driver to create the connection to sample database */
    public static final String DRIVER_NAME = "PointBase Network Server";
    
    /** The driver to create the connection to sample database */
    public static final String DRIVER = "com.pointbase.jdbc.jdbcUniversalDriver";
    
    /** The database URL to create the connection to sample database */
    //public static final String DATABASE_URL = "jdbc:pointbase://embedded/sample";
    public static final String DATABASE_URL = "jdbc:pointbase:server://localhost:9092/sample";
    
    /** The user name to create the connection to sample database */
    public static final String USER_NAME = "pbpublic";
    
    /** The schema name to create the connection to sample database */
    public static final String SCHEMA_NAME = "PBPUBLIC";
    
    /** The password to create the connection to sample database */
    public static final String PASSWORD = "pbpublic";
    
    /*error code if pointbase network server doesn't run*/
    public static final int ERR_SERVER_REJECTED = 86024;
    
    //singleton
    private PointbasePlus() {
    }
    
    /** Creating the database connection to Pointbase SAMPLE database in the Runtime window
     * according to value of PROP_SAMPLE_AUTO_CONN.
     */
    public static void addOrConnectAccordingToOption() throws DatabaseException {

        DatabaseOption setting = (DatabaseOption)SystemOption.findObject(DatabaseOption.class, false);
        if(setting==null)
            return;
        if(!setting.isAutoConn())
            return;
        
        // test if the JDBC driver is installed
        try {
            JDBCDriver[] drvs = JDBCDriverManager.getDefault().getDriver(DRIVER);
            if (drvs.length == 0) {
                Class.forName(DRIVER);
            } else {
                DbURLClassLoader l = new DbURLClassLoader(drvs[0].getURLs());
                Class.forName(DRIVER, true, l);
            }
        } catch (ClassNotFoundException exc) {
            setting.setAutoConn(false);
            return;
        }
        
        // find root node of databases in the Explorer window/Runtime
        FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("UI/Runtime"); //NOI18N
        DataFolder df;
        try {
            df = (DataFolder) DataObject.find(fo);
        } catch (DataObjectNotFoundException exc) {
            return;
        }        
        RootNodeInfo info = (RootNodeInfo) df.getNodeDelegate().getChildren().findChild("Databases").getCookie(RootNodeInfo.class); //NOI18N
        if (info == null)
            //don't create connection
            return;
        
        // setting information to create connection
        DatabaseConnection cinfo = new DatabaseConnection();
        cinfo.setDriverName( DRIVER_NAME );
        cinfo.setDriver( DRIVER );
        cinfo.setDatabase( DATABASE_URL );
        cinfo.setUser( USER_NAME );
        cinfo.setSchema( SCHEMA_NAME );
        cinfo.setPassword( PASSWORD );
        cinfo.setRememberPassword( true );

        // add connection (if needed) and make the connection to SAMPLE database connected
        info.addOrConnectConnection(cinfo);

        // add connection (if needed) and DON'T make the connection to SAMPLE database connected
//        info.addOrSetConnection(cinfo);
    }

}
... 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.