Using the schema creator to generate schema in a geodatabase
The following code example creates a data element table with three fields and puts the fields in a FieldEdit instance:
[Java]
// Create 3 fields and put them in a FieldsEdit instance
IFieldsEdit fieldsEdit = new Fields();
IFieldEdit fieldEdit1 = new Field();
fieldEdit1.setName("OBJECTID");
fieldEdit1.setType(esriFieldType.esriFieldTypeOID);
fieldsEdit.addField(fieldEdit1);
IFieldEdit fieldEdit2 = new Field();
fieldEdit2.setName("Date");
fieldEdit2.setType(esriFieldType.esriFieldTypeDate);
fieldEdit2.setIsNullable(false);
fieldsEdit.addField(fieldEdit2);
IFieldEdit fieldEdit3 = new Field();
fieldEdit3.setName("Blob");
fieldEdit3.setType(esriFieldType.esriFieldTypeBlob);
fieldsEdit.addField(fieldEdit3);
// Create a deTable and put the fields in deTable
IDETable deTable = new DETable();
deTable.setFieldsByRef(fieldsEdit);
deTable.setOIDFieldName("OBJECTID");
;
The following code fills in the data element and other properties of the data element table:
[Java]
// Fill in the data element and other properties of the deTable
IDataElement dataElement = (IDataElement)deTable; // Explicit Cast
dataElement.setName(tableName);
dataElement.setFullPropsRetrieved(true);
dataElement.setCatalogPath("/TB=" + tableName);
IDEDataset deDataset = (IDEDataset)deTable; // Explicit Cast
deDataset.setDatasetType(esriDatasetType.esriDTTable);
IDEGdbTable deGdbTable = (IDEGdbTable)deTable; // Explicit Cast
IUID UID = new UID();
UID.setValue("esriGeoDatabase.Object");
deGdbTable.setCLSID((String)UID.getValue()); // Explicit Cast
deGdbTable.setHasOID(true);
The following code creates an array and puts the data element in the array:
[Java]
// Create an array and put deTable in the array
IArray array = new Array();
array.add(deTable);
The following code creates a geodatabase—the table will be created in a geodatabase:
[Java]
// Create a new geodatabase. The table will be created in geodatabase.
// Modify the pathnames appropriately.
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
IName name = new INameProxy(workspaceFactory.create(pathName, dbName, null, 0));
// Explicit Cast
IWorkspace workspace = new IWorkspaceProxy(name.open());
The following code fills in the IEnumNameMapping that is set to null and checks for conflicts during the generate name mapping:
[Java]
//Fill in the IEnumNameMapping and check for conflicts during the data transfer to generate the name mapping.
IGdbSchemaCreator gdbSchemaCreator = new GdbSchemaCreator();
IEnumNameMapping[] enumNameMapping = new IEnumNameMapping[1];
boolean[] foundConflicts = new boolean[1];
gdbSchemaCreator.generateNameMapping(workspace, array, null, enumNameMapping,
foundConflicts);
The following code example creates the schema and passes in the workspace and enumNameMapping:
[Java]
// Normally you should check if the target ws already has a dataset whose name conflicts
// with the dataset to be created.
// Create the schema
gdbSchemaCreator.createSchema(workspace, enumNameMapping[0]);
The following code example is the complete function of how to use the schema creator to create a table using the data element method. To use the function, pass in the database name and the path where you will create the database and table name:
[Java]
static void schemaCreator(String dbName, String pathName, String tableName)throws
Exception{
// Create 3 fields and put them in a FieldsEdit instance
IFieldsEdit fieldsEdit = new Fields();
IFieldEdit fieldEdit1 = new Field();
fieldEdit1.setName("OBJECTID");
fieldEdit1.setType(esriFieldType.esriFieldTypeOID);
fieldsEdit.addField(fieldEdit1);
IFieldEdit fieldEdit2 = new Field();
fieldEdit2.setName("Date");
fieldEdit2.setType(esriFieldType.esriFieldTypeDate);
fieldEdit2.setIsNullable(false);
fieldsEdit.addField(fieldEdit2);
IFieldEdit fieldEdit3 = new Field();
fieldEdit3.setName("Blob");
fieldEdit3.setType(esriFieldType.esriFieldTypeBlob);
fieldsEdit.addField(fieldEdit3);
// Create a deTable and put the fields in deTable
IDETable deTable = new DETable();
deTable.setFieldsByRef(fieldsEdit);
deTable.setOIDFieldName("OBJECTID");
// Fill in the data element and other properties of the deTable
IDataElement dataElement = (IDataElement)deTable; // Explicit Cast
dataElement.setName(tableName);
dataElement.setFullPropsRetrieved(true);
dataElement.setCatalogPath("/TB=" + tableName);
IDEDataset deDataset = (IDEDataset)deTable; // Explicit Cast
deDataset.setDatasetType(esriDatasetType.esriDTTable);
IDEGdbTable deGdbTable = (IDEGdbTable)deTable; // Explicit Cast
IUID UID = new UID();
UID.setValue("esriGeoDatabase.Object");
deGdbTable.setCLSID((String)UID.getValue()); // Explicit Cast
deGdbTable.setHasOID(true);
// Create an array and put deTable in the array
IArray array = new Array();
array.add(deTable);
// Create a new geodatabase. The table will be created in geodatabase.
// Modify the pathnames appropriately.
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
IName name = new INameProxy(workspaceFactory.create(pathName, dbName, null, 0));
// Explicit Cast
IWorkspace workspace = new IWorkspaceProxy(name.open());
//Fill in the IEnumNameMapping and check for conflicts during the data transfer to generate the name mapping.
IGdbSchemaCreator gdbSchemaCreator = new GdbSchemaCreator();
IEnumNameMapping[] enumNameMapping = new IEnumNameMapping[1];
boolean[] foundConflicts = new boolean[1];
gdbSchemaCreator.generateNameMapping(workspace, array, null, enumNameMapping,
foundConflicts);
// Normally you should check if the target ws already has a dataset whose name conflicts
// with the dataset to be created.
// Create the schema
gdbSchemaCreator.createSchema(workspace, enumNameMapping[0]);
}
Development licensing | Deployment licensing |
---|---|
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime: Geodatabase Update |