Grails as400 / iSeries Database generate - grails

Does anyone know if it's possible to autogenerate a database on the as400 / iSeries via the domain classes in a grails application as you can do for other DB's ? I can use existing tables via mappings but i'm trying to create a new app and it won't create new tables for me ..
My datasource ..
dbcreate = "create-drop"
username = "user"
password = "password"
driverClassName = "com.ibm.as400.access.AS400JDBCDriver"
url = "jdbc:as400://xxx.xxx.xxx.xxx;naming=system;libraries=,SAMPLEDB;date format=iso;prompt=false;translate binary=true"
dialect = "org.hibernate.dialect.DB2400Dialect"
But this just throws an error basically saying it can't find the files that i'm writing to via bootstrap .. Anyone know if it's possible ? .. Fwiw i'm on v5r4 of the os/400 OS - and yes I know it's old and not supported anymore ..
Thanks

Related

Connect to H2 database using IntelliJ database client

My Grails app uses a h2 database in dev mode (the default behaviour for Grails apps). The DB connection settings in DataSource.groovy are
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
I'm trying to setup a connection for this database using IntelliJ IDEA's database client tools. I start off creating the connection like so
Then in the following dialog, I enter the JDBC URL
And choose all available databases on the "Schemas & Tables" tab.
The "Test Connection" button indicates success, but as you can see from the red circle, no tables are found. It seems like I've correctly setup a connection to the h2 server, but not the schema itself.
BTW, I try to setup this connection once the app is running, so I'm sure that the schema/tables do actually exist.
Your configuration is for an h2:mem database. Memory Databases have no tables upon connecting to them, and any & all tables are lost when all the connections are closed. Furthermore, a (named) in memory database is unique to the JVM process that opens it. From the H2 documentation:
Sometimes multiple connections to the same in-memory database are required. In this case, the database URL must include a name. Example: jdbc:h2:mem:db1. Accessing the same database using this URL only works within the same virtual machine and class loader environment. (Emphasis added)
This means IDEA will create a unique devDb in its JVM (and classloader) space and your application will create a unique devDb in its JVM (and classloader) space. You can not connect to an in memory database from an external JVM process.
If you want to connect both your application and IntelliJ IDEA (or any other DB tool) to an H2 database at the same time, you will need to either
use an embedded database (that writes to a file) in your application and use Mixed Mode to allow IntelliJ IDEA (and/or other database tools) to connect to it
use a server mode database
See http://www.h2database.com/html/features.html#connection_modes for more information.
This article has a great write up on how to set up the IntelliJ database client to connect to an H2 in-memory database if you happen to be using Spring Boot: http://web.archive.org/web/20160513065923/http://blog.techdev.de/querying-the-embedded-h2-database-of-a-spring-boot-application/
Basically, you wrap the in-memory database with a tcp server, then you have an access point to connect with a sql client via remote access.
Try to open http://localhost:8080/dbconsole and fill your jdbc url
During development you can use grails h2 dbconsole
Let's imagine you've already created entities (Users, Addresses)
Step 1. In application.yml file add H2 properties.
server:
port: 8080
spring:
datasource:
url: jdbc:h2:~/data/parserpalce (for Mac OS)
username: sa
password: password
driver-class-name: org.h2.Driver
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
h2:
console:
enabled: true
Step 2. Add H2 Database client
Step 3. Configure H2 database client properties based on your application.yml properties.
Step 4. Run the application.
Step 5. Check if tables(Users, Addresses) are created.
Or you can use H2 console for it in browser:
http://localhost:8080/h2-console
P.S. Do not forget to paste appropriate values in fields!

grails external configuration values are not read

I want to use external configuration in my application. Along with it I use mail plugin and want to store its configuration in external .property file. I've chaged my Config.groovy so now it looks for external configuration under USER_HOME/.grails/APP_NAME-configuration.properties:
environments {
development {
grails.logging.jul.usebridge = true
if (new File("${userHome}/.grails/${appName}-config.properties").exists()) {
println "*** User defined config ***"
grails.config.locations = ["file:${userHome}/.grails/${appName}-config.properties"]
}
}
.....
}
As you can see there is if statement which tests is the configuration file exists. It exists so every time I see "* User defined config *" message when application starts.
I'm running application in development mode. After that configuration of my mail plugin goes:
grails {
mail {
host = grailsApplication.config['mail']['host']
port = grailsApplication.config['mail']['host']
username = grailsApplication.config['mail']['username']
password = grailsApplication.config['mail']['password']
props = ["mail.smtp.auth": "true",
"mail.smtp.socketFactory.port": "465",
"mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback": "false"]
}
}
When I tried to send a message with email plugin it appeared that configuration of email plugin is not initialized - username, password = null and host, port have default values (localhost and -1). So it seemed to me that config.properties file is simply not loaded. I decided to check if config.properties had been loaded and found out that grailsApplication.config object contained all properties that I'd defined in config.properties: mail.host, mail.port, mail.username, mail.password. I checked if it's possible to get corresponding properties using grailsApplication.config['property']['name'] expression (in debug mode). This expression gave proper values for all mail.host, mail.port, mail.username and mail.password. I also tried to use just grailsApplication.config['property.name'] (with one pair of brackets and '.') but this variant didn't work.
Can someone help me handle this situation? I've spent almost 3 trying different variants and still don't have a solution. Thank you.
You cannot load maps from .properties file. You should use .groovy file instead of .properties.
You can load configuration from external *.groovy file where you can have maps etc. create a file with contents below...
grails {
mail {
host = smtp.gmail.com
port = 465
username = username
password = password
props = ["mail.smtp.auth" : "true",
"mail.smtp.socketFactory.port" : "465",
"mail.smtp.socketFactory.class" : "javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback": "false"]
}
}
And use this in your config.groovy,
grails.config.locations = ["classpath:mail-config.groovy"]

Can I make a Grails web app using db2 jdbc driver not commit?

My situation: I work with a lot of RPG programmers who have created files on the IBM-i in a way that does not create a journal. I've created a Grails app which uses a db2 jdbc driver to connect to a file and update, insert, etc. I'm getting an error:
com.ibm.db2.jdbc.app.DB2DBException: MYFILE in MYLIB not valid for operation.
Cause . . . . . : The reason code is 3 . Reason codes are:
...blah blah blah...
3 -- MYFILE not journaled, no authority to the journal, or the journal state is *STANDBY. Files with an RI constraint action of CASCADE, SET NULL, or SET DEFAULT must be journaled to the same journal.
...blah blah blah...
I know that I could start journaling the file with STRJRNPF, but I'd rather not keep up with it (no scolding please). Is there a parameter for the db2 jdbc connection url that I can set to let it know not to try to commit?
Here's my current connection info:
dataSource
{
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
pooled = true
url = "jdbc:db2:*local;naming=system;libraries=LIBS;errors=full"
driverClassName = "com.ibm.db2.jdbc.app.DB2Driver"
username = "user"
password = "pass"
dialect = org.hibernate.dialect.DB2400Dialect.class
}
EDIT: Here is what I've tried:
url = "jdbc:db2:*local;naming=system;libraries=LIBS;errors=full;transaction isolation=none"
Finally, this did end up having to do with Grails/Hibernate. Here is what the datasource ended up looking like:
dataSource
{
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
pooled = true
url = "jdbc:db2:*local;naming=system;libraries=LIBS;errors=full;transaction isolation=none"
driverClassName = "com.ibm.db2.jdbc.app.DB2Driver"
username = "user"
password = "pass"
dialect = org.hibernate.dialect.DB2400Dialect.class
properties{
defaultTransactionIsolation = 0
}
}
Thanks to #Buck Calabro 's comments and this question.
What do you think "keep up with it" entails? By default, the system will do a lot of journal management for you. Welcome to IBM i. ;-)

Cannot connect to mysql from grails

I am using wamp server, it comes with mysql 5.5.16 and I am trying use the mysql from grails 1.3.7. In my Buildconfig.groovy file i have added "runtime 'mysql:mysql-connector-java:5.1.6'" under dependencies and my datasource.groovy looks like this:
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
url = "jdbc:mysql://localhost:3306/moviestore_dev"
}
but when i refresh dependencies or run the app, i get error=>
:: mysql#mysql-connector-java;5.1.6: not found
I can connect to the database but the data in the database remains as long as the app is running, the next time I run the app, all the data are gone !
I have no idea what is happening, please help !
Thanks
problem is in
dbCreate = "create-drop"
use
dbCreate = "update"
• create-drop: Drops and re-creates the database schema on each application load
• create: Creates the database on application load
• update: Creates and/or attempts an update to existing tables on application load
• [blank]: Does nothing

trouble viewing h2 db used in grails project

I'm trying to have a look at the tables generated in h2 db used in Grails project, but something's amiss.
I connect to the browser console at http://127.0.1.1:8082/ but all that's there to browse is INFORMATION_SCHEMA and Users. How do I get tho the tables used/generated by the app?
Just started building out the app and only few domain classes are in place and I'm trying to get a feel for working h2. Prior to that I've been using PostgreSql in all projects so this is very unnerving for the moment.
Thanks in advance
Are you using the right JDBC URL when logging in?
The default in grails is jdbc:h2:mem:devDB.
When an non-existing URL is given, like jdbc:h2:blabla, an empty database is created, with the default INFORMATION_SCHEMA and Users as you described.
Make sure you connect to the URL where your grails application stores its tables. You can find the URL in $GRAILS_PROJECT/config/DataSource.groovy, after the url definition.
environments {
development {
dataSource {
pooled = false
logSql = false
username = "sa"
password = ""
dialect = "com.hp.opr.hibernate.dialect.H2Dialect"
driverClassName = "org.h2.Driver"
dbCreate = "create-drop"
url = "jdbc:h2:mem:devDB;DB_CLOSE_DELAY=-1;MVCC=TRUE"
}
}
}
If you're using 2.0 the web console is enabled by default in dev mode and can be enabled in other environments: http://grails.org/doc/2.0.0.M2/guide/conf.html#databaseConsole
If you're not using 2.0 yet you can install the http://grails.org/plugin/dbconsole plugin or follow the link to my blog post and set it up yourself if you want to customize the url (or if you're using Grails pre-1.3.6 since the plugin has an artificial version restriction to 1.3.6+)
... so in datasource I changed the url to: url = "jdbc:h2:rswDb" (removing the 'mem' part and changing the name of the db). Then 3 db files showed up in the root dir of the project.
Next, in db console set the jdbc url to: jdbc url: jdbc:h2:~/work/web/rsw/rswDb
... and when I hit 'connect' all the tables were there!
Thanks again!

Resources