// Path: droitatedDBProcessor/src/main/java/org/droitateddb/builder/schema/data/Table.java
// public class Table {
// 
// 	private final String name;
// 	private final String entityClassName;
// 
// 	private final Set<Column> columns = new TreeSet<Column>(new Comparator<Column>() {
// 		@Override
// 		public int compare(final Column c1, final Column c2) {
// 			return c1.getNameInEntity().compareTo(c2.getNameInEntity());
// 		}
// 	});
// 	private final Set<Association> associations = new TreeSet<Association>(new Comparator<Association>() {
// 		@Override
// 		public int compare(final Association a1, final Association a2) {
// 			return a1.getNameInEntity().compareTo(a2.getNameInEntity());
// 		}
// 	});
// 
// 	public Table(final String name, final String entityClassName) {
// 		this.name = name;
// 		this.entityClassName = entityClassName;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public String getEntityClassName() {
// 		return entityClassName;
// 	}
// 
// 	public Set<Column> getColumns() {
// 		return Collections.unmodifiableSet(columns);
// 	}
// 
// 	public void addColumn(final Column column) {
// 		columns.add(column);
// 	}
// 
// 	public Set<Association> getAssociations() {
// 		return Collections.unmodifiableSet(associations);
// 	}
// 
// 	public void addAssociation(final Association association) {
// 		associations.add(association);
// 	}
// 
// }
// 
// Path: droitatedDBProcessor/src/main/java/org/droitateddb/builder/schema/visitor/AssociationElementResolvingTypeVisitor.java
// public class AssociationElementResolvingTypeVisitor extends DefaultElementVisitor<VariableElement, Void> {
// 
// 	 @Override
// 	 public VariableElement visitVariable(final VariableElement e, final Void p) {
// 		 if (e.getAnnotation(Relationship.class) != null) {
// 			 return e;
// 		 } else {
// 			 return null;
// 		 }
// 	 }
// 
//  }
// 
// Path: droitatedDBProcessor/src/main/java/org/droitateddb/builder/schema/visitor/EmptyContructorVisitor.java
// public class EmptyContructorVisitor extends DefaultElementVisitor<ExecutableElement, Void> {
// 	@Override
// 	public ExecutableElement visitExecutable(final ExecutableElement e, final Void p) {
// 		if ("<init>".equals(e.getSimpleName().toString()) && e.getParameters().size() == 0) {
// 			return e;
// 		}
// 		return null;
// 	}
// }


import javax.tools.Diagnostic.Kind;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import org.droitateddb.builder.schema.data.Association;
import org.droitateddb.builder.schema.data.Column;
import org.droitateddb.builder.schema.data.Table;
import org.droitateddb.builder.schema.visitor.AssociationElementResolvingTypeVisitor;
import org.droitateddb.builder.schema.visitor.ColumnElementResolvingTypeVisitor;
import org.droitateddb.builder.schema.visitor.EmptyContructorVisitor;
import org.droitateddb.entity.PrimaryKey;
import org.droitateddb.entity.Relationship;
import org.droitateddb.schema.AssociationType;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.Elements;
/*
 * Copyright (C) 2014 The droitated DB Authors
 *
 * 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.droitateddb.builder.schema.reader;



/**
 * @author Alexander Frank
 * @author Falk Appel
 */
public class TableReader implements Reader<Table> {

    private final TypeElement entity;
    private final Set<String> entityNames;
    private final Elements elements;
    private final Messager messager;

    public TableReader(final TypeElement entity, final Set<String> entityNames, final Elements elements, final Messager messager) {
        this.entity = entity;
        this.entityNames = entityNames;
        this.elements = elements;
        this.messager = messager;
    }

    @Override
    public Table read() {
        int primaryKeyCount = 0;
        boolean noArgsConstructor = false;

        Table table = new Table(entity.getSimpleName().toString(), entity.toString());

        Map<String, AtomicInteger> countedToManyAssociations = new HashMap<String, AtomicInteger>();

        for (Element child : entity.getEnclosedElements()) {
// Path: droitatedDBProcessor/src/main/java/org/droitateddb/builder/schema/data/Table.java
// public class Table {
// 
// 	private final String name;
// 	private final String entityClassName;
// 
// 	private final Set<Column> columns = new TreeSet<Column>(new Comparator<Column>() {
// 		@Override
// 		public int compare(final Column c1, final Column c2) {
// 			return c1.getNameInEntity().compareTo(c2.getNameInEntity());
// 		}
// 	});
// 	private final Set<Association> associations = new TreeSet<Association>(new Comparator<Association>() {
// 		@Override
// 		public int compare(final Association a1, final Association a2) {
// 			return a1.getNameInEntity().compareTo(a2.getNameInEntity());
// 		}
// 	});
// 
// 	public Table(final String name, final String entityClassName) {
// 		this.name = name;
// 		this.entityClassName = entityClassName;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public String getEntityClassName() {
// 		return entityClassName;
// 	}
// 
// 	public Set<Column> getColumns() {
// 		return Collections.unmodifiableSet(columns);
// 	}
// 
// 	public void addColumn(final Column column) {
// 		columns.add(column);
// 	}
// 
// 	public Set<Association> getAssociations() {
// 		return Collections.unmodifiableSet(associations);
// 	}
// 
// 	public void addAssociation(final Association association) {
// 		associations.add(association);
// 	}
// 
// }
// 
// Path: droitatedDBProcessor/src/main/java/org/droitateddb/builder/schema/visitor/AssociationElementResolvingTypeVisitor.java
// public class AssociationElementResolvingTypeVisitor extends DefaultElementVisitor<VariableElement, Void> {
// 
// 	 @Override
// 	 public VariableElement visitVariable(final VariableElement e, final Void p) {
// 		 if (e.getAnnotation(Relationship.class) != null) {
// 			 return e;
// 		 } else {
// 			 return null;
// 		 }
// 	 }
// 
//  }
// 
// Path: droitatedDBProcessor/src/main/java/org/droitateddb/builder/schema/visitor/EmptyContructorVisitor.java
// public class EmptyContructorVisitor extends DefaultElementVisitor<ExecutableElement, Void> {
// 	@Override
// 	public ExecutableElement visitExecutable(final ExecutableElement e, final Void p) {
// 		if ("<init>".equals(e.getSimpleName().toString()) && e.getParameters().size() == 0) {
// 			return e;
// 		}
// 		return null;
// 	}
// }


// Path: droitatedDBProcessor/src/main/java/org/droitateddb/builder/schema/reader/TableReader.java
import javax.tools.Diagnostic.Kind;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import org.droitateddb.builder.schema.data.Association;
import org.droitateddb.builder.schema.data.Column;
import org.droitateddb.builder.schema.data.Table;
import org.droitateddb.builder.schema.visitor.AssociationElementResolvingTypeVisitor;
import org.droitateddb.builder.schema.visitor.ColumnElementResolvingTypeVisitor;
import org.droitateddb.builder.schema.visitor.EmptyContructorVisitor;
import org.droitateddb.entity.PrimaryKey;
import org.droitateddb.entity.Relationship;
import org.droitateddb.schema.AssociationType;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.Elements;

/*
 * Copyright (C) 2014 The droitated DB Authors
 *
 * 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.droitateddb.builder.schema.reader;



/**
 * @author Alexander Frank
 * @author Falk Appel
 */
public class TableReader implements Reader<Table> {

    private final TypeElement entity;
    private final Set<String> entityNames;
    private final Elements elements;
    private final Messager messager;

    public TableReader(final TypeElement entity, final Set<String> entityNames, final Elements elements, final Messager messager) {
        this.entity = entity;
        this.entityNames = entityNames;
        this.elements = elements;
        this.messager = messager;
    }

    @Override
    public Table read() {
        int primaryKeyCount = 0;
        boolean noArgsConstructor = false;

        Table table = new Table(entity.getSimpleName().toString(), entity.toString());

        Map<String, AtomicInteger> countedToManyAssociations = new HashMap<String, AtomicInteger>();

        for (Element child : entity.getEnclosedElements()) {
            if (child.accept(new EmptyContructorVisitor(), null) != null) {