Package com.dotmarketing.common.db

Examples of com.dotmarketing.common.db.DotConnect


  @Override
  public void executeUpgrade() throws DotDataException, DotRuntimeException {
    try {
      DbConnectionFactory.getConnection().setAutoCommit(true);
      DotConnect dc = new DotConnect();
      try {
        dc.executeStatement("drop table container_structures");
      } catch (SQLException e) {
        Logger.info(getClass(),
            "container_structures table does not exist. Will be created.");
      }
      String createTable = "Create table container_structures"
          + "(id varchar(36) NOT NULL  primary key,"
          + "container_id varchar(36) NOT NULL,"
          + "structure_id varchar(36) NOT NULL, " + "code text)";

      if (DbConnectionFactory.isOracle()) {
        createTable = createTable.replaceAll("varchar\\(",
            "varchar2\\(");
        createTable = createTable.replaceAll("text", "nclob");
      } else if (DbConnectionFactory.isMySql()) {
        createTable = createTable.replaceAll("text", "longtext");
      }
      dc.executeStatement(createTable);
    } catch (SQLException e) {
      throw new DotDataException(e.getMessage(), e);
    }
  }
View Full Code Here


    dc.loadResult();
    CacheLocator.getNewNotificationCache().remove(notification.getUserId());
  }

  public Notification findNotification(String notificationId) throws DotDataException {
      DotConnect dc = new DotConnect();
    dc.setSQL("select * from notification where id = ?");
    dc.addParam(notificationId);

    Notification n = null;
    List<Map<String, Object>> results = dc.loadObjectResults();

    if(results!=null && !results.isEmpty()) {
      Map<String, Object> row = results.get(0);
      n = new Notification();
      n.setId((String)row.get("id"));
View Full Code Here

    @Override
    public void executeUpgrade () throws DotDataException, DotRuntimeException {

        //Update identifier table for the SYSTEM_HOST
        DotConnect dc = new DotConnect();
        dc.setSQL( "update identifier set asset_name = ? where id = ?" );
        dc.addParam( "system host" );
        dc.addParam( Host.SYSTEM_HOST );

        dc.loadResult();

        //Verify if we already have a contentlet version for the SYSTEM_HOST contentlet
        dc = new DotConnect();
        dc.setSQL( "select identifier from contentlet_version_info where identifier = ?" );
        dc.addParam( Host.SYSTEM_HOST );
        ArrayList<Map<String, String>> versionsResults = dc.loadResults();

        //Ok, we didn't found a version for this SYSTEM_HOST contentlet, so we need to create one
        if ( versionsResults == null || versionsResults.isEmpty() ) {

            //Getting the SYSTEM_HOST contentlet
            dc = new DotConnect();
            dc.setSQL( "select inode, language_id from contentlet where title = 'System Host'" );
            ArrayList<Map<String, String>> results = dc.loadResults();

            if ( results != null && results.size() > 0 ) {

                String inode = results.get( 0 ).get( "inode" );
                String languageId = results.get( 0 ).get( "language_id" );

                //Insert a contentlet version for the SYSTEM_HOST contentlet
                dc = new DotConnect();
                dc.setSQL( "insert into contentlet_version_info (identifier, lang, working_inode, live_inode, deleted, locked_by, locked_on, version_ts) values (?,?,?,?,?,?,?,?)" );
                dc.addParam( Host.SYSTEM_HOST );
                dc.addParam( Long.valueOf( languageId ) );
                dc.addParam( inode );
                dc.addParam( inode );
                if ( DbConnectionFactory.isPostgres() ) {
                    dc.addParam( false );
                } else if ( DbConnectionFactory.isMsSql() ) {
                    dc.addParam( 0 );
                } else if ( DbConnectionFactory.isMySql() ) {
                    dc.addParam( 0 );
                } else if ( DbConnectionFactory.isOracle() ) {
                    dc.addParam( 0 );
                }
                dc.addObject( null );
                dc.addParam( new Date() );
                dc.addParam( new Date() );

                dc.loadResult();
            } else {
                throw new DotRuntimeException( "Error querying SYSTEM_HOST contentlet." );
            }
        }
View Full Code Here

    return n;
  }

  public void deleteNotification(String notificationId) throws DotDataException {
      DotConnect dc = new DotConnect();
    dc.setSQL("delete from notification where id = ?");
    dc.addParam(notificationId);
    dc.loadObjectResults();
  }
View Full Code Here

    dc.addParam(notificationId);
    dc.loadObjectResults();
  }

  public void deleteNotifications(String userId) throws DotDataException {
      DotConnect dc = new DotConnect();
    String userWhere = UtilMethods.isSet(userId)?" where user_id = ? ":"";
    dc.setSQL("delete from notification " + userWhere);

    if(UtilMethods.isSet(userId)) {
      dc.addParam(userId);
    }

    dc.loadObjectResults();
  }
View Full Code Here

  public List<Notification> getAllNotifications(String userId) throws DotDataException {
    return getNotifications(userId, -1, -1);
  }

  public Long getNotificationsCount(String userId) throws DotDataException {
      DotConnect dc = new DotConnect();
    String userWhere = UtilMethods.isSet(userId)?"where user_id = ? ":"";
    dc.setSQL("select count(*) as count from notification " + userWhere);

    if(UtilMethods.isSet(userId)) {
      dc.addParam(userId);
    }

    List<Map<String, Object>> results = dc.loadObjectResults();
    Long count = Long.parseLong(results.get(0).get("count").toString());
    return count;
  }
View Full Code Here

    Long count = Long.parseLong(results.get(0).get("count").toString());
    return count;
  }

  public List<Notification> getNotifications(String userId, long offset, long limit) throws DotDataException {
      DotConnect dc = new DotConnect();
    String userWhere = UtilMethods.isSet(userId)?" where user_id = ? ":"";
    String sql = "select * from notification " + userWhere + " order by time_sent desc";
    dc.setSQL( (UtilMethods.isSet(offset)&&offset>-1 && UtilMethods.isSet(limit) && limit>0)
        ? SQLUtil.addLimits(sql, offset, limit)
            : sql);

    if(UtilMethods.isSet(userId)) {
      dc.addParam(userId);
    }

    List<Map<String, Object>> results = dc.loadObjectResults();
    List<Notification> notifications = new ArrayList<Notification>();

    for (Map<String, Object> row : results) {
      Notification n = new Notification();
      n.setId((String)row.get("id"));
View Full Code Here

    return notifications;
  }

  public Long getNewNotificationsCount(String userIdthrows DotDataException {
      DotConnect dc = new DotConnect();
    String userWhere = UtilMethods.isSet(userId)?" user_id = ? and ":"";
    dc.setSQL("select count(*) as count from notification where " + userWhere + " was_read = " + DbConnectionFactory.getDBFalse());

    if(UtilMethods.isSet(userId)) {
      dc.addParam(userId);
    }

    List<Map<String, Object>> results = dc.loadObjectResults();
    return ((Number)results.get(0).get("count")).longValue();
  }
View Full Code Here

    List<Map<String, Object>> results = dc.loadObjectResults();
    return ((Number)results.get(0).get("count")).longValue();
  }

  public void markNotificationsAsRead(String userId) throws DotDataException {
      DotConnect dc = new DotConnect();
    if(!UtilMethods.isSet(userId)) return;

    dc.setSQL("update notification set was_read = "+ DbConnectionFactory.getDBTrue()
        + " where was_read = "+ DbConnectionFactory.getDBFalse()+" and user_id = ?");
    dc.addParam(userId);
    dc.loadResult();
  }
View Full Code Here

  public void executeUpgrade() throws DotDataException, DotRuntimeException {
    try {
      DbConnectionFactory.getConnection().setAutoCommit(true);
     
      this.dc = new DotConnect();

      if (DbConnectionFactory.isOracle()) {
        createNewTablesOracle();
      } else if (DbConnectionFactory.isMsSql()) {
        createNewTablesSQLServer();
View Full Code Here

TOP

Related Classes of com.dotmarketing.common.db.DotConnect

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.