<commit_before><project name="db.creation">
	<!-- necessary for this project being imported by another build file, basedir will be 
	     'overridden' with the importing file's basedir... that's a very disputed break of encap -->
	<dirname property="db.creation.basedir" file="${ant.file.db.creation}" />
	
	<property name="sql.driver" value="com.mysql.jdbc.Driver"/>
    <property name="sql.connector.classpath" value="../../com.mysql.jdbc"/>
	
	
	<!-- 
        Import the environment as properties prefixed with 'env'. 
        Then set env.HOSTNAME to be the value of env.COMPUTERNAME (in case of windows OS) 
        unless env.HOSTNAME (in case of linux OS) is already set in which case the 2nd line will 
        have no effect (ant props are immutable). After that use env.HOSTNAME where the hostname 
        is required.
    -->
	<target name="prepare.env">
        <property environment="env"/>
		
		<!-- 
		     sets host.name to the first env variable for the HOST/HOSTNAME/COMPUTERNAME that can be 
		     found, once set the property host.name is immutable, remaining conditions don't have 
		     any effect.
		 -->
		<condition property="host.name.org" value="${env.HOST}">
		    <isset property="env.HOST"/> <!-- Solaris -->
		</condition>

		<condition property="host.name.org" value="${env.HOSTNAME}">
		    <isset property="env.HOSTNAME"/> <!-- Linux -->
		</condition>

		<condition property="host.name.org" value="${env.COMPUTERNAME}">
		    <isset property="env.COMPUTERNAME"/> <!-- Windows -->
		</condition>

        <echo message="Original computer or host name = ${host.name.org}"/>
		
		<script language="javascript" >
			<![CDATA[
			      orgProp = project.getProperty("host.name.org");
			      project.setProperty("host.name", orgProp.toLowerCase());
		     ]]>
		</script>
		
        <echo message="...to lowercase = ${host.name}"/>
		
		<!-- 
		    Process host.properties file 
		    Filter for props for being prefixed with host.name (case-insensitive)
		    Remove all prefixes, load the props
		 -->
        <loadproperties srcfile="../../../../../config/DESY/host.properties">
            <filterchain>
            	<tokenfilter>
            	    <containsregex pattern="^${host.name}\.(.+)$" flags="i"
            	                   replace="\1"/>
            	</tokenfilter>
            </filterchain>
        </loadproperties>
		<!-- 
		    Process host.properties file again
		    Filter for props for being prefixed with "root." (case-insensitive)
		    Remove all prefixes, load the props (those being loaded before cannot be overridden - props are immutable)
		 -->
        <loadproperties srcfile="../../../../../config/DESY/host.properties">
            <filterchain>
            	<tokenfilter>
            	    <containsregex pattern="^root\.(.+)$" flags="i"
            	                   replace="\1"/>
            	</tokenfilter>
            </filterchain>
        </loadproperties>
		<echo message="Properties with prefix '${host.name}.' and 'root.' loaded!"/>
	    
	    <property name="sql.host" value="${mysqlHost}"/>
	    <property name="sql.url" value="jdbc:mysql://${sql.host}:${mysqlPort}"/>
	    <property name="sql.root.user" value="${mysqlRootUser}"/>
	    <property name="sql.root.pw" value="${mysqlRootPassword}"/>
		
	    <property name="sql.archive.db" value="${mysqlArchiveDatabase}"/>
	    <property name="sql.archive.user" value="${mysqlArchiveUser}"/>
	    <property name="sql.archive.pw" value="${mysqlArchivePassword}"/>

		<echo message="sql.url : ${sql.url}"/>
		<echo message="sql.root.user : ${sql.root.user}"/>
		<echo message="sql.root.pw : ${sql.root.pw}"/>

		<echo message="sql.archive.db : ${sql.archive.db}"/>
		<echo message="sql.archive.user : ${sql.archive.user}"/>
		<echo message="sql.archive.pw : ${sql.archive.pw}"/>
		
	</target>
	


    <target name="create.and.fill.database" 
    	    depends="create.database, create.tables, create.triggers">
    </target>
	
   <target name="create.database" depends="drop.database">
      <sql driver="${sql.driver}" 
           url="${sql.url}" 
           userid="${sql.archive.user}" 
           password="${<PASSWORD>}">
      	<classpath>
      	    <pathelement path="${sql.connector.classpath}"/>
      	</classpath>
      	
      	<transaction>
      	    CREATE DATABASE ${sql.archive.db};
      	    USE ${sql.archive.db};
      	</transaction>
      </sql>
   </target>
   
    <target name="create.tables" depends="prepare.env">
        <sql driver="${sql.driver}" 
             url="${sql.url}/${sql.archive.db}" 
             userid="${sql.archive.user}" 
             password="${<PASSWORD>}">
            <classpath>
                <pathelement path="${sql.connector.classpath}"/>
            </classpath>     	
        
         	<!-- Take care, order matters due to foreign key constraints -->
            <transaction src="tables/engine.sql"/>
            <transaction src="tables/engine_status.sql"/>
            <transaction src="tables/channel_group.sql"/>
            <transaction src="tables/control_system.sql"/>
            <transaction src="tables/channel.sql"/>
            <transaction src="tables/channel_status.sql"/>
            <transaction src="tables/sample.sql"/>
            <transaction src="tables/sample_m.sql"/>
            <transaction src="tables/sample_h.sql"/>
        </sql>
    </target>

    <target name="create.triggers" depends="prepare.env">
        <sql driver="${sql.driver}" 
             url="${sql.url}/${sql.archive.db}" 
             userid="${sql.archive.user}" 
             password="${<PASSWORD>}"
      	     delimiter="//">
            <classpath>
                <pathelement path="${sql.connector.classpath}"/>
            </classpath>
      	
            <transaction src="tables/triggers.sql"/>
       </sql>
    </target>
	
    <target name="drop.database" depends="prepare.env">
	    <input message="Do you really want to delete database '${sql.archive.db}'?" 
               validargs="y,n" 
	           addproperty="do.delete"
               defaultvalue="y" />
        <condition property="do.abort"> 
            <equals arg1="n" arg2="${do.delete}"/> 
        </condition> 
        <fail if="do.abort">Build aborted by user.</fail> 
        
        <sql driver="${sql.driver}" 
             url="${sql.url}" 
             userid="${sql.archive.user}" 
        	 password="${<PASSWORD>}">
             <classpath>
                 <pathelement path="${sql.connector.classpath}"/>
             </classpath>
            
             <transaction>
                 DROP DATABASE IF EXISTS ${sql.archive.db};
             </transaction>
         </sql>
    </target>
	
	<target name="clear.tables" depends="prepare.env">
        <sql driver="${sql.driver}" 
             url="${sql.url}/${sql.archive.db}" 
             userid="${sql.archive.user}" 
        	 password="${<PASSWORD>}">
             <classpath>
                 <pathelement path="${sql.connector.classpath}"/>
             </classpath>
            
             <!-- 
                 Order matters - it's vice versa as the table creation due to foreign key constraints
                 And deletion instead of truncation is used on tables where foreign keys point to.  
              -->
             <transaction>
             	TRUNCATE TABLE sample_h;
             	TRUNCATE TABLE sample_m;
             	TRUNCATE TABLE sample;
             	TRUNCATE TABLE channel;
             	TRUNCATE TABLE channel_status; 
             	DELETE FROM control_system;
             	DELETE FROM channel_group;
             	TRUNCATE TABLE engine_status;
             	DELETE FROM engine;
             </transaction>
         </sql>
	</target>
	
	<target name="run.on.mysqlhost.after.installation" 
		    description="Run this target on your mysql host: connect as root, set root password, \
		according to host.properties, create archive user, create archive db, \
		grant privileges"
		    depends="prepare.env">
		
        <sql driver="${sql.driver}" 
             url="jdbc:mysql://localhost:${mysqlPort}" 
             userid="${sql.root.user}"
        	 password="${<PASSWORD>}">
             <classpath>
                 <pathelement path="${sql.connector.classpath}"/>
             </classpath>
            
             <!-- 
                 Order matters - it's vice versa as the table creation due to foreign key constraints
                 And deletion instead of truncation is used on tables where foreign keys point to.
                 
                 ATTENTION: something like CREATE/DROP USER IF [NOT] EXISTS is not provided by mysql
                            but creation of a user that already exist causes an error,
                            dropping of a user if he doesn't exist causes an error as well, great. 
                            (a known bug/feature request for more than 6 years now) so
                            to make the script re-runnable, for creating there's a workaround with 
                            using the grant command. It creates a user if it doesn't exist and 
                            doesn't throw an error if it does.
                            If you want to drop a user, then you have to first grant the user a
                            harmless privilege (then the user exists for sure), then it can be 
                            safely dropped.
                              
                 The first statement about log_bin_trust_function_creators enables the 
                 trigger mechanism in a replication setup, which is too complicated to be explained <commit_msg>o.c.archive.common.service.mysqlimpl: made host name retrieval ready for solaris, linux, windows<commit_after><project name="db.creation">
	<!-- necessary for this project being imported by another build file, basedir will be 
	     'overridden' with the importing file's basedir... that's a very disputed break of encap -->
	<dirname property="db.creation.basedir" file="${ant.file.db.creation}" />
	
	<property name="sql.driver" value="com.mysql.jdbc.Driver"/>
    <property name="sql.connector.classpath" value="../../com.mysql.jdbc"/>
	
	
	<!-- 
        Import the environment as properties prefixed with 'env'. 
        Then set env.HOSTNAME to be the value of env.COMPUTERNAME (in case of windows OS) 
        unless env.HOSTNAME (in case of linux OS) is already set in which case the 2nd line will 
        have no effect (ant props are immutable). After that use env.HOSTNAME where the hostname 
        is required.
    -->
	<target name="prepare.env">
        
		<exec executable="hostname" outputproperty="host.name.org"/>
        <echo message="Original computer or host name = ${host.name.org}"/>
		
		<script language="javascript" >
			<![CDATA[
			      orgProp = project.getProperty("host.name.org");
			      project.setProperty("host.name", orgProp.toLowerCase());
		     ]]>
		</script>
		
        <echo message="...to lowercase = ${host.name}"/>
		
		<!-- 
		    Process host.properties file 
		    Filter for props for being prefixed with host.name (case-insensitive)
		    Remove all prefixes, load the props
		 -->
        <loadproperties srcfile="../../../../../config/DESY/host.properties">
            <filterchain>
            	<tokenfilter>
            	    <containsregex pattern="^${host.name}\.(.+)$" flags="i"
            	                   replace="\1"/>
            	</tokenfilter>
            </filterchain>
        </loadproperties>
		<!-- 
		    Process host.properties file again
		    Filter for props for being prefixed with "root." (case-insensitive)
		    Remove all prefixes, load the props (those being loaded before cannot be overridden - props are immutable)
		 -->
        <loadproperties srcfile="../../../../../config/DESY/host.properties">
            <filterchain>
            	<tokenfilter>
            	    <containsregex pattern="^root\.(.+)$" flags="i"
            	                   replace="\1"/>
            	</tokenfilter>
            </filterchain>
        </loadproperties>
		<echo message="Properties with prefix '${host.name}.' and 'root.' loaded!"/>
	    
	    <property name="sql.host" value="${mysqlHost}"/>
	    <property name="sql.url" value="jdbc:mysql://${sql.host}:${mysqlPort}"/>
		<echo message="sql.url : ${sql.url}"/>
	    <property name="sql.root.user" value="${mysqlRootUser}"/>
		<echo message="sql.root.user : ${sql.root.user}"/>
	    <property name="sql.root.pw" value="${mysqlRootPassword}"/>
		<echo message="sql.root.pw : ${sql.root.pw}"/>
		
	    <property name="sql.archive.db" value="${mysqlArchiveDatabase}"/>
		<echo message="sql.archive.db : ${sql.archive.db}"/>
	    <property name="sql.archive.user" value="${mysqlArchiveUser}"/>
		<echo message="sql.archive.user : ${sql.archive.user}"/>
	    <property name="sql.archive.pw" value="${mysqlArchivePassword}"/>
		<echo message="sql.archive.pw : ${sql.archive.pw}"/>
	</target>
	


    <target name="create.db.and.schema" 
    	    depends="create.database, create.tables, create.triggers">
    </target>
	
   <target name="create.database" depends="drop.database, init.users">
      <sql driver="${sql.driver}" 
           url="${sql.url}" 
           userid="${sql.archive.user}" 
           password="${<PASSWORD>.archive.pw}">
      	<classpath>
      	    <pathelement path="${sql.connector.classpath}"/>
      	</classpath>
      	
      	<transaction>
      	    CREATE DATABASE ${sql.archive.db};
      	    USE ${sql.archive.db};
      	</transaction>
      </sql>
   </target>
   
    <target name="create.tables" depends="prepare.env">
        <sql driver="${sql.driver}" 
             url="${sql.url}/${sql.archive.db}" 
             userid="${sql.archive.user}" 
             password="${<PASSWORD>}">
            <classpath>
                <pathelement path="${sql.connector.classpath}"/>
            </classpath>     	
        
         	<!-- Take care, order matters due to foreign key constraints -->
            <transaction src="tables/engine.sql"/>
            <transaction src="tables/engine_status.sql"/>
            <transaction src="tables/channel_group.sql"/>
            <transaction src="tables/control_system.sql"/>
            <transaction src="tables/channel.sql"/>
            <transaction src="tables/channel_status.sql"/>
            <transaction src="tables/sample.sql"/>
            <transaction src="tables/sample_m.sql"/>
            <transaction src="tables/sample_h.sql"/>
        </sql>
    </target>

    <target name="create.triggers" depends="prepare.env">
        <sql driver="${sql.driver}" 
             url="${sql.url}/${sql.archive.db}" 
             userid="${sql.archive.user}" 
             password="${<PASSWORD>}"
      	     delimiter="//">
            <classpath>
                <pathelement path="${sql.connector.classpath}"/>
            </classpath>
      	
            <transaction src="tables/triggers.sql"/>
       </sql>
    </target>
	
    <target name="drop.database" depends="prepare.env">
	    <input message="Do you really want to delete database '${sql.archive.db}' if exists?" 
               validargs="y,n" 
	           addproperty="do.delete"
               defaultvalue="y" />
        <condition property="do.abort"> 
            <equals arg1="n" arg2="${do.delete}"/> 
        </condition> 
        <fail if="do.abort">Build aborted by user.</fail> 
        
        <sql driver="${sql.driver}" 
             url="${sql.url}" 
             userid="${sql.archive.user}" 
        	 password="${<PASSWORD>}">
             <classpath>
                 <pathelement path="${sql.connector.classpath}"/>
             </classpath>
            
             <transaction>
                 DROP DATABASE IF EXISTS ${sql.archive.db};
             </transaction>
         </sql>
    </target>
	
	<target name="clear.tables" depends="prepare.env">
        <sql driver="${sql.driver}" 
             url="${sql.url}/${sql.archive.db}" 
             userid="${sql.archive.user}" 
        	 password="${<PASSWORD>}">
             <classpath>
                 <pathelement path="${sql.connector.classpath}"/>
             </classpath>
            
             <!-- 
                 Order matters - it's vice versa as the table creation due to foreign key constraints
                 And deletion instead of truncation is used on tables where foreign keys point to.  
              -->
             <transaction>
             	TRUNCATE TABLE sample_h;
             	TRUNCATE TABLE sample_m;
             	TRUNCATE TABLE sample;
             	TRUNCATE TABLE channel;
             	TRUNCATE TABLE channel_status; 
             	DELETE FROM control_system;
             	DELETE FROM channel_group;
             	TRUNCATE TABLE engine_status;
             	DELETE FROM engine;
             </transaction>
         </sql>
	</target>
	
	<target name="init.users" 
		    description="Run this target on your mysql host: connect as root, set root password, \
		according to host.properties, create archive user, create archive db, \
		grant privileges"
		    depends="prepare.env">
		
        <sql driver="${sql.driver}" 
             url="${sql.url}" 
             userid="${sql.root.user}"
        	 password="${<PASSWORD>}">
             <classpath>
                 <pathelement path="${sql.connector.classpath}"/>
             </classpath>
            
             <!-- 
                 Order matters - it's vice versa as the table creation due to foreign key constraints
                 And deletion instead of truncation is used on tables where foreign keys point to.
                 
                 ATTENTION: something like CREATE/DROP USER IF [NOT] EXISTS is not provided by mysql
                            but creation of a user that already exist causes an error,
                            dropping of a user if he doesn't exist causes an error as well, great. 
                            (a known bug/feature request for more than 6 years now) so
                            to make the script re-runnable, for creating there's a workaround with 
                            using the grant command. It creates a user if it doesn't exist and 
                            doesn't throw an error if it does.
                            If you want to drop a user, then you have to first grant the user a
                            harmless privilege (then the user exists for sure), then it can be 
                            safely dropped.
                              
                 The first statement about log_bin_trust_function_creators enables the 
                 trigger mechanism in a replication setup, which is too complicated to be explained 
{'fraction_non_alphanumeric': 0.13373274847544667, 'fraction_numerical': 0.000641917192682144, 'mean_word_length': 1.897551146931184, 'pattern_counts': {'":': 0, '<': 250, '<?xml version=': 0, '>': 248, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '142894', 'n_tokens_mistral': 5185, 'n_tokens_neox': 4790, 'n_words': 1315}