<p>Get MngDatabaseSqliteEncrypted in lazy mode.</p>
@return MngDatabaseSqliteEncrypted<ResultSet> - MngDatabaseSqliteEncrypted
@throws Exception - an exception
189708
public final synchronized MngDatabaseSqliteEncrypted<ResultSet>
    lazyGetMngDatabaseSqliteEncrypted() throws Exception {
    String beanName = getMngDatabaseName();
    @SuppressWarnings("unchecked")
    MngDatabaseSqliteEncrypted<ResultSet> mngDatabaseSqlite =
      (MngDatabaseSqliteEncrypted<ResultSet>) getBeansMap().get(beanName);
    if (mngDatabaseSqlite == null) {
      mngDatabaseSqlite = new MngDatabaseSqliteEncrypted<ResultSet>();
      mngDatabaseSqlite.setFactoryAppBeans(this);
      mngDatabaseSqlite.setCryptoHelper(lazyGetCryptoHelper());
      File webAppDir = new File(getWebAppPath());
      mngDatabaseSqlite.setLogDir(webAppDir);
      mngDatabaseSqlite.setDatabaseDir(getWebAppPath());
      mngDatabaseSqlite.setDatabasePrefix("jdbc:sqlite:"
        + getWebAppPath() + File.separator);
      File backupDir = new File(webAppDir.getParent()
        + File.separator + "backup");
      if (!backupDir.exists() && !backupDir.mkdir()) {
        throw new Exception("Can't create directory: " + backupDir);
      }
      mngDatabaseSqlite.setBackupDir(backupDir.getPath());
      getBeansMap().put(beanName, mngDatabaseSqlite);
      lazyGetLogger().info(null, FactoryAccAppBeansSqlite.class, beanName
        + " has been created.");
    }
    return mngDatabaseSqlite;
  }
358321
protected function loadDatabaseConfig()
    {
        if (!$this->databaseConfigFile) {
            return null;
        }

        $configPath = "{$this->path}/{$this->databaseConfigFile}";
        if (file_exists($configPath)) {
            $this->databaseConfig = require $configPath;
        } else {
            throw new Exception("Unable to load database configuration.");
        }
    }
107654
public final MngSoftware lazyGetMngSoftware() throws Exception {
    String beanName = getMngSoftwareName();
    MngSoftware mngSoftware = (MngSoftware) this.beansMap.get(beanName);
    if (mngSoftware == null) {
      mngSoftware = new MngSoftware();
      mngSoftware.setLogger(lazyGetLogger());
      this.beansMap.put(beanName, mngSoftware);
      lazyGetLogger().info(null, AFactoryAppBeans.class, beanName
        + " has been created.");
    }
    return mngSoftware;
  }
957888
static synchronized SQLiteDatabase getDatabase() {
        if(sInstance == null) {
           throw new SprinklesNotInitializedException();
        }

        if(sDatabase == null) {
            DbOpenHelper dbOpenHelper = new DbOpenHelper(sInstance.mContext, sInstance.databaseName, sInstance.initialDatabaseVersion);
            sDatabase = dbOpenHelper.getWritableDatabase();
        }

        return sDatabase;
    }
975063
private function _loadDatabase()
    {
        if (!isset(self::$db[$this->name])) {
            $config = Config::config()->{$this->name};
            if(!is_array($config))
                throw new \Exception ($config . ' not a valid db config');
            // Load database
            $db = new Database($config);

            self::$db[$this->name] = $db;
            self::$prefix = isset($config['prefix']) ? $config['prefix'] : '';
        }

        return $this->getDb();
    }
244619
@Override
  public final synchronized PrepareDbAfterGetCopy
    lazyGetPrepareDbAfterFullImport() throws Exception {
    String beanName = getPrepareDbAfterFullImportName();
    PrepareDbAfterGetCopy prepareDbAfterGetCopy =
      (PrepareDbAfterGetCopy) getBeansMap().get(beanName);
    if (prepareDbAfterGetCopy == null) {
      prepareDbAfterGetCopy = new PrepareDbAfterGetCopy();
      prepareDbAfterGetCopy.setLogger(lazyGetLogger());
      prepareDbAfterGetCopy.setFactoryAppBeans(this);
      getBeansMap().put(beanName, prepareDbAfterGetCopy);
      lazyGetLogger().info(null, FactoryAccAppBeansSqlite.class, beanName
        + " has been created.");
    }
    return prepareDbAfterGetCopy;
  }
801607
public String getDatabase() {

        if (m_databaseKey == null) {
            m_databaseKey = getExtProperty("db.name");
        }
        if (CmsStringUtil.isEmpty(m_databaseKey)) {
            m_databaseKey = getSortedDatabases().get(0);
        }
        return m_databaseKey;
    }
598603
public function getSql()
    {
        if ($this->isEmpty()) {
            throw new Exception("Invalid segment, please specify a valid segment.");
        }
        $sql = '';
        $subExpression = false;
        foreach ($this->tree as $expression) {
            $operator = $expression[self::INDEX_BOOL_OPERATOR];
            $operand = $expression[self::INDEX_OPERAND];

            if ($operator == self::BOOL_OPERATOR_OR
                && !$subExpression
            ) {
                $sql .= ' (';
                $subExpression = true;
            } else {
                $sql .= ' ';
            }

            $sql .= $operand;

            if ($operator == self::BOOL_OPERATOR_AND
                && $subExpression
            ) {
                $sql .= ')';
                $subExpression = false;
            }

            $sql .= " $operator";
        }
        if ($subExpression) {
            $sql .= ')';
        }
        return array(
            'where' => $sql,
            'bind'  => $this->valuesBind,
            'join'  => implode(' ', $this->joins)
        );
    }
74810
protected function getAESKey()
    {
        if (empty($this->AESKey)) {
            throw new Exception("Configuration mission, 'aes_key' is required.");
        }

        if (strlen($this->AESKey) !== 43) {
            throw new Exception("The length of 'aes_key' must be 43.");
        }

        return base64_decode($this->AESKey . '=', true);
    }
1012443
public SQLAST parse() {
        ParseTree parseTree = SQLParserFactory.newInstance(databaseType, sql).execute().getChild(0);
        if (parseTree instanceof ErrorNode) {
            throw new SQLParsingUnsupportedException(String.format("Unsupported SQL of `%s`", sql));
        }
        Optional<SQLStatementRule> sqlStatementRule = parsingRuleRegistry.findSQLStatementRule(databaseType, parseTree.getClass().getSimpleName());
        if (sqlStatementRule.isPresent()) {
            return new SQLAST((ParserRuleContext) parseTree, sqlStatementRule.get());
        }
        if (parsingRuleRegistry instanceof EncryptParsingRuleRegistry) {
            return new SQLAST((ParserRuleContext) parseTree);
        }
        throw new SQLParsingUnsupportedException(String.format("Unsupported SQL of `%s`", sql));
    }
276607
public function getConnection()
    {
        $conn = mysqli_init();
        if ($this->encryption === true) {
            Logger::debug("Getting connection with encryption.");
            mysqli_ssl_set($conn, $this->sslKey, $this->sslCert, $this->sslCA, $this->sslCAPath, null);
            if ($this->port === null) {
                mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName);
            } else {
                mysqli_real_connect(
                    $conn,
                    $this->serverName,
                    $this->username,
                    $this->password,
                    $this->databaseName,
                    $this->port
                );
            }
        } elseif ($this->port === null) {
            mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName);
        } else {
            mysqli_real_connect(
                $conn,
                $this->serverName,
                $this->username,
                $this->password,
                $this->databaseName,
                $this->port
            );
        }
        return $conn;
    }
1186102
public static byte[] initKey() throws Exception{
		//密钥生成器
		KeyGenerator keyGen = KeyGenerator.getInstance("AES");
		//初始化密钥生成器
		keyGen.init(128);  //默认128，获得无政策权限后可用192或256
		//生成密钥
		SecretKey secretKey = keyGen.generateKey();
		return secretKey.getEncoded();
	}
913133
public function getDatabaseAdapter() {
        try {           
            if (isset($this->db)) {
                return $this->db;
            }
        
            $config = $this->reader->getDbsConfig();
            if (!isset($config['mysql']) 
                    || !isset($config['mysql']["username"]) 
                    || !isset($config['mysql']["password"]) 
                    || !isset($config['mysql']["host"]) 
                    || !isset($config['mysql']["database"]) ) {
                throw new Exception("Mysql config is not valid!");
            }
            
            $username = $config['mysql']["username"];
            $password = $config['mysql']["password"];
            $host = $config['mysql']["host"];
            $dbname = $config['mysql']["database"];
            
            $this->db = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
            $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            return $this->db;
        } catch (Exception $ex) {
            print("ERROR:>>>>>>>" . $ex->getMessage());
            throw new Exception("Faild to connect mysql db!");
        }
    }
1132302
@Override
  public final synchronized PrepareDbAfterGetCopy
    lazyGetPrepareDbAfterFullImport() throws Exception {
    String beanName = getPrepareDbAfterFullImportName();
    PrepareDbAfterGetCopy prepareDbAfterGetCopyMysql =
      (PrepareDbAfterGetCopy) getBeansMap().get(beanName);
    if (prepareDbAfterGetCopyMysql == null) {
      prepareDbAfterGetCopyMysql =
        new PrepareDbAfterGetCopy();
      prepareDbAfterGetCopyMysql.setLogger(lazyGetLogger());
      prepareDbAfterGetCopyMysql.setFactoryAppBeans(this);
      getBeansMap().put(beanName, prepareDbAfterGetCopyMysql);
      lazyGetLogger().info(null, FactoryAppBeansMysql.class, beanName
        + " has been created.");
    }
    return prepareDbAfterGetCopyMysql;
  }
915266
public function getSql() {
    $cacheKey = self::getCacheId($this->id);
    if (!isset($this->cachedSql[$cacheKey])) {
      $sql = trim((new Sql($this->getAdapter()))->buildSqlString($this));
      $this->cachedSql[$cacheKey] = $sql;
    }
    return $this->cachedSql[$cacheKey];
  }
687861
public String getFullDatabaseKey() {

        if (m_fullDatabaseKey == null) {
            m_fullDatabaseKey = getExtProperty("db.name") + "_sql";
        }
        if (CmsStringUtil.isEmpty(m_fullDatabaseKey) || m_fullDatabaseKey.equals("_sql")) {
            m_fullDatabaseKey = getSortedDatabases().get(0) + "_sql";
        }
        return m_fullDatabaseKey;
    }
392494
public static SQLService getInstance() throws Exception {
        if (_instance == null) {
            _instance = new SQLService();
            _instance.startServer();

            // default pool size is 20
            // can be overriden by env variable
            int dbPool = 20;
            if (Utils.getEnvironmentOptionValue(Constants.SYS_DATABASE_POOL_SIZE) != null) {
                dbPool = Integer.valueOf(Utils.getEnvironmentOptionValue(Constants.SYS_DATABASE_POOL_SIZE));
            }

            // initialize connection pool
            PoolProperties p = new PoolProperties();
            String connectString = "jdbc:h2:tcp://" + _instance.databaseHost + ":" + String.valueOf(_instance.port) + "/" +
                _instance.databaseName + "/proxydb;MULTI_THREADED=true;AUTO_RECONNECT=TRUE;AUTOCOMMIT=ON";
            p.setUrl(connectString);
            p.setDriverClassName("org.h2.Driver");
            p.setUsername("sa");
            p.setJmxEnabled(true);
            p.setTestWhileIdle(false);
            p.setTestOnBorrow(true);
            p.setValidationQuery("SELECT 1");
            p.setTestOnReturn(false);
            p.setValidationInterval(5000);
            p.setTimeBetweenEvictionRunsMillis(30000);
            p.setMaxActive(dbPool);
            p.setInitialSize(5);
            p.setMaxWait(30000);
            p.setRemoveAbandonedTimeout(60);
            p.setMinEvictableIdleTimeMillis(30000);
            p.setMinIdle(10);
            p.setLogAbandoned(true);
            p.setRemoveAbandoned(true);
            _instance.datasource = new DataSource();
            _instance.datasource.setPoolProperties(p);
        }
        return _instance;
    }