Skip to content

Commit

Permalink
introducing new ThirdParty sample from https://github.com/krkodil/mORMot
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Dec 30, 2019
1 parent bf96abe commit 978cb42
Show file tree
Hide file tree
Showing 31 changed files with 1,422 additions and 1 deletion.
16 changes: 16 additions & 0 deletions SQLite3/Samples/ThirdPartyDemos/KroKodil/README.md
@@ -0,0 +1,16 @@
# mORMot
Java client for Synopse mORMot server

Java REST client for fantastic Synopse API. This client is focused to Interface based services.


Example usage:
<pre>
SynClient client = new SynClient("127.0.0.1", 8080, "service", false);
if (client.login("User", "synopse")) {
JSONArray params = new JSONArray().put(2).put(3); // Add(2, 3)
JSONObject response = client.call("Calculator.Add", params);
System.out.println("Summ: " + response);
client.logout();
}
</pre>
16 changes: 16 additions & 0 deletions SQLite3/Samples/ThirdPartyDemos/KroKodil/moRMOt.iml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.14.2" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20180813" level="project" />
</component>
</module>
28 changes: 28 additions & 0 deletions SQLite3/Samples/ThirdPartyDemos/KroKodil/pom.xml
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>groupId</groupId>
<artifactId>moRMOt</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>

<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.2</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>

</dependencies>

</project>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,31 @@
unit CalcInterface;

interface

uses FileCollect;

/// some common definitions shared by both client and server side

type
ICalculator = interface(IInvokable)
['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
function Add(n1,n2: integer): integer;
function GetFileList(path: String; out lst: TFlileCollection): Boolean;
end;

const
ROOT_NAME = 'root';
PORT_HTTP = '8080';
PORT_HTTPS = '8443';
APPLICATION_NAME = 'RestService';
SERVICE_NAME = 'service';

implementation

uses
mORMot;

initialization
// so that we could use directly ICalculator instead of TypeInfo(ICalculator)
TInterfaceFactory.RegisterInterfaces([TypeInfo(ICalculator)]);
end.
52 changes: 52 additions & 0 deletions SQLite3/Samples/ThirdPartyDemos/KroKodil/src/delphi/Client.dpr
@@ -0,0 +1,52 @@
{
Synopse mORMot framework
Sample 04 - HTTP Client-Server
purpose of this sample is to show HTTP Client/Server SQLite3 database usage:
- a TSQLSampleRecord class is defined in shared unit SampleData.pas
- this sample uses two projects, Project04Client.dpr and Project04Server.dpr
- a SQLite3 server is initialized in Project04Server
- the CreateMissingTables method will create all necessary tables in the
SQLite3 database
- one or more client instances can be run in Project04Client
- the purpose of the Client form in Unit1.pas is to add a record to the
database; the Time field is filled with the current date and time
- the 'Find a previous message' button show how to perform a basic query
- since the framework use UTF-8 encoding, we use some basic functions for
fast conversion to/from the User Interface; in real applications,
you should better use our SQLite3i18n unit and the corresponding
TLanguageFile.StringToUTF8() and TLanguageFile.UTF8ToString() methods
- note that you didn't need to write any SQL statement, only define a
class and call some methods; even the query was made very easy (just an
obvious WHERE clause to write)
- thanks to the true object oriented modeling of the framework, the same
exact Unit1 is used for both static in-memory database engine, or
with SQLite3 database storage, in local mode or in Client/Server mode:
only the TForm1.Database object creation instance was modified
- look at the tiny size of the EXE (even with SQLite3 engine embedded), less
than 400KB for the server, and 80KB for the client, with LVCL :)
Version 1.0 - February 07, 2010
Version 1.16
- added authentication to the remote process
}

program Client;

uses
Forms,
SysUtils,
ClientForm in 'ClientForm.pas' {Form1},
SampleData in 'SampleData.pas',
CalcInterface in 'CalcInterface.pas';

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Binary file not shown.
213 changes: 213 additions & 0 deletions SQLite3/Samples/ThirdPartyDemos/KroKodil/src/delphi/ClientForm.dfm
@@ -0,0 +1,213 @@
object Form1: TForm1
Left = 231
Top = 220
BorderStyle = bsSingle
ClientHeight = 397
ClientWidth = 966
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 16
object StatusBar1: TStatusBar
Left = 0
Top = 378
Width = 966
Height = 19
Panels = <>
SimplePanel = True
end
object Panel1: TPanel
Left = 0
Top = 51
Width = 966
Height = 327
Align = alBottom
BevelOuter = bvNone
Caption = 'Panel1'
TabOrder = 1
object Label1: TLabel
Left = 16
Top = 8
Width = 67
Height = 16
Caption = 'Your name:'
end
object Label2: TLabel
Left = 16
Top = 56
Width = 86
Height = 16
Caption = 'Your message:'
end
object lblA: TLabel
Left = 312
Top = 34
Width = 17
Height = 16
Caption = 'A='
end
object lblB: TLabel
Left = 312
Top = 66
Width = 16
Height = 16
Caption = 'B='
end
object lblResult: TLabel
Left = 604
Top = 72
Width = 184
Height = 16
Caption = 'Enter numbers, then Call Server'
end
object QuestionMemo: TMemo
Left = 16
Top = 72
Width = 257
Height = 193
TabOrder = 0
end
object NameEdit: TEdit
Left = 16
Top = 24
Width = 81
Height = 24
TabOrder = 1
end
object AddButton: TButton
Left = 16
Top = 280
Width = 145
Height = 25
Caption = 'Add the message'
TabOrder = 2
OnClick = AddButtonClick
end
object QuitButton: TButton
Left = 197
Top = 280
Width = 75
Height = 25
Caption = 'Quit'
TabOrder = 3
OnClick = QuitButtonClick
end
object FindButton: TButton
Left = 104
Top = 24
Width = 169
Height = 25
Caption = 'Find a previous message'
TabOrder = 4
OnClick = FindButtonClick
end
object edtA: TEdit
Left = 336
Top = 32
Width = 153
Height = 24
TabOrder = 5
Text = '2'
end
object edtB: TEdit
Left = 336
Top = 64
Width = 153
Height = 24
TabOrder = 6
Text = '3'
end
object btnCall: TButton
Left = 496
Top = 32
Width = 97
Height = 57
Caption = 'Call Server'
TabOrder = 7
OnClick = btnCallClick
end
object Button1: TButton
Left = 616
Top = 125
Width = 75
Height = 25
Caption = 'GetFileList'
TabOrder = 8
OnClick = Button1Click
end
object Edit1: TEdit
Left = 312
Top = 125
Width = 297
Height = 24
TabOrder = 9
Text = '.\'
end
object ListView1: TListView
Left = 312
Top = 155
Width = 625
Height = 151
Columns = <
item
Caption = 'Name'
Width = 200
end
item
Caption = 'Size'
Width = 90
end
item
Caption = 'Modified'
Width = 140
end
item
Caption = 'Version'
Width = 150
end>
TabOrder = 10
ViewStyle = vsReport
end
end
object Panel2: TPanel
Left = 8
Top = 8
Width = 361
Height = 41
BevelOuter = bvNone
Caption = 'Panel2'
TabOrder = 2
object txtUser: TEdit
Left = 8
Top = 9
Width = 121
Height = 24
TabOrder = 0
Text = 'User'
end
object txtPassword: TEdit
Left = 144
Top = 9
Width = 121
Height = 24
TabOrder = 1
Text = 'synopse'
end
object btnLogin: TButton
Left = 272
Top = 7
Width = 75
Height = 25
Caption = 'Login'
TabOrder = 2
OnClick = btnLoginClick
end
end
end

0 comments on commit 978cb42

Please sign in to comment.