Set container name for a datasource devservice in quarkus? - containers

I have a test setup that starts 2 postgres devservices. With the default configuration, I am not able to differ the two running containers until I connect to them and have a look at the existing tables. I was looking for a property to configure the container name of a datasource devservice, but couldn't find any.
How can I set the container name of a datasource devservice in quarkus, so that I am apple to tell which is which?

Starting with Quarkus 2.15, a datasource labels is added to database related containers.
See this for more information.

Related

Debezium MySQL parameter table.exclude.list not working

I'm using Debezium and MySQL. In the database there is a table managed by the Flyway and I want to exclude it. I used the configurations below:
name=IRS-Connector
connector.class=io.debezium.connector.mysql.MySqlConnector
database.hostname=mysql
database.port=3306
database.user=user
database.password=user
database.allowPublicKeyRetrieval=true
database.server.name=irs-conn-v1
database.include.list=decider
database.exclude.list=register
database.history.kafka.bootstrap.servers=localhost:9092
database.history.kafka.topic=schema-changes.decider
table.exclude.list=flyway_schema_history
But when I'll see the topic irs-conn-v1.decider.flyway_schema_history had been created.
According the doc of the table.exclude.list option:
Each identifier is of the form databaseName.tableName.
So you need to append databaseName:
table.exclude.list=decider.flyway_schema_history

Spring Boot & Hibernate: MySQL TEXT with local h2 and Flyway

I am building a Spring Boot application which has several long texts in it's entities.
To ensure I can handle my database migrations well I included Flyway. In production I'm using a MySQL database, for local testing I want to implement the default h2 database.
An entity might have the following property
#Column(columnDefinition = "TEXT")
val startText: String?
For my MySQL database, this works fine and looks like this in my flyway schema:
start_text TEXT,
When I now start my tests with the default h2 in-memory database in Spring, I receive the following error:
Schema-validation: wrong column type encountered in column [start_text] in table [t_table]; found [clob (Types#CLOB)], but expecting [text (Types#VARCHAR)]
I understand that h2 does not support the MySQL specific type TEXT but actually I have no clue how to fix this.
Any help is appreciated.
Thank you.
I found a workaround for this.
In my application.yaml I have the following:
spring:
flyway:
placeholders:
text-datatype: 'TEXT' #defines a placeholder that is available in flyway
In my application.yaml in my test folder I have the following
spring:
flyway:
placeholders:
text-datatype: 'VARCHAR(255)'
Now I can use the placeholder in my Flyway scripts and it works fine:
start_text ${text-datatype}

jooq specify database runtime

I have the exact same database definition for multiple databases ( and database servers ). How do I tell Jooq to use the same database as the "Connection" I created to connect to the DB?
Example ( for MySQL ):
jdbc:mysql://localhost:3306/tsm - my development DB ( tsm ), used to generate code
jdbc:mysql://RemoteAmazonDBHost:3306/customer1 - one of my customers
jdbc:mysql://RemoteAmazonDBHost:3306/customer2 - Another customer
All 3 databases have the same definition, the same tables, indexes, etc. The TSM one is the standard our application uses.
Maybe I should be using DSL.using( Connection, Setting ) instead of DSL.using(Connection)? Is that what the manual is implying here?
If I only have one "Input" schema, do I have to specify it? In other words, can I do something like this:
Settings settings = new Settings()
.withRenderMapping(new RenderMapping()
.withSchemata(
new MappedSchema().withOutput(
databaseInfo.getProperties().getProperty("database.db"))));
Or do I have to do something like this:
Settings settings = new Settings()
.withRenderMapping(new RenderMapping()
.withSchemata(
new MappedSchema().withInput("TSM")
.withOutput(databaseInfo.getProperties().getProperty("database.db"))));
I'm assuming you're using code generation. In that case, it might be the easiest to not generate the schema at all but use <outputSchemaToDefault> in the code generation configuration, e.g.
<configuration>
<generator>
<database>
<inputSchema>your_codegen_input_schema_here</inputSchema>
<outputSchemaToDefault>true</outputSchemaToDefault>
</database>
</generator>
</configuration>
See the manual for details: https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-database/codegen-database-catalog-and-schema-mapping/
If you want to keep your generated code with schema qualification and map things at runtime, then your second attempt seems correct. Pass this to your Configuration (i.e. the DSL.using() call):
Settings settings = new Settings()
.withRenderMapping(new RenderMapping()
.withSchemata(new MappedSchema()
.withInput("TSM")
.withOutput(databaseInfo.getProperties().getProperty("database.db"))));
More details can be found here: https://www.jooq.org/doc/latest/manual/sql-building/dsl-context/custom-settings/settings-render-mapping

Connecting to different mysql schemas selected at runtime in a webserver using JPA EntityManagerFactory (JSE,EclipseLink,Tomcat), is it possible?

Is there a way to recreate an EntityManagerFactory already used in a webapplication at runtime? What I want is tell the entityManagerFactory to forget the last database connection and connect to a new schema at runtime when the webuser selects an other database (mysql schema). Or not forget the already used one but also use a new connection to a different mysql schema which was not used yet. These schemas have the exact same structure (tables, etc.) but for different users for security and other reasons. Is this possible?
I am using the Vaadin framework, Eclipselink 2.4.1, Mysql 5.5 and Tomcat 7. What I found related to my situation and what I tried already are followings. I am using an Eclipselink composite persistence unit, the second member is always the same, I want to change the first schema for example to "42_candidate" when the user selects the 42nd candidate on the webpage after an other schema was already connected like "41_candidate".
private static EntityManager createEntityManagerForCandidateSchema(String candidateSchemaName) throws javax.persistence.PersistenceException {
System.out.println("createEntityManagerForCandidateSchema called");
// set persistence unit properties
HashMap<String,String> candidatePuProps = new HashMap<String,String>();
candidatePuProps.put("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/"+candidateSchemaName+"?useUnicode=true&characterEncoding=UTF-8");
HashMap<String,Map> compositePuProps = new HashMap<String,Map>();
compositePuProps.put("election_model_candidate", candidatePuProps);
Map puProps = new HashMap();
puProps.put("eclipselink.logging.level", "FINEST");
puProps.put("eclipselink.composite-unit.properties", compositePuProps);
// puProps.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, "com.beharbe.ui.ElectionSessionCustomizer");
boolean candidateDatabaseSchemaNotFound = false;
try {
EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("election_composite_pu",puProps);
emf.close(); // to forget latest things
emf = javax.persistence.Persistence.createEntityManagerFactory("election_composite_pu",puProps);
EntityManager em = emf.createEntityManager(compositePuProps);
...
public void selectionChanged(int newCandidatePersonId) {
entityManager = Util.createEntityManagerForCandidateSchema(newCandidatePersonId);
...
(Eclipselink Composite PU)
wiki.eclipse.org/EclipseLink/UserGuide/sandbox/gelernter/Composite_Persistence_Units#Persistence_Unit_Properties
(Dynamic Persistence)
dev.eclipse.org/svnroot/rt/org.eclipse.persistence/branches/2.1/trunk/examples/jpa.employee/eclipselink.example.jpa.employee.dynamic/src/example/Main.java
(EclipseLink - How to configure Database Schema name at runtime)
www.rqna.net/qna/kxvmwy-jpa-eclipselink-how-to-configure-database-schema-name-at-runtime.html
(Eclipselink with Tomcat tutorial)
wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_Customizer
(Using JPAContainer with Hibernate (Vaadin))
vaadin.com/book/-/page/jpacontainer.hibernate.html
(How can I make a JPA application access different databases?)
stackoverflow.com/questions/9315593/how-can-i-make-a-jpa-application-access-different-databases
(Connect two or more databases dynamically)
stackoverflow.com/questions/9732750/connect-two-or-more-databases-dynamically?lq=1
(JPA - Using Multiple data sources to define access control)
www.rqna.net/qna/kqqihk-jpa-using-multiple-data-sources-to-define-access-control.html
JPA2 run-time database connection
JPA - EclipseLink - How to configure Database Schema name at runtime (Eclipselink SessionCustomizer)
Maybe I should do it somehow with the EclipseLink SessionCustomizer? (see latest link)
thanks for any help in advance
Meanwhile I found something, this can be what I have to use:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Auditing
I am trying this way but it still connects to the schema which was connected first when the EMF called first time:
....
candidatePuProps.put(PersistenceUnitProperties.JDBC_URL, "jdbc:mysql://localhost:3306/"+candidateSchemaName+"?useUnicode=true&characterEncoding=UTF-8");
candidatePuProps.put(PersistenceUnitProperties.EXCLUSIVE_CONNECTION_MODE, "Always");
candidatePuProps.put(PersistenceUnitProperties.EXCLUSIVE_CONNECTION_IS_LAZY, "false");
...
If you want to access two different databases/schemas, you can just call createEntityManagerFactory() passing a properties map with your new connection.
To set the schema with EclipseLink in code you can set the tableQualifier in a Customizer. To get a new EntityManagerFactory you can pass the "eclipselink.session-name" property.
Your code looks correct. What version of EclipseLink are you using?
Remove the composite persistence unit, I think you seem to just want to connect to a different database. Composite persistence units are for when you have relationships across databases.

Set database name dynamically in LINQ to SQL

I am using LINQ to SQL to connect to database from my application. When I am changing environment from production to staging, I can update my connection string in web.config.
But there is one more value I need to update when environment changes. That is database name. In LINQ to SQL designer file, database name is mentioned as attribute like-
[System.Data.Linq.Mapping.DatabaseAttribute(Name="somedbname")]
How can I pick up value of Name dynamically from some config file?
Any help is really appreciated.
as mentioned on the
http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.databaseattribute.name.aspx
"The DatabaseName is used only if the connection itself does not specify the database name."
so you can delete this attribute and all is gonna work fine!
I've used a wrapper class to provide a context along the lines of
public DataContext Context = new DataContext(SqlConnectionString); //much simplified
I fixed this problem by editing the .dbml file outside of Visual Studio (the designer doesn't seem to allow access to the DatabaseAttribute) and getting rid of the name property here:
<Database Name="BadName" Class="OutputDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
(note that the accepted answer is no longer correct: this attribute was overriding my connection string)