Package org.qdao

Examples of org.qdao.TableDescriptor


   * @param tableClazz
   * @return 2010/02/25 10:41:42
   */
  public static TableDescriptor getTableDescriptor(Class<?> tableClazz) {
    // TODO : use reflect to get annotation from table class
    TableDescriptor tableDescriptor = new TableDescriptor();

    Table table = (Table) tableClazz.getAnnotation(Table.class);
    if (table != null) {
      tableDescriptor.name = table.name();
      tableDescriptor.description = table.description();
View Full Code Here


    StringBuffer buf = getSQLTigger();
    System.out.println(buf);
  }

  private static StringBuffer getSQLTigger() {
    TableDescriptor table = getTableDescriptor(Program.class);
    StringBuffer buf = new StringBuffer("CREATE TABLE ");
    buf.append(table.name + "(\r\n");
    for (int i = 0; i < table.columns.length; i++) {
      buf.append("\t" + table.columns[i].name + ' ')
          .append(table.columns[i].type)
View Full Code Here

    }
    return buf;
  }

  public static TableDescriptor getTableDescriptor(Class<?> tableClazz) {
    TableDescriptor tableDescriptor = new TableDescriptor();

    Table table = (Table) tableClazz.getAnnotation(Table.class);
    if (table != null) {
      tableDescriptor.name = table.name();
      tableDescriptor.description = table.description();
View Full Code Here

    close();
    return result;
  }

  public Integer count() {
    TableDescriptor table = dbEngine.getTableDescriptor(entity);
    int result = -1;
    sql.append("SELECT COUNT(*) FROM ").append(table.name);
    try {
      prepare();
      rs = pstmt.executeQuery();
View Full Code Here

    return result;
  }

 
  public Integer count(String sqlPart) {
    TableDescriptor table = dbEngine.getTableDescriptor(entity);
    int result = -1;
    sql.append("SELECT COUNT(*) FROM ").append(table.name).append(" WHERE 1 = 1 AND ").append(sqlPart);
    try {
      pstmt = getDBEngine().getConnection().prepareStatement(sql.toString());
      rs = pstmt.executeQuery();
View Full Code Here

    return result;
  }

 
  public boolean create() {
    TableDescriptor table = dbEngine.getTableDescriptor(entity);
    sql.append(SQLTigger.getMySqlCreateTigger(table));
    try {
      pstmt = getDBEngine().getConnection().prepareStatement(sql.toString());
      pstmt.executeUpdate();
      return true;
View Full Code Here

    if (entity != clazz) {
      // logWarning("Your data is wrong!");
      logWarning("数据部匹配!");
      return false;
    }
    TableDescriptor table = dbEngine.getTableDescriptor(entity);
    sql.append("DELETE FROM ").append(table.name).append(" WHERE ");
    for (int i = 0; i < table.primaryKeys.length; i++) {
      if (i != table.primaryKeys.length - 1) {
        sql.append(table.primaryKeys[i]).append(" = ? AND ");
      } else
View Full Code Here

  public boolean deletePart(String sqlPart) {
    return delete0(sqlPart);
  }

  private boolean delete0(String sqlPart) {
    TableDescriptor table = dbEngine.getTableDescriptor(entity);
    int result = -1;
    sql.append("DELETE FROM ").append(table.name).append(" WHERE ").append(sqlPart);
    try {
      pstmt = getDBEngine().getConnection().prepareStatement(sql.toString());
      result = pstmt.executeUpdate();
View Full Code Here

  }

 
  public boolean delete(List<T> datas) {
    Iterator<?> iter = datas.iterator();
    TableDescriptor table = dbEngine.getTableDescriptor(entity);
    Field[] fs = entity.getDeclaredFields();
    if (fs.length != table.columns.length) {
      // logger.log(Level.WARNING,
      // "The object's fields can not match the table's columns!");
      logWarning(" 插入的数据项与表中的项不匹配");
View Full Code Here

    }
  }

 
  public boolean drop() {
    TableDescriptor table = dbEngine.getTableDescriptor(entity);
    sql.append("DROP TABLE ").append(table.name);
    try {
      prepare();
      pstmt.executeUpdate();
      return true;
View Full Code Here

TOP

Related Classes of org.qdao.TableDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.