Package cx.fbn.nevernote.sql.driver

Examples of cx.fbn.nevernote.sql.driver.NSqlQuery


    
  }
  // Drop the table
  public void dropTable() {
    NSqlQuery query = new NSqlQuery(db.getConnection());
    query.exec("Drop table "+dbName);
  }
View Full Code Here


  // Save an individual notebook
  public void addNotebook(Notebook tempNotebook, boolean isDirty, boolean local, boolean linked, boolean readOnly) {
    boolean check;
   
    SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
        NSqlQuery query = new NSqlQuery(db.getConnection());
    check = query.prepare("Insert Into "+dbName+" (guid, sequence, name, defaultNotebook, "
        +"serviceCreated, serviceUpdated, published, "  
        + "publishingUri, publishingOrder, publishingAscending, publishingPublicDescription, "
        + "isDirty, autoEncrypt, stack, "
        + "local, archived, readOnly, linked) Values("
        +":guid, :sequence, :name, :defaultNotebook,  "
        +":serviceCreated, :serviceUpdated, :published, "
        +":publishingUri, :publishingOrder, :publishingAscending, :publishingPublicDescription, "
        +":isDirty, :autoEncrypt, "
        +":stack, :local, false, :readOnly, :linked)");
    query.bindValue(":guid", tempNotebook.getGuid());
    query.bindValue(":sequence", tempNotebook.getUpdateSequenceNum());
    query.bindValue(":name", tempNotebook.getName());
    query.bindValue(":defaultNotebook", tempNotebook.isDefaultNotebook());
   
    StringBuilder serviceCreated = new StringBuilder(simple.format(tempNotebook.getServiceCreated()));     
    StringBuilder serviceUpdated = new StringBuilder(simple.format(tempNotebook.getServiceUpdated()));
    if (serviceUpdated.toString() == null)
      serviceUpdated = serviceCreated;
    query.bindValue(":serviceCreated", serviceCreated.toString());
    query.bindValue(":serviceUpdated", serviceCreated.toString());
    query.bindValue(":published",tempNotebook.isPublished());
    query.bindValue(":linked", linked);
    query.bindValue(":readOnly", readOnly);
   
    if (tempNotebook.isPublished() && tempNotebook.getPublishing() != null) {
      Publishing p = tempNotebook.getPublishing();
      query.bindValue(":publishingUri", p.getUri());
      query.bindValue(":publishingOrder", p.getOrder().getValue());
      query.bindValue(":publishingAscending", p.isAscending());
      query.bindValue(":publishingPublicDescription", p.getPublicDescription());
    } else {
      query.bindValue(":publishingUri", "");
      query.bindValue(":publishingOrder", 1);
      query.bindValue(":publishingAscending", 1);
      query.bindValue(":publishingPublicDescription", "");
    }
   
    if (isDirty)
      query.bindValue(":isDirty", true);
    else
      query.bindValue(":isDirty", false);
    query.bindValue(":autoEncrypt", false);
    query.bindValue(":local", local);
    query.bindValue(":stack", tempNotebook.getStack());

    check = query.exec();
    if (!check) {
      logger.log(logger.MEDIUM, ""+dbName+" Table insert failed.");
      logger.log(logger.MEDIUM, query.lastError().toString());
    }
  }
View Full Code Here

  // Delete the notebook based on a guid
  public void expungeNotebook(String guid, boolean needsSync) {
    boolean check;
    Notebook n;
    n = getNotebook(guid);
        NSqlQuery query = new NSqlQuery(db.getConnection());

         check = query.prepare("delete from "+dbName+" where guid=:guid");
    if (!check) {
      logger.log(logger.EXTREME, dbName+" SQL delete prepare has failed.");
      logger.log(logger.EXTREME, query.lastError().toString());
    }
    query.bindValue(":guid", guid);
    check = query.exec();
    if (!check)
      logger.log(logger.MEDIUM, dbName+" delete failed.");
   
    // Signal the parent that work needs to be done
    if  (needsSync && n!=null && n.getUpdateSequenceNum() > 0) {
View Full Code Here

  public void updateNotebook(Notebook tempNotebook, boolean isDirty) {
    boolean check;
   
    SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
   
        NSqlQuery query = new NSqlQuery(db.getConnection());
         check = query.prepare("Update "+dbName+" set sequence=:sequence, name=:name, defaultNotebook=:defaultNotebook, " +
             "serviceCreated=:serviceCreated, serviceUpdated=:serviceUpdated, "+
        "published=:published, isDirty=:isDirty, publishinguri=:uri, "+
        "publishingOrder=:order, " +
        "publishingAscending=:ascending, " +
        "publishingPublicDescription=:desc, " +
        "stack=:stack " +
        "where guid=:guid ");
        
    query.bindValue(":sequence", tempNotebook.getUpdateSequenceNum());
    query.bindValue(":name", tempNotebook.getName());
    query.bindValue(":defaultNotebook", tempNotebook.isDefaultNotebook());

    StringBuilder serviceCreated = new StringBuilder(simple.format(tempNotebook.getServiceCreated()));     
    StringBuilder serviceUpdated = new StringBuilder(simple.format(tempNotebook.getServiceUpdated()));     
    query.bindValue(":serviceCreated", serviceCreated.toString());
    query.bindValue(":serviceUpdated", serviceUpdated.toString());
   
    query.bindValue(":published", tempNotebook.isPublished());
    query.bindValue(":isDirty", isDirty);
   
    if (tempNotebook.isPublished()) {
      query.bindValue(":uri", tempNotebook.getPublishing().getUri());
      query.bindValue(":order", tempNotebook.getPublishing().getOrder().getValue());
      query.bindValue(":ascending", tempNotebook.getPublishing().isAscending());
      query.bindValue(":desc", tempNotebook.getPublishing().getPublicDescription());
    } else {
      query.bindValue(":uri", "");
      query.bindValue(":order", NoteSortOrder.CREATED.getValue());
      query.bindValue(":ascending", false);
      query.bindValue(":desc", "");
    }
   
    query.bindValue(":guid", tempNotebook.getGuid());
    query.bindValue(":stack", tempNotebook.getStack());
   
    check = query.exec();
    if (!check) {
      logger.log(logger.MEDIUM, dbName+" Table update failed.");
      logger.log(logger.MEDIUM, query.lastError().toString());
    }
  }
View Full Code Here

  public List<Notebook> getAll() {
    Notebook tempNotebook;
    List<Notebook> index = new ArrayList<Notebook>();
    boolean check;
         
        NSqlQuery query = new NSqlQuery(db.getConnection());
               
    check = query.exec("Select guid, sequence, name, defaultNotebook, " +
        "serviceCreated, "+
        "serviceUpdated, "+
        "published, stack, publishinguri, publishingascending, publishingPublicDescription, "+
        "publishingOrder from "+dbName+" order by name");
    if (!check)
      logger.log(logger.EXTREME, dbName+" SQL retrieve has failed.");
    while (query.next()) {
      tempNotebook = new Notebook();
      tempNotebook.setGuid(query.valueString(0));
      int sequence = new Integer(query.valueString(1)).intValue();
      tempNotebook.setUpdateSequenceNum(sequence);
      tempNotebook.setName(query.valueString(2));
      tempNotebook.setDefaultNotebook(query.valueBoolean(3, false));
      DateFormat indfm = null;
      try {
        indfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
//        indfm = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
      } catch (Exception e) {  }
      try {
        tempNotebook.setServiceCreated(indfm.parse(query.valueString(4)).getTime());
        tempNotebook.setServiceUpdated(indfm.parse(query.valueString(5)).getTime());
      } catch (ParseException e) {
        e.printStackTrace();
      }
      tempNotebook.setPublished(new Boolean(query.valueString(6)));
      tempNotebook.setStack(query.valueString(7));
      if (tempNotebook.isPublished()) {
        Publishing p = new Publishing();
        p.setUri(query.valueString(8));
        p.setAscending(query.valueBoolean(9, false));
        p.setPublicDescription(query.valueString(10));
        p.setOrder(NoteSortOrder.findByValue(query.valueInteger(11)));
        tempNotebook.setPublishing(p);
      }
      index.add(tempNotebook);
   
    return index;
View Full Code Here

  public List<Notebook> getAllLocal() {
    Notebook tempNotebook;
    List<Notebook> index = new ArrayList<Notebook>();
    boolean check;

        NSqlQuery query = new NSqlQuery(db.getConnection());
               
    check = query.exec("Select guid, sequence, name, defaultNotebook, " +
        "serviceCreated, serviceUpdated, published, stack from "+dbName+" where local=true order by name");
    if (!check)
      logger.log(logger.EXTREME, dbName+" SQL retrieve has failed.");
    while (query.next()) {
      tempNotebook = new Notebook();
      tempNotebook.setGuid(query.valueString(0));
      int sequence = new Integer(query.valueString(1)).intValue();
      tempNotebook.setUpdateSequenceNum(sequence);
      tempNotebook.setName(query.valueString(2));
     
      DateFormat indfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
//      indfm = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
      try {
        tempNotebook.setServiceCreated(indfm.parse(query.valueString(4)).getTime());
        tempNotebook.setServiceUpdated(indfm.parse(query.valueString(5)).getTime());
      } catch (ParseException e) {
        e.printStackTrace();
      }
      if (query.valueString(7) != null && !query.valueString(7).trim().equals(""))
        tempNotebook.setStack(query.valueString(7));
      index.add(tempNotebook);
   
    return index;
  }
View Full Code Here

    return index;
  }
  // Archive or un-archive a notebook
  public void setArchived(String guid, boolean val) {
    boolean check;     
        NSqlQuery query = new NSqlQuery(db.getConnection());            
    check = query.prepare("Update "+dbName+" set archived=:archived where guid=:guid");
    if (!check)
      logger.log(logger.EXTREME, dbName+" SQL archive update has failed.");
    query.bindValue(":guid", guid);
    query.bindValue(":archived", val);
    query.exec();
  }
View Full Code Here

  public List<Notebook> getAllArchived() {
    Notebook tempNotebook;
    List<Notebook> index = new ArrayList<Notebook>();
    boolean check;
           
        NSqlQuery query = new NSqlQuery(db.getConnection());
               
    check = query.exec("Select guid, sequence, name, defaultNotebook, " +
        "serviceCreated, serviceUpdated, published, stack, "+
        "publishinguri, publishingascending, publishingPublicDescription, "+
        "publishingOrder " +
        "from "+dbName+" where archived=true order by name");
    if (!check)
      logger.log(logger.EXTREME, dbName+" SQL retrieve has failed.");
    while (query.next()) {
      tempNotebook = new Notebook();
      tempNotebook.setGuid(query.valueString(0));
      int sequence = new Integer(query.valueString(1)).intValue();
      tempNotebook.setUpdateSequenceNum(sequence);
      tempNotebook.setName(query.valueString(2));
     
      DateFormat indfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
//      indfm = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
      try {
        tempNotebook.setServiceCreated(indfm.parse(query.valueString(4)).getTime());
        tempNotebook.setServiceUpdated(indfm.parse(query.valueString(5)).getTime());
      } catch (ParseException e) {
        e.printStackTrace();
      }
      tempNotebook.setPublished(new Boolean(query.valueString(6)));
      if (query.valueString(7) != null && !query.valueString(7).trim().equals(""))
        tempNotebook.setStack(query.valueString(7));
     
      if (tempNotebook.isPublished()) {
        Publishing p = new Publishing();
        p.setUri(query.valueString(8));
        p.setAscending(query.valueBoolean(9, false));
        p.setPublicDescription(query.valueString(10));
        p.setOrder(NoteSortOrder.findByValue(query.valueInteger(11)));
        tempNotebook.setPublishing(p);
      }
     
      index.add(tempNotebook);
   
View Full Code Here

   
    return index;
 
  // Check for a local/remote notebook
  public boolean isNotebookLocal(String guid) {
        NSqlQuery query = new NSqlQuery(db.getConnection());
   
    query.prepare("Select local from "+dbName+" where guid=:guid");
    query.bindValue(":guid", guid);
    query.exec();
    if (!query.next()) {
      return false;
    }
    boolean returnValue = query.valueBoolean(0, false);
    return returnValue;
  }
View Full Code Here

    boolean returnValue = query.valueBoolean(0, false);
    return returnValue;
  }
  // Check for a local/remote notebook
  public boolean isNotebookLinked(String guid) {
        NSqlQuery query = new NSqlQuery(db.getConnection());
   
    query.prepare("Select linked from "+dbName+" where guid=:guid");
    query.bindValue(":guid", guid);
    query.exec();
    if (!query.next()) {
      return false;
    }
    boolean returnValue = query.valueBoolean(0, false);
    return returnValue;
  }
View Full Code Here

TOP

Related Classes of cx.fbn.nevernote.sql.driver.NSqlQuery

Copyright © 2018 www.massapicom. 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.