Package app.database.model.note

Source Code of app.database.model.note.NoteStrategyJdbc

package app.database.model.note;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.naming.OperationNotSupportedException;

import org.ytreza.data.Filter;
import org.ytreza.data.database.jdbc.FilterJdbc;
import org.ytreza.data.origin.Origin;
import org.ytreza.data.table.SpecialCommand;
import org.ytreza.data.table.Table;
import org.ytreza.data.table.TableStrategy;
import org.ytreza.data.table.exception.ItemException;
import org.ytreza.data.table.jdbc.TableStrategyJdbc;


public class NoteStrategyJdbc extends TableStrategyJdbc<ModelNote>{
 
  Table<ModelNote> table;

  @Override
  public String getStringToCreateTable() {
    return "CREATE TABLE IF NOT EXISTS note (" +
        "id INTEGER PRIMARY KEY AUTOINCREMENT," +
        "subject VARCHAR(150)," +
        "text TEXT)";
  }

  @Override
  public TableStrategy<ModelNote> getRealStrategy() {
    return this;
  }
  @Override
  public List<Integer> getIdWhere(Filter filter) throws ItemException {
    List<Integer> list = new ArrayList<Integer>();
    ResultSet set;
    try {
      Connection connection = connectionManager.getConnection();
      Statement statement = connection.createStatement();

      set = statement.executeQuery("SELECT id FROM " + getTableName() + new FilterJdbc(filter) + " ORDER BY subject");

      while (set.next()) {
        list.add(set.getInt("id"));
      }

      set.close();
      statement.close();
    } catch (SQLException e) {
      throw new ItemException(ItemException.ErrorType.CANT_GET, e);
    }
    return list;
  }

  @Override
  public List<Origin<ModelNote>> getOrigins(SpecialCommand command)
      throws OperationNotSupportedException {
    // AUTO_TODO Auto-generated method stub
    return null;
  }

 
 
}
TOP

Related Classes of app.database.model.note.NoteStrategyJdbc

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.