How to interpret grails datasource - grails

I am reading Grails in Action and it says to use
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:file:devDB;shutdown=true"
}
This causes an error when I run grails console: Unsupported connection setting "SHUTDOWN"
grails console works fine when I remove ;shutdown=true
What is shutdown=true meant to do?

This is described here: http://www.hsqldb.org/doc/guide/ch04.html
It's probably not useful for an in-memory database since it is lost when the web server stops anyway.

Related

HSQL server mode while connection from DatabaseSwingManager throws exception java.sql.SQLTransientConnectionException

I have written a java code of connecting to server mode
p.setProperty("server.database.3",
"file:G:/SERVERMODE/soamware;user=soamware;password=123#123");
p.setProperty("server.dbname.3", "soamware");
server.setProperties(p);
server.setLogWriter(null); // can use custom writer
server.setErrWriter(null); // can use custom writer
server.start();
try {
//Registering the HSQLDB JDBC driver
Class.forName("org.hsqldb.jdbc.JDBCDriver");
con = DriverManager.getConnection("jdbc:hsqldb:hsql://ip/soamware;
file:G:/SERVERMODE/soamware;user=soamware;password=123#123");
this code is working fine in netbeans with jdk8 and hsqldb2.5.1, however the console shows the build is not terminated and its still running. While when i connect to SwingDatabaseManager
with same url, username and password as mentioned in java code. It throws above mentioned exception. Kindly clarify also, why my program doesnt exit. I am not adding "server.shutdownCatalogs(1);" statement at end because then I cannot perform multiple operations in one session.
Because you are starting the server with only one database, you should set database.0 properties. You shouldn't use the # character at all on a connection string because it has a special meaning. You shouldn't use the file path when connecting to a server database. Use the dbname.0 value only. Edited code below:
p.setProperty("server.database.0", "file:G:/SERVERMODE/soamware;user=soamware;password=123x123");
p.setProperty("server.dbname.0", "soamware");
server.setProperties(p);
server.setLogWriter(null); // can use custom writer
server.setErrWriter(null); // can use custom writer
server.start();
try {
Class.forName("org.hsqldb.jdbc.JDBCDriver");
con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/soamware", "soamware", "123x123");

Grails 3.3.8 does not reload the changes made to the project

I have a project with grails 3.3.8, the problem is that once I edit a controller or a gsp file, the changes are not reflected in the web browser even though the following message appears when it detects a change:
Controller.groovy change, compiling...
I have tried to start the app in the following way:
grails -reloading run-app.
And also with:
// File: build.gradle
import grails.util.Environment
...
bootRun {
final Boolean reloadEnabled =
Boolean.valueOf(
System.properties[Environment.RELOAD_ENABLED])
if (reloadEnabled) {
systemProperty Environment.RELOAD_ENABLED, reloadEnabled
}
}
...
grails -Dgrails.env=custom -Dgrails.reload.enabled=true run-app
According to this link https://intellij-support.jetbrains.com/hc/en-us/community/posts/207602705-Grails-3-not-automatically-hot-swapping-changed-code-after-upgrading-to-2016-1-3 it appears that hot reloading of classes only suns to happen in grails 3.3.x when the environment is set to development.
I've not been able to confirm that for myself however. I notice you are providing "custom" as your environment. Maybe try changing it to the development environment and see if that helps.
Also just want to confirm that your not just seeing behaviour listed in Grails auto recompile never completes (Grails 3.3.6)

Tenanti "Undefined variable: Database"

I'm developing an application for multi tenant purpose, for this, I've used Orchestral/Tenanti but I'm experiencing the following problem.
I already performed some of the required steps for Multi Database Connection Setup.
Configuration Tenant Driver for Multiple Database: on my tenanti.php
Setting Default Database Connection: on my Tenant.php Middleware
Definition of my Tenants Connection: on my config/database.php
The problem becomes on the Database Connection Resolver step. In my Middleware I'm defining the connection to be used (I don't post the code because is not relevant for Tenanti use) which is correctly setted.
My resolver code is:
public function boot()
{
Tenanti::connection('tenants', function (User $entity, array $template) {
$template['database'] = "db_{$entity->getKey()}";
return $template;
});
}
This code is located on my AppServiceProvider. But my database to be used, is not correctly setted from my Resolver, throwing the following error:
ErrorException in MySqlConnector.php line 110:
Undefined variable: database
Clearly the error means that database is no setted.
Someone can help? Thanks in advance.
After many tests, I didn't find the solution using Tenanti, instead of that, I used Config class to set the database to use, and maintained my tenants configuration on database.php.
Config::set('database.connections.tenants.database', 'legal_'.$request->route()->parameter('account'));
Config::set('database.default', 'tenants');

Problems setting up Grails 2.3.5 App on Heroku with ClearDB

I am setting up a Grails 2.3.5 App on a Heroku Server and I keep getting the following error when tomcat starts up:
Caused by: java.sql.SQLException: Driver:com.mysql.jdbc.Driver#5a7359fe returned null for URL:jdbc:h2:mem:grailsDB;MVCC=TRUE;LOCK_TIMEOUT=10000
I am not using h2 as the Database. I would like to use ClearDB. My environment variables all look correct and everything looks correct in DataSource.groovy. I even setup the connection string to be hard coded to see if this would make a difference. Nada.
production {
datasource {
dbCreate = "create-drop"
url = "jdbc:mysql://us-cdbr-east-05.cleardb.net/heroku_5a952ab6aXXXXXXX?reconnect=true"
username = "XXXXX"
password = "xxxxx"
}
}
Obviously I'm missing something, but I cannot see what.
Where is the production setup getting the h2 connection string from?!
You don't show your full DataSource.groovy file, but it probably has the H2 driver in the top section (driverClassName = "org.h2.Driver"). The values there are the defaults, and the environment-specific blocks are merged into that to create the final settings. You can override that in the production block
production {
datasource {
dbCreate = "create-drop"
url = "jdbc:mysql://us-cdbr-east-05.cleardb.net/heroku_5a952ab6aXXXXXXX?reconnect=true"
username = "XXXXX"
password = "xxxxx"
driverClassName = 'com.mysql.jdbc.Driver'
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
}
}
Additionally, you should always specify the dialect when using MySQL. Grails auto-detects the dialect well in most cases, but can't determine if you're using MyISAM or InnoDB, so it defaults to a dialect that uses the default engine type configured for the whole server. Newer versions of MySQL default to InnoDB and it's easy to change it in any version, but if you don't or it's an older version you'll end up with non-transactional MyISAM tables. Specifying the dialect ensures that your app uses the proper table type.
I found out the reason for my problems.
The code block for data source has a lower case "s" in source. It should have been dataSource, not datasource.
When this block is missing, it appears the default is a h2 database with the name "grailsDB". I could not find this documented anywhere, hence all my confusion.
Check your cases!!!!

How to log sql in grails 1.3.7

I try to configure logs for sql in grails with logSql=true in datasource (test env) but nothing is displayed in test output.
I read this post but It's not working.
How to log SQL statements in Grails
Thanks
We did it in Config.groovy,
log4j = {
// ... whatever
debug 'org.hibernate.SQL',
'org.hibernate.transaction' // optionally
}
Log4j is configured differently since Grails 1.1.

Resources