示例#1
0
  public static void updatePackageJar(PackageVersion version) {
    InvocationContext context = InvocationContext.get();
    DataStore store = context.getDataStore();
    int actualId = UploadingPackage.getActualId();

    // Getting all members of this package except UploadedPackageMember
    List<Instance> instances = store.getAllPackageMembers(actualId);

    // Load all UploadedPackageMembers
    Set<Long> existedMembers = store.getUploadedComponentIds(actualId, context.getOrganizationId());

    // Newly added members
    List<Instance> notExisted =
        instances
            .stream()
            .filter(i -> !existedMembers.contains(i.getId()))
            .collect(Collectors.toList());

    List<UploadedPackageMember> newMembers = createUploadPackageMembers(notExisted, version);

    context.getDatabase().upsert(newMembers, DMLOperationType.THROW_ERRORS);

    prepareJAR(version, instances);

    prepatePackageData(version, instances);

    store.updateInstalledPackageLastUpdate(version.getId());
  }
示例#2
0
  private static void prepatePackageData(PackageVersion version, List<Instance> members) {
    LOG.info("Preparing Package Data file for package '" + version);
    String jarName = JarUtils.getPackagePath(version, false);
    // Prepare jar for this package version
    DataStore dataStore = InvocationContext.get().getDataStore();
    try (GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(jarName))) {
      Kryo kryo = new Kryo();
      Output output = new Output(out);

      // Write Package Members
      List<Instance> collect = members.stream().collect(Collectors.toList());
      long id = version.getId();
      SerializationUtil.writeInstances(kryo, output, collect);

      // Write QueryPlans
      List<ReplicationSQLQueryPlan> qPlans = dataStore.getAllQueryPlansByPackageVersion(id);
      output.writeInt(qPlans.size());
      qPlans.forEach(m -> m.write(kryo, output));

      // Write ModelHierarchyInfos
      List<ModelHierarchyInfo> mHierarchies = dataStore.getAllModelHierachyInfoByPackageVersion(id);
      output.writeInt(mHierarchies.size());
      mHierarchies.forEach(
          m -> {
            output.writeInt(m.getParent());
            output.writeInt(m.getSubModel());
          });

      // Write ClassHierarchy infos
      List<ClassHierarchyInfo> clsHierarchies =
          dataStore.getAllClassHierachyInfoByPackageVersion(id);
      output.writeInt(clsHierarchies.size());
      clsHierarchies.forEach(
          m -> {
            output.writeString(m.getCls());
            output.writeString(m.getSubClass());
          });
      output.close();

    } catch (Exception e) {
      LOG.info("Package Data not prepared for " + jarName);
      throw new RuntimeException(e);
    }
  }