// Path: couchbase-as-a-datasource/src/main/java/org/teiid/example/JDBCUtils.java
// public static void execute(Connection connection, String sql) throws Exception {
//     execute(connection, sql, false);
// }


import static org.teiid.example.JDBCUtils.execute;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;
import org.teiid.resource.adapter.mongodb.MongoDBManagedConnectionFactory;
import org.teiid.runtime.EmbeddedConfiguration;
import org.teiid.runtime.EmbeddedServer;
import org.teiid.translator.mongodb.MongoDBExecutionFactory;
/*
 * Copyright Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags and
 * the COPYRIGHT.txt file distributed with this work.
 *
 * 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.teiid.example;




@SuppressWarnings("nls")
public class TeiidEmbeddedMongoDBDataSource {
	
	private static String SERVERLIST = "127.0.0.1:27017" ;
	private static String DBNAME = "test" ;

	public static void main(String[] args) throws Exception {
		
		initMongoProperties();
		
		EmbeddedServer server = new EmbeddedServer();
		
		MongoDBExecutionFactory factory = new MongoDBExecutionFactory();
		factory.start();
		server.addTranslator("translator-mongodb", factory);
		
		MongoDBManagedConnectionFactory managedconnectionFactory = new MongoDBManagedConnectionFactory();
		managedconnectionFactory.setRemoteServerList(SERVERLIST);
		managedconnectionFactory.setDatabase(DBNAME);
		server.addConnectionFactory("java:/mongoDS", managedconnectionFactory.createConnectionFactory());

		server.start(new EmbeddedConfiguration());
    	
		server.deployVDB(TeiidEmbeddedMongoDBDataSource.class.getClassLoader().getResourceAsStream("mongodb-vdb.xml"));
		
		Connection c = server.getDriver().connect("jdbc:teiid:nothwind", null);
		
// Path: couchbase-as-a-datasource/src/main/java/org/teiid/example/JDBCUtils.java
// public static void execute(Connection connection, String sql) throws Exception {
//     execute(connection, sql, false);
// }


// Path: mongodb-as-a-datasource/src/main/java/org/teiid/example/TeiidEmbeddedMongoDBDataSource.java
import static org.teiid.example.JDBCUtils.execute;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;
import org.teiid.resource.adapter.mongodb.MongoDBManagedConnectionFactory;
import org.teiid.runtime.EmbeddedConfiguration;
import org.teiid.runtime.EmbeddedServer;
import org.teiid.translator.mongodb.MongoDBExecutionFactory;

/*
 * Copyright Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags and
 * the COPYRIGHT.txt file distributed with this work.
 *
 * 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.teiid.example;




@SuppressWarnings("nls")
public class TeiidEmbeddedMongoDBDataSource {
	
	private static String SERVERLIST = "127.0.0.1:27017" ;
	private static String DBNAME = "test" ;

	public static void main(String[] args) throws Exception {
		
		initMongoProperties();
		
		EmbeddedServer server = new EmbeddedServer();
		
		MongoDBExecutionFactory factory = new MongoDBExecutionFactory();
		factory.start();
		server.addTranslator("translator-mongodb", factory);
		
		MongoDBManagedConnectionFactory managedconnectionFactory = new MongoDBManagedConnectionFactory();
		managedconnectionFactory.setRemoteServerList(SERVERLIST);
		managedconnectionFactory.setDatabase(DBNAME);
		server.addConnectionFactory("java:/mongoDS", managedconnectionFactory.createConnectionFactory());

		server.start(new EmbeddedConfiguration());
    	
		server.deployVDB(TeiidEmbeddedMongoDBDataSource.class.getClassLoader().getResourceAsStream("mongodb-vdb.xml"));
		
		Connection c = server.getDriver().connect("jdbc:teiid:nothwind", null);
		
		execute(c, "DELETE FROM Employee", false);