Esempio n. 1
0
 public static Container setup(
     DataSource dataSource,
     Properties properties,
     Optional<File> pluginsPath,
     Optional<ClassLoader> classLoader)
     throws IOException {
   ClassLoader loader;
   if (pluginsPath.isPresent()) {
     File[] jars = pluginsPath.get().listFiles(f -> f.getPath().toLowerCase().endsWith(".jar"));
     List<URL> urls = new ArrayList<>(jars.length);
     for (File j : jars) {
       try {
         urls.add(j.toURI().toURL());
       } catch (MalformedURLException ex) {
         throw new IOException(ex);
       }
     }
     loader =
         classLoader.isPresent()
             ? new URLClassLoader(urls.toArray(new URL[urls.size()]), classLoader.get())
             : new URLClassLoader(urls.toArray(new URL[urls.size()]));
   } else if (classLoader.isPresent()) {
     loader = classLoader.get();
   } else {
     loader = Thread.currentThread().getContextClassLoader();
   }
   ServiceLoader<SystemAspect> aspects = ServiceLoader.load(SystemAspect.class, loader);
   return setup(dataSource, properties, Optional.of(loader), aspects.iterator());
 }
Esempio n. 2
0
  @Test
  public void stringOrderingViaLambda() throws IOException {
    ServiceLocator locator = container;
    InfoRepository infoRepository = locator.resolve(InfoRepository.class);

    String id = UUID.randomUUID().toString();

    List<Info> infos = new ArrayList<Info>();
    for (char letter = 'A'; letter < 'Z'; letter++) {
      infos.add(
          new Info()
              .setCode(String.format("code %s %c", id, letter))
              .setName(String.format("name %s %c", id, letter)));
    }

    infoRepository.insert(infos);

    Specification<Info> filter = it -> it.getCode().startsWith("code " + id);

    List<Info> found =
        infoRepository
            .search(filter)
            .stream()
            .sorted((a, b) -> a.getName().compareTo(b.getName()))
            .collect(Collectors.toList());

    List<Info> infosAscByName =
        infoRepository.query().filter(filter).sortedBy(Info::getName).list();
    Assert.assertEquals(found, infosAscByName);

    List<Info> infosDescByName =
        infoRepository.query().filter(filter).sortedDescendingBy(Info::getName).list();
    Collections.reverse(infosDescByName);
    Assert.assertEquals(found, infosDescByName);
  }
Esempio n. 3
0
  @Test
  public void stringOrderingViaPropertyName() throws IOException, NoSuchMethodException {
    ServiceLocator locator = container;
    InfoRepository infoRepository = locator.resolve(InfoRepository.class);

    String id = UUID.randomUUID().toString();

    List<Info> infos = new ArrayList<Info>();
    for (char letter = 'A'; letter < 'Z'; letter++) {
      infos.add(
          new Info()
              .setCode(String.format("code %s %c", id, letter))
              .setName(String.format("name %s %c", id, letter)));
    }

    JinqMetaModel jinqMetaModel = locator.resolve(JinqMetaModel.class);
    Method method = Info.class.getMethod("getName");
    Query.Compare<Info, ?> nameOrder = jinqMetaModel.findGetter(method);

    Specification<Info> filter = it -> it.getCode().startsWith("code " + id);

    infoRepository.insert(infos);
    List<Info> found =
        infoRepository
            .search(filter)
            .stream()
            .sorted((a, b) -> a.getName().compareTo(b.getName()))
            .collect(Collectors.toList());

    List<Info> infosAscByName = infoRepository.query(filter).sortedBy(nameOrder).list();
    Assert.assertEquals(found, infosAscByName);

    List<Info> infosDescByName = infoRepository.query(filter).sortedDescendingBy(nameOrder).list();
    Collections.reverse(infosDescByName);
    Assert.assertEquals(found, infosDescByName);
  }