예제 #1
0
 public static Relation GetMatchingRelation(List<Relation> relations, Relation relation)
 {
     return relations.Find(
         delegate(Relation rel)
             {
                 return (rel.RelationName == relation.RelationName &&
                         rel.PrimaryModelClass != relation.PrimaryModelClass &&
                         rel.PrimaryColumn == relation.PrimaryColumn &&
                         rel.ForeignColumn == relation.ForeignColumn &&
                         rel.PrimaryOwner == relation.PrimaryOwner &&
                         rel.PrimaryTable == relation.PrimaryTable &&
                         rel.ForeignOwner == relation.ForeignOwner &&
                         rel.ForeignTable == relation.ForeignTable);
             }
         );
 }
예제 #2
0
 public static List<Relation> GetFKRelationsFromSameClassToDifferentClasses(List<Relation> relations, Relation relation)
 {
     return relations.FindAll(
         delegate(Relation rel)
             {
                 return (rel.ForeignOwner == relation.ForeignOwner &&
                         rel.ForeignTable == relation.ForeignTable &&
                         !(rel.PrimaryOwner == relation.PrimaryOwner && rel.PrimaryTable == relation.PrimaryTable)
                        );
             }
         );
 }
예제 #3
0
		public List<Relation> GetPKRelations(ModelClass cls)
		{
			List<Relation> list = new List<Relation>();

			IDbCommand command = _connection.CreateCommand();
			command.CommandText =
				@"select 
                    kcu.CONSTRAINT_NAME,
                    kcu.TABLE_SCHEMA,
                    kcu.TABLE_NAME,
                    kcu.COLUMN_NAME,
                    kcu.REFERENCED_TABLE_SCHEMA,
                    kcu.REFERENCED_TABLE_NAME,
                    kcu.REFERENCED_COLUMN_NAME
                from
                    INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu
                where
                    kcu.CONSTRAINT_SCHEMA is not null
                    and kcu.TABLE_NAME is not null
                    and kcu.COLUMN_NAME is not NULL
                    and kcu.REFERENCED_TABLE_SCHEMA = ?schema
                    and kcu.REFERENCED_TABLE_NAME = ?table";

			AddSchemaAndTableParams(command, cls.Schema, cls.Table);

			using(IDataReader reader = command.ExecuteReader())
			{
				while(reader.Read())
				{
					Relation relation = new Relation();
					relation.RelationType = RelationType.Unknown;
					relation.RelationName = reader["CONSTRAINT_NAME"].ToString();
					relation.PrimaryOwner = cls.Schema;
					relation.PrimaryTable = cls.Table;
					relation.PrimaryColumn = reader["REFERENCED_COLUMN_NAME"].ToString();
					relation.ForeignOwner = reader["TABLE_SCHEMA"].ToString();
					relation.ForeignTable = reader["TABLE_NAME"].ToString();
					relation.ForeignColumn = reader["COLUMN_NAME"].ToString();

					list.Add(relation);
				}
			}

			return list;
		}
예제 #4
0
		public List<Relation> GetPKRelations(ModelClass cls)
		{
			List<Relation> list = new List<Relation>();

			IDbCommand command = GetForeginKeyCommand(cls.Table, cls.Schema, null, null);
			using(IDataReader reader = command.ExecuteReader())
			{
				while(reader.Read())
				{
					Relation relation = new Relation();
					relation.RelationType = RelationType.Unknown; // Caller will decide
					relation.RelationName = reader["FK_NAME"].ToString();
					relation.PrimaryOwner = cls.Schema;
					relation.PrimaryTable = cls.Table;
					relation.PrimaryColumn = reader["PKCOLUMN_NAME"].ToString();
					relation.ForeignOwner = reader["FKTABLE_OWNER"].ToString();
					relation.ForeignTable = reader["FKTABLE_NAME"].ToString();
					relation.ForeignColumn = reader["FKCOLUMN_NAME"].ToString();

					list.Add(relation);
				}
			}

			return list;
		}
예제 #5
0
        public ManyToManyRelation NewManyToManyRelation(Relation source, Relation target)
        {
            ManyToManyRelation relation = new ManyToManyRelation(source.PrimaryModelClass, target.PrimaryModelClass);
            relation.Table = source.ForeignModelClass.Name;
            relation.Schema = source.ForeignModelClass.Schema;
            relation.SourceColumn = source.ForeignColumn;
            relation.TargetColumn = target.ForeignColumn;

            return relation;
        }
예제 #6
0
        public List<Relation> GetPKRelations(ModelClass cls)
        {
            List<Relation> list = new List<Relation>();

            IDbCommand command = _connection.CreateCommand();
            command.CommandText =
                @"
            SELECT st.column_name, om.owner, om.constraint_name, om.table_name, sr.column_name r_column_name
              FROM all_constraints om INNER JOIN all_constraints rm ON om.r_owner = rm.owner
                                                                  AND om.r_constraint_name = rm.constraint_name
                   INNER JOIN all_cons_columns st ON om.constraint_name = st.constraint_name
                                                AND st.owner = om.owner
                                                AND st.table_name = om.table_name
                   INNER JOIN all_cons_columns sr ON rm.constraint_name = sr.constraint_name
                                                AND sr.owner = rm.owner
                                                AND sr.table_name = rm.table_name
             WHERE om.constraint_type = 'R'
               AND rm.table_name = :tname
               AND om.r_owner = :owner
                ";

            AddSchemaAndTableParams(command, cls.Schema, cls.Table);

            using (IDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    Relation relation = new Relation();
                    relation.RelationType = RelationType.Unknown;
                    relation.RelationName = reader["CONSTRAINT_NAME"].ToString();
                    relation.PrimaryOwner = cls.Schema;
                    relation.PrimaryTable = cls.Table;
                    relation.PrimaryColumn = reader["R_COLUMN_NAME"].ToString();
                    relation.ForeignOwner = reader["OWNER"].ToString();
                    relation.ForeignTable = reader["TABLE_NAME"].ToString();
                    relation.ForeignColumn = reader["COLUMN_NAME"].ToString();

                    list.Add(relation);
                }
            }

            return list;

        }
예제 #7
0
 public static List <Relation> GetFKRelationsFromSameClassToDifferentClasses(List <Relation> relations, Relation relation)
 {
     return(relations.FindAll(
                delegate(Relation rel)
     {
         return (rel.ForeignOwner == relation.ForeignOwner &&
                 rel.ForeignTable == relation.ForeignTable &&
                 !(rel.PrimaryOwner == relation.PrimaryOwner && rel.PrimaryTable == relation.PrimaryTable)
                 );
     }
                ));
 }