// Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/storage/ConnectionFactory.java
// public class ConnectionFactory
// {
// 
// 	private static AbstractGraphDatabase graphDb = new EmbeddedGraphDatabase(Settings.create().getConfiguration().getString("neo4j.path"));
// 
// 	private static Index<Node> newsletterIndex;
// 
// 	private static Index<Node> userIndex;
// 
// 	private static Index<Node> groupIndex;
// 
// 	private static Index<Node> senderIndex;
// 
// 	private static Index<Node> bounceIndex;
// 
// 	private static Index<Node> campaignIndex;
// 
// 	private static Index<Node> templateIndex;
// 
// 	private static Index<Node> tagIndex;
// 
// 	public static final long DEFAULT_BOUNCE_NODE = 1337L;
// 
// 	private static boolean notStarted = true;
// 
// 	/**
// 	 * The wrapper for the graph db to be exposed as server
// 	 */
// 	private static WrappingNeoServerBootstrapper srv;
// 
// 	static
// 	{
// 		newsletterIndex = graphDb.index().forNodes("newsletter");
// 		userIndex = graphDb.index().forNodes("user");
// 		groupIndex = graphDb.index().forNodes("group");
// 		senderIndex = graphDb.index().forNodes("sender");
// 		senderIndex = graphDb.index().forNodes("bounce");
// 		campaignIndex = graphDb.index().forNodes("campaign");
// 		templateIndex = graphDb.index().forNodes("template");
//         
// 		if (notStarted)
// 		{
// 			srv = new WrappingNeoServerBootstrapper(graphDb);
// 			srv.start();
// 			registerShutdownHook();
// 			notStarted = false;
// 		}
// 	}
// 
// 	private ConnectionFactory()
// 	{
// 	}
// 
// 	/**
// 	 * Singleton like getter for the graph db.
// 	 *
// 	 * @return the graphdb instance
// 	 */
// 	public static GraphDatabaseService getDatabase()
// 	{
// 		return graphDb;
// 	}
// 
// 	public static Index<Node> getNewsletterIndex()
// 	{
// 		return newsletterIndex;
// 	}
// 
// 	public static Index<Node> getUserIndex()
// 	{
// 		return userIndex;
// 	}
// 
// 	public static Index<Node> getGroupIndex()
// 	{
// 		return groupIndex;
// 	}
// 
// 	public static Index<Node> getSenderIndex()
// 	{
// 		return senderIndex;
// 	}
// 
// 	public static Index<Node> getBounceIndex()
// 	{
// 		return bounceIndex;
// 	}
// 
// 	public static Index<Node> getCampaignIndex()
// 	{
// 		return campaignIndex;
// 	}
// 
// 	public static Index<Node> getTemplateIndex()
// 	{
// 		return templateIndex;
// 	}
// 
// 	public static Index<Node> getTagIndex()
// 	{
// 		return tagIndex;
// 	}
// 
// 	private static void shutdown()
// 	{
// 		srv.stop();
// 		graphDb.shutdown();
// 	}
// 
// 	private static void registerShutdownHook()
// 	{
// 		// Registers a shutdown hook for the Neo4j and index service instances
// 		// so that it shuts down nicely when the VM exits (even if you
// 		// "Ctrl-C" the running example before it's completed)
// 		Runtime.getRuntime().addShutdownHook(new Thread()
// 		{
// 			@Override
// 			public void run()
// 			{
// 				shutdown();
// 			}
// 		});
// 	}
// }


import com.trivago.mail.pigeon.storage.ConnectionFactory;
import org.apache.log4j.Logger;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Transaction;
import org.svenson.JSONProperty;

/**
 * Copyright (C) 2011-2012 trivago GmbH <mario.mueller@trivago.com>, <christian.krause@trivago.com>
 *
 * 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 com.trivago.mail.pigeon.bean;


/**
 * Abstract Bean as parent for the other entity beans. Your new beans should
 * inherit from this one.
 *
 * @author Mario Mueller mario.mueller@trivago.com
 */
public abstract class AbstractBean
{

	/**
	 * The data node from neo4j
	 */
	protected Node dataNode;

	protected static final Logger log = Logger.getLogger("com.trivago.mail.pigeon.bean");

	/**
	 * The Node class is a wrapper from the neo4j libraries.
	 *
	 * @return returns the data node from neo4j
	 */
	@JSONProperty(ignore = true)
	public Node getDataNode()
	{
		return dataNode;
	}

	/**
	 * Wrapper for writing properties directly to the node. Do not use this within another transaction as it will fail.
	 *
	 * @param key name of the property
	 * @param value value of the property. Should be of type String, a boxed scalar or at least serializable.
	 */
	protected void writeProperty(final String key, final Object value)
	{

// Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/storage/ConnectionFactory.java
// public class ConnectionFactory
// {
// 
// 	private static AbstractGraphDatabase graphDb = new EmbeddedGraphDatabase(Settings.create().getConfiguration().getString("neo4j.path"));
// 
// 	private static Index<Node> newsletterIndex;
// 
// 	private static Index<Node> userIndex;
// 
// 	private static Index<Node> groupIndex;
// 
// 	private static Index<Node> senderIndex;
// 
// 	private static Index<Node> bounceIndex;
// 
// 	private static Index<Node> campaignIndex;
// 
// 	private static Index<Node> templateIndex;
// 
// 	private static Index<Node> tagIndex;
// 
// 	public static final long DEFAULT_BOUNCE_NODE = 1337L;
// 
// 	private static boolean notStarted = true;
// 
// 	/**
// 	 * The wrapper for the graph db to be exposed as server
// 	 */
// 	private static WrappingNeoServerBootstrapper srv;
// 
// 	static
// 	{
// 		newsletterIndex = graphDb.index().forNodes("newsletter");
// 		userIndex = graphDb.index().forNodes("user");
// 		groupIndex = graphDb.index().forNodes("group");
// 		senderIndex = graphDb.index().forNodes("sender");
// 		senderIndex = graphDb.index().forNodes("bounce");
// 		campaignIndex = graphDb.index().forNodes("campaign");
// 		templateIndex = graphDb.index().forNodes("template");
//         
// 		if (notStarted)
// 		{
// 			srv = new WrappingNeoServerBootstrapper(graphDb);
// 			srv.start();
// 			registerShutdownHook();
// 			notStarted = false;
// 		}
// 	}
// 
// 	private ConnectionFactory()
// 	{
// 	}
// 
// 	/**
// 	 * Singleton like getter for the graph db.
// 	 *
// 	 * @return the graphdb instance
// 	 */
// 	public static GraphDatabaseService getDatabase()
// 	{
// 		return graphDb;
// 	}
// 
// 	public static Index<Node> getNewsletterIndex()
// 	{
// 		return newsletterIndex;
// 	}
// 
// 	public static Index<Node> getUserIndex()
// 	{
// 		return userIndex;
// 	}
// 
// 	public static Index<Node> getGroupIndex()
// 	{
// 		return groupIndex;
// 	}
// 
// 	public static Index<Node> getSenderIndex()
// 	{
// 		return senderIndex;
// 	}
// 
// 	public static Index<Node> getBounceIndex()
// 	{
// 		return bounceIndex;
// 	}
// 
// 	public static Index<Node> getCampaignIndex()
// 	{
// 		return campaignIndex;
// 	}
// 
// 	public static Index<Node> getTemplateIndex()
// 	{
// 		return templateIndex;
// 	}
// 
// 	public static Index<Node> getTagIndex()
// 	{
// 		return tagIndex;
// 	}
// 
// 	private static void shutdown()
// 	{
// 		srv.stop();
// 		graphDb.shutdown();
// 	}
// 
// 	private static void registerShutdownHook()
// 	{
// 		// Registers a shutdown hook for the Neo4j and index service instances
// 		// so that it shuts down nicely when the VM exits (even if you
// 		// "Ctrl-C" the running example before it's completed)
// 		Runtime.getRuntime().addShutdownHook(new Thread()
// 		{
// 			@Override
// 			public void run()
// 			{
// 				shutdown();
// 			}
// 		});
// 	}
// }


// Path: pigeon-common/src/main/java/com/trivago/mail/pigeon/bean/AbstractBean.java
import com.trivago.mail.pigeon.storage.ConnectionFactory;
import org.apache.log4j.Logger;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Transaction;
import org.svenson.JSONProperty;

/**
 * Copyright (C) 2011-2012 trivago GmbH <mario.mueller@trivago.com>, <christian.krause@trivago.com>
 *
 * 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 com.trivago.mail.pigeon.bean;


/**
 * Abstract Bean as parent for the other entity beans. Your new beans should
 * inherit from this one.
 *
 * @author Mario Mueller mario.mueller@trivago.com
 */
public abstract class AbstractBean
{

	/**
	 * The data node from neo4j
	 */
	protected Node dataNode;

	protected static final Logger log = Logger.getLogger("com.trivago.mail.pigeon.bean");

	/**
	 * The Node class is a wrapper from the neo4j libraries.
	 *
	 * @return returns the data node from neo4j
	 */
	@JSONProperty(ignore = true)
	public Node getDataNode()
	{
		return dataNode;
	}

	/**
	 * Wrapper for writing properties directly to the node. Do not use this within another transaction as it will fail.
	 *
	 * @param key name of the property
	 * @param value value of the property. Should be of type String, a boxed scalar or at least serializable.
	 */
	protected void writeProperty(final String key, final Object value)
	{

		Transaction tx = ConnectionFactory.getDatabase().beginTx();
