<commit_before>/*
* File   : $Source: /alkacon/cvs/opencms/src/com/opencms/defaults/master/genericsql/Attic/CmsDbAccess.java,v $
* Date   : $Date: 2003/06/13 10:04:20 $
* Version: $Revision: 1.41 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.defaults.master.genericsql;

import com.opencms.boot.CmsBase;
import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import org.opencms.db.CmsIdGenerator;
import com.opencms.defaults.master.CmsMasterContent;
import com.opencms.defaults.master.CmsMasterDataSet;
import com.opencms.defaults.master.CmsMasterMedia;
import com.opencms.file.CmsGroup;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsResource;
import com.opencms.file.CmsUser;
import com.opencms.flex.util.CmsUUID;

import java.io.ByteArrayInputStream;
import java.lang.reflect.Constructor;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Vector;

/**
 * This class provides methods to access the database in a generic way.
 */
public class CmsDbAccess {

    /** Prefix for the content object store */
    public static final String C_COS_PREFIX = "/" + I_CmsConstants.C_ROOTNAME_COS;

    /** The root channel of the module */
    protected String m_rootChannel = "/";
    
    /** TODO: delete this after successful change of dbpool */
    private String m_poolUrl;
    
    /** 'Constants' file. */
   protected com.opencms.defaults.master.genericsql.CmsSqlManager m_sqlManager;

    /**
     * Public empty constructor, call "init(String)" on this class afterwards.
     * This allows more flexible custom module development.<p>
     */
    public CmsDbAccess() {
    }

    /**
     * Constructs a new DbAccessObject and calls init(String) with the given String.<p>
     * @param dbPool the pool to access resources.
     */
    public CmsDbAccess(String dbPool) {
        init(dbPool);
    }
    
    /**
     * Initializes the SqlManager with the used pool.<p>
     */
    public void init(String dbPool) {      
        m_sqlManager = initQueries(dbPool, getClass());
        m_poolUrl = dbPool;
    }
    
    /**
     * Retrieve the correct instance of the queries holder.
     * This method should be overloaded if other query strings should be used.<p>
     */
    public com.opencms.defaults.master.genericsql.CmsSqlManager initQueries(String dbPoolUrl, Class currentClass) {           
        return new com.opencms.defaults.master.genericsql.CmsSqlManager(dbPoolUrl, currentClass);
    }

    /**
     * Set the root channel of the content.<p>
     * 
     * @param newRootChannel the new value for the rootChannel.
     */
    public void setRootChannel(String newRootChannel) {
        m_rootChannel = newRootChannel;
    }

    /**
     * Get the root channel of the content.<p>
     * 
     * @return String the root channel.
     */
    public String getRootChannel() {
        return m_rootChannel;
    }

    /**
     * Inserts a new single row in the database with the dataset.<p>
     * 
     * @param cms the CmsObject to get access to cms resources.
     * @param content the CmsMasterContent to write to the database.
     * @param dataset the set of data for this contentdefinition.
     */
    public void insert(CmsObject cms, CmsMasterContent content,
                       CmsMasterDataSet dataset)
        throws CmsException {
        if(isOnlineProject(cms)) {
            // this is the onlineproject - don't write into this project directly
            throw new CmsException("Can't write to the online project", CmsException.C_NO_ACCESS);
        }
        //int newMasterId = CmsIdGenerator.nextId(m_poolName, "CMS_MODULE_MASTER");
        CmsUUID newMasterId = new CmsUUID();
        int projectId = cms.getRequestContext().currentProject().getId();
        CmsUUID currentUserId = cms.getRequestContext().currentUser().getId();
        long currentTime = new java.util.Date().getTime();
        // filling some default-values for new dataset's
        dataset.m_masterId = newMasterId;
        dataset.m_userId = currentUserId;
        dataset.m_groupId = cms.getRequestContext().currentGroup().getId();<commit_msg>Corrected Javadoc comments.<commit_after>/*
* File   : $Source: /alkacon/cvs/opencms/src/com/opencms/defaults/master/genericsql/Attic/CmsDbAccess.java,v $
* Date   : $Date: 2003/06/16 13:35:44 $
* Version: $Revision: 1.42 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.defaults.master.genericsql;

import com.opencms.boot.CmsBase;
import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import org.opencms.db.CmsIdGenerator;
import com.opencms.defaults.master.CmsMasterContent;
import com.opencms.defaults.master.CmsMasterDataSet;
import com.opencms.defaults.master.CmsMasterMedia;
import com.opencms.file.CmsGroup;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsResource;
import com.opencms.file.CmsUser;
import com.opencms.flex.util.CmsUUID;

import java.io.ByteArrayInputStream;
import java.lang.reflect.Constructor;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Vector;

/**
 * This class provides methods to access the database in a generic way.
 */
public class CmsDbAccess {

    /** Prefix for the content object store */
    public static final String C_COS_PREFIX = "/" + I_CmsConstants.C_ROOTNAME_COS;

    /** The root channel of the module */
    protected String m_rootChannel = "/";
    
    /** TODO: delete this after successful change of dbpool */
    private String m_poolUrl;
    
    /** 'Constants' file. */
   protected com.opencms.defaults.master.genericsql.CmsSqlManager m_sqlManager;

    /**
     * Public empty constructor, call "init(String)" on this class afterwards.
     * This allows more flexible custom module development.<p>
     */
    public CmsDbAccess() {
    }

    /**
     * Constructs a new DbAccessObject and calls init(String) with the given String.<p>
     * @param dbPool the pool to access resources.
     */
    public CmsDbAccess(String dbPool) {
        init(dbPool);
    }
    
    /**
     * Initializes the SqlManager with the used pool.<p>
     */
    public void init(String dbPool) {      
        m_sqlManager = initQueries(dbPool, getClass());
        m_poolUrl = dbPool;
    }
    
    /**
     * Retrieve the correct instance of the queries holder.
     * This method should be overloaded if other query strings should be used.<p>
     */
    public com.opencms.defaults.master.genericsql.CmsSqlManager initQueries(String dbPoolUrl, Class currentClass) {           
        return new com.opencms.defaults.master.genericsql.CmsSqlManager(dbPoolUrl, currentClass);
    }

    /**
     * Set the root channel of the content.<p>
     * 
     * @param newRootChannel the new value for the rootChannel.
     */
    public void setRootChannel(String newRootChannel) {
        m_rootChannel = newRootChannel;
    }

    /**
     * Get the root channel of the content.<p>
     * 
     * @return String the root channel.
     */
    public String getRootChannel() {
        return m_rootChannel;
    }

    /**
     * Inserts a new single row in the database with the dataset.<p>
     * 
     * @param cms the CmsObject to get access to cms resources.
     * @param content the CmsMasterContent to write to the database.
     * @param dataset the set of data for this contentdefinition.
     * @throws CmsException if somethong goes wrong
     */
    public void insert(CmsObject cms, CmsMasterContent content,
                       CmsMasterDataSet dataset)
        throws CmsException {
        if(isOnlineProject(cms)) {
            // this is the onlineproject - don't write into this project directly
            throw new CmsException("Can't write to the online project", CmsException.C_NO_ACCESS);
        }
        //int newMasterId = CmsIdGenerator.nextId(m_poolName, "CMS_MODULE_MASTER");
        CmsUUID newMasterId = new CmsUUID();
        int projectId = cms.getRequestContext().currentProject().getId();
        CmsUUID currentUserId = cms.getRequestContext().currentUser().getId();
        long currentTime = new java.util.Date().getTime();
        // filling some default-values for new dataset's
        dataset.m_masterId = newMasterId;
        dataset.m_userId = currentUserId;
        dataset.m_groupId = cms.getRequestContext().currentGroup().getId();
{'fraction_non_alphanumeric': 0.09031089071142476, 'fraction_numerical': 0.007057028418844173, 'mean_word_length': 3.1582077716098333, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2401840', 'n_tokens_mistral': 3116, 'n_tokens_neox': 3055, 'n_words': 961}