Package com.dotmarketing.common.db

Examples of com.dotmarketing.common.db.DotConnect


 
  /* (non-Javadoc)
   * @see com.dotmarketing.startup.StartupTask#executeUpgrade()
   */
  public void executeUpgrade() throws DotDataException, DotRuntimeException{
    DotConnect dc = new DotConnect();
    Connection conn = null;
    List<PrimaryKey> primaryKeys=null;
    List<ForeignKey> foreignKeys=null;
    List<Index> indexes=null;
   
    try {
        conn = DbConnectionFactory.getDataSource().getConnection();
      conn.setAutoCommit(true);
     
      List<String> tables = getTablesToDropConstraints();
      if(tables!=null){
                foreignKeys=getForeingKeys(conn, tables,true);
                //conn.commit();
                primaryKeys=getPrimaryKey(conn, tables, true);
                //conn.commit();
                indexes=getIndexes(conn, tables,true);
                //conn.commit();
                if(DbConnectionFactory.isMsSql())
                    // for mssql we pass again as we might have index dependencies
                    getPrimaryKey(conn, tables, true);
            }
      //conn.commit();
    } catch (Exception e) {
        /*try {
            conn.rollback();
        }
        catch(SQLException ex) {}*/
      throw new DotDataException(e.getMessage(), e);
    }
    finally {
        try {
            conn.close();
        }
        catch(SQLException ex) {
            throw new DotDataException(ex.getMessage(), ex);
        }
    }
     
    List<String> schemaList = new ArrayList<String>();

    //Execute the SQL Script in accordance with the database type
    if(DbConnectionFactory.isPostgres()){
      schemaList = SQLUtil.tokenize(getPostgresScript());
    }else if(DbConnectionFactory.isMySql()){
      schemaList = SQLUtil.tokenize(getMySQLScript());
    }else if(DbConnectionFactory.isOracle()){
      schemaList = SQLUtil.tokenize(getOracleScript());
    }else if(DbConnectionFactory.isMsSql()) {
      schemaList = SQLUtil.tokenize(getMSSQLScript());
    }else {
        schemaList = SQLUtil.tokenize(getH2Script());
    }

    try {
        conn = DbConnectionFactory.getDataSource().getConnection();
            conn.setAutoCommit(false);
       
      if(DbConnectionFactory.isMySql()){
        dc.executeStatement("SET storage_engine=INNODB", conn);
      }else if(DbConnectionFactory.isMsSql()){
        dc.executeStatement("SET TRANSACTION ISOLATION LEVEL READ COMMITTED;", conn);
      }
     
      for (String query : schemaList) {
                if(!runInSingleTransaction){
                    try {
                        HibernateUtil.startTransaction();
                        dc.executeStatement(query);
                    } catch (Exception e) {
                        Logger.error(this, "Unable to execute query : " + query);
                        HibernateUtil.rollbackTransaction();
                        continue;
                    }
                    HibernateUtil.commitTransaction();
                } else {
                    try {
                        dc.executeStatement(query, conn);
                    } catch (SQLException e) {
                        Logger.fatal(this, "Unable to execute SQL upgrade", e);
                        throw new DotDataException(e.getMessage(), e);
                    }
                }
View Full Code Here


  }

  public void insertInode(String inode, String owner, String type, String identifier) throws SQLException {
    String sql = "INSERT INTO INODE(INODE, OWNER, IDATE, TYPE, IDENTIFIER) VALUES (?,?,CURRENT TIMESTAMP,?,?)";
    DotConnect dot = new DotConnect();
    dot.setSQL(sql);
    dot.addParam(inode);
    dot.addParam(owner);
    dot.addParam(type);
    dot.addParam(identifier);
    dot.executeStatement(sql);

  }
View Full Code Here

    if (UtilMethods.isSet(url_params)) {
      url_page = url_page + "?" + url_params ;
    }

    DotConnect dotConnect = new DotConnect();
    StringBuffer sql = new StringBuffer("select * from user_favorites where page_url = ? and user_id = ?");

    dotConnect.setSQL(sql.toString());
    dotConnect.addParam(url_page);
    dotConnect.addParam(user_id);
    ArrayList results =null;
    try {
      results = dotConnect.getResults();
    } catch (DotDataException e) {
      Logger.error(FavoritesWebAPI.class,"isUrlFavorite method failed:"+ e, e);
    }
   
    if (results.size() > 0)
View Full Code Here

  public static boolean setUrlFavorite(String url_page, String url_params, String user_id) {
    boolean retVal = true;

    try {
      DotConnect dotConnect = new DotConnect();
 
      StringBuffer sql;
      if (!isUrlFavorite(url_page, url_params, user_id)) {
        sql = new StringBuffer("insert into user_favorites values (?, ?)");
      }
      else {
        sql = new StringBuffer("delete from user_favorites where user_id = ? and page_url = ?");
      }
 
      if (UtilMethods.isSet(url_params)) {
        url_page = url_page + "?" + url_params ;
      }

      dotConnect.setSQL(sql.toString());
      dotConnect.addParam(user_id);
      dotConnect.addParam(url_page);
      dotConnect.getResult();
    }
    catch (Exception e) {
      retVal = false;
    }
View Full Code Here

    List<Map> l = new ArrayList<Map>();

    try {
      Host host = APILocator.getHostAPI().findDefaultHost(APILocator.getUserAPI().getSystemUser(), false);

      DotConnect dotConnect = new DotConnect();

      String sql = "select * from user_favorites where user_id = ?";

      dotConnect.setSQL(sql);
      dotConnect.addParam(user_id);
      ArrayList<HashMap> favorites = (ArrayList<HashMap>) dotConnect.getResults();

      for (HashMap<String, String> favorite : favorites) {
        String page_url = String.valueOf(favorite.get("page_url"));

        Map<String, String> hm = new HashMap<String, String>();
View Full Code Here

      bob.append(" WHERE "+ query.getBuilderType()+".inode=inode.inode");
    }
    else {
      bob.append(" AND "+ query.getBuilderType()+".inode=inode.inode");
    }
    DotConnect dc = new DotConnect();
    dc.setSQL(bob.toString().toLowerCase());
    if(params != null){
      for (Object value : params) {
        dc.addParam(value);
      }
    }
    if(query.getStart() > 0){
      dc.setStartRow(query.getStart());
    }
    if(query.getLimit() > 0){
      dc.setStartRow(query.getLimit());
    }
    String blank= "";
    List<Map<String, Object>> dbrows = dc.loadObjectResults();
    for (Map<String, Object> row : dbrows) {
      Map<String, Serializable> m = new HashMap<String, Serializable>();
       PermissionableProxy permDummy= new PermissionableProxy();
       permDummy.setPermissionByIdentifier(isPermissionsByIdentifier);
       permDummy.setInode(row.get("inode").toString());
View Full Code Here

    public int deleteOldVersions(Date assetsOlderThan) throws DotDataException, DotHibernateException {
        String condition = " mod_date < ? and not exists (select * from fileasset_version_info "+
                " where working_inode=file_asset.inode or live_inode=file_asset.inode)";
       
        String inodesToDelete = "select inode from file_asset where "+condition;
        DotConnect dc = new DotConnect();
        dc.setSQL(inodesToDelete);
        dc.addParam(assetsOlderThan);
        for(Map<String,Object> inodeMap : dc.loadObjectResults()) {
            String inode=inodeMap.get("inode").toString();
            java.io.File fileFolderPath = new java.io.File(
                    APILocator.getFileAPI().getRealAssetPath() +
                    java.io.File.separator + inode.substring(0, 1) +
                    java.io.File.separator + inode.substring(1, 2));
View Full Code Here

        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date date = calendar.getTime();
        DotConnect dc = new DotConnect();

        String countSQL = ("select count(*) as count from "+ assetType);
        dc.setSQL(countSQL);
        List<Map<String, String>> result = dc.loadResults();
        int before = Integer.parseInt(result.get(0).get("count"));
        String versionInfoTable = UtilMethods.getVersionInfoTableName(assetType);

        String condition = " mod_date < ? and not exists (select * from "+versionInfoTable+
                " where working_inode="+assetType+".inode or live_inode="+assetType+".inode)";

        String inodesToDelete = "select inode from "+assetType+" where "+condition;

        String treeChildDelete = "delete from tree where child in ("+inodesToDelete+")";
        dc.setSQL(treeChildDelete);
        dc.addParam(date);
        dc.loadResult();

        String treeParentDelete = "delete from tree where parent in ("+inodesToDelete+")";
        dc.setSQL(treeParentDelete);
        dc.addParam(date);
        dc.loadResult();

        String deleteContentletSQL = "delete from "+assetType+" where  "+condition;
        dc.setSQL(deleteContentletSQL);
        dc.addParam(date);
        dc.loadResult();

        String deleteInodesSQL = "delete from inode where type=? and idate < ? and inode not in (select inode from "+assetType+")";
        dc.setSQL(deleteInodesSQL);
        dc.addParam(assetType);
        dc.addParam(date);
        dc.loadResult();

        dc.setSQL(countSQL);
        result = dc.loadResults();
        int after = Integer.parseInt(result.get(0).get("count"));

      return before-after;
  }
View Full Code Here

    Calendar runDate = Calendar.getInstance();
    runDate.setTime(assetsOlderThan);
    runDate.add(Calendar.YEAR, -2);
   
        try{
        DotConnect dc = new DotConnect();
            String minIdateSQL = "select idate from inode order by idate";
           
            dc.setSQL(minIdateSQL);
            dc.setMaxRows(1);
          List<Map<String, Object>> map =  dc.loadObjectResults();
          Date d = (Date) map.get(0).get("idate");
          if(d !=null)
            runDate.setTime(d);
        }
        catch(Exception e){
View Full Code Here

   * Deletes all ReportParamters for a Report Object.
   * @param report Report to delete all paramters for
   * @return void
   */
  public static void deleteReportsParameters(Report report){
    DotConnect dc = new DotConnect();
    dc.setSQL(DELETEALLRPSQL);
    dc.addParam(report.getInode());
    dc.getResult();   
  }
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.