Cmobilecom JPA Examples
Cmobilecom JPA examples illustrate how to get started with Cmobilecom JPA for Java SE/EE and Android.

Preparations before running examples:
-------------------------------------

1. Start database server.
2. Create database empty schema: jpa_example_schema.
3. Create user (jpa_example_user) and password (123456).
4. Install gradle: version 7.6.1.

MySql is used by default. For a different database, change properties in
META-INF/persistence.xml according to the database, or pass -Ddbms command
line option.

Create a database schema and a user as followings:

1) MySql 8.0.x:

create database jpa_example_schema DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
create user 'jpa_example_user'@'localhost' identified by '123456';
grant all privileges on jpa_example_schema.* to 'jpa_example_user'@'localhost' with grant option;

2) Oracle XE 21c:

-- create user in PDB XEPDB1:
-- sqlplus: system/password@XEPDB1
grant CONNECT, RESOURCE, CREATE VIEW, UNLIMITED TABLESPACE to jpa_example_schema identified by 123456;

3) SQL Server Express 2022:

-- Sql server management studio: Enable Sql server authentication.
-- Sql server configuration manager: enable TCP/IP, port 1433.

create database jpa_example_db;
GO
use jpa_example_db;
exec('create schema jpa_example_schema');
create login jpa_example_login with password = '123456';
create user jpa_example_user for login jpa_example_login with DEFAULT_SCHEMA = jpa_example_schema;
EXEC sp_addrolemember 'db_owner', 'jpa_example_user';

4) Sqlite 3.41.x:

Database "build/jpa_example_schema" under current directory will be created automatically.
User and password are not needed, and there is no server to start.

5) Android API-level 33:

Database "jpa_example_schema" will be created automatically. User and password are not needed.

Run examples:
-------------

1. Java SE

   gradle wrapper
   gradlew run [-Ddbms=dbmsType]
   
   dbmsType: mysql, oracle, sqlserver, sqlite.
   
   For example,
   
   gradlew run    // default dbms: mysql
   gradlew run -Ddbms=oracle
   gradlew run -Ddbms=sqlserver
   gradlew run -Ddbms=sqlite
   
   Without -Ddbms option, configure JDBC properties in META-INF/persistence.xml
   for different databases.
   
2. Android

   cd android 
   gradle wrapper
   import project into Android Studio 2022.x, and run examples.
   
   Build and install APK from command line:
   
   1) set ANDROID_SDK_ROOT environment variable, or set sdk.dir in local.properties
   2) gradlew installDebug
      
3. Jakarta EE

   cd jakartaee
   gradle wrapper
   gradlew assemble
   deploy build/libs/cmobilecom-jpa-jakartaee-examples-@CMOBILECOM_JPA_VERSION@.ear
   
   Glassfish 5.1
   [glassfish_root_dir] is glassfish root directory, e.g., /opt/glassfish5/glassfish
   
   1) Copy a supported JDBC driver to [glassfish_root_dir]/domains/domain1/lib/ext
   
   2) Start glassfish:
   
      [glassfish_root_dir]/bin/asadmin start-domain --verbose
      
   3) Create a DataSource in glassfish admin web UI:
      http://localhost:4848

      create a JDBC connection pool.
      create a JDBC DataSource named "jdbc/CmobilecomJPAExampleDataSource" using the connection pool.
   
   4) Deploy EAR:
   
      copy build/libs/cmobilecom-jpa-jakartaee-examples-@CMOBILECOM_JPA_VERSION@.ear 
          [glassfish_root_dir]/domains/domain1/autodeploy/
          
   5) Make HTTP requests
   
      http://localhost:8080/cmobilecom-jpa-jakartaee-examples
      
Powered by Cmobilecom AF/JPA