package org.fastnate.generator.dialect;

import java.util.Date;

import javax.persistence.GenerationType;
import javax.persistence.TemporalType;

/**
 * Handles Oracle specific conversions.
 *
 * @see <a href="http://www.oracle.com/technetwork/indexes/documentation/index.html">Oracle - Documentation</a>
 * @author Tobias Liefke
 */
public final class OracleDialect extends GeneratorDialect {

	@Override
	public String buildCurrentSequenceValue(final String sequence) {
		return sequence + ".currval";
	}

	@Override
	public String buildNextSequenceValue(final String sequence) {
		return sequence + ".nextval";
	}

	@Override
	public String convertTemporalValue(final Date value, final TemporalType type) {
		if (NOW.equals(value)) {
			return "CURRENT_TIMESTAMP";
		}
		switch (type) {
		case DATE:
			return "to_date(" + super.convertTemporalValue(value, type) + ", 'YYYY-MM-DD')";
		case TIME:
			return "to_date(" + super.convertTemporalValue(value, type) + ", 'HH24:MI:SS')";
		case TIMESTAMP:
		default:
			return "to_timestamp(" + super.convertTemporalValue(value, type) + ", 'YYYY-MM-DD HH24:MI:SS.FF9')";
		}
	}

	@Override
	public String createBlobExpression(final byte[] blob) {
		return createHexBlobExpression("hextoraw('", blob, "')");
	}

	@Override
	public GenerationType getAutoGenerationType() {
		return GenerationType.SEQUENCE;
	}

	@Override
	public boolean isEmptyStringEqualToNull() {
		return true;
	}

	@Override
	public boolean isSequenceInWhereSupported() {
		return false;
	}
}
@@ -388,16 +388,70 @@
 lect %7B%0A%0A
+%09private static final int MAX_VARCHAR_LENGTH = 2000;%0A%0A
 %09@Overri
@@ -1553,10 +1553,596 @@
 alse;%0A%09%7D
+%0A%0A%09@Override%0A%09public String quoteString(final String value) %7B%0A%09%09if (value.length() %3E MAX_VARCHAR_LENGTH) %7B%0A%09%09%09// If our string is to long, we use %22TO_CLOB%22 to ensure that the content fits%0A%09%09%09final StringBuilder result = new StringBuilder();%0A%09%09%09for (int i = 0; i %3C value.length(); i += MAX_VARCHAR_LENGTH) %7B%0A%09%09%09%09if (i %3E 0) %7B%0A%09%09%09%09%09result.append(%22 %7C%7C %22);%0A%09%09%09%09%7D%0A%09%09%09%09result.append(%22TO_CLOB(%22)%0A%09%09%09%09%09%09.append(super.quoteString(value.substring(i, Math.min(value.length(), i + MAX_VARCHAR_LENGTH))))%0A%09%09%09%09%09%09.append(')');%0A%09%09%09%7D%0A%09%09%09return result.toString();%0A%09%09%7D%0A%09%09return super.quoteString(value);%0A%09%7D
 %0A%7D

Support large strings in Oracle