コード例 #1
0
ファイル: DBAdapter.cs プロジェクト: wurlinc/rhodes
 public DBAdapter()
 {
     try{
         m_dbStorage = RhoClassFactory.createDBStorage();
     }catch (Exception exc) {
         LOG.ERROR("createDBStorage failed.", exc);
     }
 }
コード例 #2
0
ファイル: DBAdapter.cs プロジェクト: wurlinc/rhodes
        public void rb_destroy_tables(Vector <String> vecIncludes, Vector <String> vecExcludes)
        {
            if (!m_bIsOpen)
            {
                return;
            }

            IDBStorage db = null;

            try{
                String dbNewName = CFilePath.changeBaseName(m_strDBPath, "resetdbtemp.sqlite");

                CRhoFile.deleteFile(dbNewName);
                CRhoFile.deleteFile(dbNewName + "-journal");
                CRhoFile.deleteFile(dbNewName + ".version");

                db = RhoClassFactory.createDBStorage();
                db.open(dbNewName, getSqlScript(), getEncryptionInfo());

                String[] vecTables = m_dbStorage.getAllTableNames();
                //IDBResult res;

                db.startTransaction();

                for (int i = 0; i < vecTables.Length; i++)
                {
                    String tableName = vecTables[i];
                    if (destroyTableName(tableName, vecIncludes, vecExcludes))
                    {
                        continue;
                    }

                    copyTable(tableName, this.m_dbStorage, db);
                }

                db.commit();
                db.close();

                String dbOldName = m_strDBPath;

                m_dbStorage.close();
                m_dbStorage = null;
                m_bIsOpen   = false;

                CRhoFile.deleteFilesInFolder(RHODESAPP().getBlobsDirPath());

                string[] ar1 = CRhoFile.enumDirectory("db");

                CRhoFile.deleteFile(dbOldName);
                CRhoFile.deleteFile(dbOldName + "-journal");
                CRhoFile.renameFile(dbNewName, dbOldName);
                CRhoFile.renameFile(dbNewName + "-journal", dbOldName + "-journal");

                string[] ar2 = CRhoFile.enumDirectory("db");

                m_dbStorage = RhoClassFactory.createDBStorage();
                m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo());
                m_bIsOpen = true;

                string[] ar3 = CRhoFile.enumDirectory("db");
                m_dbStorage.setDbCallback(new DBCallback(this));
            }catch (Exception e)
            {
                LOG.ERROR("destroy_table failed.", e);

                if (!m_bIsOpen)
                {
                    LOG.ERROR("destroy_table error.Try to open old DB.");
                    try{
                        m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo());
                        m_bIsOpen = true;
                    }catch (Exception exc)
                    {
                        LOG.ERROR("destroy_table open old table failed.", exc);
                    }
                }

                try {
                    if (db != null)
                    {
                        db.close();
                    }
                } catch (DBException e1) {
                    LOG.ERROR("closing of DB caused exception: " + e1.Message);
                }

                throw e;
            }
        }
コード例 #3
0
ファイル: DBAdapter.cs プロジェクト: wurlinc/rhodes
        void checkDBVersion()
        {
            DBVersion dbNewVer = new DBVersion();

            dbNewVer.m_strRhoVer = RhoRuby.getRhoDBVersion();
            dbNewVer.m_strAppVer = RhoConf.getInstance().getString("app_db_version");
            String strEncryptionInfo = getEncryptionInfo();

            dbNewVer.m_bEncrypted = strEncryptionInfo != null && strEncryptionInfo.length() > 0;
            dbNewVer.m_bSqlite    = true;

            DBVersion dbVer = new DBVersion();

            dbVer.fromFile(m_strDbVerPath);

            if (dbVer.m_strRhoVer.length() == 0)
            {
                dbNewVer.toFile(m_strDbVerPath);
                return;
            }

            boolean bRhoReset = dbVer.isRhoVerChanged(dbNewVer);
            boolean bAppReset = dbVer.isAppVerChanged(dbNewVer);

            boolean bDbFormatChanged = dbVer.isDbFormatChanged(dbNewVer);

            if (!bDbFormatChanged && dbVer.m_bEncrypted)
            {
                //TODO: check encryption key
                //if (!com.rho.RhoCrypto.isKeyExist(strEncryptionInfo) )
                //	bDbFormatChanged = true;
            }

            if (bDbFormatChanged)
            {
                LOG.INFO("Reset Database( format changed ):" + m_strDBPath);
            }

            if (bRhoReset && !bAppReset && !bDbFormatChanged)
            {
                bRhoReset = !migrateDB(dbVer, dbNewVer);
            }

            if (bRhoReset || bAppReset || bDbFormatChanged)
            {
                if (!bDbFormatChanged)
                {
                    IDBStorage db = null;
                    try
                    {
                        db = RhoClassFactory.createDBStorage();
                        if (db.isDbFileExists(m_strDBPath))
                        {
                            db.open(m_strDBPath, "", strEncryptionInfo);
                            IDBResult res = db.executeSQL("SELECT * FROM client_info", null, false, false);
                            if (!res.isEnd())
                            {
                                m_strClientInfoInsert = createInsertStatement(res, "client_info");
                                m_dataClientInfo      = res.getCurData();
                            }
                        }
                    }catch (Exception exc)
                    {
                        LOG.ERROR("Copy client_info table failed.", exc);
                    }finally
                    {
                        if (db != null)
                        {
                            try { db.close(); } catch (Exception) {  }
                        }
                    }
                }

                m_dbStorage.deleteAllFiles(m_strDBPath);

                if (this.m_strDbPartition.compareTo("user") == 0)           //do it only once
                {
                    String fName = makeBlobFolderName();
                    CRhoFile.deleteDirectory(fName);
                    makeBlobFolderName();             //Create folder back
                }

                dbNewVer.toFile(m_strDbVerPath);

                if (RhoConf.getInstance().isExist("bulksync_state") && RhoConf.getInstance().getInt("bulksync_state") != 0)
                {
                    RhoConf.getInstance().setInt("bulksync_state", 0, true);
                }
            }
        }