Пример #1
1
  @Override
  public Map<String, Object> saveMap(Map<String, Object> object, Class clazz) throws Exception {

    StringBuilder sql = new StringBuilder();
    EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz);

    sql.append("INSERT INTO ");
    sql.append(entityInfo.getTableName());
    sql.append("(");

    List<String> columns = new ArrayList<String>();
    List<Object> values = new ArrayList<Object>();
    Map<String, String> ptcMap = ClassUtils.propToColumnMap.get(entityInfo.getClazzName());
    for (Map.Entry<String, Object> entry : object.entrySet()) {
      columns.add(ptcMap.get(entry.getKey()));
      values.add(entry.getValue());
    }
    sql.append(StringUtils.join(columns, ","));
    sql.append(") VALUES(");
    String[] params = new String[values.size()];
    Arrays.fill(params, "?");
    sql.append(StringUtils.join(params, ","));
    sql.append(")");
    if (entityInfo.getStrategy().equals(GenerationType.IDENTITY)) {
      Long id = addReutrnId(sql.toString(), values);
      if (id != null) {
        object.put(entityInfo.getPkName(), id);
      }
    } else {
      add(sql.toString(), values);
    }
    return object;
  }
 private boolean isEnabled(Class<?> pluginClass) {
   for (String disabledPlugin : this.disabledPlugins) {
     if (ClassUtils.getShortName(pluginClass).equalsIgnoreCase(disabledPlugin)
         || ClassUtils.getQualifiedName(pluginClass).equalsIgnoreCase(disabledPlugin)) {
       return false;
     }
   }
   return true;
 }
Пример #3
0
  @Override
  public int update(Object object) throws Exception {

    EntityInfo entityInfo = ClassUtils.getEntityInfoByObject(object);
    Map<String, Object> valueMap = ClassUtils.describe(object);

    SqlHelper sqlHelper = getUpdateSql(valueMap, entityInfo);

    return update(sqlHelper);
  }
Пример #4
0
  @Override
  public int updateMap(Map<String, Object> object, Class clazz) throws Exception {

    EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz);
    if (entityInfo == null) {
      throw new DaoException("无效的实体类class");
    }
    SqlHelper sqlHelper = getUpdateSql(object, entityInfo);
    return update(sqlHelper);
  }
Пример #5
0
  @Override
  public int del(Object id, Class clazz) throws Exception {
    EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz);
    if (entityInfo == null) {
      throw new DaoException("无效的实体类class");
    }

    SqlHelper sqlHelper = SqlHelper.getDeleteHelper(clazz);
    sqlHelper.append(" WHERE ").append(entityInfo.getPkClumnName()).append("=?");
    sqlHelper.setParameters(id);
    return del(sqlHelper, clazz);
  }
Пример #6
0
 public static boolean nameCanBeImported(@NotNull String fqName, @NotNull PsiElement context) {
   final PsiClass containingClass = PsiTreeUtil.getParentOfType(context, PsiClass.class);
   if (containingClass != null) {
     if (fqName.equals(containingClass.getQualifiedName())) {
       return true;
     }
     final String shortName = ClassUtil.extractClassName(fqName);
     final PsiClass[] innerClasses = containingClass.getAllInnerClasses();
     for (PsiClass innerClass : innerClasses) {
       if (innerClass.hasModifierProperty(PsiModifier.PRIVATE)) {
         continue;
       }
       if (innerClass.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
         if (!ClassUtils.inSamePackage(innerClass, containingClass)) {
           continue;
         }
       }
       final String className = innerClass.getName();
       if (shortName.equals(className)) {
         return false;
       }
     }
     PsiField field = containingClass.findFieldByName(shortName, false);
     if (field != null) {
       return false;
     }
     field = containingClass.findFieldByName(shortName, true);
     if (field != null
         && PsiUtil.isAccessible(containingClass.getProject(), field, containingClass, null)) {
       return false;
     }
   }
   final PsiJavaFile file = PsiTreeUtil.getParentOfType(context, PsiJavaFile.class);
   if (file == null) {
     return false;
   }
   if (hasExactImportConflict(fqName, file)) {
     return false;
   }
   if (hasOnDemandImportConflict(fqName, file, true)) {
     return false;
   }
   if (containsConflictingReference(file, fqName)) {
     return false;
   }
   if (containsConflictingClass(fqName, file)) {
     return false;
   }
   return !containsConflictingClassName(fqName, file);
 }
Пример #7
0
  @Override
  public Map<String, Object> findMapById(Object id, Class clazz) throws Exception {

    EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz);

    if (entityInfo == null) {
      throw new DaoException("无效的实体类class");
    }

    SqlHelper sqlHelper = SqlHelper.getSelectHelper(clazz);
    sqlHelper.append(" AND ").append(entityInfo.getPkClumnName()).append("=?");
    sqlHelper.setParameters(id);
    return searchMapForOne(sqlHelper);
  }
Пример #8
0
 @Override
 public void batchDel(List<Object> ids, Class clazz) throws Exception {
   EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz);
   if (entityInfo == null) {
     throw new DaoException("无效的实体类class");
   }
   Object[] objects = new Object[ids.size()];
   Arrays.fill(objects, "?");
   SqlHelper sqlHelper = SqlHelper.getDeleteHelper(clazz);
   sqlHelper
       .append(" WHERE ")
       .append(entityInfo.getPkClumnName())
       .append(" IN (")
       .append(StringUtils.join(objects, ","))
       .append(")");
   update(sqlHelper.getSql(), ids);
 }
    protected boolean isEnabled(CRaSHPlugin<?> plugin) {
      Assert.notNull(plugin, "Plugin must not be null");

      if (ObjectUtils.isEmpty(this.disabledPlugins)) {
        return true;
      }

      Set<Class<?>> pluginClasses = ClassUtils.getAllInterfacesAsSet(plugin);
      pluginClasses.add(plugin.getClass());

      for (Class<?> pluginClass : pluginClasses) {
        if (isEnabled(pluginClass)) {
          return true;
        }
      }
      return false;
    }