Same as {@link DB#withDb(String, Properties, Supplier)}, but with db name {@link DB#DEFAULT_NAME}.
355878
public static <T> T withDb(String driver, String url, Properties properties, Supplier<T> supplier) {
        return new DB(DB.DEFAULT_NAME).withDb(driver, url, properties, supplier);
    }
604859
@POST
    @Path("getDatabaseProductName")    
	public String getDatabaseProductName(String id) throws SQLException {
		return DatabaseMetaDataHolder.get().get(id).getDatabaseProductName();
	}
513135
public Database getDatabase(String strDBName, int iDatabaseType, Map<String, Object> properties)
    {
        return m_databaseCollection.getDatabase(strDBName, iDatabaseType, properties);
    }
285971
public Database getDatabase(String strDBName, int iDatabaseType, Map<String, Object> properties)
    {
        if ((strDBName == null) || (strDBName.length() == 0))
            return null;
        Database database = this.getDatabaseList(iDatabaseType).get(strDBName);
        if (database == null)
        {
            if ((properties != null)
            	&& (DBConstants.FALSE.equals(properties.get(DBConstants.CREATE_DB_IF_NOT_FOUND)))
            	&& (Environment.DATABASE_DOESNT_EXIST == ((Environment)m_databaseOwner.getEnvironment()).getCachedDatabaseProperties(strDBName)))
            		return null;	// Hey, if the database doesn't exist, don't try again.
            if (iDatabaseType != DBConstants.SCREEN)
                database = this.makeDatabase(iDatabaseType);    // BaseDatabase not found, open it!
            else
                database = new BaseDatabase();                  // Special case: A screen database
            if (database != null)
                database.init(m_databaseOwner, strDBName, iDatabaseType & DBConstants.TABLE_MASK, properties); // init it!
            if (database != null)
            {
                try   {
                    ((BaseDatabase)database).open();    // open it!
                } catch (DBException ex) {
                    database.free();
                    database = null;    // Failure on db open
                    if ((ex.getErrorCode() == DBConstants.DB_NOT_FOUND)
                		&& (properties != null)
                        && (DBConstants.FALSE.equals(properties.get(DBConstants.CREATE_DB_IF_NOT_FOUND))))
                    {	// If the db doesn't exist, cache the name so I won't try this (expensive) operation again
                        ((Environment)m_databaseOwner.getEnvironment()).cacheDatabaseProperties(strDBName, Environment.DATABASE_DOESNT_EXIST);
                    }
                }
            }
        }
        return database;
    }
834376
private DBService createDefaultDBService() {
        m_logger.info("Creating DBService for default tenant");
        String dbServiceName = ServerParams.instance().getModuleParamString("DBService", "dbservice");
        if (Utils.isEmpty(dbServiceName)) {
            throw new RuntimeException("'DBService.dbservice' parameter is not defined.");
        }

        DBService dbservice = null;
        Tenant defaultTenant = TenantService.instance().getDefaultTenant();
        boolean bDBOpened = false;
        while (!bDBOpened) {
            try {
                // Find and call the constructor DBService(Tenant).
                @SuppressWarnings("unchecked")
                Class<DBService> serviceClass = (Class<DBService>) Class.forName(dbServiceName);
                Constructor<DBService> constructor = serviceClass.getConstructor(Tenant.class);
                dbservice = constructor.newInstance(defaultTenant);
                dbservice.initialize();
                dbservice.start();
                bDBOpened = true;
            } catch (IllegalArgumentException e) {
                throw new RuntimeException("Cannot load specified 'dbservice': " + dbServiceName, e);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("Could not load dbservice class '" + dbServiceName + "'", e);
            } catch (NoSuchMethodException e) {
                throw new RuntimeException("Required constructor missing for dbservice class: " + dbServiceName, e);
            } catch (SecurityException | InstantiationException | IllegalAccessException e) {
                throw new RuntimeException("Could not invoke constructor for dbservice class: " + dbServiceName, e);
            } catch (InvocationTargetException e) {
                // This is thrown when a constructor is invoked via reflection.
                if (!(e.getTargetException() instanceof DBNotAvailableException)) {
                    throw new RuntimeException("Could not invoke constructor for dbservice class: " + dbServiceName, e);
                }
            } catch (DBNotAvailableException e) {
                // Fall through to retry.
            } catch (Throwable e) {
                throw new RuntimeException("Failed to initialize default DBService: " + dbServiceName, e);
            }
            if (!bDBOpened) {
                m_logger.info("Database is not reachable. Waiting to retry");
                try {
                    Thread.sleep(db_connect_retry_wait_millis);
                } catch (InterruptedException ex2) {
                    // ignore
                }
            }
        }
        return dbservice;
        
    }
867729
public static boolean registerJdbcDataSource(String name, DataSource dataSource) {
        return jdbcDataSources.putIfAbsent(name, dataSource) == null;
    }
652096
@NotNull
    public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbInt value) throws SQLException {
        return value == null ? setNull(name, JDBCType.INTEGER) : set(name, value.getDbValue());
    }
181732
String getDatabaseName(String dbName) {
        if (mFileNameMap == null) {
            return null;
        }
        String name = mFileNameMap.get(dbName);
        if (name == null && dbName != null) {
            name = mFileNameMap.get(null);
        }
        if (name == null) {
            return null;
        }
        if (mDatabaseHook != null) {
            try {
                dbName = mDatabaseHook.databaseName(dbName);
            } catch (IncompatibleClassChangeError e) {
                // Method not implemented.
            }
        }
        return dbName;
    }
943667
@Override
	public JdbcDatabaseDescriptor dbByName(final String dbName) {
		Collection<H2DatabaseWorking> select = CollectionUtils.select(dbsw, new Predicate<H2DatabaseWorking>() {

			@Override
			public boolean evaluate(H2DatabaseWorking db) {
				return dbName.equals( db.getName() );
			}

		});
		if(CollectionUtils.size(select)==0){
			throw new IllegalArgumentException("There are no databases called '" + dbName + "'");
		}
		if(CollectionUtils.size(select)>=2){
			throw new IllegalArgumentException("More than one database is called '" + dbName + "'");
		}
		return CollectionUtils.extractSingleton( select );
	}
538924
protected void initDatabase() throws NamingException, RepositoryException, IOException
   {
      DBInitializer dbInitializer = null;
      if (containerConfig.dbDialect.equals(DBConstants.DB_DIALECT_ORACLEOCI))
      {
         LOG.warn(DBConstants.DB_DIALECT_ORACLEOCI + " dialect is experimental!");

         this.connFactory = defaultConnectionFactory();
         dbInitializer = new OracleDBInitializer(this.connFactory.getJdbcConnection(), containerConfig);
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_ORACLE))
      {
         this.connFactory = defaultConnectionFactory();
         dbInitializer = new OracleDBInitializer(this.connFactory.getJdbcConnection(), containerConfig);
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_PGSQL))
      {
         this.connFactory = defaultConnectionFactory();
         dbInitializer = new PgSQLDBInitializer(this.connFactory.getJdbcConnection(), containerConfig);
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_MYSQL))
      {
         if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_MYSQL_MYISAM))
         {
            LOG.warn("MyISAM is not supported due to its lack of transaction support and integrity check, so use it only"
               + " if you don't expect any support and performances in read accesses are more important than the consistency"
               + " in your use-case. This dialect is only dedicated to the community.");
         }
         this.connFactory = new MySQLConnectionFactory(getDataSource(), containerConfig);
         dbInitializer = new MysqlDBInitializer(this.connFactory.getJdbcConnection(),containerConfig);
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_MSSQL))
      {
         this.connFactory = new MSSQLConnectionFactory(getDataSource(), containerConfig);
         dbInitializer=new MSSQLDBInitializer(this.connFactory.getJdbcConnection(),containerConfig);
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_DERBY))
      {
         this.connFactory = defaultConnectionFactory();
         dbInitializer = defaultDBInitializer();
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_DB2))
      {
         this.connFactory = defaultConnectionFactory();
         dbInitializer = new DB2DBInitializer(this.connFactory.getJdbcConnection(),containerConfig);
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_SYBASE))
      {
         this.connFactory = new SybaseConnectionFactory(getDataSource(), containerConfig);
         dbInitializer = new SybaseDBInitializer(this.connFactory.getJdbcConnection(),containerConfig);
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_INGRES))
      {
         this.connFactory = defaultConnectionFactory();
         dbInitializer = new IngresSQLDBInitializer(this.connFactory.getJdbcConnection(), containerConfig);
      }
      else if (containerConfig.dbDialect.startsWith(DBConstants.DB_DIALECT_HSQLDB))
      {
         this.connFactory = new HSQLDBConnectionFactory(getDataSource(), containerConfig);
         dbInitializer = new HSQLDBInitializer(this.connFactory.getJdbcConnection(),containerConfig);
      }
      else
      {
         // generic, DB_HSQLDB
         this.connFactory = defaultConnectionFactory();
         dbInitializer = defaultDBInitializer();
      }

      // database type
      try
      {
         dbInitializer.init();
      }
      catch (DBInitializerException e)
      {
         LOG.error("Error of init db " + e, e);
      }
   }
835144
public Map<String, Object> addDatabaseProperties(Map<String,Object> properties, DatabaseOwner databaseOwner)
    {
        Map<String,Object> oldProperties = databaseOwner.getProperties();
        if (properties != null)
        {   // Also move any application params up.
            for (String key : properties.keySet())
            {   // Move these params to the application
                if ((key.endsWith(BaseDatabase.DBSHARED_PARAM_SUFFIX))
            		|| (key.endsWith(BaseDatabase.DBUSER_PARAM_SUFFIX))
                    || (DBConstants.DB_USER_PREFIX.equals(key))
                        || (DBConstants.SYSTEM_NAME.equals(key)))
                {
                    if (oldProperties == databaseOwner.getProperties())
                    {   // Return the old properties
                        oldProperties = new HashMap<String,Object>();
                        oldProperties.putAll(databaseOwner.getProperties());
                    }
                    databaseOwner.setProperty(key, (String)properties.get(key));
                }
            }
        }
        return oldProperties;
    }
894601
function (DB_name, name, onDone, prefix) {

	//LOG.warn('init ' + DB_name + ' collection: ' + name, 'SR.DB');

	if (l_DBclient.hasOwnProperty(DB_name) === false) {
		LOG.error('DBclient not init or authenticated for DB [' + DB_name + ']', 'SR.DB');
		return UTIL.safeCall(onDone, false);
	}

	// check if already init
	if (l_getCollection(name, undefined, DB_name) !== undefined) {
		LOG.warn('DB [' + DB_name + '] collection [' + name + '] already loaded', 'SR.DB');
		LOG.warn('please check if different codes are using the same collection names', 'SR.DB');
		// NOTE: we assume double declaration of collection name is ok
		return UTIL.safeCall(onDone, true);
	}

	// build collection name to prefix with server name or a specified prefix
	var collection_name = (prefix || SR.Settings.SERVER_INFO.name) + ':' + name;

	// original simple version
	//var collection_name = name;

	l_DBclient[DB_name].collection(collection_name,
		function (err, collection) {
			if (err) {
				LOG.error(err, 'SR.DB');
				LOG.error('init DB [' + DB_name + ' ] collection [' + collection_name + '] error', 'SR.DB');
				UTIL.safeCall(onDone, false);
			} else {
				// store each name as a collection entry in collection object
				// collection name, instance(conn) , cache (idx by _id)
				var msg = 'init DB [' + DB_name + '] collection [' + collection_name + '] success';
				LOG.debug(msg, 'SR.DB');
				if (l_clts.hasOwnProperty(DB_name) === false) {
					l_clts[DB_name] = {};
				}

				// store collection instance into a two-level map
				l_clts[DB_name][name] = collection;

				// attach entity list to collection (for object caching)
				l_clts[DB_name][name].cache = {};

				UTIL.safeCall(onDone, true);
			}
		}
	);
}
999866
@Override
	public SqlContext param(final String paramName, final Supplier<Object> supplier) {
		return this.param(paramName, supplier != null ? supplier.get() : null);
	}
233007
private static String getTable(final Map<String, String> properties) {
		String table = properties.get("table");
		if (table == null) {
			throw new IllegalArgumentException("Name of database table is missing for JDBC writer");
		} else {
			return table;
		}
	}
773132
@Override
  public final void createDatabase(final String pDbName,
    final int pDbId) throws Exception {
    String dbNm = this.databasePrefix + pDbName + ".sqlite";
    synchronized (this.factoryAppBeans) {
      if (!this.factoryAppBeans.getDatabaseName().equals(dbNm)) {
        this.factoryAppBeans.setDatabaseName(dbNm);
        this.factoryAppBeans.setNewDatabaseId(pDbId);
        this.factoryAppBeans.handleDatabaseChanged();
      }
    }
  }
520632
@Override
	public String onTableName(String tableName) {
		if (onlyBindParameter)
			return null;

		if (currentSchema != null) {
			Finder<SQLProperty> finder = currentSchema.getEntityBySimpleName(tableName);
			AssertKripton.assertTrueOrUnknownClassInJQLException(finder != null, currentMethod, tableName);
			return finder.getTableName();
		} else {
			return null;
		}
	}
284121
public void setName(String name) {
		if (name == null) {
			throw new IllegalArgumentException("Field name cannot be null");
		}

		if (name.length() == 0 || name.length() > 10) {
			throw new IllegalArgumentException("Field name should be of length 0-10");
		}
		if (!DBFUtils.isPureAscii(name)) {
			throw new IllegalArgumentException("Field name must be ASCII");
		}
		this.name = name;
	}