package org.teiid.translator.jdbc.informix;

import org.teiid.core.util.StringUtil;
import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.translator.jdbc.JDBCMetadataProcessor;


public class InformixMetadataProcessor extends JDBCMetadataProcessor {
	
	private static final String INFORMIX_DB_DELIM_CHAR = ":";
	
	@Override
	protected  String getFullyQualifiedName(String catalogName, String schemaName, String objectName, boolean quoted) {
		//databaseName:schemaName.tableName
		String fullName = objectName;
		if (schemaName != null && schemaName.length() > 0) {
			fullName = (quoted?quoteSchemaName(schemaName):schemaName) + AbstractMetadataRecord.NAME_DELIM_CHAR + fullName;
		}
		if (useCatalogName && catalogName != null && catalogName.length() > 0) {
			fullName = catalogName + INFORMIX_DB_DELIM_CHAR + fullName;
		}
		return fullName;
	}

	protected String quoteSchemaName(String name) {
		String quoteString = "\"";
		return quoteString + StringUtil.replaceAll(name, quoteString, quoteString + quoteString) + quoteString;
	}
}
