VietNetwork.Vn

 


Tác giả Chủ đề: How to configure multiple Primavera database instance in Primavera P6 EPPM  (Đã xem 169 lần)

0 Thành viên và 1 Khách đang xem chủ đề.

server360

  • Administrator
  • Hero Member
  • *****
  • Bài viết: 3208
  • Số Lần: +72/-0
In my previous post, I have explained How to configure the different database in Primavera P6 and access in P6 Web.[/url] This is the continuation of the previous post but here we are going to access this multiple database instance in Primavera P6 API.
 

 
Below I configured Oracle database & Microsoft SQL Server database instance in my P6 admin config.
 

 
020818_0536_Howtoconfig1 How to configure multiple Primavera database instance in Primavera P6 EPPM and access it in Primavera P6 API[/size]
 
 
Below is the Primavera P6 API code that accesses the above two database instance and prints all the projects on each database instance.
 

package com.catgovind;
 
import com.primavera.ServerException;
import com.primavera.common.value.ObjectId;
import com.primavera.integration.client.EnterpriseLoadManager;
import com.primavera.integration.client.RMIURL;
import com.primavera.integration.client.Session;
import com.primavera.integration.client.bo.BOIterator;
import com.primavera.integration.client.bo.object.Project;
import com.primavera.integration.common.DatabaseInstance;
 
public class Main {
 
 static{
 System.setProperty("primavera.bootstrap.home","C:\\P6EPPM_172\\p6");
 }
 
public static void main(String[] args) {
       
 
 
       //P6 Application admin username and password for Oracle Database
        String username="admin";
        String password="admin";
       
      //P6 Application admin username and password for SQL SERVER Database
        String username1="admin";
        String password1="admin123";
        try{ 
           //Connect to P6 usiing Local Mode
          
           DatabaseInstance[] dbInstances =  Session.getDatabaseInstances( RMIURL.getRmiUrl( RMIURL.LOCAL_SERVICE ) );
           int size = dbInstances.length;
           
           //SQL Server DB Instance
           DatabaseInstance SQL_SERVER_Instance = null;
           //Oracle Server DB Instance
           DatabaseInstance ORACLE_Instance = null;
           
           for(int i=0;i<size;i++){
              if(dbInstances.getDatabaseName().equalsIgnoreCase("SQL_SERVER")){
            SQL_SERVER_Instance = dbInstances;
              }
              else if(dbInstances.getDatabaseName().equalsIgnoreCase("orcl")){
            ORACLE_Instance = dbInstances;
              }
              
              System.out.println(dbInstances.getDatabaseUrl());
           }
           //Retrieve SQL Server Database Instance 
           Session SQL_SERVER_session = Session.login( RMIURL.getRmiUrl( RMIURL.LOCAL_SERVICE ), SQL_SERVER_Instance.getDatabaseId(), username1,password1 ); 
           BOIterator<Project> SQL_SERVER_PROJECTS = SQL_SERVER_session.getEnterpriseLoadManager().loadProjects(new String[]{"Name","Id"}, null, null);
           while(SQL_SERVER_PROJECTS.hasNext()){
              Project proj = SQL_SERVER_PROJECTS.next();
              System.out.println(proj.getId()+" || "+proj.getName());
           }
 
           //Retrieve Oracle Database Instance
           Session ORACLE_session = Session.login( RMIURL.getRmiUrl( RMIURL.LOCAL_SERVICE ),ORACLE_Instance.getDatabaseId(), username,password ); 
           BOIterator<Project> ORACLE_PROJECTS = ORACLE_session.getEnterpriseLoadManager().loadProjects(new String[]{"Name","Id"}, null, null);
           while(ORACLE_PROJECTS.hasNext()){
              Project proj = ORACLE_PROJECTS.next();
              System.out.println(proj.getId()+" || "+proj.getName());
           }
           
        }
        catch(Exception e){
           e.printStackTrace();
        }
       
}
}
     
Output:-
 
jdbc:oracle:thin:@localhost:1521:orcl
 jdbc:sqlserver://localhost:1433;database=PMDB;
 Project_SQL_SERVER || Project_SQL_Server
 Project_Oracle || Project_Oracle
« Sửa lần cuối: Tháng Chín 18, 2018, 04:44:08 PM gửi bởi server360 »


 

Copyright © VietNetwork.Vn