public void Save(Versions obj) { using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } }
public static void CreateInitialSchema() { SQLiteConnection myConn = new SQLiteConnection(GetConnectionString()); myConn.Open(); string cmd = string.Format("SELECT count(*) as NumTables FROM sqlite_master WHERE name='Versions'"); SQLiteCommand sqCommandCheck = new SQLiteCommand(cmd); sqCommandCheck.Connection = myConn; long count = long.Parse(sqCommandCheck.ExecuteScalar().ToString()); // if the Versions already exists, it means we have done this already if (count > 0) return; //Create all the commands to be executed List<string> commands = new List<string>(); commands.AddRange(CreateTableString_Versions()); commands.AddRange(CreateTableString_AniDB_Anime()); commands.AddRange(CreateTableString_AniDB_Anime_Category()); commands.AddRange(CreateTableString_AniDB_Anime_Character()); commands.AddRange(CreateTableString_AniDB_Anime_Relation()); commands.AddRange(CreateTableString_AniDB_Anime_Review()); commands.AddRange(CreateTableString_AniDB_Anime_Similar()); commands.AddRange(CreateTableString_AniDB_Anime_Tag()); commands.AddRange(CreateTableString_AniDB_Anime_Title()); commands.AddRange(CreateTableString_AniDB_Category()); commands.AddRange(CreateTableString_AniDB_Character()); commands.AddRange(CreateTableString_AniDB_Character_Seiyuu()); commands.AddRange(CreateTableString_AniDB_Seiyuu()); commands.AddRange(CreateTableString_AniDB_Episode()); commands.AddRange(CreateTableString_AniDB_File()); commands.AddRange(CreateTableString_AniDB_GroupStatus()); commands.AddRange(CreateTableString_AniDB_ReleaseGroup()); commands.AddRange(CreateTableString_AniDB_Review()); commands.AddRange(CreateTableString_AniDB_Tag()); commands.AddRange(CreateTableString_AnimeEpisode()); commands.AddRange(CreateTableString_AnimeGroup()); commands.AddRange(CreateTableString_AnimeSeries()); commands.AddRange(CreateTableString_CommandRequest()); commands.AddRange(CreateTableString_CrossRef_AniDB_Other()); commands.AddRange(CreateTableString_CrossRef_AniDB_TvDB()); commands.AddRange(CreateTableString_CrossRef_File_Episode()); commands.AddRange(CreateTableString_CrossRef_Languages_AniDB_File()); commands.AddRange(CreateTableString_CrossRef_Subtitles_AniDB_File()); commands.AddRange(CreateTableString_FileNameHash()); commands.AddRange(CreateTableString_Language()); commands.AddRange(CreateTableString_ImportFolder()); commands.AddRange(CreateTableString_ScheduledUpdate()); commands.AddRange(CreateTableString_VideoInfo()); commands.AddRange(CreateTableString_VideoLocal()); commands.AddRange(CreateTableString_DuplicateFile()); commands.AddRange(CreateTableString_GroupFilter()); commands.AddRange(CreateTableString_GroupFilterCondition()); commands.AddRange(CreateTableString_AniDB_Vote()); commands.AddRange(CreateTableString_TvDB_ImageFanart()); commands.AddRange(CreateTableString_TvDB_ImageWideBanner()); commands.AddRange(CreateTableString_TvDB_ImagePoster()); commands.AddRange(CreateTableString_TvDB_Episode()); commands.AddRange(CreateTableString_TvDB_Series()); commands.AddRange(CreateTableString_AniDB_Anime_DefaultImage()); commands.AddRange(CreateTableString_MovieDB_Movie()); commands.AddRange(CreateTableString_MovieDB_Poster()); commands.AddRange(CreateTableString_MovieDB_Fanart()); commands.AddRange(CreateTableString_JMMUser()); commands.AddRange(CreateTableString_Trakt_Episode()); commands.AddRange(CreateTableString_Trakt_ImagePoster()); commands.AddRange(CreateTableString_Trakt_ImageFanart()); commands.AddRange(CreateTableString_Trakt_Show()); commands.AddRange(CreateTableString_Trakt_Season()); commands.AddRange(CreateTableString_CrossRef_AniDB_Trakt()); commands.AddRange(CreateTableString_AnimeEpisode_User()); commands.AddRange(CreateTableString_AnimeSeries_User()); commands.AddRange(CreateTableString_AnimeGroup_User()); commands.AddRange(CreateTableString_VideoLocal_User()); foreach (string cmdTable in commands) { SQLiteCommand sqCommand = new SQLiteCommand(cmdTable); sqCommand.Connection = myConn; sqCommand.ExecuteNonQuery(); } myConn.Close(); logger.Trace("Creating version..."); Versions ver1 = new Versions(); ver1.VersionType = Constants.DatabaseTypeKey; ver1.VersionValue = "1"; VersionsRepository repVer = new VersionsRepository(); repVer.Save(ver1); }
public static void CreateInitialSchema() { int count = 0; //string sql = string.Format("select count(VERSIONS) from INFORMATION_SCHEMA where TABLE_SCHEMA = '{0}' and TABLE_NAME = 'VERSIONS' group by TABLE_NAME", // ServerSettings.MySQL_SchemaName); string sql = string.Format("select count(*) from information_schema.tables where table_schema='{0}' and table_name = 'VERSIONS'", ServerSettings.MySQL_SchemaName); logger.Trace(sql); using (MySqlConnection conn = new MySqlConnection(GetConnectionString())) { conn.Open(); MySqlCommand cmd = new MySqlCommand(sql, conn); object result = cmd.ExecuteScalar(); count = int.Parse(result.ToString()); } // if the Versions already exists, it means we have done this already if (count > 0) { logger.Trace("Initial schema already exists"); return; } logger.Trace("Initial schema doesn't exists, creating now..."); //Create all the commands to be executed List<string> commands = new List<string>(); commands.AddRange(CreateTableString_Versions()); commands.AddRange(CreateTableString_AniDB_Anime()); commands.AddRange(CreateTableString_AniDB_Anime_Category()); commands.AddRange(CreateTableString_AniDB_Anime_Character()); commands.AddRange(CreateTableString_AniDB_Anime_Relation()); commands.AddRange(CreateTableString_AniDB_Anime_Review()); commands.AddRange(CreateTableString_AniDB_Anime_Similar()); commands.AddRange(CreateTableString_AniDB_Anime_Tag()); commands.AddRange(CreateTableString_AniDB_Anime_Title()); commands.AddRange(CreateTableString_AniDB_Category()); commands.AddRange(CreateTableString_AniDB_Character()); commands.AddRange(CreateTableString_AniDB_Character_Seiyuu()); commands.AddRange(CreateTableString_AniDB_Seiyuu()); commands.AddRange(CreateTableString_AniDB_Episode()); commands.AddRange(CreateTableString_AniDB_File()); commands.AddRange(CreateTableString_AniDB_GroupStatus()); commands.AddRange(CreateTableString_AniDB_ReleaseGroup()); commands.AddRange(CreateTableString_AniDB_Review()); commands.AddRange(CreateTableString_AniDB_Tag()); commands.AddRange(CreateTableString_AnimeEpisode()); commands.AddRange(CreateTableString_AnimeEpisode_User()); commands.AddRange(CreateTableString_AnimeGroup()); commands.AddRange(CreateTableString_AnimeSeries()); commands.AddRange(CreateTableString_AnimeSeries_User()); commands.AddRange(CreateTableString_AnimeGroup_User()); commands.AddRange(CreateTableString_VideoLocal()); commands.AddRange(CreateTableString_VideoLocal_User()); commands.AddRange(CreateTableString_CommandRequest()); commands.AddRange(CreateTableString_CrossRef_AniDB_Other()); commands.AddRange(CreateTableString_CrossRef_AniDB_TvDB()); commands.AddRange(CreateTableString_CrossRef_File_Episode()); commands.AddRange(CreateTableString_CrossRef_Languages_AniDB_File()); commands.AddRange(CreateTableString_CrossRef_Subtitles_AniDB_File()); commands.AddRange(CreateTableString_FileNameHash()); commands.AddRange(CreateTableString_Language()); commands.AddRange(CreateTableString_ImportFolder()); commands.AddRange(CreateTableString_ScheduledUpdate()); commands.AddRange(CreateTableString_VideoInfo()); commands.AddRange(CreateTableString_DuplicateFile()); commands.AddRange(CreateTableString_GroupFilter()); commands.AddRange(CreateTableString_GroupFilterCondition()); commands.AddRange(CreateTableString_AniDB_Vote()); commands.AddRange(CreateTableString_TvDB_ImageFanart()); commands.AddRange(CreateTableString_TvDB_ImageWideBanner()); commands.AddRange(CreateTableString_TvDB_ImagePoster()); commands.AddRange(CreateTableString_TvDB_Episode()); commands.AddRange(CreateTableString_TvDB_Series()); commands.AddRange(CreateTableString_AniDB_Anime_DefaultImage()); commands.AddRange(CreateTableString_MovieDB_Movie()); commands.AddRange(CreateTableString_MovieDB_Poster()); commands.AddRange(CreateTableString_MovieDB_Fanart()); commands.AddRange(CreateTableString_JMMUser()); commands.AddRange(CreateTableString_Trakt_Episode()); commands.AddRange(CreateTableString_Trakt_ImagePoster()); commands.AddRange(CreateTableString_Trakt_ImageFanart()); commands.AddRange(CreateTableString_Trakt_Show()); commands.AddRange(CreateTableString_Trakt_Season()); commands.AddRange(CreateTableString_CrossRef_AniDB_Trakt()); using (MySqlConnection conn = new MySqlConnection(GetConnectionString())) { conn.Open(); foreach (string cmdTable in commands) { using (MySqlCommand command = new MySqlCommand(cmdTable, conn)) { try { command.ExecuteNonQuery(); } catch (Exception ex) { logger.Error(cmdTable + " - " + ex.Message); } } } } Console.WriteLine("Creating version..."); Versions ver1 = new Versions(); ver1.VersionType = Constants.DatabaseTypeKey; ver1.VersionValue = "1"; VersionsRepository repVer = new VersionsRepository(); repVer.Save(ver1); }
public static void CreateInitialSchema() { int count = 0; string cmd = string.Format("Select count(*) from sysobjects where name = 'Versions'"); using (SqlConnection tmpConn = new SqlConnection(string.Format("Server={0};User ID={1};Password={2};database={3}", ServerSettings.DatabaseServer, ServerSettings.DatabaseUsername, ServerSettings.DatabasePassword, ServerSettings.DatabaseName))) { using (SqlCommand command = new SqlCommand(cmd, tmpConn)) { tmpConn.Open(); object result = command.ExecuteScalar(); count = int.Parse(result.ToString()); } } // if the Versions already exists, it means we have done this already if (count > 0) return; //Create all the commands to be executed List<string> commands = new List<string>(); commands.AddRange(CreateTableString_Versions()); commands.AddRange(CreateTableString_AniDB_Anime()); commands.AddRange(CreateTableString_AniDB_Anime_Category()); commands.AddRange(CreateTableString_AniDB_Anime_Character()); commands.AddRange(CreateTableString_AniDB_Anime_Relation()); commands.AddRange(CreateTableString_AniDB_Anime_Review()); commands.AddRange(CreateTableString_AniDB_Anime_Similar()); commands.AddRange(CreateTableString_AniDB_Anime_Tag()); commands.AddRange(CreateTableString_AniDB_Anime_Title()); commands.AddRange(CreateTableString_AniDB_Category()); commands.AddRange(CreateTableString_AniDB_Character()); commands.AddRange(CreateTableString_AniDB_Character_Seiyuu()); commands.AddRange(CreateTableString_AniDB_Seiyuu()); commands.AddRange(CreateTableString_AniDB_Episode()); commands.AddRange(CreateTableString_AniDB_File()); commands.AddRange(CreateTableString_AniDB_GroupStatus()); commands.AddRange(CreateTableString_AniDB_ReleaseGroup()); commands.AddRange(CreateTableString_AniDB_Review()); commands.AddRange(CreateTableString_AniDB_Tag()); commands.AddRange(CreateTableString_AnimeEpisode()); commands.AddRange(CreateTableString_AnimeGroup()); commands.AddRange(CreateTableString_AnimeSeries()); commands.AddRange(CreateTableString_CommandRequest()); commands.AddRange(CreateTableString_CrossRef_AniDB_Other()); commands.AddRange(CreateTableString_CrossRef_AniDB_TvDB()); commands.AddRange(CreateTableString_CrossRef_File_Episode()); commands.AddRange(CreateTableString_CrossRef_Languages_AniDB_File()); commands.AddRange(CreateTableString_CrossRef_Subtitles_AniDB_File()); commands.AddRange(CreateTableString_FileNameHash()); commands.AddRange(CreateTableString_Language()); commands.AddRange(CreateTableString_ImportFolder()); commands.AddRange(CreateTableString_ScheduledUpdate()); commands.AddRange(CreateTableString_VideoInfo()); commands.AddRange(CreateTableString_VideoLocal()); commands.AddRange(CreateTableString_DuplicateFile()); commands.AddRange(CreateTableString_GroupFilter()); commands.AddRange(CreateTableString_GroupFilterCondition()); commands.AddRange(CreateTableString_AniDB_Vote()); commands.AddRange(CreateTableString_TvDB_ImageFanart()); commands.AddRange(CreateTableString_TvDB_ImageWideBanner()); commands.AddRange(CreateTableString_TvDB_ImagePoster()); commands.AddRange(CreateTableString_TvDB_Episode()); commands.AddRange(CreateTableString_TvDB_Series()); commands.AddRange(CreateTableString_AniDB_Anime_DefaultImage()); commands.AddRange(CreateTableString_MovieDB_Movie()); commands.AddRange(CreateTableString_MovieDB_Poster()); commands.AddRange(CreateTableString_MovieDB_Fanart()); commands.AddRange(CreateTableString_JMMUser()); commands.AddRange(CreateTableString_Trakt_Episode()); commands.AddRange(CreateTableString_Trakt_ImagePoster()); commands.AddRange(CreateTableString_Trakt_ImageFanart()); commands.AddRange(CreateTableString_Trakt_Show()); commands.AddRange(CreateTableString_Trakt_Season()); commands.AddRange(CreateTableString_CrossRef_AniDB_Trakt()); commands.AddRange(CreateTableString_AnimeEpisode_User()); commands.AddRange(CreateTableString_AnimeSeries_User()); commands.AddRange(CreateTableString_AnimeGroup_User()); commands.AddRange(CreateTableString_VideoLocal_User()); //commands.AddRange(CreateTableString_CrossRef_AnimeEpisode_Hash()); using (SqlConnection tmpConn = new SqlConnection(string.Format("Server={0};User ID={1};Password={2};database={3}", ServerSettings.DatabaseServer, ServerSettings.DatabaseUsername, ServerSettings.DatabasePassword, ServerSettings.DatabaseName))) { tmpConn.Open(); foreach (string cmdTable in commands) { using (SqlCommand command = new SqlCommand(cmdTable, tmpConn)) { command.ExecuteNonQuery(); } } } Console.WriteLine("Creating version..."); Versions ver1 = new Versions(); ver1.VersionType = Constants.DatabaseTypeKey; ver1.VersionValue = "1"; VersionsRepository repVer = new VersionsRepository(); repVer.Save(ver1); }