Skip to content

Commit 7adbe50

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 39bc710 + e916495 commit 7adbe50

File tree

14 files changed

+169
-6
lines changed

14 files changed

+169
-6
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
JWS Object Relational Mapping
44
</p>
55

6+
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/JavaWebStack/ORM/Maven%20Deploy/master)
7+
![GitHub](https://img.shields.io/github/license/JavaWebStack/ORM)
8+
![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo.javawebstack.org%2Forg%2Fjavawebstack%2FORM%2Fmaven-metadata.xml)
9+
![GitHub contributors](https://img.shields.io/github/contributors/JavaWebStack/ORM)
10+
![Lines of code](https://img.shields.io/tokei/lines/github/JavaWebStack/ORM)
11+
![Discord](https://img.shields.io/discord/815612319378833408?color=%237289DA&label=discord)
12+
![Twitter Follow](https://img.shields.io/twitter/follow/JavaWebStack?style=social)
13+
614
## Introduction
715
When it came to using an ORM Lib in java I used ORMLite before. It worked quite well, but I didn't like the query builder.
816

@@ -11,7 +19,7 @@ Another thing was that I wanted to have control over the JDBC Wrapper to have a
1119
I finally decided to make an own ORM that fits my needs and here it is.
1220

1321
## Documentation
14-
Docs for version 2 will follow as soon as version 2 is fully stable.
22+
You can find the current docs on our [website](https://docs.javawebstack.org/framework/orm). This is a work-in-progress project though so it's not yet complete.
1523

1624
### Example usage
1725

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
<version>8.0.22</version>
5454
<scope>test</scope>
5555
</dependency>
56+
<dependency>
57+
<groupId>org.atteo</groupId>
58+
<artifactId>evo-inflector</artifactId>
59+
<version>1.2.2</version>
60+
</dependency>
5661
<dependency>
5762
<groupId>org.reflections</groupId>
5863
<artifactId>reflections</artifactId>

src/main/java/org/javawebstack/orm/TableInfo.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.javawebstack.orm;
22

3+
import org.atteo.evo.inflector.English;
34
import org.javawebstack.orm.annotation.*;
45
import org.javawebstack.orm.exception.ORMConfigurationException;
56
import org.javawebstack.orm.util.Helper;
@@ -45,10 +46,7 @@ public TableInfo(Class<? extends Model> model, ORMConfig config) throws ORMConfi
4546
Table table = model.getDeclaredAnnotationsByType(Table.class)[0];
4647
tableName = table.value();
4748
} else {
48-
tableName = Helper.toSnakeCase(model.getSimpleName());
49-
tableName += tableName.endsWith("ss") ? "es" : "s";
50-
if (tableName.endsWith("ys"))
51-
tableName = tableName.substring(0, tableName.length() - 2) + "ies";
49+
tableName = Helper.toSnakeCase(English.plural(model.getSimpleName()));
5250
}
5351
if (model.isAnnotationPresent(MorphType.class)) {
5452
morphType = model.getDeclaredAnnotationsByType(MorphType.class)[0].value();

src/test/java/org/javawebstack/orm/test/automigrate/DefaultSizeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class DefaultSizeTest extends ORMTestCase {
5656
final static String columnNameString = "string";
5757

5858
// Not renaming the table name as this is not focus of the test
59-
final static String tableNameCharArray = "just_char_arraies";
59+
final static String tableNameCharArray = "just_char_arrays";
6060
final static String columnNameCharArray = "char_array";
6161

6262
final static String tableNameDatatype = "datatypes";
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.javawebstack.orm.test.querybuilding;
2+
3+
import org.atteo.evo.inflector.English;
4+
import org.javawebstack.orm.Model;
5+
import org.javawebstack.orm.ORM;
6+
import org.javawebstack.orm.Repo;
7+
import org.javawebstack.orm.exception.ORMConfigurationException;
8+
import org.javawebstack.orm.test.ORMTestCase;
9+
import org.javawebstack.orm.test.shared.models.tablenames.*;
10+
import org.junit.jupiter.api.Test;
11+
12+
import static org.junit.jupiter.api.Assertions.assertFalse;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
15+
/**
16+
* The focus does not lie on a correct plural with this test, therefore we are only testing it sample-wise.
17+
* For tests see the library that is used in TableInfo: https://github.com/atteo/evo-inflector
18+
*/
19+
class FromClauseTest extends ORMTestCase {
20+
21+
@Test
22+
void testOneWordSAppendixPlural() throws ORMConfigurationException {
23+
String query = getBaseQuery(Word.class);
24+
assertTrue(query.contains("FROM `words`"));
25+
}
26+
27+
@Test
28+
void testTwoWordsBecomeSnakeCases() throws ORMConfigurationException {
29+
String query = getBaseQuery(TwoWord.class);
30+
assertTrue(query.contains("FROM `two_words`"));
31+
}
32+
33+
@Test
34+
void testThreeWordBecomeSnakeCases() throws ORMConfigurationException {
35+
String query = getBaseQuery(ThreeWordClass.class);
36+
assertTrue(query.contains("FROM `three_word_classes`"));
37+
}
38+
39+
@Test
40+
void testIrregularWordPlural() throws ORMConfigurationException {
41+
String query = getBaseQuery(Mouse.class);
42+
assertTrue(query.contains("FROM `mice`"));
43+
}
44+
45+
/*
46+
* Error / Not Closer Specified Cases
47+
*/
48+
@Test
49+
void testOneWordAlreadyInPluralDoesntWork() throws ORMConfigurationException {
50+
String query = getBaseQuery(Words.class);
51+
// Should try to find a non-sense plural and not map to itself as plural; for the purpose of
52+
// not breaking existing code
53+
assertFalse(query.contains("FROM `words`"));
54+
}
55+
56+
@Test
57+
void testOverwrittenTableName() throws ORMConfigurationException {
58+
String query = getBaseQuery(OverwritteTableName.class);
59+
assertTrue(query.contains("FROM `oVer_writtenValue`"));
60+
}
61+
62+
/*
63+
* Boiler Code Reduction Funtions
64+
*/
65+
66+
/**
67+
* Gets the generated base query for a model when only calling .query() on it.
68+
* @return
69+
*/
70+
private String getBaseQuery(Class<? extends Model> clazz) throws ORMConfigurationException {
71+
ORM.register(clazz, sql());
72+
return Repo.get(clazz).query().getQueryString().getQuery();
73+
}
74+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# General Remark About The Methodology used
2+
In the encapsulation via ´´ will be assumed. If this quotation is removed the SQL query can behave differently, which is why it must be a stable aspect.
3+
Also they are required to use reserved keyword.

src/test/java/org/javawebstack/orm/test/shared/models/OnlyIdModel.java

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.javawebstack.orm.test.shared.models.tablenames;
2+
3+
import org.javawebstack.orm.Model;
4+
import org.javawebstack.orm.annotation.Column;
5+
6+
/**
7+
* This class' name has an irregular plural (mice) and is here for this purpose.
8+
*/
9+
public class Mouse extends Model {
10+
@Column
11+
int id;
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.javawebstack.orm.test.shared.models.tablenames;
2+
3+
import org.javawebstack.orm.Model;
4+
import org.javawebstack.orm.annotation.Column;
5+
import org.javawebstack.orm.annotation.Table;
6+
7+
/**
8+
* This class overwrites the model name to a seemingly random word to test multiple cases at once.
9+
*/
10+
@Table("oVer_writtenValue")
11+
public class OverwritteTableName extends Model {
12+
@Column
13+
int id;
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Purposes of classes in this package
2+
3+
These classes are designed to cover different that can occur with the table names. For example - but not limited to:
4+
5+
- class with a single word name
6+
- class with irregular plural
7+
- class with an already plural name
8+
9+
10+
Since the focus is on their name they will usually only contain the - to date - required id field.

0 commit comments

Comments
 (0)