ヘッダーをスキップ
Oracle® Fusion Middleware Oracle Enterprise Repository統合ガイド
11g リリース1 (11.1.1.7)
B72433-02
  目次へ移動
目次
索引へ移動
索引

前
 
次
 

21 部門API

この章では、部門APIのユースケースについて説明します。このユースケースで、Oracle Enterprise Repositoryの部門の作成、更新、問合せおよび削除を行う方法について解説します。

この章では、次の項目について説明します。

21.1 概要

部門の作成、読込み、問合せおよび変更を行うことができます。これらの操作は、次のとおりです。部門の作成後は削除できないことに注意してください。部門の2つの属性(名前と説明)のみがユーザーに有効です。

追加で必要なインポート

import com.flashline.registry.openapi.entity.Department;

21.2 ユースケース

この項では、部門APIを使用するユースケースについて説明します。内容は次のとおりです。

21.2.1「ユースケース: 部門の操作」

説明

次のサンプル・コードは、Oracle Enterprise Repositoryの部門の操作が含まれる典型的なタスクを示します。これには、作成、更新、問合せおよび削除が含まれます。

サンプル・コード

例21-1 ユースケース: 部門の操作

package com.flashline.sample.departmentapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.Department;
import com.flashline.registry.openapi.query.DepartmentCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class Departments {
  public static void main(String pArgs[]) throws java.rmi.RemoteException,
      OpenAPIException {
    try {
      ///////////////////////////////////////////////////////////
      // Connect to Oracle Enterprise Repository
      ///////////////////////////////////////////////////////////
      URL lURL = null;
      lURL = new URL(pArgs[0]);
      FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
          .getFlashlineRegistry(lURL);
      // //////////////////////////////
      // Authenticate with OER
      // //////////////////////////////
      AuthToken authToken = repository.authTokenCreate(pArgs[1],
          pArgs[2]);
      // //////////////////////////////
      // Create a new department
      // Each Department requires a unique name. Descriptions are optional.
      // //////////////////////////////
      Department dept = repository.departmentCreate(authToken,
          "My Dept "+Calendar.getInstance().getTimeInMillis(), "A New
 Department");
      // //////////////////////////////
      // Read a department
      // To read a Department you must have the Department name.
      // //////////////////////////////
      Department dept2 = repository.departmentRead(authToken,
          "ADepartment");
      // //////////////////////////////
      // Query for a department
      //
      // To query for a Department you must fill out a
      // DepartmentCriteria object with an array of SearchTerms. A SearchTerm
      // is a key/value pair. Currently the only valid key is "name".
      //
      // A query for name is a match if the value for the name term
      // occurs anywhere in the name of the department. For example,
      // a search for fred matches fred, alfred, and fredrick.
      // //////////////////////////////
      DepartmentCriteria criteria = new DepartmentCriteria();
      criteria.setNameCriteria("DepartmentName");
      Department[] depts = repository.departmentQuery(authToken,
          criteria);
      // //////////////////////////////
      // Update a department
      //
      // To update a Department you need only to modify a Department
      // reference and call departmentUpdate...
      // //////////////////////////////
      String lOldName = dept.getName();
      String lNewName = "New " + dept.getName();
      Department dept3 = repository.departmentRead(authToken, lOldName);
      dept3.setName(lNewName);
      repository.departmentUpdate(authToken, dept3);
    } catch (OpenAPIException lEx) {
      System.out.println("ServerCode = " + lEx.getServerErrorCode());
      System.out.println("Message    = " + lEx.getMessage());
      System.out.println("StackTrace:");
      lEx.printStackTrace();
    } catch (RemoteException lEx) {
      lEx.printStackTrace();
    } catch (ServiceException lEx) {
      lEx.printStackTrace();
    } catch (MalformedURLException lEx) {
      lEx.printStackTrace();
    }
  }
}