-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-9998 - Continue documentation TLC - mapping basic-types
- Loading branch information
Showing
31 changed files
with
911 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
457 changes: 432 additions & 25 deletions
457
documentation/src/main/docbook/mapping/en-US/chapters/basic/Basic_Types.xml
Large diffs are not rendered by default.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/Blob.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
create table step( | |||
... | |||
instruction BLOB not null, | |||
... | |||
) |
8 changes: 8 additions & 0 deletions
8
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/BlobLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
@Entity | |||
public class Step { | |||
... | |||
@Lob | |||
@Basic | |||
public Blob instructions; | |||
... | |||
} |
8 changes: 8 additions & 0 deletions
8
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/BlobMaterialized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
@Entity | |||
public class Step { | |||
... | |||
@Lob | |||
@Basic | |||
public byte[] instructions; | |||
... | |||
} |
5 changes: 5 additions & 0 deletions
5
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/Clob.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
create table product( | |||
... | |||
description CLOB not null, | |||
... | |||
) |
8 changes: 8 additions & 0 deletions
8
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/ClobLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
@Entity | |||
public class Product { | |||
... | |||
@Lob | |||
@Basic | |||
public Clob description; | |||
... | |||
} |
8 changes: 8 additions & 0 deletions
8
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/ClobMaterialized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
@Entity | |||
public class Product { | |||
... | |||
@Lob | |||
@Basic | |||
public String description; | |||
... | |||
} |
8 changes: 8 additions & 0 deletions
8
...ation/src/main/docbook/mapping/en-US/chapters/basic/extras/ClobMaterializedCharArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
@Entity | |||
public class Product { | |||
... | |||
@Lob | |||
@Basic | |||
public char[] description; | |||
... | |||
} |
53 changes: 53 additions & 0 deletions
53
...entation/src/main/docbook/mapping/en-US/chapters/basic/extras/EnumAttributeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
@Entity | |||
public class Person { | |||
... | |||
@Basic | |||
@Convert( converter=GenderConverter.class ) | |||
public Gender gender; | |||
} | |||
|
|||
public enum Gender { | |||
MALE( 'M' ), | |||
FEMALE( 'F' ); | |||
|
|||
private final char code; | |||
|
|||
private Gender(char code) { | |||
this.code = code; | |||
} | |||
|
|||
public char getCode() { | |||
return code; | |||
} | |||
|
|||
public static Gender fromCode(char code) { | |||
if ( code == 'M' || code == 'm' ) { | |||
return MALE; | |||
} | |||
if ( code == 'F' || code == 'f' ) { | |||
return FEMALE; | |||
} | |||
throw ... | |||
} | |||
} | |||
|
|||
@Converter | |||
public class GenderConverter | |||
implements AttributeConverter<Character,Gender> { | |||
|
|||
public Character convertToDatabaseColumn(Gender value) { | |||
if ( value == null ) { | |||
return null; | |||
} | |||
|
|||
return value.getCode(); | |||
} | |||
|
|||
public Gender convertToEntityAttribute(Character value) { | |||
if ( value == null ) { | |||
return null; | |||
} | |||
|
|||
return Gender.fromCode( value ); | |||
} | |||
} |
82 changes: 82 additions & 0 deletions
82
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/EnumCustomType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,82 @@ | |||
import org.hibernate.type.descriptor.java.CharacterTypeDescriptor; | |||
|
|||
@Entity | |||
public class Person { | |||
... | |||
@Basic | |||
@Type( type = GenderType.class ) | |||
public Gender gender; | |||
} | |||
|
|||
public enum Gender { | |||
MALE( 'M' ), | |||
FEMALE( 'F' ); | |||
|
|||
private final char code; | |||
|
|||
private Gender(char code) { | |||
this.code = code; | |||
} | |||
|
|||
public char getCode() { | |||
return code; | |||
} | |||
|
|||
public static Gender fromCode(char code) { | |||
if ( code == 'M' || code == 'm' ) { | |||
return MALE; | |||
} | |||
if ( code == 'F' || code == 'f' ) { | |||
return FEMALE; | |||
} | |||
throw ... | |||
} | |||
} | |||
|
|||
@Converter | |||
public class GenderType | |||
extends AbstractSingleColumnStandardBasicType<Gender> { | |||
|
|||
public static final GenderType INSTANCE = new GenderType(); | |||
|
|||
private GenderType() { | |||
super( | |||
CharTypeDescriptor.INSTANCE, | |||
GenderJavaTypeDescriptor.INSTANCE | |||
); | |||
} | |||
|
|||
public String getName() { | |||
return "gender"; | |||
} | |||
|
|||
@Override | |||
protected boolean registerUnderJavaType() { | |||
return true; | |||
} | |||
} | |||
|
|||
public static class GenderJavaTypeDescriptor | |||
extends AbstractTypeDescriptor<Gender> { | |||
public static final GenderJavaTypeDescriptor INSTANCE = new GenderJavaTypeDescriptor(); | |||
|
|||
public String toString(Gender value) { | |||
return value == null ? null : value.name(); | |||
} | |||
|
|||
public Gender fromString(String string) { | |||
return string == null ? null : Gender.valueOf( string ); | |||
} | |||
|
|||
public <X> X unwrap(Gender value, Class<X> type, WrapperOptions options) { | |||
return CharacterTypeDescriptor.INSTANCE.unwrap( | |||
value == null ? null : value.getCode(), | |||
type, | |||
options | |||
); | |||
} | |||
|
|||
public <X> Gender wrap(X value, WrapperOptions options) { | |||
return CharacterTypeDescriptor.INSTANCE.wrap( value, options ); | |||
} | |||
} |
11 changes: 11 additions & 0 deletions
11
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/EnumeratedOrdinal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
@Entity | |||
public class Person { | |||
... | |||
@Enumerated | |||
public Gender gender; | |||
|
|||
public static enum Gender { | |||
MALE, | |||
FEMALE | |||
} | |||
} |
11 changes: 11 additions & 0 deletions
11
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/EnumeratedString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
@Entity | |||
public class Person { | |||
... | |||
@Enumerated(STRING) | |||
public Gender gender; | |||
|
|||
public static enum Gender { | |||
MALE, | |||
FEMALE | |||
} | |||
} |
13 changes: 13 additions & 0 deletions
13
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/ExplicitColumnNaming.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
@Entity | |||
public class Product { | |||
@Id | |||
@Basic | |||
private Integer id; | |||
@Basic | |||
private String sku; | |||
@Basic | |||
private String name; | |||
@Basic | |||
@Column( name = "NOTES" ) | |||
private String description; | |||
} |
12 changes: 12 additions & 0 deletions
12
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/NCLOB_locator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
@Entity | |||
public class Product { | |||
... | |||
@Lob | |||
@Basic | |||
@Nationalized | |||
public NClob description; | |||
// Clob also works, because NClob | |||
// extends Clob. The db type is | |||
// still NCLOB either way and | |||
// handled as such | |||
} |
8 changes: 8 additions & 0 deletions
8
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/NCLOB_materialized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
@Entity | |||
public class Product { | |||
... | |||
@Lob | |||
@Basic | |||
@Nationalized | |||
public String description; | |||
} |
8 changes: 8 additions & 0 deletions
8
documentation/src/main/docbook/mapping/en-US/chapters/basic/extras/NVARCHAR.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
@Entity | |||
public class Product { | |||
... | |||
@Basic | |||
@Nationalized | |||
public String description; | |||
... | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
documentation/src/main/docbook/mapping/en-US/chapters/entity/Entity.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!-- | |||
~ Hibernate, Relational Persistence for Idiomatic Java | |||
~ | |||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. | |||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | |||
--> | |||
<chapter xml:id="entity" | |||
version="5.0" | |||
xml:lang="en" | |||
xmlns="http://docbook.org/ns/docbook" | |||
> | |||
<title>Entity</title> | |||
<para> | |||
* POJO, etc discussion from manual/en-US/chapters/domain/DomainModel.xml | |||
* dynamic models (hbm.xml) | |||
* Map mode | |||
* proxy solutions (hibernate-core/src/test/java/org/hibernate/test/dynamicentity/tuplizer2) | |||
* inheritance | |||
* optimistic locking | |||
</para> | |||
</chapter> |
Oops, something went wrong.