When generating code using JOOQ for a SQL Server database the generation creates three-part qualifiers like: [catalog].[schema].[table]. This is exactly what I want when working with the SQL Server databases but is an issue when using the generated code with another database like an H2 in memory database for unit testing.
The H2 dialect does not support these three-part qualifiers, H2 expects something like [catalog].[table]. This causes syntax errors when executing commands like the following against H2:
context.createTable(TBLBUSINESSENTITY).columns(TBLBUSINESSENTITY.fields()).execute();
To solve this I need to change the qualifier at runtime which I thought could be done using a render mapping and mapped schema. Unfortunately, this seems to only have the ability to modify the schema portion of the qualifier like this:
Settings settings = new Settings().withRenderMapping(new RenderMapping().withSchemata(
new MappedSchema().withInput("dbo").withOutput("mySchema")));
Given the qualifier [MyDatabase].[dbo].[MyTable], this maps to [MyDatabase].[mySchema].[MyTable] but I cant figure out how to remove that section entirely.
Is there some way to rewrite the mapping to [MyDatabase].[MyTable]?
Use this setting instead:
Settings settings = new Settings()
.withRenderCatalog(false)
.withRenderMapping(new RenderMapping()
.withCatalogs(new MappedCatalog()
.withInput("MyDatabase")
.withSchemata(new MappedSchema()
.withInput("dbo")
.withOutput("MyDatabase"))));
Related
I'm trying to create a query like:
INSERT INTO users (id, level)
VALUES (1, 0)
ON CONFLICT (id) DO UPDATE
SET level = users.level + 1;
However I can't see how to do this with opaleye? Is this not supported?
Strangely we have Insert defined with a field of iOnConflict :: Maybe OnConflict. However OnConflict is defined as: data OnConflict = DoNothing so it just looks like a placeholder for now?
Following through the issue listed on github, I see it leads to this eventual PR: https://github.com/tomjaguarpaw/haskell-opaleye/pull/385/files but I can't really make sense of it? I'm not sure if it's implementing just the placeholder, or it actually implements the functionality.
Firstly, you will generally get a quicker, and probably better, response to these kinds of questions if you
file a new issue on the Opaleye repo.
Opaleye currently only supports ON CONFLICT DO NOTHING. I'm happy to look into supporting more functionality though. Please chime in with a new issue or on a relevant existing one.
I recently changed my domain objects from LocalDate to ZonedDateTime. I also created a brand new play JHipster application and one play entity choosing ZonedDateTime for two class members. The test application (new) works while my existing application does not, even after going through all the code twice. I loaded CSV data using Liquibase and my listing code shows the dates properly. Here's what the data looks like in my Maven output, e.g. entrydate='2017-02-23T19:53:18-05:00[America/New_York]', transaction='Initial Balance',
When I choose to update the date-time value with the "datetime-picker" in the dialog.html, a string date time is shown in the text box but when I push "Save" I get an "Internal Server Error" and the Maven output shows:
.HttpMessageNotReadableException: Could not read document: Text '2017-02- 26T00:53:18.000Z' could not be parsed at index 23 (through reference chain: org.ciwise.blackhole.domain.GenLedger["entrydate"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Text '2017-02-26T00:53:18.000Z' could not be parsed at index 23 (through reference chain: org.ciwise.blackhole.domain.GenLedger["entrydate"])]
Does anyone have an idea why the picker would produce String text in the text box that isn't acceptable when the HTTP PUT occurs (edit)?
My application does use Service classes but they handle the same Java domain objects as the JPA Repository classes do.
One more thing, the schema for the API shows e.g. "entrydate": "2017-02-23T21:44:04.859Z", but the actual JSON return is "entrydate": "2017-02-23T19:53:18.000-0500",
I'm hoping someone else has encountered this before.
Thanks
David
The answer here was to re-introduce application.yml. Inside this file it defines some Spring profiles but of most importance, it provides an option for Jackson serialization into JSON e.g.
jackson:
serialization.write_dates_as_timestamps: false
This resolved my issue.
I have a reporting-based website using ServiceStack and OrmLite, using a SQL Server back-end. Due to the duration of some of the reports, I'd like to either globally, or selectively (via Service-derived class or some attribute) make queries that run reports have a longer CommandTimeout. I'd like to keep using the existing code to query data for the reports (Db.Select, Db.SqlList calls), so I won't have to write boiler-plate code in each reporting class & method.
I've tried using the AlwaysUseCommand, but that requires declaring a single command that has an open connection. I don't see how I can do that without opening the connection in my AppHost.Configure method and never closing it. It'd be nicer if it were a function pointer, but alas.
I've also looked at overriding the Db property of Service, but that just returns an open IDbConnection without letting me override command created.
It seems like my last option is to create a custom DbConnection class, like the MiniProfiler's ProfiledDbConnection, but I'd have to implement a dozen abstract methods. It seems like overkill in order to set one property on a DbCommand.
So, in ServiceStack.OrmLite, how do I globally modify the CommandTimeout of DbCommands that are created?
You can change the CommandTimeout globally with:
OrmLiteConfig.CommandTimeout = NewTimeoutInSeconds;
Scoped Timeout
You can also specify a Timeout for a particular db connection with:
using (var db = dbFactory.OpenDbConnection())
{
db.SetCommandTimeout(NewTimeoutInSeconds);
}
I would like to know, how should we execute the rules written in technical rule of IBM ODM.
I am using ODM V8.0.1. I have tried as below.
I created a XOM having class named Courier.java
public class Courier {
private String courierType;
private int distance;
with getters & setters
}
I created a rule project adding this XOM and created respective BOM.
I have added Courier Object as IN_OUT ruleset parameter with Name as "courier"
Then created a Technical Rule with below code
when {
cour : Courier();
}
then {
note("Courier Object Check is Satisfied");
}
Created a ruleflow having only one rule task pointing the above technical rule.
Then I run this ruleflow as
Run as --> Run Configuration
In Run Configuration dailog box, written below function to create courier object and
ran the configuration.
com.seldart.Courier cour= new com.seldart.Courier();
return cour;
Ruleflow execution went for 2 seconds but the statement in note() method has not
printed in the console.
I am not sure, whether rule flow has not picked the technical rule itself to run or courier object is not recognized ? Kindly guide me on executing this technical rule in right way. Thanks.
I think you have to explicitly add your courier ruleset parameter to the working memory, for instance in the Initial Action of the Start Node of your ruleflow.
For example, in IRL:
insert courier;
Simply, first of all create an action verbalization for your function in B2X. This way, it becames "visible" to all rule objects in your project and references.
Second, try to create an action rule and reference this new verbalization with it.
Third, create a rule flow to orchestrate this action rule.
To execute all this stuff try to simulate the ruleset or export and run the jar package with the ILOG/IBM JRules API.
Is there a way to use the orm factory to pull from a view instead of a table? I was hoping that the syntax would be equivalent to pulling from a table:
$buyers = ORM::factory('vbuyer'); //where vbuyers is the name of the view
This results in the error : ErrorException [ Fatal Error ]: Class 'Model_Vbuyer' not found
Unfortunately that doesn't seem to work. Can I have the orm map a view to a model, or do I have to use the DB::select('*')->from('vbuyers') approach?
EDIT: The problem was actually that the filename of the vbuyer model was incorrect, it had an underscore v_buyer. Removed the underscore and it worked.
EDIT: To answer the original question - yes, you can use the ORM factory to generate models based on database views. The problem in this case was unrelated, see above.