Exemplo n.º 1
0
 public void handleLobs(long fromTime, long toTime, CDOLobHandler handler) throws IOException {
   for (DB4OBlob db4oBlob : DB4OStore.getElementsOfType(getObjectContainer(), DB4OBlob.class)) {
     byte[] id = HexUtil.hexToBytes(db4oBlob.getId());
     byte[] blob = db4oBlob.getValue();
     ByteArrayInputStream in = new ByteArrayInputStream(blob);
     OutputStream out = handler.handleBlob(id, blob.length);
     if (out != null) {
       try {
         IOUtil.copyBinary(in, out, blob.length);
       } finally {
         IOUtil.close(out);
       }
     }
   }
   for (DB4OClob db4oClob : DB4OStore.getElementsOfType(getObjectContainer(), DB4OClob.class)) {
     byte[] id = HexUtil.hexToBytes(db4oClob.getId());
     char[] clob = db4oClob.getValue();
     CharArrayReader in = new CharArrayReader(clob);
     Writer out = handler.handleClob(id, clob.length);
     if (out != null) {
       try {
         IOUtil.copyCharacter(in, out, clob.length);
       } finally {
         IOUtil.close(out);
       }
     }
   }
 }
Exemplo n.º 2
0
  public void restartScenario() throws Exception {
    IOUtil.OUT().println("RESTARTING SCENARIO");
    stopTransport();

    IScenario scenario = getScenario();
    scenario.tearDown();
    scenario.setUp();

    startTransport();
    IOUtil.OUT().println("RESTARTING SCENARIO - FINISHED");
  }
Exemplo n.º 3
0
 public void onMessage(Message message) {
   try {
     Object object = ((ObjectMessage) message).getObject();
     IOUtil.OUT()
         .println(
             "\n------> MESSAGE for "
                 + name
                 + ": "
                 + object
                 + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     message.acknowledge();
   } catch (JMSException ex) {
     IOUtil.print(ex);
   }
 }
  // A fake because afterClass does not seem to work :(
  @AfterClass
  public void testTearDown() throws IOException {
    String ext = "NATIVE";
    if (isConfig(LEGACY)) {
      ext = "LEGACY";
    }

    String location =
        System.getProperty("user.home")
            + "/cdo_Performance_"
            + ext
            + "_"
            + new Date().getTime()
            + ".csv";
    System.out.println("Writing performance results to: " + location);
    File file = new File(location);
    FileWriter fileWriter = new FileWriter(file);

    try {
      StringBuffer stringBuffer = new StringBuffer();
      for (String key : results.keySet()) {
        stringBuffer.append(key + ";" + results.get(key).getTiming() + "\n");
      }

      fileWriter.write(stringBuffer.toString());
    } finally {
      IOUtil.close(fileWriter);
    }
  }
  @Override
  public void saveRepositories() {
    if (storage != null) {
      try {
        OutputStream output = storage.createOutputStream();
        try {
          repositoryRegistry.eResource().save(output, null);
        } finally {
          if (output != null) {
            IOUtil.closeSilent(output);
          }
        }
      } catch (IOException e) {
        Activator.log.error(
            "Failed to save model repositories to custom storage.", e); // $NON-NLS-1$
      }
    } else {
      try {
        repositoryRegistry.eResource().save(null);
      } catch (IOException e) {
        Activator.log.error("Failed to save model repositories.", e); // $NON-NLS-1$
      }
    }

    // save passwords, if any
    try {
      SecurePreferencesFactory.getDefault().flush();
    } catch (IOException e) {
      Activator.log.error(
          "Failed to save repository passwords to secure storage.", e); // $NON-NLS-1$
    }
  }
  private RepositoryRegistry loadRepositories() {
    ResourceSet rset = new ResourceSetImpl();
    rset.getResourceFactoryRegistry()
        .getExtensionToFactoryMap()
        .put("xml", new XMLResourceFactoryImpl()); // $NON-NLS-1$

    File repositoriesFile =
        new File(
            Activator.getDefault().getStateLocation().toFile(), "repositories.xml"); // $NON-NLS-1$
    URI uri = URI.createFileURI(repositoriesFile.getAbsolutePath());
    Resource resource = rset.createResource(uri);

    if (storage != null) {
      try {
        InputStream input = storage.createInputStream();
        if (input != null) {
          try {
            resource.load(input, null);
          } finally {
            IOUtil.closeSilent(input);
          }
        }
      } catch (Exception e) {
        Activator.log.error(
            "Failed to load repository registry from custom storage.", //$NON-NLS-1$
            e);
      }
    } else {
      if (repositoriesFile.exists()) {
        try {
          resource.load(null);
        } catch (Exception e) {
          Activator.log.error(
              "Failed to load repository registry.", //$NON-NLS-1$
              e);
          // if there's any junk, clear it out
          resource.getContents().clear();
        }
      } else {
        resource = rset.createResource(uri);
      }
    }

    RepositoryRegistry result =
        (RepositoryRegistry)
            EcoreUtil.getObjectByType(
                resource.getContents(), RepositoriesPackage.Literals.REPOSITORY_REGISTRY);

    if (result == null) {
      result = RepositoriesFactory.eINSTANCE.createRepositoryRegistry();
      resource.getContents().add(result);
    }

    return result;
  }
Exemplo n.º 7
0
  public void loadLob(byte[] id, OutputStream out) throws IOException {
    String key = HexUtil.bytesToHex(id);
    IDB4OIdentifiableObject identifiableObject =
        DB4OStore.getIdentifiableObject(getObjectContainer(), key);
    if (identifiableObject == null) {
      throw new IOException("Lob not found: " + key);
    }

    if (identifiableObject instanceof DB4OBlob) {
      DB4OBlob blob = (DB4OBlob) identifiableObject;
      byte[] byteArray = blob.getValue();
      ByteArrayInputStream in = new ByteArrayInputStream(byteArray);
      IOUtil.copyBinary(in, out, byteArray.length);
    } else {
      DB4OClob clob = (DB4OClob) identifiableObject;
      char[] charArray = clob.getValue();
      CharArrayReader in = new CharArrayReader(charArray);
      IOUtil.copyCharacter(in, new OutputStreamWriter(out), charArray.length);
    }
  }
Exemplo n.º 8
0
  public synchronized Properties getHomeProperties() {
    if (homeProperties == null) {
      homeProperties = new Properties();
      String home = System.getProperty("user.home");
      if (home != null) {
        File file = new File(home, ".cdo_config_test.properties");
        if (file.exists()) {
          FileInputStream stream = IOUtil.openInputStream(file);

          try {
            homeProperties.load(stream);
          } catch (IOException ex) {
            throw WrappedException.wrap(ex);
          } finally {
            IOUtil.close(stream);
          }
        }
      }
    }

    return homeProperties;
  }
Exemplo n.º 9
0
  @Override
  protected void doTearDown() throws Exception {
    try {
      getScenario().tearDown();

      if (testProperties != null) {
        testProperties.clear();
        testProperties = null;
      }

      if (homeProperties != null) {
        homeProperties.clear();
        homeProperties = null;
      }
    } catch (Exception ex) {
      IOUtil.print(ex);
    }

    try {
      super.doTearDown();
    } catch (Exception ex) {
      IOUtil.print(ex);
    }
  }
Exemplo n.º 10
0
  void saveNode(Node node) {
    OutputStream out = null;

    try {
      File folder = node.getFolder();
      folder.mkdirs();

      File file = new File(folder, NODE_PROPERTIES);
      out = new FileOutputStream(file);
      node.getSettings().store(out, "Node Settings");
    } catch (IOException ex) {
      throw new IORuntimeException(ex);
    } finally {
      IOUtil.close(out);
    }
  }
Exemplo n.º 11
0
  private void commitBlob() throws Exception {
    InputStream inputStream = null;

    try {
      Image image = getModel3Factory().createImage();
      image.setWidth(320);
      image.setHeight(200);

      CDOSession session = openSession();
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource(getResourcePath("res"));
      resource.getContents().add(image);

      transaction.commit();
    } finally {
      IOUtil.close(inputStream);
    }
  }
Exemplo n.º 12
0
  private Properties loadProperties(File folder) {
    File file = new File(folder, NODE_PROPERTIES);
    if (file.isFile()) {
      InputStream in = null;

      try {
        in = new FileInputStream(file);

        Properties properties = new Properties();
        properties.load(in);
        return properties;
      } catch (IOException ex) {
        throw new IORuntimeException(ex);
      } finally {
        IOUtil.close(in);
      }
    }

    return null;
  }
Exemplo n.º 13
0
 @Override
 protected void writeClob(byte[] id, long size, Reader reader) throws IOException {
   CharArrayWriter out = new CharArrayWriter();
   IOUtil.copyCharacter(reader, out, size);
   writeObject(new DB4OClob(HexUtil.bytesToHex(id), out.toCharArray()), new Monitor());
 }
Exemplo n.º 14
0
 @Override
 protected void writeBlob(byte[] id, long size, InputStream inputStream) throws IOException {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   IOUtil.copyBinary(inputStream, out, size);
   writeObject(new DB4OBlob(HexUtil.bytesToHex(id), out.toByteArray()), new Monitor());
 }