Ejemplo n.º 1
0
  /**
   * Creates an {@link Table} object from an {@link RelationalPath}
   *
   * @param tablePath the table path
   * @return the {@link Table} object
   */
  public static Table createTable(RelationalPath<?> tablePath) {
    final Map<String, Column> columns = CollectionFactory.newMap();
    for (final Path<?> path : tablePath.getColumns()) {
      final Column col = createColumn(tablePath, path);
      columns.put(col.getName(), col);
    }

    return new Table(
        tablePath.getTableName(),
        columns,
        createPK(tablePath, columns),
        createFKs(tablePath, columns));
  }
Ejemplo n.º 2
0
 /**
  * @param tablePath the query entity
  * @param columns the columns
  * @return the primary key object
  */
 private static PrimaryKey createPK(RelationalPath<?> tablePath, Map<String, Column> columns) {
   return new PrimaryKey(
       columns.get(
           tablePath
               .getPrimaryKey()
               .getLocalColumns()
               .get(0)
               .getMetadata()
               .getExpression()
               .toString()));
 }
Ejemplo n.º 3
0
 /**
  * Creates the foreign key list
  *
  * @param tablePath the table object
  * @param columns the columns
  * @return the foreign key list
  */
 private static List<ForeignKey> createFKs(
     RelationalPath<?> tablePath, Map<String, Column> columns) {
   final List<ForeignKey> fks = CollectionFactory.newList();
   for (final com.mysema.query.sql.ForeignKey<?> fk : tablePath.getForeignKeys()) {
     StringBuilder name = new StringBuilder();
     final List<Column> cols = CollectionFactory.newList();
     for (final Path<?> path : fk.getLocalColumns()) {
       String colName = path.getMetadata().getExpression().toString();
       cols.add(columns.get(colName));
       name.append(colName).append("-");
     }
     name.setLength(name.length() - 1);
     fks.add(new ForeignKey(name.toString(), cols));
   }
   return fks;
 }
Ejemplo n.º 4
0
 @SuppressWarnings("rawtypes")
 @Override
 public Map<Path<?>, Object> createMap(RelationalPath<?> entity, Object bean) {
   try {
     Map<Path<?>, Object> values = new HashMap<Path<?>, Object>();
     BeanMap map = new BeanMap(bean);
     Map<String, Field> fields = getPathFields(entity.getClass());
     for (Map.Entry entry : map.entrySet()) {
       String property = entry.getKey().toString();
       if (!property.equals("class") && fields.containsKey(property)) {
         Field field = fields.get(property);
         Path path = (Path<?>) field.get(entity);
         if (entry.getValue() != null) {
           values.put(path, entry.getValue());
         } else if (withNullBindings) {
           values.put(path, Null.DEFAULT);
         }
       }
     }
     return values;
   } catch (IllegalAccessException e) {
     throw new QueryException(e);
   }
 }