use of javax.persistence.metamodel.Attribute in project hibernate-orm by hibernate.
the class AbstractManagedType method getBuilder.
public Builder<X> getBuilder() {
if (locked) {
throw new IllegalStateException("Type has been locked");
}
return new Builder<X>() {
@Override
@SuppressWarnings("unchecked")
public void addAttribute(Attribute<X, ?> attribute) {
declaredAttributes.put(attribute.getName(), attribute);
final Bindable.BindableType bindableType = ((Bindable) attribute).getBindableType();
switch(bindableType) {
case SINGULAR_ATTRIBUTE:
{
declaredSingularAttributes.put(attribute.getName(), (SingularAttribute<X, ?>) attribute);
break;
}
case PLURAL_ATTRIBUTE:
{
declaredPluralAttributes.put(attribute.getName(), (PluralAttribute<X, ?, ?>) attribute);
break;
}
default:
{
throw new AssertionFailure("unknown bindable type: " + bindableType);
}
}
}
};
}
use of javax.persistence.metamodel.Attribute in project hibernate-orm by hibernate.
the class AbstractFromImpl method joinCollection.
@Override
@SuppressWarnings({ "unchecked" })
public <X, Y> CollectionJoin<X, Y> joinCollection(String attributeName, JoinType jt) {
final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute(attributeName);
if (!attribute.isCollection()) {
throw new IllegalArgumentException("Requested attribute was not a collection");
}
final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
if (!PluralAttribute.CollectionType.COLLECTION.equals(pluralAttribute.getCollectionType())) {
throw new IllegalArgumentException("Requested attribute was not a collection");
}
return (CollectionJoin<X, Y>) join((CollectionAttribute) attribute, jt);
}
use of javax.persistence.metamodel.Attribute in project hibernate-orm by hibernate.
the class AbstractFromImpl method joinSet.
@Override
@SuppressWarnings({ "unchecked" })
public <X, Y> SetJoin<X, Y> joinSet(String attributeName, JoinType jt) {
final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute(attributeName);
if (!attribute.isCollection()) {
throw new IllegalArgumentException("Requested attribute was not a set");
}
final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
if (!PluralAttribute.CollectionType.SET.equals(pluralAttribute.getCollectionType())) {
throw new IllegalArgumentException("Requested attribute was not a set");
}
return (SetJoin<X, Y>) join((SetAttribute) attribute, jt);
}
use of javax.persistence.metamodel.Attribute in project invesdwin-context-persistence by subes.
the class MySqlLoadDataInfile method createQuery.
@SuppressWarnings({ "unchecked", "GuardedBy" })
private String createQuery(final String workFile) {
final StringBuilder sb = new StringBuilder();
sb.append("LOAD DATA LOCAL INFILE '");
sb.append(workFile);
sb.append("' INTO TABLE ");
sb.append(genericType.getSimpleName());
sb.append(" ");
sb.append("FIELDS TERMINATED BY ',' ");
sb.append("ENCLOSED BY '\"' ");
sb.append("ESCAPED BY '\\\\' ");
sb.append("LINES TERMINATED BY '\\n' ");
sb.append("(");
final EntityManager em = puContext.getEntityManager();
final EntityType<E> et = (EntityType<E>) em.getMetamodel().entity(genericType);
final Set<Attribute<? super E, ?>> attrs = et.getAttributes();
boolean first = true;
final List<String> booleanColumns = new ArrayList<String>();
for (final Attribute<? super E, ?> attr : attrs) {
if (skipColumn(attr.getJavaMember().getName())) {
continue;
}
if (!first) {
sb.append(", ");
}
first = false;
final String sqlName = Attributes.extractNativeSqlColumnName(attr);
// handling boolean properly http://stackoverflow.com/questions/15683809/load-data-from-csv-inside-bit-field-in-mysql
if (Reflections.isBoolean(attr.getJavaType())) {
sb.append("@");
booleanColumns.add(sqlName);
}
sb.append(sqlName);
}
sb.append(")");
if (!booleanColumns.isEmpty()) {
// set valore=cast(@valore as signed);
sb.append(" set ");
boolean firstBooleanColumn = true;
for (final String booleanColumn : booleanColumns) {
if (!firstBooleanColumn) {
sb.append(",");
}
firstBooleanColumn = false;
sb.append(booleanColumn);
sb.append("=cast(@");
sb.append(booleanColumn);
sb.append(" as signed)");
}
}
return sb.toString();
}
use of javax.persistence.metamodel.Attribute in project invesdwin-context-persistence by subes.
the class MySqlLoadDataInfile method determineJavaColumnNames.
@SuppressWarnings("unchecked")
private List<String> determineJavaColumnNames(final PersistenceUnitContext puContext) {
final List<String> javaColumnNames = new ArrayList<String>();
final EntityManager em = puContext.getEntityManager();
final EntityType<E> et = (EntityType<E>) em.getMetamodel().entity(genericType);
final Set<Attribute<? super E, ?>> attrs = et.getAttributes();
for (final Attribute<? super E, ?> attr : attrs) {
final String javaName = attr.getJavaMember().getName();
javaColumnNames.add(javaName);
}
return javaColumnNames;
}
Aggregations