コード例 #1
0
  @Override
  public void run() throws OseeCoreException {
    Conditions.checkNotNull(configuration, "DbInitConfiguration Info");

    OseeClientProperties.setInDbInit(true);

    createOseeDatastore();

    Bundle bundle = Platform.getBundle("org.eclipse.osee.framework.skynet.core");
    int state = bundle.getState();
    if (state != Bundle.ACTIVE) {
      try {
        bundle.start();
      } catch (BundleException ex) {
        throw new OseeCoreException(ex);
      }
    }
    IOseeCachingService service = DatabaseInitActivator.getInstance().getCachingService();
    service.clearAll();

    IOseeDatabaseService databaseService = DatabaseInitActivator.getInstance().getDatabaseService();
    databaseService.getSequence().clear();
    IdentityService identityService = DatabaseInitActivator.getInstance().getIdentityService();
    identityService.clear();

    Branch systemRoot = BranchManager.getSystemRootBranch();
    Conditions.checkNotNull(systemRoot, "System root was not created - ");

    ClientSessionManager.releaseSession();
    ClientSessionManager.authenticate(
        new BaseCredentialProvider() {

          @Override
          public OseeCredential getCredential() {
            OseeCredential credential = super.getCredential();
            credential.setUserName(SystemUser.BootStrap.getName());
            return credential;
          }
        });

    List<String> oseeTypes = configuration.getOseeTypeExtensionIds();
    Conditions.checkExpressionFailOnTrue(oseeTypes.isEmpty(), "osee types cannot be empty");

    OseeTypesSetup oseeTypesSetup = new OseeTypesSetup();
    oseeTypesSetup.execute(oseeTypes);

    service.clearAll();
  }
 private void handleBranchSelectEnabled(boolean isSelected) {
   setSelectable(true);
   if (ClientSessionManager.isSessionValid() != true) {
     statusLabel.setText(AUTHENTICATION_WARNING_MESSAGE);
     setSelectable(false);
     isSelected = false;
   }
   branchSelectEnabled.setSelection(isSelected);
   branchSelectComposite.setEnabled(isSelected);
   for (Control control : branchSelectComposite.getChildren()) {
     control.setEnabled(isSelected);
   }
 }
 public void restoreWidgetValues(boolean saveAsArtifact, String[] branchIds, String lastSelected) {
   branchSelectEnabled.setSelection(saveAsArtifact && ClientSessionManager.isSessionValid());
   branchSelectComposite.restoreWidgetValues(branchIds, lastSelected);
 }
  @Override
  public ArrayList<ChangeBuilder> acquireChanges() throws OseeCoreException {
    Map<Integer, ChangeBuilder> attributesWasValueCache = new HashMap<Integer, ChangeBuilder>();
    Map<Integer, ModificationType> artModTypes = new HashMap<Integer, ModificationType>();
    Set<Integer> modifiedArtifacts = new HashSet<Integer>();
    IOseeStatement chStmt = ConnectionHandler.getStatement();
    boolean hasBranch = getSourceBranch() != null;
    long time = System.currentTimeMillis();
    try {
      if (getMonitor() != null) {
        getMonitor().subTask("Gathering Attribute Changes");
      }
      TransactionRecord fromTransactionId;
      TransactionRecord toTransaction;
      boolean hasSpecificArtifact = getSpecificArtifact() != null;

      for (ChangeBuilder changeBuilder :
          getChangeBuilders()) { // cache in map for performance look ups
        artModTypes.put(changeBuilder.getArtId(), changeBuilder.getModType());
      }
      // Changes per a branch
      if (hasBranch) {
        fromTransactionId = getSourceBranch().getBaseTransaction();
        toTransaction = TransactionManager.getHeadTransaction(getSourceBranch());
        chStmt.runPreparedQuery(
            ClientSessionManager.getSql(OseeSql.CHANGE_BRANCH_ATTRIBUTE_IS),
            getSourceBranch().getId(),
            fromTransactionId.getId());

      } // Changes per transaction number
      else {
        toTransaction = getTransaction();
        if (hasSpecificArtifact) {
          chStmt.runPreparedQuery(
              ClientSessionManager.getSql(OseeSql.CHANGE_TX_ATTRIBUTE_IS_FOR_SPECIFIC_ARTIFACT),
              toTransaction.getBranchId(),
              toTransaction.getId(),
              getSpecificArtifact().getArtId());
          fromTransactionId = getTransaction();
        } else {
          chStmt.runPreparedQuery(
              ClientSessionManager.getSql(OseeSql.CHANGE_TX_ATTRIBUTE_IS),
              toTransaction.getBranchId(),
              toTransaction.getId());
          fromTransactionId = TransactionManager.getPriorTransaction(toTransaction);
        }
      }
      loadIsValues(
          getSourceBranch(),
          getArtIds(),
          getChangeBuilders(),
          getNewAndDeletedArtifactIds(),
          getMonitor(),
          attributesWasValueCache,
          artModTypes,
          modifiedArtifacts,
          chStmt,
          hasBranch,
          time,
          fromTransactionId,
          toTransaction,
          hasSpecificArtifact);
      loadAttributeWasValues(
          getSourceBranch(),
          getTransaction(),
          getArtIds(),
          getMonitor(),
          attributesWasValueCache,
          hasBranch);
    } finally {
      chStmt.close();
    }
    return getChangeBuilders();
  }
  private void loadAttributeWasValues(
      Branch sourceBranch,
      TransactionRecord transactionId,
      Set<Integer> artIds,
      IProgressMonitor monitor,
      Map<Integer, ChangeBuilder> attributesWasValueCache,
      boolean hasBranch)
      throws OseeCoreException, OseeDataStoreException {
    if (!artIds.isEmpty()) {
      int sqlParamter; // Will either be a branch id or transaction id
      Branch wasValueBranch;
      String sql;

      if (hasBranch) {
        wasValueBranch = sourceBranch;
        sql = ClientSessionManager.getSql(OseeSql.CHANGE_BRANCH_ATTRIBUTE_WAS);
        sqlParamter = wasValueBranch.getId();
      } else {
        wasValueBranch = transactionId.getBranch();
        sql = ClientSessionManager.getSql(OseeSql.CHANGE_TX_ATTRIBUTE_WAS);
        sqlParamter = transactionId.getId();
      }

      int queryId = ArtifactLoader.getNewQueryId();
      Timestamp insertTime = GlobalTime.GreenwichMeanTimestamp();
      List<Object[]> datas = new LinkedList<Object[]>();
      IOseeStatement chStmt = ConnectionHandler.getStatement();

      try {
        // insert into the artifact_join_table
        for (int artId : artIds) {
          datas.add(
              new Object[] {
                queryId, insertTime, artId, wasValueBranch.getId(), SQL3DataType.INTEGER
              });
        }
        ArtifactLoader.insertIntoArtifactJoin(datas);
        chStmt.runPreparedQuery(sql, sqlParamter, queryId);
        int previousAttrId = -1;

        while (chStmt.next()) {
          int attrId = chStmt.getInt("attr_id");

          if (previousAttrId != attrId) {
            String wasValue = chStmt.getString("was_value");
            if (attributesWasValueCache.containsKey(attrId)
                && attributesWasValueCache.get(attrId) instanceof AttributeChangeBuilder) {
              AttributeChangeBuilder changeBuilder =
                  (AttributeChangeBuilder) attributesWasValueCache.get(attrId);

              if (changeBuilder.getArtModType() != ModificationType.NEW) {
                if (changeBuilder.getModType() != ModificationType.DELETED
                    && changeBuilder.getModType() != ModificationType.ARTIFACT_DELETED) {
                  changeBuilder.setModType(ModificationType.MODIFIED);
                }
                changeBuilder.setWasValue(wasValue);
              }
            }
            previousAttrId = attrId;
          }
        }
      } finally {
        ArtifactLoader.clearQuery(queryId);
        chStmt.close();
      }
      if (getMonitor() != null) {
        monitor.worked(12);
      }
    }
  }