PostgreSQL and Glassfish EJB__TIMER__TBL table - postgresql

I'm trying to use the timer service provided by Glassfish. Thus, I have to create a table named EJB__TIMER__TBL and configure jdbc resource in Glassfish.
I want to store this table on postgreSQL on a schema named glassfish. So my ddl is this one (I replace the BLOB type to BYTEA) :
CREATE SCHEMA glassfish;
CREATE TABLE glassfish.EJB__TIMER__TBL (
CREATIONTIMERAW BIGINT NOT NULL,
BLOB BYTEA,
TIMERID VARCHAR(255) NOT NULL,
CONTAINERID BIGINT NOT NULL,
OWNERID VARCHAR(255) NULL,
STATE INTEGER NOT NULL,
PKHASHCODE INTEGER NOT NULL,
INTERVALDURATION BIGINT NOT NULL,
INITIALEXPIRATIONRAW BIGINT NOT NULL,
LASTEXPIRATIONRAW BIGINT NOT NULL,
SCHEDULE VARCHAR(255) NULL,
APPLICATIONID BIGINT NOT NULL,
CONSTRAINT PK_EJB__TIMER__TBL PRIMARY KEY (TIMERID)
);
DROP ROLE IF EXISTS glassfish;
CREATE ROLE glassfish WITH NOINHERIT LOGIN PASSWORD '...';
REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA glassfish FROM glassfish;
REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA glassfish FROM glassfish;
GRANT USAGE ON SCHEMA glassfish TO glassfish;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA glassfish TO glassfish;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA glassfish TO glassfish;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA glassfish TO glassfish;
ALTER USER glassfish SET search_path to 'glassfish';
I configured a jdbc pool and resource for Glassfish :
asadmin create-jdbc-connection-pool
--datasourceclassname org.postgresql.ds.PGConnectionPoolDataSource
--restype javax.sql.ConnectionPoolDataSource
--property User=glassfish:Password=...:PortNumber=5432:DatabaseName=...:ServerName=localhost jdbc/simPool/glassfish
asadmin create-jdbc-resource --connectionpoolid jdbc/simPool/glassfish jdbc/sim/glassfish
And I properly enter jdbc/sim/glassfish in the jdbc resource to use for timer service in Glassish GUI.
Each time I deploy my app, I receive Exception :
[#|2013-02-18T11:42:42.562+0100|WARNING|glassfish3.1.2|org.eclipse.persistence.session.file
:/E:/softs/serveurs/glassfish3_1122/glassfish/domains/domain1/applications/ejb-timer-service-app/WEB-INF/classes/___EJB__Timer__App|_ThreadID=58;_ThreadName=Thread-2;|Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERREUR: la relation « EJB__TIMER__TBL » n'existe pas
Position : 193
Error Code: 0
Call: SELECT "TIMERID", "APPLICATIONID", "BLOB", "CONTAINERID", "CREATIONTIMERAW", "INITIALEXPIRATIONRAW", "INTERVALDURATION", "LASTEXPIRATIONRAW", "OWNERID", "PKHASHCODE", "SCHEDULE", "STATE" FROM "EJB__TIMER__TBL" WHERE (("OWNERID" = ?) AND ("STATE" = ?))
bind => [2 parameters bound]
Query: ReadAllQuery(name="findTimersByOwnerAndState" referenceClass=TimerState sql="SELECT "TIMERID", "APPLICATIONID", "BLOB", "CONTAINERID", "CREATIONTIMERAW", "INITIALEXPIRATIONRAW", "INTERVALDURATION", "LASTEXPIRATIONRAW", "OWNERID", "PKHASHCODE", "SCHEDULE", "STATE" FROM "EJB__TIMER__TBL" WHERE (("OWNERID" = ?) AND ("STATE" = ?))")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1717)
So my table EJB__TIMER__TBL doesn't seem to be accessible by Glassfish.
When I create another project, configure a persistence.xml file with the same credentials as my pooled connexion above and create a simple query SELECT COUNT(*) FROM EJB__TIMER__TBL, I receive 0 so my connexion is well established and the default schema accessed is glassfish as espected.
In ${glassfish_root}\glassfish\lib\install\databases there is some ddls but neither for postgresql...so where am I doing wrong ?
NB: when I test to configure service timer with MySQL jdbc resource, it's work...
Thanks for help

Ok I found the solution of my problem.
I didn't know that SQL can be case sensitive. Glassfish calls SELECT ... FROM "EJB__TIMER__TBL" with double quotes so I have to create a table named "EJB__TIMER__TBL" not "ejb__timer__tbl" or anything else.
The workaround is just to recreate my table with double quotes :
CREATE TABLE glassfish."EJB__TIMER__TBL" (
"CREATIONTIMERAW" BIGINT NOT NULL,
"BLOB" BYTEA,
"TIMERID" VARCHAR(255) NOT NULL,
"CONTAINERID" BIGINT NOT NULL,
"OWNERID" VARCHAR(255) NULL,
"STATE" INTEGER NOT NULL,
"PKHASHCODE" INTEGER NOT NULL,
"INTERVALDURATION" BIGINT NOT NULL,
"INITIALEXPIRATIONRAW" BIGINT NOT NULL,
"LASTEXPIRATIONRAW" BIGINT NOT NULL,
"SCHEDULE" VARCHAR(255) NULL,
"APPLICATIONID" BIGINT NOT NULL,
CONSTRAINT "PK_EJB__TIMER__TBL" PRIMARY KEY ("TIMERID")
);

Related

Laravel 8 Eloquent migration generated error " 1068 Multiple primary key defined"

I have the following migration file:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateHeadersTable extends Migration
{
public function up()
{
Schema::create('headers', function (Blueprint $table) {
$table->increments('entry')->unsigned();
$table->string('id',16);
$table->string('address',256);
$table->string('desciption',512)->nullable()->default('NULL');
$table->tinyInteger('currency',)->default('0');
$table->decimal('sum',13,4);
$table->datetime('entered');
$table->tinyInteger('aborted',)->default('0');
$table->primary('entry');
});
}
public function down()
{
Schema::dropIfExists('headers');
}
}
This file was automatically generated by an online tool from a SQL file. However, when I ran "php artisan migrate," I got the following error:
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'headers'
already exists (SQL: create table `headers` (`entry` int unsigned not null
auto_increment primary key, `id` varchar(16) not null, `address`
varchar(256) not null, `desciption` varchar(512) null default 'NULL',
`currency` tinyint not null default '0', `sum` decimal(13, 4) not null,
`entered` datetime not null, `aborted` tinyint not null default '0')
default character set utf8mb4 collate 'utf8mb4_unicode_ci')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
+9 vendor frames
10 database/migrations/2023_01_31_1675138133_create_headers_table.php:23
Illuminate\Support\Facades\Facade::__callStatic()
+22 vendor frames
33 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
I am not familiar with Laravel migration files. How can I fix this? Many thanks!
Do not drop the table manually. use php artisan migrate:rollback
and then re-try php artisan migrate
Error you got states that Table 'headers' already exists in database if you have deleted table from database just check their may be entry in migrations table in database just delete it and run migration again

Correct syntax for DbContext.Database.ExecuteSqlRaw()

I've been frustrating myself for too long trying to get the syntax for an Insert correct and am hoping someone can point out my error. I'm using EF Core 5.0.1.
I am trying to insert on the following table using raw SQL:
CREATE TABLE [dbo].[MyTable](
[MyTableId] [smallint] IDENTITY(1,1) NOT NULL,
[Description] [nvarchar](50) NOT NULL,
[UpdateDt] [datetime] NOT NULL,
[UpdateBy] [nvarchar](30) NOT NULL,
[CreateDt] [datetime] NOT NULL,
[CreateBy] [nvarchar](30) NOT NULL,
CONSTRAINT [PK_C_MyTable] PRIMARY KEY CLUSTERED
(
[MyTableId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
I've tried this:
dbContext.Database.ExecuteSqlRaw($"INSERT INTO MyTable(Description, UpdateDt, UpdateBy, CreateDt, CreateBy) VALUES(#Description, #UpdateDt, #UpdateBy, #CreateDt, #CreateBy)", new[] { "status description", "2021-01-17 10:47:45.760", "updater", "2021-01-17 10:47:45.760", "creator" });
I also tried this:
db.Database.ExecuteSqlRaw($"INSERT INTO MyTable (Description, UpdateDt, UpdateBy, CreateDt, CreateBy) VALUES(#Description, #UpdateDt, #UpdateBy, #CreateDt, #CreateBy)", "status description", "2021-01-17 10:47:45.760", "updater", "2021-01-17 10:47:45.760", "creator");
Running either of these gives me the following exception:
System.TypeInitializationException : The type initializer for 'MyClass' threw an exception.
---- Microsoft.Data.SqlClient.SqlException : Must declare the scalar variable "#Description".
I have a hunch I'm overlooking something that's going to make me want to slap my forehead later, but am hoping someone can see what I'm doing wrong.
dbContext.Database.ExecuteSqlRaw(
$"INSERT INTO MyTable(Description, UpdateDt, UpdateBy, CreateDt, CreateBy) VALUES({0}, {1}, {2}, {3}, {4})",
new[]
{
"status description", "2021-01-17 10:47:45.760", "updater", "2021-01-17 10:47:45.760", "creator"
});
This should work. The problem with your solution is that #description, #updatedDt doesn't work as a placeholder. Please follow this documentation here .

Knex cannot find table in Cloud SQL Postgres from Cloud Functions

I am trying to connect to a Postgres 12 DB running in Cloud SQL from a Cloud Function written in TypeScript.
I create the database with the following:
import * as Knex from "knex"
const { username, password, instance } = ... // username, password, connection name (<app-name>:<region>:<database>)
const config = {
client: 'pg',
connection: {
user: username,
password: password,
database: 'ingredients',
host: `/cloudsql/${instance}`,
pool: { min: 1, max: 1}
}
}
const knex = Knex(config as Knex.Config)
I am then querying the database using:
const query = ... // passed in as param
const result = await knex('tableName').where('name', 'ilike', query).select('*')
When I run this code, I get the following error in the Cloud Functions logs:
Unhandled error { error: select * from "tableName" where "name" ilike $1 - relation "tableName" does not exist
at Parser.parseErrorMessage (/workspace/node_modules/pg-protocol/dist/parser.js:278:15)
at Parser.handlePacket (/workspace/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/workspace/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.stream.on (/workspace/node_modules/pg-protocol/dist/index.js:10:42)
at Socket.emit (events.js:198:13)
at Socket.EventEmitter.emit (domain.js:448:20)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
I created the table using the following commands in the GCP Cloud Shell (then populated with a data from a CSV):
\connect ingredients;
CREATE TABLE tableName (name VARCHAR(255), otherField VARCHAR(255), ... );
In that console, if I run the query SELECT * FROM tableName;, I see the correct data listed.
Why does Knex not see the table: tableName, but the GCP Cloud Shell does?
BTW, I am definitely connecting to the correct db, as I see the same error logs in the Cloud SQL logging interface.
Looks like you are creating the table tableName without quoting, which makes it actually lower case (case insensitive). So when creating schema do:
CREATE TABLE "tableName" ("name" VARCHAR(255), "otherField" VARCHAR(255), ... );
or use only lower-case table / column names.

geoserver wfs-t is read-only exception

I am trying to save changes via WFS-T using GeoServer:
This is my code that is getting feature from geoserver
var sourceWFS = new ol.source.Vector({
loader: function (extent) {
$.ajax('http://127.0.0.1:8080/geoserver/kairosDB/ows', {
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'getFeature',
typename: 'wfs_geom',
srsname: 'EPSG:3857',
bbox: extent.join(',') + ',EPSG:3857'
}
}).done(function (response) {
sourceWFS.addFeatures(formatWFS.readFeatures(response));
});
},
// strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ()),
strategy: ol.loadingstrategy.bbox,
projection: 'EPSG:3857'
});
And This is code that is saving feature to server
var formatGML = new ol.format.GML({
featureNS: 'http://127.0.0.1:8080/geoserver/kairosDB',
featureType: 'wfs_geom',
srsName: 'EPSG:3857'
});
But When I saveFeature to server, This error's occured
2017-02-01 14:30:02,339 ERROR [geoserver.ows] -
org.geoserver.wfs.WFSTransactionException: {http://127.0.0.1:8080/geoserver/kairosDB}wfs_geom is read-only
at org.geoserver.wfs.Transaction.execute(Transaction.java:269)
at org.geoserver.wfs.Transaction.transaction(Transaction.java:106)
at org.geoserver.wfs.DefaultWebFeatureService.transaction(DefaultWebFeatureService.java:172)
at sun.reflect.GeneratedMethodAccessor195.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
wfs_geom table already has a primary key, create script:
CREATE TABLE public.wfs_geom
(
id bigint NOT NULL,
geometry geometry,
CONSTRAINT wfs_geom_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.wfs_geom
OWNER to postgres;
GRANT ALL ON TABLE public.wfs_geom TO postgres;
-- Index: sidx_wfs_geom
-- DROP INDEX public.sidx_wfs_geom;
CREATE INDEX sidx_wfs_geom
ON public.wfs_geom USING gist
(geometry)
TABLESPACE pg_default;
Could you help me?
This works like a charm: http://osgeo-org.1560.x6.nabble.com/Read-only-error-when-editing-a-WFS-T-td5284537.html
There is a rule in the "Data security" section that do allow to write
to this workspace for all, but the writing is not allowed to anonymous
user for all the workspace (..w) The strange behaviour is that in
yesterday I can edit the layer using a client.. and I do not
understand why, moreover using QGIS I cannot edit the layer, but QGIS
support the WFS-T
There are two things you need to change in GeoServer to makes this possible.
Enable Transactional under the WFS tab on GeoServer
Under the Data tab on GeoServer you need to edit the rule ..w to enable the role ROLE_ANONYMOUS
After doing these two things I was able to get rid of this error and post data to GeoServer.
Add a primary key constraint to the table.

symfony2 session storage with postgresql

I tried to store my session data into a postgresql database.
I have to precise that with the default session storage i've got any problem.
So i configure my config file as explained here :
http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html
session:
handler_id: session.handler.pdo
parameters:
pdo.db_options:
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
pdo:
class: PDO
arguments:
- "pgsql:dbname=%database_name%"
- %database_user%
- %database_password%
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
arguments: [#pdo, %pdo.db_options%]
and then when i clear the cache i got this error :
[PDOException]
SQLSTATE[08006] [7] FATAL: authentification peer ?chou?e pour l'utilisateur
here is my script used to create table session :
CREATE TABLE session
(
session_id character varying(255) NOT NULL,
session_value text NOT NULL,
session_time integer NOT NULL,
CONSTRAINT session_pkey PRIMARY KEY (session_id )
)
WITH (
OIDS=FALSE
);
ALTER TABLE session
OWNER TO myuser;
can't Anyone to help me ?
The PDO dsn is missing the host :
session:
handler_id: session.handler.pdo
parameters:
pdo.db_options:
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
pdo:
class: PDO
arguments:
- "pgsql:host=%database_host%;dbname=%database_name%"
- %database_user%
- %database_password%
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
arguments: [#pdo, %pdo.db_options%]
Without the host value, i had the same error as you :
[PDOException]
SQLSTATE[08006] [7] FATAL: Peer authentication failed for user "postgres"
Hope this helps