示例#1
0
 private static KeyValue property2KeyValue(Property property, Object entity) {
   KeyValue kv = null;
   String pcolumn = property.getColumn();
   Object value = property.getValue(entity);
   if (value != null) {
     kv = new KeyValue(pcolumn, value);
   } else {
     if (property.getDefaultValue() != null && property.getDefaultValue().trim().length() != 0)
       kv = new KeyValue(pcolumn, property.getDefaultValue());
   }
   return kv;
 }
示例#2
0
  public static String getCreatTableSQL(Class<?> clazz) {
    TableInfo table = TableInfo.get(clazz);

    Id id = table.getId();
    StringBuffer strSQL = new StringBuffer();
    strSQL.append("CREATE TABLE IF NOT EXISTS ");
    strSQL.append(table.getTableName());
    strSQL.append(" ( ");

    Class<?> primaryClazz = id.getDataType();
    if (primaryClazz == int.class
        || primaryClazz == Integer.class
        || primaryClazz == long.class
        || primaryClazz == Long.class) {
      strSQL.append(id.getColumn()).append(" INTEGER PRIMARY KEY AUTOINCREMENT,");
    } else {
      strSQL.append(id.getColumn()).append(" TEXT PRIMARY KEY,");
    }

    Collection<Property> propertys = table.propertyMap.values();
    for (Property property : propertys) {
      strSQL.append(property.getColumn());
      Class<?> dataType = property.getDataType();
      if (dataType == int.class
          || dataType == Integer.class
          || dataType == long.class
          || dataType == Long.class) {
        strSQL.append(" INTEGER");
      } else if (dataType == float.class
          || dataType == Float.class
          || dataType == double.class
          || dataType == Double.class) {
        strSQL.append(" REAL");
      } else if (dataType == boolean.class || dataType == Boolean.class) {
        strSQL.append(" NUMERIC");
      }
      strSQL.append(",");
    }

    strSQL.deleteCharAt(strSQL.length() - 1);
    strSQL.append(" )");
    return strSQL.toString();
  }