<commit_before>package org.asup.db.syntax.db2;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.asup.db.core.*;
import org.asup.db.syntax.*;
import org.asup.db.syntax.impl.SyntaxBuilderImpl;

public class DB2SyntaxBuilderImpl extends SyntaxBuilderImpl {
	
	@Inject
	private QQueryParserRegistry queryParserRegistry;

	private final Quoter quoter = new Quoter("\"");

	private QQueryConverter queryConverter;
	
	@PostConstruct
	private void init() {
		this.queryConverter = new DB2QueryConverterImpl();
	}
	
	@Override
	public String createSchema(QSchema schema) {
		return "CREATE SCHEMA "+ quoter.quote(schema.getName());
	}
	
	@Override
	public String dropSchema(QSchema schema) {
		return "DROP SCHEMA " + quoter.quote(schema.getName()) + " RESTRICT";		
	}


	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String createTable(QTable table) {
		return db2CreateTable(new QuotedTable(table, quoter));
	}

	private String db2CreateTable(QTable table) {
		StringBuffer result = new StringBuffer("CREATE TABLE ");
		result.append(table.getFullName()+" (");

		boolean pkey = false;
		String pkey_name = null;
		
		boolean first = true;
		for(QTableColumn field: table.getColumns()) {

			if(!first)
				result.append(", ");
			
			switch (field.getDataType()) {
				case IDENTITY:
					result.append(field.getName()+" INTEGER NOT NULL  GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1)");					
					pkey = true;
					pkey_name = field.getName();
					break;
				case CHARACTER:
					if (field.getPrecision() <= 254) {
						result.append(field.getName()+" CHAR("+field.getPrecision()+")");
					} else {
						result.append(field.getName()+" VARCHAR("+field.getPrecision()+")");
					}
					break;
				case VARCHAR:
					result.append(field.getName()+" VARCHAR("+field.getPrecision()+")");
					break;
				case DECIMAL:
					if (field.getPrecision() > 31) {
						result.append(field.getName()+" DECFLOAT("+field.getPrecision()+")");
					} 
					else if(field.getScale() != 0)
						result.append(field.getName()+" DECIMAL("+field.getPrecision()+", "+field.getScale()+")");
					else
						result.append(field.getName()+" DECIMAL("+field.getPrecision()+",  0)");
					break;
				case TEXT:
					result.append(field.getName()+" BLOB");
					break;
				default:
					result.append(field.getName()+" "+field.getDataType().getName() .toUpperCase());
			}			
			first = false;
		}
		if(pkey)
			result.append(", PRIMARY KEY ("+pkey_name+")");
		result.append(")");
		return result.toString();
	}
	@Override
	public String dropTable(QTable table) {
		return "DROP TABLE " + quoter.quoteFullName(table.getSchema(),  table.getName()) ;		
	}

	@Override
	public String createIndex(QIndex index) {
		return db2CreateIndex(new QuotedIndex(index, quoter));
	}
<commit_msg>Database DB2 plugin #44<commit_after>package org.asup.db.syntax.db2;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.asup.db.core.*;
import org.asup.db.syntax.*;
import org.asup.db.syntax.impl.SyntaxBuilderImpl;

public class DB2SyntaxBuilderImpl extends SyntaxBuilderImpl {
	
	@Inject
	private QQueryParserRegistry queryParserRegistry;

	private final Quoter quoter = new Quoter("\"");

	private QQueryConverter queryConverter;
	
	@PostConstruct
	private void init() {
		this.queryConverter = new DB2QueryConverterImpl();
	}
	
	@Override
	public String createSchema(QSchema schema) {
		return "CREATE SCHEMA "+ quoter.quote(schema.getName());
	}
	
	@Override
	public String dropSchema(QSchema schema) {
		return "DROP SCHEMA " + quoter.quote(schema.getName()) + " RESTRICT";		
	}


	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String createTable(QTable table) {
		return db2CreateTable(new QuotedTable(table, quoter));
	}

	private String db2CreateTable(QTable table) {
		StringBuffer result = new StringBuffer("CREATE TABLE ");
		result.append(table.getFullName()+" (");

		boolean pkey = false;
		String pkey_name = null;
		
		boolean first = true;
		for(QTableColumn field: table.getColumns()) {

			if(!first)
				result.append(", ");
			
			switch (field.getDataType()) {
				case IDENTITY:
					result.append(field.getName()+" INTEGER NOT NULL  GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1)");					
					pkey = true;
					pkey_name = field.getName();
					break;
				case CHARACTER:
					if (field.getPrecision() <= 254) {
						result.append(field.getName()+" CHAR("+field.getPrecision()+")");
					} else {
						result.append(field.getName()+" VARCHAR("+field.getPrecision()+")");
					}
					break;
				case VARCHAR:
					result.append(field.getName()+" VARCHAR("+field.getPrecision()+")");
					break;
				case DECIMAL:
					if (field.getPrecision() > 31) {
						result.append(field.getName()+" DECFLOAT(34)");
					} 
					else if(field.getScale() != 0)
						result.append(field.getName()+" DECIMAL("+field.getPrecision()+", "+field.getScale()+")");
					else
						result.append(field.getName()+" DECIMAL("+field.getPrecision()+",  0)");
					break;
				case TEXT:
					result.append(field.getName()+" BLOB");
					break;
				default:
					result.append(field.getName()+" "+field.getDataType().getName() .toUpperCase());
			}			
			first = false;
		}
		if(pkey)
			result.append(", PRIMARY KEY ("+pkey_name+")");
		result.append(")");
		return result.toString();
	}
	@Override
	public String dropTable(QTable table) {
		return "DROP TABLE " + quoter.quoteFullName(table.getSchema(),  table.getName()) ;		
	}

	@Override
	public String createIndex(QIndex index) {
		return db2CreateIndex(new QuotedIndex(index, quoter));
	}

{'fraction_non_alphanumeric': 0.15514809590973203, 'fraction_numerical': 0.006170662905500705, 'mean_word_length': 3.7393483709273183, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3230655', 'n_tokens_mistral': 2235, 'n_tokens_neox': 1828, 'n_words': 377}