Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
07ed94ec
Commit
07ed94ec
authored
Sep 10, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[dev] gen oracle talble column is order by entity filed
parent
1e162c01
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
403 additions
and
5 deletions
+403
-5
PropertyContainer.java
...en/src/main/java/org/hibernate/cfg/PropertyContainer.java
+398
-0
Const.java
atms-gen/src/main/java/pwc/taxtech/Const.java
+1
-1
PeriodTaxRuleSettingOrganization.java
.../taxtech/vat/entity/PeriodTaxRuleSettingOrganization.java
+2
-2
application-mysql.yml
atms-gen/src/main/resources/application-mysql.yml
+1
-1
application-oracle.yml
atms-gen/src/main/resources/application-oracle.yml
+1
-1
No files found.
atms-gen/src/main/java/org/hibernate/cfg/PropertyContainer.java
0 → 100644
View file @
07ed94ec
package
org
.
hibernate
.
cfg
;
import
org.hibernate.AnnotationException
;
import
org.hibernate.MappingException
;
import
org.hibernate.annotations.ManyToAny
;
import
org.hibernate.annotations.Target
;
import
org.hibernate.annotations.Type
;
import
org.hibernate.annotations.common.reflection.XClass
;
import
org.hibernate.annotations.common.reflection.XProperty
;
import
org.hibernate.boot.jaxb.Origin
;
import
org.hibernate.boot.jaxb.SourceType
;
import
org.hibernate.cfg.annotations.HCANNHelper
;
import
org.hibernate.internal.CoreMessageLogger
;
import
org.hibernate.internal.util.StringHelper
;
import
org.jboss.logging.Logger
;
import
javax.persistence.Access
;
import
javax.persistence.ManyToMany
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.OneToMany
;
import
javax.persistence.OneToOne
;
import
javax.persistence.Transient
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
/**
* A helper class to keep the {@code XProperty}s of a class ordered by access type.
*
* @author Hardy Ferentschik
*/
class
PropertyContainer
{
//
// static {
// System.setProperty("jboss.i18n.generate-proxies", "true");
// }
private
static
final
CoreMessageLogger
LOG
=
Logger
.
getMessageLogger
(
CoreMessageLogger
.
class
,
PropertyContainer
.
class
.
getName
());
/**
* The class for which this container is created.
*/
private
final
XClass
xClass
;
private
final
XClass
entityAtStake
;
/**
* Holds the AccessType indicated for use at the class/container-level for cases where persistent attribute
* did not specify.
*/
private
final
AccessType
classLevelAccessType
;
private
final
LinkedHashMap
<
String
,
XProperty
>
persistentAttributeMap
;
PropertyContainer
(
XClass
clazz
,
XClass
entityAtStake
,
AccessType
defaultClassLevelAccessType
)
{
this
.
xClass
=
clazz
;
this
.
entityAtStake
=
entityAtStake
;
if
(
defaultClassLevelAccessType
==
AccessType
.
DEFAULT
)
{
// this is effectively what the old code did when AccessType.DEFAULT was passed in
// to getProperties(AccessType) from AnnotationBinder and InheritanceState
defaultClassLevelAccessType
=
AccessType
.
PROPERTY
;
}
AccessType
localClassLevelAccessType
=
determineLocalClassDefinedAccessStrategy
();
assert
localClassLevelAccessType
!=
null
;
this
.
classLevelAccessType
=
localClassLevelAccessType
!=
AccessType
.
DEFAULT
?
localClassLevelAccessType
:
defaultClassLevelAccessType
;
assert
classLevelAccessType
==
AccessType
.
FIELD
||
classLevelAccessType
==
AccessType
.
PROPERTY
;
this
.
persistentAttributeMap
=
new
LinkedHashMap
<
String
,
XProperty
>();
final
List
<
XProperty
>
fields
=
xClass
.
getDeclaredProperties
(
AccessType
.
FIELD
.
getType
());
final
List
<
XProperty
>
getters
=
xClass
.
getDeclaredProperties
(
AccessType
.
PROPERTY
.
getType
());
getters
.
sort
(
new
Comparator
<
XProperty
>()
{
@Override
public
int
compare
(
XProperty
o1
,
XProperty
o2
)
{
return
getProperty
(
fields
,
o1
)
-
getProperty
(
fields
,
o2
);
}
});
preFilter
(
fields
,
getters
);
final
LinkedHashMap
<
String
,
XProperty
>
persistentAttributesFromGetters
=
new
LinkedHashMap
<
String
,
XProperty
>();
collectPersistentAttributesUsingLocalAccessType
(
persistentAttributeMap
,
persistentAttributesFromGetters
,
fields
,
getters
);
collectPersistentAttributesUsingClassLevelAccessType
(
persistentAttributeMap
,
persistentAttributesFromGetters
,
fields
,
getters
);
}
private
int
getProperty
(
List
<
XProperty
>
fields
,
XProperty
property
)
{
for
(
int
i
=
0
;
i
<
fields
.
size
();
i
++)
{
if
(
fields
.
get
(
i
).
getName
().
equals
(
property
.
getName
()))
return
i
;
}
throw
new
RuntimeException
(
"not found field for property ["
+
fields
.
toString
()
+
":"
+
property
.
getName
()
+
"]"
);
}
private
void
preFilter
(
List
<
XProperty
>
fields
,
List
<
XProperty
>
getters
)
{
Iterator
<
XProperty
>
propertyIterator
=
fields
.
iterator
();
while
(
propertyIterator
.
hasNext
())
{
final
XProperty
property
=
propertyIterator
.
next
();
if
(
mustBeSkipped
(
property
))
{
propertyIterator
.
remove
();
}
}
propertyIterator
=
getters
.
iterator
();
while
(
propertyIterator
.
hasNext
())
{
final
XProperty
property
=
propertyIterator
.
next
();
if
(
mustBeSkipped
(
property
))
{
propertyIterator
.
remove
();
}
}
}
private
void
collectPersistentAttributesUsingLocalAccessType
(
LinkedHashMap
<
String
,
XProperty
>
persistentAttributeMap
,
LinkedHashMap
<
String
,
XProperty
>
persistentAttributesFromGetters
,
List
<
XProperty
>
fields
,
List
<
XProperty
>
getters
)
{
// Check fields...
Iterator
<
XProperty
>
propertyIterator
=
fields
.
iterator
();
while
(
propertyIterator
.
hasNext
())
{
final
XProperty
xProperty
=
propertyIterator
.
next
();
final
Access
localAccessAnnotation
=
xProperty
.
getAnnotation
(
Access
.
class
);
if
(
localAccessAnnotation
==
null
||
localAccessAnnotation
.
value
()
!=
javax
.
persistence
.
AccessType
.
FIELD
)
{
continue
;
}
propertyIterator
.
remove
();
persistentAttributeMap
.
put
(
xProperty
.
getName
(),
xProperty
);
}
// Check getters...
propertyIterator
=
getters
.
iterator
();
while
(
propertyIterator
.
hasNext
())
{
final
XProperty
xProperty
=
propertyIterator
.
next
();
final
Access
localAccessAnnotation
=
xProperty
.
getAnnotation
(
Access
.
class
);
if
(
localAccessAnnotation
==
null
||
localAccessAnnotation
.
value
()
!=
javax
.
persistence
.
AccessType
.
PROPERTY
)
{
continue
;
}
propertyIterator
.
remove
();
final
String
name
=
xProperty
.
getName
();
// HHH-10242 detect registration of the same property getter twice - eg boolean isId() + UUID getId()
final
XProperty
previous
=
persistentAttributesFromGetters
.
get
(
name
);
if
(
previous
!=
null
)
{
throw
new
org
.
hibernate
.
boot
.
MappingException
(
LOG
.
ambiguousPropertyMethods
(
xClass
.
getName
(),
HCANNHelper
.
annotatedElementSignature
(
previous
),
HCANNHelper
.
annotatedElementSignature
(
xProperty
)
),
new
Origin
(
SourceType
.
ANNOTATION
,
xClass
.
getName
())
);
}
persistentAttributeMap
.
put
(
name
,
xProperty
);
persistentAttributesFromGetters
.
put
(
name
,
xProperty
);
}
}
private
void
collectPersistentAttributesUsingClassLevelAccessType
(
LinkedHashMap
<
String
,
XProperty
>
persistentAttributeMap
,
LinkedHashMap
<
String
,
XProperty
>
persistentAttributesFromGetters
,
List
<
XProperty
>
fields
,
List
<
XProperty
>
getters
)
{
if
(
classLevelAccessType
==
AccessType
.
FIELD
)
{
for
(
XProperty
field
:
fields
)
{
if
(
persistentAttributeMap
.
containsKey
(
field
.
getName
()))
{
continue
;
}
persistentAttributeMap
.
put
(
field
.
getName
(),
field
);
}
}
else
{
for
(
XProperty
getter
:
getters
)
{
final
String
name
=
getter
.
getName
();
// HHH-10242 detect registration of the same property getter twice - eg boolean isId() + UUID getId()
final
XProperty
previous
=
persistentAttributesFromGetters
.
get
(
name
);
if
(
previous
!=
null
)
{
throw
new
org
.
hibernate
.
boot
.
MappingException
(
LOG
.
ambiguousPropertyMethods
(
xClass
.
getName
(),
HCANNHelper
.
annotatedElementSignature
(
previous
),
HCANNHelper
.
annotatedElementSignature
(
getter
)
),
new
Origin
(
SourceType
.
ANNOTATION
,
xClass
.
getName
())
);
}
if
(
persistentAttributeMap
.
containsKey
(
name
))
{
continue
;
}
persistentAttributeMap
.
put
(
getter
.
getName
(),
getter
);
persistentAttributesFromGetters
.
put
(
name
,
getter
);
}
}
}
public
XClass
getEntityAtStake
()
{
return
entityAtStake
;
}
public
XClass
getDeclaringClass
()
{
return
xClass
;
}
public
AccessType
getClassLevelAccessType
()
{
return
classLevelAccessType
;
}
public
Collection
<
XProperty
>
getProperties
()
{
assertTypesAreResolvable
();
return
Collections
.
unmodifiableCollection
(
persistentAttributeMap
.
values
());
}
private
void
assertTypesAreResolvable
()
{
for
(
XProperty
xProperty
:
persistentAttributeMap
.
values
())
{
if
(!
xProperty
.
isTypeResolved
()
&&
!
discoverTypeWithoutReflection
(
xProperty
))
{
String
msg
=
"Property "
+
StringHelper
.
qualify
(
xClass
.
getName
(),
xProperty
.
getName
())
+
" has an unbound type and no explicit target entity. Resolve this Generic usage issue"
+
" or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type"
;
throw
new
AnnotationException
(
msg
);
}
}
}
//
// private void considerExplicitFieldAndPropertyAccess() {
// for ( XProperty property : fieldAccessMap.values() ) {
// Access access = property.getAnnotation( Access.class );
// if ( access == null ) {
// continue;
// }
//
// // see "2.3.2 Explicit Access Type" of JPA 2 spec
// // the access type for this property is explicitly set to AccessType.FIELD, hence we have to
// // use field access for this property even if the default access type for the class is AccessType.PROPERTY
// AccessType accessType = AccessType.getAccessStrategy( access.value() );
// if (accessType == AccessType.FIELD) {
// propertyAccessMap.put(property.getName(), property);
// }
// else {
// LOG.debug( "Placing @Access(AccessType.FIELD) on a field does not have any effect." );
// }
// }
//
// for ( XProperty property : propertyAccessMap.values() ) {
// Access access = property.getAnnotation( Access.class );
// if ( access == null ) {
// continue;
// }
//
// AccessType accessType = AccessType.getAccessStrategy( access.value() );
//
// // see "2.3.2 Explicit Access Type" of JPA 2 spec
// // the access type for this property is explicitly set to AccessType.PROPERTY, hence we have to
// // return use method access even if the default class access type is AccessType.FIELD
// if (accessType == AccessType.PROPERTY) {
// fieldAccessMap.put(property.getName(), property);
// }
// else {
// LOG.debug( "Placing @Access(AccessType.PROPERTY) on a field does not have any effect." );
// }
// }
// }
// /**
// * Retrieves all properties from the {@code xClass} with the specified access type. This method does not take
// * any jpa access rules/annotations into account yet.
// *
// * @param access The access type - {@code AccessType.FIELD} or {@code AccessType.Property}
// *
// * @return A maps of the properties with the given access type keyed against their property name
// */
// private TreeMap<String, XProperty> initProperties(AccessType access) {
// if ( !( AccessType.PROPERTY.equals( access ) || AccessType.FIELD.equals( access ) ) ) {
// throw new IllegalArgumentException( "Access type has to be AccessType.FIELD or AccessType.Property" );
// }
//
// //order so that property are used in the same order when binding native query
// TreeMap<String, XProperty> propertiesMap = new TreeMap<String, XProperty>();
// List<XProperty> properties = xClass.getDeclaredProperties( access.getType() );
// for ( XProperty property : properties ) {
// if ( mustBeSkipped( property ) ) {
// continue;
// }
// // HHH-10242 detect registration of the same property twice eg boolean isId() + UUID getId()
// XProperty oldProperty = propertiesMap.get( property.getName() );
// if ( oldProperty != null ) {
// throw new org.hibernate.boot.MappingException(
// LOG.ambiguousPropertyMethods(
// xClass.getName(),
// HCANNHelper.annotatedElementSignature( oldProperty ),
// HCANNHelper.annotatedElementSignature( property )
// ),
// new Origin( SourceType.ANNOTATION, xClass.getName() )
// );
// }
//
// propertiesMap.put( property.getName(), property );
// }
// return propertiesMap;
// }
private
AccessType
determineLocalClassDefinedAccessStrategy
()
{
AccessType
classDefinedAccessType
;
AccessType
hibernateDefinedAccessType
=
AccessType
.
DEFAULT
;
AccessType
jpaDefinedAccessType
=
AccessType
.
DEFAULT
;
org
.
hibernate
.
annotations
.
AccessType
accessType
=
xClass
.
getAnnotation
(
org
.
hibernate
.
annotations
.
AccessType
.
class
);
if
(
accessType
!=
null
)
{
hibernateDefinedAccessType
=
AccessType
.
getAccessStrategy
(
accessType
.
value
());
}
Access
access
=
xClass
.
getAnnotation
(
Access
.
class
);
if
(
access
!=
null
)
{
jpaDefinedAccessType
=
AccessType
.
getAccessStrategy
(
access
.
value
());
}
if
(
hibernateDefinedAccessType
!=
AccessType
.
DEFAULT
&&
jpaDefinedAccessType
!=
AccessType
.
DEFAULT
&&
hibernateDefinedAccessType
!=
jpaDefinedAccessType
)
{
throw
new
MappingException
(
"@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. "
);
}
if
(
hibernateDefinedAccessType
!=
AccessType
.
DEFAULT
)
{
classDefinedAccessType
=
hibernateDefinedAccessType
;
}
else
{
classDefinedAccessType
=
jpaDefinedAccessType
;
}
return
classDefinedAccessType
;
}
private
static
boolean
discoverTypeWithoutReflection
(
XProperty
p
)
{
if
(
p
.
isAnnotationPresent
(
OneToOne
.
class
)
&&
!
p
.
getAnnotation
(
OneToOne
.
class
)
.
targetEntity
()
.
equals
(
void
.
class
))
{
return
true
;
}
else
if
(
p
.
isAnnotationPresent
(
OneToMany
.
class
)
&&
!
p
.
getAnnotation
(
OneToMany
.
class
)
.
targetEntity
()
.
equals
(
void
.
class
))
{
return
true
;
}
else
if
(
p
.
isAnnotationPresent
(
ManyToOne
.
class
)
&&
!
p
.
getAnnotation
(
ManyToOne
.
class
)
.
targetEntity
()
.
equals
(
void
.
class
))
{
return
true
;
}
else
if
(
p
.
isAnnotationPresent
(
ManyToMany
.
class
)
&&
!
p
.
getAnnotation
(
ManyToMany
.
class
)
.
targetEntity
()
.
equals
(
void
.
class
))
{
return
true
;
}
else
if
(
p
.
isAnnotationPresent
(
org
.
hibernate
.
annotations
.
Any
.
class
))
{
return
true
;
}
else
if
(
p
.
isAnnotationPresent
(
ManyToAny
.
class
))
{
if
(!
p
.
isCollection
()
&&
!
p
.
isArray
())
{
throw
new
AnnotationException
(
"@ManyToAny used on a non collection non array property: "
+
p
.
getName
());
}
return
true
;
}
else
if
(
p
.
isAnnotationPresent
(
Type
.
class
))
{
return
true
;
}
else
if
(
p
.
isAnnotationPresent
(
Target
.
class
))
{
return
true
;
}
return
false
;
}
private
static
boolean
mustBeSkipped
(
XProperty
property
)
{
//TODO make those hardcoded tests more portable (through the bytecode provider?)
return
property
.
isAnnotationPresent
(
Transient
.
class
)
||
"net.sf.cglib.transform.impl.InterceptFieldCallback"
.
equals
(
property
.
getType
().
getName
())
||
"org.hibernate.bytecode.internal.javassist.FieldHandler"
.
equals
(
property
.
getType
().
getName
());
}
}
atms-gen/src/main/java/pwc/taxtech/Const.java
View file @
07ed94ec
...
...
@@ -10,7 +10,7 @@ public class Const {
public
static
final
String
B_Delimiter
=
"["
;
//begin
public
static
final
String
E_Delimiter
=
"]"
;
//end
public
static
final
String
PROJECT_SCHEMA
=
"tax_
admin
"
;
public
static
final
String
PROJECT_SCHEMA
=
"tax_
project
"
;
public
static
final
String
PROJECT_ADMIN
=
"tax_admin"
;
...
...
atms-gen/src/main/java/pwc/taxtech/vat/entity/PeriodTaxRuleSettingOrganization.java
View file @
07ed94ec
...
...
@@ -92,11 +92,11 @@ public class PeriodTaxRuleSettingOrganization {
@Basic
@Column
(
name
=
"SETTING_ORG_ID"
,
nullable
=
false
)
@ColumnDefault
(
DEF_DEFAULT_NUMBER
)
public
long
get
TaxRuleSettingOrganization
Id
()
{
public
long
get
SettingOrg
Id
()
{
return
settingOrgId
;
}
public
void
set
TaxRuleSettingOrganization
Id
(
long
settingOrgId
)
{
public
void
set
SettingOrg
Id
(
long
settingOrgId
)
{
this
.
settingOrgId
=
settingOrgId
;
}
...
...
atms-gen/src/main/resources/application-mysql.yml
View file @
07ed94ec
...
...
@@ -8,5 +8,5 @@ spring:
database
:
MYSQL
show-sql
:
true
hibernate
:
ddl-auto
:
cre
ate
ddl-auto
:
upd
ate
naming.physical-strategy
:
org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
atms-gen/src/main/resources/application-oracle.yml
View file @
07ed94ec
...
...
@@ -9,5 +9,5 @@ spring:
properties.hibernate
:
default_schema
:
tax_admin
hibernate
:
ddl-auto
:
cre
ate
ddl-auto
:
upd
ate
naming.physical-strategy
:
org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment