How do you configure Grails Datasources Plugin to have a schema search path on a datasource? - postgresql

I'm using Postgres and also the Datasources plugin.
Rails has a property called schema_search_path. Is there an equivalent in Grails?
I have two schemas, hk and public in the database.
Where can I specify a search path for the schema or a specific schema name?
I was able to make this work using the syntax like the following on the individual class.
static mapping = {
table name:'he_stats_item_summary_keywords', schema:'he'
}
However, it would still be nice to know if there was an equivalent to the schema_search_path on the datasource.

Possible solution found at:
PostgreSQL Default Schema in DataSource
Add support the hibernate.default_schema property to the _DataSource.groovy file
development {
dataSource {
dbCreate = "update"
url = "jdbc:postgresql://localhost:5432/deploy"
hibernate.default_schema = "turnkey_dev"
dialect = org.hibernate.dialect.PostgreSQLDialect
}
}

Related

Can DB2 DDL be generated using the IBM.Data.Db2 library

I'm new to Db2 and need to generate DDL for an existing table but don't have access to any tools. Is it possible to do this through the IBM.Data.DB2 library? I can get a datareader but only the field name is available. I work in a very restrictive environment hence the no tools statement. I don't know what operating system is used on the server. I'm a c#\vb.net developer and can execute commands of type text and stored procedures; however, creating stored procedures is very limited. I've done this sort of thing with Sql's SMO library but am not well versed with IBM.Data.DB2.
using (DB2Command dB2Command = new DB2Command($"SELECT * FROM {database}.{tableName}", dB2Connection))
{
dB2Command.CommandType = System.Data.CommandType.Text;
using (DB2DataReader dB2DataReader = dB2Command.ExecuteReader())
{
DataTable dataTable = dB2DataReader.GetSchemaTable();
foreach(DataRow dataRow in dataTable.Rows)
{
Console.WriteLine($"ColumnName: {dataRow.Field<string>("ColumnName")}\nColumnSize: {dataRow.Field<int>("ColumnSize").ToString()}\nNumericPrecision: { dataRow.Field<Int16>("NumericPrecision").ToString()}\nNumericScale: { dataRow.Field<Int16>("NumericScale").ToString()}\nDataType: {dataRow.Field<DbType>("ProviderType").ToString()}");
Console.WriteLine("");
}
}
}

How to filter documents in MongoDB and Spring boot

I am creating a Spring boot where I have "articulos" documents. I want to retrieve them from the DB depending on their fields value but I can not seem to achieve it with the examples I found in this website or anywhere else. This is because I see someone people use mongoTemplate which I assume is the interface class I have created for my repository but when I try to use that it says the method wasn't found.
This is what I am trying to do:
Query query = new Query();
query.addCriteria(Criteria.where("name").ne("Eric"));
List<Articulo> articulos = this.articuloRepository.find(query, Articulo.class);
articulosRepository is just and empty interface with all the annotations needed
Create the below repository method in ArticulosRepository
List<Articulo> findByNameNot(String name);
Use like
List<Articulo> articulos = this.articuloRepository.findByNameNot("Eric");
In your repository interface create a named query with your property like below if you have name in your document then method will be:
List<Articulo> articulos = findByName(String name);
Call this from your service by #Autowired repository.

Apply default mapping to mock Mongo domains in Grails unit test

I've started using the new mocking support in grails-datastore-gorm-mongodb. My app defaults domain mappings to use references when persisting relationships to mongodb. I need to find a way to get the mocked mongo to do the same thing. How do I apply the same default mapping in a unit test?
In Config.groovy, it looks like this:
// configure mongo to use dbrefs:
grails.mongo.default.mapping = {
'*'(reference: true)
}
Here's a sample of code that I currently use:
import spock.lang.*
import grails.test.mixin.mongodb.MongoDbTestMixin
import com.github.fakemongo.Fongo
#Mixin([MongoDbTestMixin])
class MySpec extends Specification {
def setup() {
mongoDomain(new Fongo("test").mongo, [ MyDomain ])
new MyDomain(name: 'domain').save(validate: false, flush: true)
}
}
How do I apply that config to this test code?
I'm using Grails 2.3.9 and mongodb 3.0.1 plugin.
Looks like MongoDbTestMixin offers a few flavors of the mongoDomain method:
mongoDomain(Mongo mongo, Collection<Class> persistentClasses) - Sets up a GORM for MongoDB domain for the given Mongo instance and domain classes
mongoDomain(Map config, Collection<Class> persistentClasses) - Sets up a GORM for MongoDB domain for the given configuration and domain classes
The 2nd option allows to pass a configuration map which allows to configure mongo to use dbrefs (otherwise an empty configuration is used, see MongoDbDataStoreSpringInitializer ). However this method does not allow you to pass the Fongo instance.
You can try to:
Ask the Grails team to add a method which combines both options (pull request?)
Extend MongoDbTestMixin or create your own mixin

TYPO3: Access old-style piBase methods from Extbase extension

Can I access old-style piBase classes and methods from my Extbase extension?
For example, can I create an AccessMyoldExtensionService.php Service as a wrapper class and then pull the return values into my controller?
In my case, I need to return a list of old data records that can't be migrated to MVC style directly.
If so, what would the basic approach be?
To get access on the db records of your old extension you can map the table into your new extension.
Create a new model with matching properties of the needed table fields.
Create the mapping in TS setup.txt like
persistence{
[...]
classes{
Tx_YourNewExtension_Domain_Model_Bar {
mapping {
tableName = tableNameOfOldExtension
}
}
}
}
Create the related repository.

Mapping to "pages" table from Extbase in TYPO3 6.1

I created an extension with a domain model Message. This model has a relation m:n with the TYPO3 pages (the one which has the details of the pages, like title, issite_root etc) table. However, by using the mapping to existing tables option, it gives me type error saying page :
The configured type field for table "pages" is of type int(11) unsigned
This means the type field can not be used for defining the record type.
You have to configure the mappings yourself if you want to map to this
table or extend the correlated class
So I just create the relation without mapping, so that I can later map it from setup.txt.
The I created model Pages in MyExt/Classes/Domain/Model/ with all the getters/setters and repository in MyExt/Classes/Domain/Repository/.
In my setup.txt I did this:
config.tx_extbase {
    persistence{
        enableAutomaticCacheClearing = 1
        updateReferenceIndex = 0
        classes {
        Tx_Playfield_Domain_Model_Pages {
            mapping {
                    tableName = pages
                columns {
                                uid.mapOnProperty               = uid
                                pid.mapOnProperty               = pid
                                sorting.mapOnProperty           = sorting
                                title.mapOnProperty             = title
                                subtitle.mapOnProperty          = subtitle
                            }
                }
            }
      }
    }
}
But when I try to access the Pages model I created,
var_dump($this->pagesRepository->findByUid(74));
its searching for tx_playfield_domain_model_pages which does not exists, it shows
Table 'typo3.tx_playfield_domain_model_pages' doesn't exist: SELECT tx_playfield_domain_model_pages.* FROM tx_playfield_domain_model_pages WHERE tx_playfield_domain_model_pages.uid = '74' LIMIT 1
What am I missing here?
Update
After following http://t3-developer.com/extbase-fluid/cheats-extbase/model/tabelle-pages-in-extbase/ suggested by #Michael I get an empty result from $this->pagesRepository->findByUid(74)
setup.txt is loading. I did this to check it:
plugin.tx_playfield{
settings{
temp=yes
}
}
And this is being accessed from my controller.
Is it possible that you didn't create the Pages domain model (within the extension builder or not at all)? The file my_ext/Classes/Domain/Model/Pages.php needs to exist. Check that your "Pages" domain model has the property Map to existing table set to pages, it should look like that:
I don't know where exactly your error is, but I did some more tinkering in the extension builder and made it work. You can probably find out by comparing your extension playfield to my temporary extension testfield: Download it here (updated).
Btw, you don't need to map properties that you do not want to be displayed in the frontend unless they are named differently.
mapping {
tableName = pages
columns {
title.mapOnProperty = title
subtitle.mapOnProperty = subtitle
}
}
I think you have to write the mapping with camel case letters (the class name). Although this post is in German, I think the code might help you. The author added some fields he is going to use to the class and also added a mapping in the typoscript of the extension (see the example code there). The most important part of the German text is that this example there was designed only to read from the db. If you want to create new pages using the model, you have (at least) to add the TCA and setters in the model class to make it work.