# Class: Server

## jala.db.Server(baseDir, port, createOnDemand, makePublic, useSsl)

Instances of this class represent a H2 database listener that allows multiple databases to be accessed via tcp.
Important: You need the h2.jar in directory "lib/ext" of your helma installation for this library to work, which you can get at http://www.h2database.com/.

## Constructor

#### new Server(baseDir, port, createOnDemand, makePublic, useSsl)

Returns a new Server instance.

##### Parameters:

Name | Type | Description
--- | --- | ---
`baseDir` | helma.File | The directory where the database files are located or should be stored
`port` | Number | The port to listen on (defaults to 9001)
`createOnDemand` | Boolean | If true this server will create non-existing databases on-the-fly, if false it only accepts connections to already existing databases in the given base directory
`makePublic` | Boolean | If true this database is reachable from outside, if false it's only reachable from localhost
`useSsl` | Boolean | If true SSL will be used to encrypt the connection

Source:
  - jala/code/Database.js, line 234

##### Returns:

A newly created Server instance

### Methods

#### createOnDemand(bool)

If called with boolean true as argument, this server creates databases on-the-fly, otherwise it only accepts connections to already existing databases. This should be set before starting the server.

##### Parameters:

Name | Type | Description
--- | --- | ---
`bool` | Boolean | If true this server creates non-existing databases on demand, if false it only allows connections to existing databases. If no argument is given, this method returns the current setting.

Source:
  - jala/code/Database.js, line 387

##### Returns:

The current setting if no argument is given, or void

#### getConnection(name, username, password, props)

Returns a connection to a database within this server.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the database running within this server
`username` | String | Optional username to use for this connection
`password` | String | Optional password to use for this connection
`props` | Object | An optional parameter object containing connection properties to add to the connection Url.

Source:
  - jala/code/Database.js, line 466

##### Returns:

A connection to the specified database

#### getDirectory()

Returns the directory used by this server instance

Source:
  - jala/code/Database.js, line 273

##### Returns:

The directory where the databases used by this server are located in

#### getPort()

Returns the port this server listens on

Source:
  - jala/code/Database.js, line 282

##### Returns:

The port this server listens on

#### getProperties(name, username, password, props)

Returns a properties object containing the connection properties of the database with the given name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the database
`username` | String | Optional username to use for this connection
`password` | String | Optional password to use for this connection
`props` | Object | An optional parameter object containing connection properties to add to the connection Url.

Source:
  - jala/code/Database.js, line 446

##### Returns:

A properties object containing the connection properties

#### getUrl(name, props)

Returns the JDBC Url to use for connections to a given database.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | An optional name of a database running
`props` | Object | Optional connection properties to add

Source:
  - jala/code/Database.js, line 423

##### Returns:

The JDBC Url to use for connecting to a database within this sever

#### isPublic(bool)

If called with boolean true as argument, this server accepts connections from outside localhost. This should be set before starting the server.

##### Parameters:

Name | Type | Description
--- | --- | ---
`bool` | Boolean | If true this server accepts connections from outside localhost. If no argument is given, this method returns the current setting.

Source:
  - jala/code/Database.js, line 405

##### Returns:

The current setting if no argument is given, or void

#### isRunning()

Returns true if the database server is running.

Source:
  - jala/code/Database.js, line 354

##### Returns:

True if the database server is running

#### start()

Starts the database server.

Source:
  - jala/code/Database.js, line 300

##### Returns:

True in case the server started successfully, false otherwise

#### stop()

Stops the database server.

Source:
  - jala/code/Database.js, line 337

##### Returns:

True if stopping the server was successful, false otherwise

#### useSsl(bool)

Toggles the use of Ssl encryption within this server. This should be set before starting the server.

##### Parameters:

Name | Type | Description
--- | --- | ---
`bool` | Boolean | If true SSL encryption will be used, false otherwise. If no argument is given, this method returns the current setting.

Source:
  - jala/code/Database.js, line 367

##### Returns:

The current setting if no argument is given, or void