Exemple #1
0
  public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {

    final Molecule<Object> m =
        new Molecule<Object>() {
          public void run() {
            try {
              setObj(method.invoke(dao, args));
            } catch (IllegalArgumentException e) {
              throw Lang.wrapThrow(e);
            } catch (IllegalAccessException e) {
              throw Lang.wrapThrow(e);
            } catch (InvocationTargetException e) {
              throw Lang.wrapThrow(e.getTargetException());
            }
          }
        };
    if (filter != null && tableName != null) {
      TableName.run(
          tableName,
          new Runnable() {
            public void run() {
              filter.run(m);
            }
          });
      return m.getObj();
    }
    if (filter != null) filter.run(m);
    else TableName.run(tableName, m);
    return m.getObj();
  }
Exemple #2
0
 protected List<Sql> createIndexs(Entity<?> en) {
   List<Sql> sqls = new ArrayList<Sql>();
   StringBuilder sb = new StringBuilder();
   List<EntityIndex> indexs = en.getIndexes();
   for (EntityIndex index : indexs) {
     sb.setLength(0);
     if (index.isUnique()) sb.append("Create UNIQUE Index ");
     else sb.append("Create Index ");
     if (index.getName().contains("$"))
       sb.append(TableName.render(new CharSegment(index.getName())));
     else sb.append(index.getName());
     sb.append(" ON ").append(en.getTableName()).append("(");
     for (EntityField field : index.getFields()) {
       if (field instanceof MappingField) {
         MappingField mf = (MappingField) field;
         sb.append(mf.getColumnNameInSql()).append(',');
       } else {
         throw Lang.makeThrow(
             DaoException.class,
             "%s %s is NOT a mapping field, can't use as index field!!",
             en.getClass(),
             field.getName());
       }
     }
     sb.setCharAt(sb.length() - 1, ')');
     sqls.add(Sqls.create(sb.toString()));
   }
   return sqls;
 }
Exemple #3
0
 public static String getTableName(Dao dao, final Entity<?> en, Object t) {
   if (t == null) return en.getTableName();
   final String[] name = new String[1];
   TableName.run(
       t,
       new Runnable() {
         public void run() {
           name[0] = en.getTableName();
         }
       });
   return name[0];
 }
Exemple #4
0
 public Sql sql() {
   return Sqls.fetchInt((TableName.render(seg)));
 }