Package com.tubeilike.model

Source Code of com.tubeilike.model.TubeModel

package com.tubeilike.model;

import java.util.List;

import javax.jdo.PersistenceManager;

import javax.jdo.Query;
import com.tubeilike.entity.Tube;

public class TubeModel {

  static PersistenceManager pm = PMF.get().getPersistenceManager();

  public static void initPm() {
    if (pm.isClosed()) {
      pm = PMF.get().getPersistenceManager();
    }
  }

  public static boolean add(Tube tube) {
    initPm();
    try {
      pm.makePersistent(tube);
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }

  public static boolean addAll(List<Tube> listTube) {
    initPm();
    try {
      pm.makePersistentAll(listTube);
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }

  public static boolean update(Tube tube) {
    initPm();
    pm.makePersistent(tube);
    return true;
  }

  @SuppressWarnings("unchecked")
  public static Tube getByTubeId(String tubeId) {
    initPm();
    Tube tube = null;
    Query query = pm.newQuery(Tube.class);
    query.setFilter("tubeId=='" + tubeId + "' && status==1");
    query.setRange(0, 1);
    List<Tube> listResult = (List<Tube>) query.execute();
    if (listResult.size() > 0) {
      tube = listResult.get(0);
    }
    return tube;
  }

  public static void closePM() {
    pm.close();
  }

}
TOP

Related Classes of com.tubeilike.model.TubeModel

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.