DB connector

@param db
SQLiteDatabase object
767330
@Override
   public void onCreate(SQLiteDatabase db) {
      int pointer = context.getResources().getIdentifier(INIT_CREATE_SQL, "string", context.getPackageName());
      if (pointer == 0) {
         Log.e(TAG, "undefined sql id - " + INIT_CREATE_SQL);
      } else {
         String createTabelSql = context.getResources().getString(pointer);
         for (String sql : createTabelSql.split(";")) {
            db.execSQL(sql);
         }
      }
   }
799269
public void addDatabase(Database database)
    {
        this.getDatabaseList((database.getDatabaseType() & DBConstants.TABLE_MASK)).put(database.getDatabaseName(false), database);
    }
231124
@Override
    public DesignDocument getFromDatabase(CouchDbConnector db, String designDocumentId) {
    	return db.get(DesignDocument.class, designDocumentId);
    }
988121
private void checkAccess(Database database) {
        //
        //	Manage Access control
        //
        if (database.check_access && !database.isAccess_checked()) {
            database.access = checkAccessControl(database, database.devname, database.url);
            database.setAccess_checked(true);
            //	Initialize value.
            ApiUtil.getReconnectionDelay();
            //System.out.println(this + "." + database.deviceName + " -> " +
            //		((database.access==TangoConst.ACCESS_READ)? "Read" : "Write"));
        }
    }
294051
public void open() throws DBException
    {
        if (m_pDatabase == null)
        {
            PhysicalDatabaseParent pDBParent = null;
            Environment env = (Environment)this.getDatabaseOwner().getEnvironment();
            if (env != null)
                pDBParent = (PhysicalDatabaseParent)env.getPDatabaseParent(mapDBParentProperties, true);
            String databaseName = this.getDatabaseName(true);
            if (databaseName.endsWith(BaseDatabase.SHARED_SUFFIX))
                databaseName = databaseName.substring(0, databaseName.length() - BaseDatabase.SHARED_SUFFIX.length());
            else if (databaseName.endsWith(BaseDatabase.USER_SUFFIX))
                databaseName = databaseName.substring(0, databaseName.length() - BaseDatabase.USER_SUFFIX.length());
            char strPDatabaseType = this.getPDatabaseType();
            m_pDatabase = pDBParent.getPDatabase(databaseName, strPDatabaseType, false);
            if (m_pDatabase == null)
                m_pDatabase = this.makePDatabase(pDBParent, databaseName);
            m_pDatabase.addPDatabaseOwner(this);
        }
        m_pDatabase.open();
        
        super.open(); // Do any inherited
    }
44346
private void connect_to_dbase(final Connection connection) throws DevFailed {
		if (connection.device == null) {
	    	try {
                // Prepare the connection string
                final String db_corbaloc = "corbaloc:iiop:" + connection.url.host + ":"
                    + connection.url.strPort + "/database";
                // And connect to database.
                createDevice(connection, db_corbaloc);
                connection.classname = "Database";
 	    	} catch (final SystemException ex) {
				if (connection.transparent_reconnection) {
		    		try {
                        final DbRedundancy dbr = DbRedundancy.get_instance();
                        final String th2 = dbr.get(connection.url.host + ":" + connection.url.port);

                        // Prepare the connection string
                        final String db_corbaloc = "corbaloc:iiop:" + th2 + "/database";

                        // And connect to database.
                        createDevice(connection, db_corbaloc);
                        // System.out.println("Connected to " + db_corbaloc);
                    } catch (final SystemException e) {
                        // e.printStackTrace();
                        connection.device = null;
                        connection.ior = null;
                        Except.throw_connection_failed("TangoApi_DATABASE_CONNECTION_FAILED",
                            "Connection to database failed  !\n" + e, "connect_to_dbase("
                                + connection.url.host + "," + connection.url.strPort + ")");
 		    		}
				} else {
		    		// e.printStackTrace();
		    		connection.device = null;
		    		connection.ior = null;
    		    	Except.throw_connection_failed("TangoApi_DATABASE_CONNECTION_FAILED",
	    		    	"Connection to database failed  !\n" + ex, "connect_to_dbase("
		    		    	+ connection.url.host + "," + connection.url.strPort + ")");
				}
	    	}
		}
    }
159509
@Override
    protected Object openConnection() throws ConnectionException {
        try {
            String dataSource = getDataSource();
            if (dataSource == null)
                throw new ConnectionException("Missing attribute: " + JDBC_DATASOURCE);

            DatabaseAccess dbAccess = new DatabaseAccess(dataSource);
            dbAccess.openConnection();
            return dbAccess;
        }
        catch (Exception ex) {
            throw new ConnectionException(ConnectionException.CONNECTION_DOWN, ex.getMessage(), ex);
        }
    }
463971
@Override
   public DatabaseDataType toDatabaseDataType(final Database database) {
      final DatabaseDataType databaseDataType;
      if (database instanceof DerbyDatabase) {
         databaseDataType = new DatabaseDataType("VARCHAR(32672) FOR BIT DATA");
      } else if (database instanceof H2Database) {
         // User's wanting to use a BLOB can use modifySql.
         databaseDataType = new DatabaseDataType("BINARY");
      } else if (database instanceof OracleDatabase) {
         databaseDataType = new DatabaseDataType("SDO_GEOMETRY");
      } else if (database instanceof PostgresDatabase) {
         databaseDataType = new DatabaseDataType(getName(), getParameters());
      } else {
         databaseDataType = new DatabaseDataType("GEOMETRY");
      }
      return databaseDataType;
   }
57277
public static void setDbFile(final File dbFile, final String[] devices, final String className) throws DevFailed {
        DatabaseFactory.useDb = false;
        DatabaseFactory.fileDatabase = new FileTangoDB(dbFile, Arrays.copyOf(devices, devices.length), className);
    }
670091
public DataSource getDataSource(JdbcDatabase database)
    {
      com.mysql.jdbc.jdbc2.optional.MysqlDataSource dataSource = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource();
      this.setDatasourceParams(database, dataSource);
      return dataSource;
    }
886494
public void setDatabaseList(java.util.Collection<Database> databaseList) {
        if (databaseList == null) {
            this.databaseList = null;
            return;
        }

        this.databaseList = new java.util.ArrayList<Database>(databaseList);
    }
345656
@Override
	public void execute(SQLiteDatabase database, int previuosVersion, int currentVersion) {
		List<String> executionList=null;
	
		if (inputStream==null) {
			File f = new File(schemaDefinitionFile);
			executionList = SQLiteUpdateTaskHelper.readSQLFromFile(schemaDefinitionFile);
			Logger.info("Load DDL from " + f.getAbsolutePath());
		} else {
			executionList = SQLiteUpdateTaskHelper.readSQLFromFile(inputStream);
			Logger.info("Load DDL from stream");
		}
		
		for (String item : executionList) {
			Logger.info(item);
			database.execSQL(item);
		}

	}
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;
    }
1330708
private synchronized void open() throws DatabaseException {
        try {
            if (!isOpen()) {
                connection = connectionFactory.getConnection();
                final String databaseProductName = determineDatabaseProductName(this.connection);
                statementBundle = databaseProductName != null
                        ? ResourceBundle.getBundle("data/dbStatements", new Locale(databaseProductName))
                        : ResourceBundle.getBundle("data/dbStatements");
                prepareStatements();
                databaseProperties = new DatabaseProperties(this);
            }
        } catch (DatabaseException e) {
            releaseResources();
            throw e;
        }
    }
1190967
private void loadCategories(SQLiteDatabase db) throws UnknownPoiCategoryException {
        // Maximum ID (for root node)
        int maxID = 0;

        // Maps categories to their parent IDs
        Map<PoiCategory, Integer> parentMap = new HashMap<>();

        Cursor cursor = null;
        try {
            cursor = db.rawQuery(SELECT_STATEMENT, null);
            while (cursor.moveToNext()) {
                // Column values
                int categoryID = cursor.getInt(0);
                String categoryTitle = cursor.getString(1);
                int categoryParentID = cursor.getInt(2);

                PoiCategory pc = new DoubleLinkedPoiCategory(categoryTitle, null, categoryID);
                this.categoryMap.put(categoryID, pc);

                // category --> parent ID
                parentMap.put(pc, categoryParentID);

                // check for root node
                if (categoryID > maxID) {
                    maxID = categoryID;
                }
            }
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        } finally {
            try {
                if (cursor != null) {
                    cursor.close();
                }
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
            }
        }

        // Set root category and remove it from parents map
        this.rootCategory = getPoiCategoryByID(maxID);
        parentMap.remove(this.rootCategory);

        // Assign parent categories
        for (PoiCategory c : parentMap.keySet()) {
            c.setParent(getPoiCategoryByID(parentMap.get(c)));
        }
    }
986593
@Override
  public final void changeDatabase(final String pDbName) throws Exception {
    String dbNm = this.databasePrefix + pDbName + ".sqlite";
    synchronized (this.factoryAppBeans) {
      if (!this.factoryAppBeans.getDatabaseName().equals(dbNm)) {
        this.factoryAppBeans.setDatabaseName(dbNm);
        this.factoryAppBeans.handleDatabaseChanged();
      }
    }
  }
1265193
@SuppressWarnings("unchecked")
	private static void readDB(String dbName) {
        PersistenceManager pm = ZooJdoHelper.openDB(dbName);
        pm.currentTransaction().begin();

        //Extents are one way to get objects from a database:
        System.out.println("Person extent: ");
        Extent<Person> ext = pm.getExtent(Person.class);
        for (Person p: ext) {
            System.out.println("Person found: " + p.getName());
        }
        ext.closeAll();
        
        //Queries are more powerful:
        System.out.println("Queries: ");
        Query query = pm.newQuery(Person.class, "name == 'Bart'");
        Collection<Person> barts = (Collection<Person>) query.execute();
        for (Person p: barts) {
            System.out.println("Person found called 'Bart': " + p.getName());
        }
        query.closeAll();
        
        //Once an object is loaded, normal method calls can be used to traverse the object graph.
        Person bart = barts.iterator().next();
        System.out.println(bart.getName() + " has " + bart.getFriends().size() + " friend(s):");
        for (Person p: bart.getFriends()) {
            System.out.println(p.getName() + " is a friend of " + bart.getName());
        }
        
        
        pm.currentTransaction().commit();
        closeDB(pm);
    }