Package com.j256.ormlite.stmt.mapped

Source Code of com.j256.ormlite.stmt.mapped.MappedDelete

package com.j256.ormlite.stmt.mapped;

import java.sql.SQLException;

import com.j256.ormlite.db.DatabaseType;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.table.TableInfo;

/**
* A mapped statement for deleting an object.
*
* @author graywatson
*/
public class MappedDelete<T, ID> extends BaseMappedStatement<T, ID> {

  private MappedDelete(TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes) {
    super(tableInfo, statement, argFieldTypes);
  }

  public static <T, ID> MappedDelete<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo)
      throws SQLException {
    FieldType idField = tableInfo.getIdField();
    if (idField == null) {
      throw new SQLException("Cannot delete from " + tableInfo.getDataClass()
          + " because it doesn't have an id field");
    }
    StringBuilder sb = new StringBuilder(64);
    appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName());
    appendWhereId(databaseType, idField, sb, null);
    return new MappedDelete<T, ID>(tableInfo, sb.toString(), new FieldType[] { idField });
  }
}
TOP

Related Classes of com.j256.ormlite.stmt.mapped.MappedDelete

TOP
Copyright © 2018 www.massapi.com. 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.