Esempio n. 1
0
  public static String getEntityName(Class entity) {

    if (mappedName.get(entity) != null) {
      return mappedName.get(entity);
    }

    String name = null;

    Table table = (Table) entity.getAnnotation(Table.class);
    if (table != null && table.name() != null && !table.name().isEmpty()) {
      name = table.name();
    } else {
      Entity entityAnnotation = (Entity) entity.getAnnotation(Entity.class);
      if (entityAnnotation != null
          && entityAnnotation.name() != null
          && !entityAnnotation.name().isEmpty()) {
        name = entityAnnotation.name();
      } else {
        name = entity.getSimpleName();
      }
    }

    mappedName.put(entity, name);

    return name;
  }
Esempio n. 2
0
 public PullRequestMergeResult getPullRequestMergeResult() {
   PullRequestMergeResult mergeResult = null;
   if (!StringUtils.isEmpty(this.fromBranch) && !StringUtils.isEmpty(this.toBranch)) {
     mergeResult = this.attemptMerge();
     Map<String, String> suggestText =
         suggestTitleAndBodyFromDiffCommit(mergeResult.getGitCommits());
     this.title = suggestText.get("title");
     this.body = suggestText.get("body");
   }
   return mergeResult;
 }
Esempio n. 3
0
 /**
  * Get the EntityManager for the specified persistence unit name.
  *
  * @param name The persistence unit name
  */
 public EntityManager em(String name) {
   EntityManagerFactory emf = emfs.get(name);
   if (emf == null) {
     return null;
   }
   return emf.createEntityManager();
 }
Esempio n. 4
0
 private Collection<ConversationSummary> fetchCorrespondents(final User user) {
   final Map<String, ConversationSummary> correspondants =
       new HashMap<String, ConversationSummary>();
   {
     final Query query =
         query(
             "select m.sender.name, m.receiver.name, count(m), m.read from PrivateMessageImpl m where (m.receiver=:user OR "
                 + "(m.sender=:user)) AND(m.deleter IS NULL OR m.deleter <> :user) "
                 + "group by m.sender.name, m.receiver.name, m.read");
     query.setParameter("user", user);
     for (final Object[] row : (List<Object[]>) query.getResultList()) {
       final boolean sent = row[0].equals(((UserImpl) user).getBareName());
       final String name = (String) (sent ? row[1] : row[0]);
       final ConversationSummary previous = correspondants.get(name);
       final long count = ((Number) row[2]).longValue();
       final long newCount;
       if (row[3].equals(Boolean.FALSE) && !sent) newCount = count;
       else newCount = 0;
       if (previous != null) {
         correspondants.put(
             name,
             new ConversationSummary(
                 UserStringImpl.valueOf(name),
                 count + previous.messageCount,
                 newCount + previous.newMessageCount));
       } else
         correspondants.put(
             name, new ConversationSummary(UserStringImpl.valueOf(name), count, newCount));
     }
   }
   return new TreeSet<ConversationSummary>(correspondants.values());
 }
Esempio n. 5
0
 public boolean isOneToOneCascadeAll(Method method) throws Exception {
   Boolean isOneToOneAll = mappedOneToOneCascadeAll.get(method);
   if (isOneToOneAll != null) {
     return isOneToOneAll;
   }
   OneToOne oneToOne = method.getAnnotation(OneToOne.class);
   if (oneToOne == null) {
     Field field = getDeclaredField(method.getDeclaringClass(), getMethodName(method));
     if (field != null) {
       oneToOne = field.getAnnotation(OneToOne.class);
     }
   }
   CascadeType[] cascadeTypes = null;
   if (oneToOne != null) {
     cascadeTypes = oneToOne.cascade();
   }
   if (oneToOne != null
       && cascadeTypes != null
       && cascadeTypes.length > 0
       && Arrays.asList(cascadeTypes).contains(CascadeType.ALL)) {
     isOneToOneAll = true;
   } else {
     isOneToOneAll = false;
   }
   mappedOneToOneCascadeAll.put(method, isOneToOneAll);
   return isOneToOneAll;
 }
Esempio n. 6
0
 @Transient
 public UserScore getCurrentScore() {
   QuestionPackType currentQuestionPack = QuestionPackType.packForToday();
   UserScore score = userScores.get(currentQuestionPack);
   if (score == null) {
     score = new UserScore();
     userScores.put(currentQuestionPack, score);
   }
   return score;
 }
Esempio n. 7
0
 public boolean equals(Object o) {
   Employee e = (Employee) o;
   Map<String, PhoneNumber> map = e.getPhoneNumbers();
   if (map.size() != phones.size()) return false;
   Collection<Map.Entry<String, PhoneNumber>> entries =
       (Collection<Map.Entry<String, PhoneNumber>>) phones.entrySet();
   for (Map.Entry<String, PhoneNumber> entry : entries) {
     String key = entry.getKey();
     PhoneNumber p = entry.getValue();
     PhoneNumber p0 = map.get(key);
     if (p.getNumber() != p0.getNumber()) return false;
   }
   return true;
 }
Esempio n. 8
0
 /**
  * Método que inspecciona las propiedades de una entidad y los valores asignados a cada
  * propiedad para la construcción de los criterios a ser aplicados al momento de ejecutar una
  * búsqueda.
  *
  * @param propiedades Mapa de propiedades de una entidad con los valores que serán utilizados
  *     como criterios para la ejecución de una búsqueda.
  */
 public void contruccion(Map<String, Object> propiedades) {
   Set<String> keys = propiedades.keySet();
   for (String key : keys) {
     Object value = propiedades.get(key);
     if (value.getClass().toString().startsWith("class java.sql")) {
       continue;
     } else if (value.getClass().toString().startsWith("class java.lang")) {
       if (value.toString().indexOf('%') >= 0) {
         like.put(key, value);
       } else if (value.toString().length() > 0) {
         igualdad.put(key, value);
       }
     } else if (value.getClass().toString().startsWith("class java.util.Date")
         && value instanceof Date) {
       // Fechas solo puede realizar igualdad
       igualdad.put(key, value);
     } else {
       compuesto.put(key, value);
     }
   }
 }
 public AnnotationInfo getAnnotationInfoByDiscriminator(String discriminatorValue) {
   return discriminatorMap.get(discriminatorValue);
 }