Library References  

DataSourcesGDB


Library dependencies: System, SystemUI, Geometry, Display, Server, Output, GeoDatabase, GISClient, DataSourcesFile

The DataSourcesGDB library contains the implementation of the GeoDatabase API for the database data sources. These data sources include Microsoft Access, File Geodatabases and any RDBMS supported by ArcSDE.

The DataSourcesGDB library is not extended by developers.


The major objects within DataSourcesGDB are workspace factories and the Data Server Manager. A workspace factory object is a dispenser of workspaces and allows a client to connect to a workspace specified by a set of connection properties. A workspace represents a database or a data source that contains one or more datasets. Examples of datasets include tables, feature classes, and relationships. DataSourcesGDB has workspace factories for connecting to Access, File Geodatabase and ArcSDE data sources.

Workspace factories are creatable, singleton objects. (A singleton object can only be instantiated once in a process.) Each workspace factory maintains a pool of currently connected, active workspaces that are being referenced by the application. Connection properties are specified using a PropertySet object and can be saved to a connection file.

The main workspace factories contained within this library are:


 

AccessWorkspaceFactory

An AccessWorkspaceFactory is used to connect to a Microsoft Access database.

The following example shows how to connect to an Access database.

	// Create an instance of AccessWorkspaceFactory
	AccessWorkspaceFactory accessFactory = new AccessWorkspaceFactory();
	
	// Open the Workspace
	Workspace ws = new Workspace(accessFactory.openFromFile("../LinearReferencing/PITT.mdb",0));
                    

FileGDBWorkspaceFactory

A FileGDBWorkspaceFactory is used to connect to a File geodatabase. Note that a file Geodatabase is denoted by the .gdb extension as opposed to Access workspaces with have an mdb extension.

The following example shows how to connect to a File geodatabase.

	// Create an instance of FileGDBWorkspaceFactory
	FileGDBWorkspaceFactory wsFactory = new FileGDBWorkspaceFactory();
	
	// Open the Workspace
	Workspace fws = new Workspace(wsFactory.openFromFile("../arcgis/ArcTutor/Map/airport.gdb",0));
                    

 

ScratchWorkspaceFactory

A ScratchWorkspaceFactory is used to connect to a temporary database stored in Microsoft Access. These workspaces are commonly used to hold the results of a selection set. This workspace factory is fundamentally different than the AccessWorkspaceFactory in a couple ways. First, there are interfaces (IScratchWorkspaceFactory and IScratchWorkspaceFactory2) on it to create new temporary workspaces or connect to existing temporary workspaces. Second, when the last reference to the workspace is released, the Access database is automatically deleted from the disk.

The following example shows how to create a scratch workspace to use as part of a Table select.

	// Create the ScratchWorkspaceFactory
	ScratchWorkspaceFactory factory = new ScratchWorkspaceFactory();
	
	// Create the ScratchWorkspace
	Workspace sws = new Workspace(factory.createNewScratchWorkspace());
	
	// Use the ScratchWorkspace in a table select
	SelectionSet selSet = new SelectionSet(table.select(queryFilter,esriSelectionType.esriSelectionTypeHybrid,esriSelectionOption.esriSelectionOptionNormal,sws));
		
                    

SdeWorkspaceFactory

A SdeWorkspaceFactory is used to connect to an ArcSDE database. ISetDefaultConnectionInfo and ISetDefaultConnectionInfo2 are used to specify the username, password, and version of connections to SDE workspaces when those parameters are not specified by the connection properties. This is important if you want to save a connection file that does not persist this information. IRemoteDatabaseWorkspaceFactory is used to maintain connection files. These files, which store the connection properties used to connect to ArcSDE workspaces, commonly have the .sde extension.

The following example uses SdeWorkspaceFactory to connect to an ArcSDE database and prints out all of the datasets within that database.

	
	// Create a PropertySet object that will contain all of the
	// SDE connection parameters	
	PropertySet propSet  = new PropertySet();
	
	// Create the SdeWorkspaceFactory
	SdeWorkspaceFactory sdeFact = new SdeWorkspaceFactory();

	// Populate the property set with the connection parameters
	propSet.setProperty("SERVER", "pine");
	propSet.setProperty("INSTANCE", "9192");
	propSet.setProperty("DATABASE", "");
	propSet.setProperty("USER", "map");
	propSet.setProperty("PASSWORD", "map");
	propSet.setProperty("VERSION", "sde.DEFAULT");
	
	// Open the ArcSDE workspace using the connection PropertySet
	Workspace ws = new Workspace(sdeFact.open(propSet, 0));
	
	// Get the collection of dataset names in the database and display their names
	IEnumDatasetName dsNames = ws.getDatasetNames(esriDatasetType.esriDTAny);
	
	IDatasetName name = dsNames.next();
	while(name != null){
		System.out.println(name.getName());
		name = dsNames.next();
	}
		
		            

Data Server Manager

The Data Server Manager is used to access and administer one or more Geodatabases stored on a data server using ArcSDE direct connect. You can also create WorkspaceNames from which you can open up Workspaces to these Geodatabases. The following example shows how to connect to a Geodatabase in a Personal ArcSDE for SQL Server using the Data Server Manager.

	DataServerManager dsm = new DataServerManager();
	
	dsm.setServerName("katahdin\\sqlexpress");
		
	dsm.connect();
		
	WorkspaceName wsname = (WorkspaceName)dsm.createWorkspaceName("Landbase","dbo.Default")