<commit_before>/*
 * Copyright 2007-2009 Jiemamy Project and the Others. Created on 2008/07/14
 * 
 * This file is part of Jiemamy.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package org.jiemamy.dialect.postgresql;

import static org.jiemamy.model.datatype.DataTypeCategory.BIT;
import static org.jiemamy.model.datatype.DataTypeCategory.BLOB;
import static org.jiemamy.model.datatype.DataTypeCategory.BOOLEAN;
import static org.jiemamy.model.datatype.DataTypeCategory.CHARACTER;
import static org.jiemamy.model.datatype.DataTypeCategory.CLOB;
import static org.jiemamy.model.datatype.DataTypeCategory.DATE;
import static org.jiemamy.model.datatype.DataTypeCategory.DECIMAL;
import static org.jiemamy.model.datatype.DataTypeCategory.DOUBLE;
import static org.jiemamy.model.datatype.DataTypeCategory.FLOAT;
import static org.jiemamy.model.datatype.DataTypeCategory.INTEGER;
import static org.jiemamy.model.datatype.DataTypeCategory.INTERVAL;
import static org.jiemamy.model.datatype.DataTypeCategory.NUMERIC;
import static org.jiemamy.model.datatype.DataTypeCategory.OTHER;
import static org.jiemamy.model.datatype.DataTypeCategory.REAL;
import static org.jiemamy.model.datatype.DataTypeCategory.SMALLINT;
import static org.jiemamy.model.datatype.DataTypeCategory.TIME;
import static org.jiemamy.model.datatype.DataTypeCategory.TIMESTAMP;
import static org.jiemamy.model.datatype.DataTypeCategory.VARBIT;
import static org.jiemamy.model.datatype.DataTypeCategory.VARCHAR;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import org.jiemamy.dialect.AbstractDialect;
import org.jiemamy.dialect.TypeParameterSpec;
import org.jiemamy.dialect.TypeParameterSpec.Necessity;
import org.jiemamy.model.datatype.DefaultTypeReference;
import org.jiemamy.model.datatype.TypeParameterKey;
import org.jiemamy.model.datatype.TypeReference;
import org.jiemamy.validator.CompositeValidator;
import org.jiemamy.validator.Validator;

/**
 * PostgreSQLに対するSQL方言実装クラス。
 * 
 * @author daisuke
 */
public class PostgresqlDialect extends AbstractDialect {
	
	private static Map<TypeReference, TypeParameterSpec[]> types;
	
	static {
		Map<TypeReference, TypeParameterSpec[]> map = Maps.newLinkedHashMap();
		map.put(new DefaultTypeReference(INTEGER, "INTEGER", "int4"), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.SERIAL, Necessity.OPTIONAL),
		});
		map.put(new DefaultTypeReference(INTEGER, "BIGINT", "int8"), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.SERIAL, Necessity.OPTIONAL),
		});
		map.put(new DefaultTypeReference(SMALLINT), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(NUMERIC), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.PRECISION, Necessity.REQUIRED),
			new TypeParameterSpec(TypeParameterKey.SCALE, Necessity.REQUIRED)
		});
		map.put(new DefaultTypeReference(DECIMAL), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(FLOAT, "REAL"), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.PRECISION, Necessity.REQUIRED),
			new TypeParameterSpec(TypeParameterKey.SCALE, Necessity.REQUIRED)
		});
		map.put(new DefaultTypeReference(REAL), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(DOUBLE, "DOUBLE PRECISION"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(BIT), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.SIZE, Necessity.REQUIRED),
		});
		map.put(new DefaultTypeReference(CHARACTER), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.SIZE, Necessity.REQUIRED),
		});
		map.put(new DefaultTypeReference(VARCHAR), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.SIZE, Necessity.REQUIRED),
		});
		map.put(new DefaultTypeReference(CLOB, "TEXT"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(BLOB, "BYTEA"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(VARBIT), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.SIZE, Necessity.REQUIRED),
		});
		map.put(new DefaultTypeReference(BOOLEAN), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(DATE), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(TIME), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.WITH_TIMEZONE, Necessity.REQUIRED),
		});
		map.put(new DefaultTypeReference(TIMESTAMP), new TypeParameterSpec[] {
			new TypeParameterSpec(TypeParameterKey.WITH_TIMEZONE, Necessity.REQUIRED),
		});
		map.put(new DefaultTypeReference(INTERVAL), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "UUID"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "MACADDR"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "MONEY"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "INET"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "CIDR"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "XML"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "LINE"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "LSEG"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "CIRCLE"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "BOX"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "PATH"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "POINT"), new TypeParameterSpec[0]);
		map.put(new DefaultTypeReference(OTHER, "POLYGON"), new TypeParameterSpec[0]);
		PostgresqlDialect.types = ImmutableMap.copyOf(map);
	}
	

	/**
	 * インスタンスを生成する。
	 */
	public PostgresqlDialect() {
		super("jdbc:postgresql://localhost:5432/");
	}
	
	public List<TypeReference> getAllTypeReferences() {
		return Lists.newArrayList(types.keySet());
	}
	
	public String getName() {
		return "PostgreSQL 8.1";
	}
	
	public Collection<TypeParameterSpec> getTypeParameterSpecs(TypeReference reference) {
		return Lists.newArrayList(types.get(reference));
	}
	
	@Override
	public Validator getValidator() {
		CompositeValidator validator = (CompositeValidator) super.getValidator();
		validator.getValidators().add(new PostgresqlIdentifierValidator());
		return validator;
	}
}<commit_msg>[CORE-0] Dialectのインターフェイスと骨格実装整備。<commit_after>/*
 * Copyright 2007-2009 Jiemamy Project and the Others. Created on 2008/07/14
 * 
 * This file is part of Jiemamy.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package org.jiemamy.dialect.postgresql;

import static org.jiemamy.model.datatype.DataTypeCategory.BIT;
import static org.jiemamy.model.datatype.DataTypeCategory.BLOB;
import static org.jiemamy.model.datatype.DataTypeCategory.BOOLEAN;
import static org.jiemamy.model.datatype.DataTypeCategory.CHARACTER;
import static org.jiemamy.model.datatype.DataTypeCategory.CLOB;
import static org.jiemamy.model.datatype.DataTypeCategory.DATE;
import static org.jiemamy.model.datatype.DataTypeCategory.DECIMAL;
import static org.jiemamy.model.datatype.DataTypeCategory.DOUBLE;
import static org.jiemamy.model.datatype.DataTypeCategory.FLOAT;
import static org.jiemamy.model.datatype.DataTypeCategory.INTEGER;
import static org.jiemamy.model.datatype.DataTypeCategory.INTERVAL;
import static org.jiemamy.model.datatype.DataTypeCategory.NUMERIC;
import static org.jiemamy.model.datatype.DataTypeCategory.OTHER;
import static org.jiemamy.model.datatype.DataTypeCategory.REAL;
import static org.jiemamy.model.datatype.DataTypeCategory.SMALLINT;
import static org.jiemamy.model.datatype.DataTypeCategory.TIME;
import static org.jiemamy.model.datatype.DataTypeCategory.TIMESTAMP;
import static org.jiemamy.model.datatype.DataTypeCategory.VARBIT;
import static org.jiemamy.model.datatype.DataTypeCategory.VARCHAR;

import java.util.Arrays;
import java.util.List;

import com.google.common.collect.Lists;

import org.jiemamy.dialect.AbstractDialect;
import org.jiemamy.dialect.TypeParameterSpec;
import org.jiemamy.dialect.TypeParameterSpec.Necessity;
import org.jiemamy.model.datatype.DefaultTypeReference;
import org.jiemamy.model.datatype.TypeParameterKey;
import org.jiemamy.validator.CompositeValidator;
import org.jiemamy.validator.Validator;

/**
 * PostgreSQLに対するSQL方言実装クラス。
 * 
 * @author daisuke
 */
public class PostgresqlDialect extends AbstractDialect {
	
	private static List<Entry> typeEntries = Lists.newArrayList();
	
	static {
		// FORMAT-OFF
		typeEntries.add(new Entry(new DefaultTypeReference(INTEGER, "INTEGER", "int4"), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.SERIAL, Necessity.OPTIONAL)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(INTEGER, "BIGINT", "int8"), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.SERIAL, Necessity.OPTIONAL)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(SMALLINT)));
		typeEntries.add(new Entry(new DefaultTypeReference(NUMERIC), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.PRECISION, Necessity.REQUIRED),
			new TypeParameterSpec(TypeParameterKey.SCALE, Necessity.REQUIRED)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(DECIMAL)));
		typeEntries.add(new Entry(new DefaultTypeReference(FLOAT, "REAL"), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.PRECISION, Necessity.REQUIRED),
			new TypeParameterSpec(TypeParameterKey.SCALE, Necessity.REQUIRED)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(REAL)));
		typeEntries.add(new Entry(new DefaultTypeReference(DOUBLE, "DOUBLE PRECISION")));
		typeEntries.add(new Entry(new DefaultTypeReference(BIT), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.SIZE, Necessity.REQUIRED)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(CHARACTER), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.SIZE, Necessity.REQUIRED)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(VARCHAR), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.SIZE, Necessity.REQUIRED)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(CLOB, "TEXT")));
		typeEntries.add(new Entry(new DefaultTypeReference(BLOB, "BYTEA")));
		typeEntries.add(new Entry(new DefaultTypeReference(VARBIT), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.SIZE, Necessity.REQUIRED)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(BOOLEAN)));
		typeEntries.add(new Entry(new DefaultTypeReference(DATE)));
		typeEntries.add(new Entry(new DefaultTypeReference(TIME), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.WITH_TIMEZONE, Necessity.REQUIRED)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(TIMESTAMP), Arrays.asList(
			new TypeParameterSpec(TypeParameterKey.WITH_TIMEZONE, Necessity.REQUIRED)
		)));
		typeEntries.add(new Entry(new DefaultTypeReference(INTERVAL)));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "UUID")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "MACADDR")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "MONEY")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "INET")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "CIDR")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "XML")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "LINE")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "LSEG")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "CIRCLE")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "BOX")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "PATH")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "POINT")));
		typeEntries.add(new Entry(new DefaultTypeReference(OTHER, "POLYGON")));
		// FORMAT-ON
	}
	

	/**
	 * インスタンスを生成する。
	 */
	public PostgresqlDialect() {
		super("jdbc:postgresql://localhost:5432/", typeEntries);
	}
	
	public String getName() {
		return "PostgreSQL 8.1";
	}
	
	@Override
	public Validator getValidator() {
		CompositeValidator validator = (CompositeValidator) super.getValidator();
		validator.getValidators().add(new PostgresqlIdentifierValidator());
		return validator;
	}
}
{'fraction_non_alphanumeric': 0.11262721447418017, 'fraction_numerical': 0.005955522050508858, 'mean_word_length': 6.546075085324232, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '5044771', 'n_tokens_mistral': 4333, 'n_tokens_neox': 4131, 'n_words': 799}