	public Domain generateDomain(DatabaseMeta databaseMeta, List<LogicalRelationship> joinTemplates) {
		Domain domain = null;
		try {
			String locale = LocalizedString.DEFAULT_LOCALE;
			this.generator.setLocale(locale);
			this.generator.setDatabaseMeta(databaseMeta);
			this.generator.setModelName(datasourceName);
			List<SchemaTable> schemas = new ArrayList<SchemaTable>();
			for (LogicalRelationship joinTemplate : joinTemplates) {
				schemas.add(new SchemaTable("", joinTemplate.getFromTable().getName(locale)));
				schemas.add(new SchemaTable("", joinTemplate.getToTable().getName(locale)));
			}
			SchemaTable tableNames[] = new SchemaTable[schemas.size()];
			tableNames = schemas.toArray(tableNames);
			this.generator.setTableNames(tableNames);
			domain = this.generator.generateDomain();
			domain.setId(datasourceName);
			ModelerWorkspaceHelper helper = new ModelerWorkspaceHelper(locale);
			ModelerWorkspace workspace = new ModelerWorkspace(helper);
			workspace.setModelName(datasourceName);
			workspace.setDomain(domain);
			LogicalModel logicalModel = domain.getLogicalModels().get(0);
			logicalModel.setName(new LocalizedString(locale, datasourceName));
			logicalModel.setDescription(new LocalizedString(locale, "This is the data model for "
		        + datasourceName));
		    LogicalTable businessTable = logicalModel.getLogicalTables().get(0);
		    businessTable.setName(new LocalizedString(locale, datasourceName));
			for (LogicalRelationship joinTemplate : joinTemplates) {
				String lTable = joinTemplate.getFromTable().getName(locale);
				String rTable = joinTemplate.getToTable().getName(locale);
				LogicalTable fromTable = null;
				LogicalColumn fromColumn = null;
				LogicalTable toTable = null;
				LogicalColumn toColumn = null;
				for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
					if (logicalTable.getName(locale).equals(lTable)) {
						fromTable = logicalTable;
						for (LogicalColumn logicalColumn : fromTable.getLogicalColumns()) {
							if (logicalColumn.getName(locale).equals(joinTemplate.getFromColumn().getName(locale))) {
								fromColumn = logicalColumn;
							}
						}
					}
					if (logicalTable.getName(locale).equals(rTable)) {
						toTable = logicalTable;
						for (LogicalColumn logicalColumn : toTable.getLogicalColumns()) {
							if (logicalColumn.getName(locale).equals(joinTemplate.getToColumn().getName(locale))) {
								toColumn = logicalColumn;
							}
						}
					}
				}
				LogicalRelationship logicalRelationship = new LogicalRelationship();
				logicalRelationship.setRelationshipType(RelationshipType._1_1);
				logicalRelationship.setFromTable(fromTable);
				logicalRelationship.setFromColumn(fromColumn);
				logicalRelationship.setToTable(toTable);
				logicalRelationship.setToColumn(toColumn);
				logicalModel.addLogicalRelationship(logicalRelationship);
			}
			helper.autoModelMultiTableRelational(workspace);
			helper.populateDomain(workspace);			
		} catch (PentahoMetadataException e) {
			e.printStackTrace();
			logger.info(e.getLocalizedMessage());
		} catch (ModelerException e) {
			e.printStackTrace();
			logger.info(e.getLocalizedMessage());
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e.getLocalizedMessage());
		}
		return domain;
	}

	public Domain generateDomain(DatabaseMeta databaseMeta, List<LogicalRelationship> joinTemplates) {
		Domain domain = null;
		try {
			String locale = LocalizedString.DEFAULT_LOCALE;
			this.generator.setLocale(locale);
			this.generator.setDatabaseMeta(databaseMeta);
			this.generator.setModelName(datasourceName);
			List<SchemaTable> schemas = new ArrayList<SchemaTable>();
			for (LogicalRelationship joinTemplate : joinTemplates) {
				schemas.add(new SchemaTable("", joinTemplate.getFromTable().getName(locale)));
				schemas.add(new SchemaTable("", joinTemplate.getToTable().getName(locale)));
			}
			SchemaTable tableNames[] = new SchemaTable[schemas.size()];
			tableNames = schemas.toArray(tableNames);
			this.generator.setTableNames(tableNames);
			domain = this.generator.generateDomain();
			domain.setId(datasourceName);
			ModelerWorkspaceHelper helper = new ModelerWorkspaceHelper(locale);
			ModelerWorkspace workspace = new ModelerWorkspace(helper);
			workspace.setModelName(datasourceName);
			workspace.setDomain(domain);
			LogicalModel logicalModel = domain.getLogicalModels().get(0);
			logicalModel.setName(new LocalizedString(locale, datasourceName));
			logicalModel.setDescription(new LocalizedString(locale, "This is the data model for "
		        + datasourceName));
		    LogicalTable businessTable = logicalModel.getLogicalTables().get(0);
		    businessTable.setName(new LocalizedString(locale, datasourceName));
			for (LogicalRelationship joinTemplate : joinTemplates) {
				String lTable = joinTemplate.getFromTable().getName(locale);
				String rTable = joinTemplate.getToTable().getName(locale);
				LogicalTable fromTable = null;
				LogicalColumn fromColumn = null;
				LogicalTable toTable = null;
				LogicalColumn toColumn = null;
				for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
					if (logicalTable.getName(locale).equals(lTable)) {
						fromTable = logicalTable;
						for (LogicalColumn logicalColumn : fromTable.getLogicalColumns()) {
							if (logicalColumn.getName(locale).equals(joinTemplate.getFromColumn().getName(locale))) {
								fromColumn = logicalColumn;
							}
						}
					}
					if (logicalTable.getName(locale).equals(rTable)) {
						toTable = logicalTable;
						for (LogicalColumn logicalColumn : toTable.getLogicalColumns()) {
							if (logicalColumn.getName(locale).equals(joinTemplate.getToColumn().getName(locale))) {
								toColumn = logicalColumn;
							}
						}
					}
				}
				LogicalRelationship logicalRelationship = new LogicalRelationship();
				logicalRelationship.setRelationshipType(RelationshipType._1_1);
				logicalRelationship.setFromTable(fromTable);
				logicalRelationship.setFromColumn(fromColumn);
				logicalRelationship.setToTable(toTable);
				logicalRelationship.setToColumn(toColumn);
				logicalModel.addLogicalRelationship(logicalRelationship);
			}
			helper.autoModelMultiTableRelational(workspace);
			workspace.setModelName(datasourceName);
			helper.populateDomain(workspace);			
		} catch (PentahoMetadataException e) {
			e.printStackTrace();
			logger.info(e.getLocalizedMessage());
		} catch (ModelerException e) {
			e.printStackTrace();
			logger.info(e.getLocalizedMessage());
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e.getLocalizedMessage());
		}
		return domain;
	}
