Package com.tubeilike.model

Source Code of com.tubeilike.model.TagModel

package com.tubeilike.model;

import java.util.List;
import com.tubeilike.entity.Tag;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public class TagModel {

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

  public static boolean add(Tag tag) {
    try {
      pm.makePersistent(tag);

    } catch (Exception e) {
      System.out.println("Error when add tag object.");
      e.printStackTrace();
      return false;
    }
    return true;
  }

  public static boolean addAll(List<Tag> listTag) {
    try {
      pm.makePersistentAll(listTag);
      System.out.println("Add all tube success.");
    } catch (Exception e) {
      System.out.println("Error when add many tag object.");
      e.printStackTrace();
      return false;
    }
    return true;
  }

  public static boolean update(Tag tag) {
    pm.makePersistent(tag);
    return true;
  }

  @SuppressWarnings("unchecked")
  public static Tag getByAlias(String alias) {
    Tag tag = null;
    Query query = pm.newQuery(Tag.class);
    query.setFilter("alias=='" + alias + "'");
    query.setRange(0, 1);
    List<Tag> listResult = (List<Tag>) query.execute();
    if (listResult.size() > 0) {
      tag = listResult.get(0);
    }
    return tag;
  }

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

}
TOP

Related Classes of com.tubeilike.model.TagModel

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.