Ejemplo n.º 1
0
  public static void main(String[] args) {
    DataContext oc = CommonQueries.createAndBindThreadContext();

    for (String numero : new String[] {"200902069801", "200902081501"}) {
      System.out.println("Numero: " + numero);
      Bon bon = CommonQueries.unique(oc, Bon.class, "numero", numero);
      System.out.println("  - " + bon.getPersonne());
      UsageBon usage = bon.getUsage();
      if (usage != null) {
        System.out.println("  - Facture: " + usage.getFacture().getFacture().getNumero());
        System.out.println(
            "  - Arrêté: " + (usage.getArrete() != null ? usage.getArrete().getNumero() : null));
      }
      System.out.println();
    }
  }
Ejemplo n.º 2
0
        @Override
        protected Object buildValue(ConstRef ref) {
          Class<?> clazz = ref.clazz;
          String nom = ref.nom;

          DataContext dc = DataContext.createDataContext();
          String constEntity = "Const" + clazz.getSimpleName();
          if (dc.getEntityResolver().getObjEntity(constEntity) == null) {
            throw new RuntimeException("Pas de constantes de type " + clazz.getName());
          }
          DataObject result = CommonQueries.unique(dc, constEntity, "nom", nom);
          if (result == null) {
            result = dc.createAndRegisterNewObject(constEntity);
            result.writeProperty("nom", nom);
            result.writeProperty("libelle", nom);
            dc.commitChanges();
            // throw new RuntimeException("Pas de constante nommée " + nom
            // + " (type:" + clazz.getName() + ")");
          }
          return result.readProperty("valeur");
        }