* @author Christoph Wurst * @author Joas Schilling * @author Jonny007-MKD <1-23-4-5@web.de> * @author Morris Jobke * @author Ole Ostergaard * @author Ole Ostergaard * @author Robin Appelman * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see * */ namespace OC\DB; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; /** * This handles the way we use to write queries, into something that can be * handled by the database abstraction layer. */ class Adapter { /** * @var \OC\DB\Connection $conn */ protected $conn; public function __construct($conn) { $this->conn = $conn; } /** * @param string $table name * * @return int id of last insert statement * @throws Exception */ public function lastInsertId($table) { return (int) $this->conn->realLastInsertId($table); } /** * @param string $statement that needs to be changed so the db can handle it * @return string changed statement */ public function fixupStatement($statement) { return $statement; } /** * Create an exclusive read+write lock on a table * * @param string $tableName * @throws Exception * @since 9.1.0 */ public function lockTable($tableName) { $this->conn->beginTransaction(); $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); } /** * Release a previous acquired lock again * * @throws Exception * @since 9.1.0 */ public function unlockTable() { $this->conn->commit(); } /** * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance * it is needed that there is also a unique constraint on the values. Then this method will * catch the exception and return 0. * * @param string $table The table name (will replace *PREFIX* with the actual prefix) * @param array $input data that should be inserted into the table (column name => value) * @param array|null $compare List of values that should be checked for "if not exists" * If this is null or an empty array, all keys of $input will be compared * Please note: text fields (clob) must not be used in the compare array * @return int number of inserted rows * @throws Exception * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 */ public function insertIfNotExist($table, $input, array $compare = null) { if (empty($compare)) { $compare = array_keys($input); } $query = 'INSERT INTO `' .$table . '` (`' . implode('`,`', array_keys($input)) . '`) SELECT ' . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? . 'FROM `' . $table . '` WHERE '; $inserts = array_values($input); foreach ($compare as $key) { $query .= '`' . $key . '`'; if (is_null($input[$key])) { $query .= ' IS NULL AND '; } else { $inserts[] = $input[$key]; $query .= ' = ? AND '; } } $query = substr($query, 0, -5); $query .= ' HAVING COUNT(*) = 0'; try { return $this->conn->executeUpdate($query, $inserts); } catch (UniqueConstraintViolationException $e) { // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it // it's fine to ignore this then // // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 return 0; } } /** * @throws \OCP\DB\Exception */ public function insertIgnoreConflict(string $table,array $values) : int { try { $builder = $this->conn->getQueryBuilder(); $builder->insert($table); foreach ($values as $key => $value) { $builder->setValue($key, $builder->createNamedParameter($value)); } return $builder->execute(); } catch (UniqueConstraintViolationException $e) { return 0; } } } >feature/vaadin8-book Vaadin 6, 7, 8 is a Java framework for modern Java web applications: https://github.com/vaadin/frameworkwww-data
aboutsummaryrefslogtreecommitdiffstats
blob: 64948471fec63b53004b6ee9c0325398ced44fa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
title: Creating a Project in NetBeans
order: 110
layout: page
---

[[getting-started.netbeans]]
= Creating a Project with the NetBeans IDE

In the following, we walk you through the creation of a Vaadin project in NetBeans and show how to run it.

Installation of NetBeans and the Vaadin plugin is covered in <<DUMMY/../../../framework/installing/installing-netbeans#installing.netbeans, "Installing the NetBeans IDE and Plugin">>.

Without the plugin, you can most easily create a Vaadin project as a Maven
project using a Vaadin archetype. You can also create a Vaadin project as a
regular web application project, but it requires many manual steps to install
all the Vaadin libraries, create the UI class, configure the servlet, create
theme, and so on.

[[getting-started.netbeans.creating]]
== Creating a Project

. Select "File > Net Project..." from the main menu or press kbd:[Ctrl+Shift+N].

. In the [guilabel]#New Project# window that opens, select the [guilabel]#Vaadin# category and one of the Vaadin archetypes from the right.
+
image::img/netbeans-newproject-1.png[width=80%, scaledwidth=100%]
+
The archetypes are described in more detail in <<getting-started-archetypes#getting-started.archetypes, "Overview of Maven Archetypes">>.

. In the [guilabel]#Name and Location# step, enter the project parameters.
+
image::img/netbeans-newproject-2.png[width=80%, scaledwidth=100%]

[guilabel]#Project Name#:: A project name.
The name must be a valid identifier that may only contains alphanumerics, minus, and underscore.
It is appended to the group ID to obtain the Java package name for the sources.

[guilabel]#Project Location#::
Path to the folder where the project is to be created.

[guilabel]#Group Id#:: A Maven group ID for your project.
It is normally your organization domain name in reverse order, such as `com.example`.
The group ID is also used as a prefix for the Java source package, so it should be Java-compatible package name.

[guilabel]#Version#:: Initial version of your application.
The number must obey the Maven version numbering format.

[guilabel]#Package#:: The Java package name to put sources in.

[guilabel]#Additional Creation Properties#::
The properties control various names.
They are specific to the archetype you chose.

+
Click [guibutton]#Finish#.

Creating the project can take a while as Maven loads all the needed
dependencies.

[[getting-started.netbeans.exploring]]
== Exploring the Project

The project wizard has done all the work for you: a UI class skeleton has been written to the [filename]#src# directory.
The project hierarchy shown in the Project Explorer is shown in <<figure.getting-started.netbeans.exploring>>.

[[figure.getting-started.netbeans.exploring]]
.A new Vaadin project in NetBeans
image::img/netbeans-created-annotated-hi.png[width=80%, scaledwidth=100%]

[filename]#mytheme#::
The theme of the UI.
See <<DUMMY/../../../framework/themes/themes-overview#themes.overview, "Themes">> for information about themes.

[filename]#MyUI.java#::
The UI class, which is the main entry-point of your application.
See <<DUMMY/../../../framework/application/application-overview#application.overview, "Server-Side Applications">> for information about the basic structure of Vaadin applications.

The Vaadin libraries and other dependencies are managed by Maven.
Notice that the libraries are not stored under the project folder, even though they are listed in the "Java Resources > Libraries > Maven Dependencies" virtual folder.

[[getting-started.netbeans.running]]
== Running the Application

Once created, you can run it in a server as follows.

. In [guilabel]#Projects# tab, select the project and click in the [guilabel]#Run Project# button in the tool bar (or press kbd:[F6]).

. In the [guilabel]#Select deployment server# window, select a server from the [guilabel]#Server# list.
It should show either GlassFish or Apache Tomcat or both, depending on what you chose in NetBeans installation.
+
image::img/netbeans-server.png[width=75%, scaledwidth=100%]
+
Also, select [guilabel]#Remember Permanently# if you want to use the same server also in future while developing applications.
+
Click [guibutton]#OK#.

The widget set will be compiled at this point, which may take a while.

If all goes well, NetBeans starts the server in port 8080 and, depending on your
system configuration, launches the default browser to display the web
application. If not, you can open it manually, for example, at
http://localhost:8080/myproject. The project name is used by default as the
context path of the application.

Now when you edit the UI class in the source editor and save it, NetBeans will automatically redeploy the application. After it has finished after a few seconds, you can reload the application in the browser.