// OS_STATUS: public
package com.tesora.dve.sql.util;


import java.util.ArrayList;
import java.util.List;

import com.tesora.dve.sql.util.Functional;
import com.tesora.dve.sql.util.UnaryFunction;

public abstract class ProjectDDL extends TestDDL {

	protected List<DatabaseDDL> dbs = new ArrayList<DatabaseDDL>();
	
	public ProjectDDL() {
	}
	
	public ProjectDDL(ProjectDDL other) {
		this.created = other.created;
		this.dbs = new ArrayList<DatabaseDDL>();
		for(DatabaseDDL ddl : other.dbs)
			this.dbs.add(ddl.copy());
	}
	
		
	public boolean isNative() {
		return false;
	}

	public ProjectDDL withDatabase(DatabaseDDL ddl) {
		this.dbs.add(ddl);
		return this;
	}
	
	public abstract StorageGroupDDL getPersistentGroup();
	
	public List<String> getCreateDatabaseStatements() {
		return Functional.apply(dbs, new UnaryFunction<String,DatabaseDDL>() {

			@Override
			public String evaluate(DatabaseDDL object) {
				return object.getCreateDatabaseStatement();
			}
			
		});
	}

	public String getCreateDatabaseStatement() {
		return getSingleDB().getCreateDatabaseStatement();
	}

	public String getDatabaseName() {
		return getSingleDB().getDatabaseName();
	}
	
	protected DatabaseDDL getSingleDB() {
		if (dbs.size() != 1)
			throw new IllegalStateException("More than one database found");
		return dbs.get(0);
	}
	
	
	
	public abstract ProjectDDL buildTenantDDL(String tenantName);

	public List<DatabaseDDL> getDatabases() {
		return dbs;
	}
	
	// clear is a deep operation, but set is not
	@Override
	public void clearCreated() {
		for(DatabaseDDL ddl : dbs)
			ddl.clearCreated();
		super.clearCreated();
	}
}
@@ -243,16 +243,51 @@
 tDDL %7B%0A%0A
+%09boolean throwIfSingleDB = true;%0A%09%0A
 %09protect
@@ -1242,16 +1242,39 @@
 %7B%0A%09%09if (
+isThrowIfSingleDB() && 
 dbs.size
@@ -1671,10 +1671,183 @@
 ed();%0A%09%7D
+%0A%0A%09public boolean isThrowIfSingleDB() %7B%0A%09%09return throwIfSingleDB;%0A%09%7D%0A%0A%09public void setThrowIfSingleDB(boolean throwIfSingleDB) %7B%0A%09%09this.throwIfSingleDB = throwIfSingleDB;%0A%09%7D
 %0A%7D

Fix for PE-1492.