{@inheritDoc}

s	 * @see jp.co.future.uroborosql.fluent.SqlEntityQuery#desc(java.lang.String, jp.co.future.uroborosql.fluent.SqlEntityQuery.Nulls)
484409
@Override
	public SqlEntityQuery<E> desc(final String col, final Nulls nulls) {
		this.sortOrders.add(new SortOrder(col, Order.DESCENDING, nulls));
		return this;
	}
122746
public static void sqlifnull(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
    twoArgumentsFunctionCall(buf, "coalesce(", "ifnull", parsedArgs);
  }
300915
private void onDiscriminatorColumn(ThriftRow tr, long timestamp, EntityType entityType)
    {
        String discrColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn();
        String discrValue = ((AbstractManagedType) entityType).getDiscriminatorValue();

        // No need to check for empty or blank, as considering it as valid name
        // for nosql!
        if (discrColumn != null && discrValue != null)
        {
            Column column = prepareColumn(PropertyAccessorHelper.getBytes(discrValue),
                    PropertyAccessorHelper.getBytes(discrColumn), timestamp, 0);
            tr.addColumn(column);
        }
    }
20664
public static TypeDesc forDescriptor(final String desc) throws IllegalArgumentException {
        TypeDesc type = cDescriptorsToInstances.get(desc);
        if (type != null) {
            return type;
        }

        // TODO: Support generics in descriptor.

        String rootDesc = desc;
        int cursor = 0;
        int dim = 0;
        try {
            char c;
            while ((c = rootDesc.charAt(cursor++)) == '[') {
                dim++;
            }

            switch (c) {
            case 'V':
                type = VOID;
                break;
            case 'Z':
                type = BOOLEAN;
                break;
            case 'C':
                type = CHAR;
                break;
            case 'B':
                type = BYTE;
                break;
            case 'S':
                type = SHORT;
                break;
            case 'I':
                type = INT;
                break;
            case 'J':
                type = LONG;
                break;
            case 'F':
                type = FLOAT;
                break;
            case 'D':
                type = DOUBLE;
                break;
            case 'L':
                if (dim > 0) {
                    rootDesc = rootDesc.substring(dim);
                    cursor = 1;
                }
                StringBuffer name = new StringBuffer(rootDesc.length() - 2);
                while ((c = rootDesc.charAt(cursor++)) != ';') {
                    if (c == '/') {
                        c = '.';
                    }
                    name.append(c);
                }
                type = intern(new ObjectType(rootDesc, name.toString()));
                break;
            default:
                throw invalidDescriptor(desc);
            }
        } catch (NullPointerException e) {
            throw invalidDescriptor(desc);
        } catch (IndexOutOfBoundsException e) {
            throw invalidDescriptor(desc);
        }

        if (cursor != rootDesc.length()) {
            throw invalidDescriptor(desc);
        }

        while (--dim >= 0) {
            type = type.toArrayType();
        }

        cDescriptorsToInstances.put(desc, type);
        return type;
    }
690318
public List<Entity> findBy(String tableName, Condition... wheres) throws SQLException {
		final Query query = new Query(wheres, tableName);
		return find(query, EntityListHandler.create());
	}
752478
private void _deserializeQueryField(Query query, Element field) throws PageException, ConverterException {
	String name = field.getAttribute("name");
	NodeList list = field.getChildNodes();
	int len = list.getLength();
	int count = 0;
	for (int i = 0; i < len; i++) {
	    Node node = list.item(i);
	    if (node instanceof Element) {
		query.setAt(KeyImpl.init(name), ++count, _deserialize((Element) node));
	    }
	}

    }
963633
protected void mergeEntityProperty(EntityPropertyDesc dest, EntityPropertyInfo src) {
    dest.setEntityClassName(src.entityClass.getName());
    dest.setPropertyClassName(src.propertyField.getType().getName());
    Class<?> maybeNumberClass =
        ClassUtil.toBoxedPrimitiveTypeIfPossible(src.propertyField.getType());
    if (Number.class.isAssignableFrom(maybeNumberClass)) {
      dest.setNumber(true);
    }
    if (src.version != null) {
      dest.setVersion(true);
    }
    if (src.id != null) {
      dest.setId(true);
      if (src.generatedValue != null) {
        switch (src.generatedValue.strategy()) {
          case IDENTITY:
            dest.setGenerationType(GenerationType.IDENTITY);
            break;
          case SEQUENCE:
            dest.setGenerationType(GenerationType.SEQUENCE);
            if (src.sequenceGenerator != null) {
              dest.setInitialValue(src.sequenceGenerator.initialValue());
              dest.setAllocationSize(src.sequenceGenerator.allocationSize());
              dest.setAllocationSize(src.sequenceGenerator.allocationSize());
            }
            break;
          case TABLE:
            dest.setGenerationType(GenerationType.TABLE);
            if (src.tableGenerator != null) {
              dest.setInitialValue(src.tableGenerator.initialValue());
              dest.setAllocationSize(src.tableGenerator.allocationSize());
              dest.setAllocationSize(src.tableGenerator.allocationSize());
            }
            break;
          default:
            break;
        }
      }
    }
  }
572757
@Override
    public <E> List<E> getColumnsById(String schemaName, String joinTableName, String joinColumnName,
            String inverseJoinColumnName, Object parentId, Class columnJavaType)
    {
        List<Object> foreignKeys = new ArrayList<Object>();

        if (getCqlVersion().equalsIgnoreCase(CassandraConstants.CQL_VERSION_3_0))
        {
            foreignKeys = getColumnsByIdUsingCql(schemaName, joinTableName, joinColumnName, inverseJoinColumnName,
                    parentId, columnJavaType);
        }
        else
        {
            Selector selector = clientFactory.getSelector(pool);

            List<Column> columns = selector.getColumnsFromRow(joinTableName,
                    Bytes.fromByteArray(PropertyAccessorHelper.getBytes(parentId)),
                    Selector.newColumnsPredicateAll(true, 10), getConsistencyLevel());

            foreignKeys = dataHandler.getForeignKeysFromJoinTable(inverseJoinColumnName, columns, columnJavaType);

            if (log.isInfoEnabled())
            {
                log.info("Returning number of keys from join table", foreignKeys != null ? foreignKeys.size() : null);
            }
        }
        return (List<E>) foreignKeys;
    }
380976
public Entity queryOne(String sql, Object... params) throws SQLException {
		return query(sql, new EntityHandler(), params);
	}
415548
@POST
    @Path("{uuid}")
    public Result migrate(@FormParam("description") String desc,
                          @PathParam("uuid") String uuid) {
        MigrationFeature.checkMigrationId(uuid);
        String generatedDesc = (mode.isDev() ? "dev " : "") + "migrate";
        if (StringUtils.isNotBlank(desc)) {
            generatedDesc = desc;
        }

        Map<String, Migration> migrations = getMigrations();
        for (String dbName : migrations.keySet()) {
            Migration migration = migrations.get(dbName);
            ScriptInfo info = migration.generate();
            info.setDescription(generatedDesc);
            Flyway flyway = locator.getService(Flyway.class, dbName);
            flyway.setBaselineDescription(info.getDescription());
            flyway.setBaselineVersionAsString(info.getRevision());
            flyway.setValidateOnMigrate(false);

            try {
                flyway.migrate();
                migration.persist();
                migration.reset();
            } catch (Throwable err) {
                if (failMigrations == null) {
                    synchronized (this) {
                        if (failMigrations == null) {
                            failMigrations = Maps.newHashMap();
                        }
                    }
                }
                failMigrations.put(dbName, MigrationFail.create(flyway, err, migration));
            }
        }
        if (failMigrations == null || failMigrations.isEmpty()) {
            return Result.success();
        } else {
            return Result.failure();
        }
    }
386074
public void checkTypeQueryAnnotation(String desc) {
    if (isEntityBeanAnnotation(desc)) {
      throw new NoEnhancementRequiredException("Not enhancing entity bean");
    }
    if (isTypeQueryBeanAnnotation(desc)) {
      typeQueryBean = true;
    } else if (isAlreadyEnhancedAnnotation(desc)) {
      alreadyEnhanced = true;
    }
  }
1020990
@Override
    public Object[] findIdsByColumn(String schemaName, String tableName, String pKeyName, String columnName,
            Object columnValue, Class entityClazz)
    {
        String childIdStr = (String) columnValue;
        StringBuffer sqlQuery = new StringBuffer();
        sqlQuery.append("SELECT ").append(pKeyName).append(" FROM ").append(getFromClause(schemaName, tableName))
                .append(" WHERE ").append(columnName).append("='").append(childIdStr).append("'");

        Session s = getSession();

        SQLQuery query = s.createSQLQuery(sqlQuery.toString());

        List<Object> primaryKeys = new ArrayList<Object>();

        primaryKeys = query.list();

        if (primaryKeys != null && !primaryKeys.isEmpty())
        {
            return primaryKeys.toArray(new Object[0]);
        }
        return null;
    }
731638
@SuppressWarnings("unchecked")
	@Override
	public <E> int delete(final Class<? extends E> entityType, final Object... keys) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isAssignableFrom(entityType)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			TableMetadata metadata = handler.getMetadata(this.transactionManager, entityType);
			TableMetadata.Column keyColumn = null;
			List<? extends TableMetadata.Column> keyColumns = metadata.getKeyColumns();
			if (keyColumns.size() == 1) {
				keyColumn = keyColumns.get(0);
			} else if (keyColumns.isEmpty()) {
				keyColumn = metadata.getColumns().get(0);
			} else {
				throw new IllegalArgumentException("Entity has multiple keys");
			}
			return delete(entityType).in(keyColumn.getCamelColumnName(), keys).count();
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.DELETE, e);
		}
	}
642779
private void initEntityClass() {
        if (from == null) {
            throw new JPQLParseException("Bad query format FROM clause is mandatory for SELECT queries");
        }
        String fromArray[] = from.split(" ");

        if (!this.isDeleteUpdate) {
            if (fromArray.length == 3 && fromArray[1].equalsIgnoreCase("as")) {
                fromArray = new String[] { fromArray[0], fromArray[2] };
            }

            if (fromArray.length != 2) {
                throw new JPQLParseException("Bad query format: " + from
                    + ". Identification variable is mandatory in FROM clause for SELECT queries");
            }

            // TODO
            StringTokenizer tokenizer = new StringTokenizer(result[0], ",");
            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken();
                if (!StringUtils.containsAny(fromArray[1] + ".", token)) {
                    throw new QueryHandlerException("bad query format with invalid alias:" + token);
                }
            }
        }

        this.entityName = fromArray[0];
        if (fromArray.length == 2)
            this.entityAlias = fromArray[1];

        persistenceUnit = kunderaMetadata.getApplicationMetadata().getMappedPersistenceUnit(entityName);

        // Get specific metamodel.
        MetamodelImpl model = getMetamodel(persistenceUnit);

        if (model != null) {
            entityClass = model.getEntityClass(entityName);
        }

        if (null == entityClass) {
            logger.error(
                "No entity {} found, please verify it is properly annotated with @Entity and not a mapped Super class",
                entityName);
            throw new QueryHandlerException("No entity found by the name: " + entityName);
        }

        EntityMetadata metadata = model.getEntityMetadata(entityClass);

        if (metadata != null && !metadata.isIndexable()) {
            throw new QueryHandlerException(entityClass + " is not indexed. Not possible to run a query on it."
                + " Check whether it was properly annotated for indexing.");
        }
    }
1190036
public static String desc2name(String desc) {
		StringBuilder sb = new StringBuilder();
		int c = desc.lastIndexOf('[') + 1;
		if (desc.length() == c + 1) {
			switch (desc.charAt(c)) {
			case JVM_VOID: {
				sb.append("void");
				break;
			}
			case JVM_BOOLEAN: {
				sb.append("boolean");
				break;
			}
			case JVM_BYTE: {
				sb.append("byte");
				break;
			}
			case JVM_CHAR: {
				sb.append("char");
				break;
			}
			case JVM_DOUBLE: {
				sb.append("double");
				break;
			}
			case JVM_FLOAT: {
				sb.append("float");
				break;
			}
			case JVM_INT: {
				sb.append("int");
				break;
			}
			case JVM_LONG: {
				sb.append("long");
				break;
			}
			case JVM_SHORT: {
				sb.append("short");
				break;
			}
			default:
				throw new RuntimeException();
			}
		} else {
			sb.append(desc.substring(c + 1, desc.length() - 1)
					.replace('/', '.'));
		}
		while (c-- > 0)
			sb.append("[]");
		return sb.toString();
	}
139162
private void analyzeForeignKey(SQLiteDatabaseSchema schema) {
		for (SQLiteEntity entity : schema.getEntities()) {
			for (SQLProperty property : entity.getCollection()) {
				if (property.isForeignKey()) {
					SQLiteEntity reference = schema.getEntity(property.foreignParentClassName);

					AssertKripton.asserTrueOrUnspecifiedBeanException(reference != null, schema, entity,
							property.foreignParentClassName);

					if (!entity.equals(reference)) {
						entity.referedEntities.add(reference);
					}
				}

			}
		}

		for (SQLiteDaoDefinition dao : schema.getCollection()) {
			if (dao.getElement().getAnnotation(BindDaoMany2Many.class) != null) {
				ClassName entity1 = TypeUtility.className(AnnotationUtility.extractAsClassName(dao.getElement(),
						BindDaoMany2Many.class, AnnotationAttributeType.ENTITY_1));
				ClassName entity2 = TypeUtility.className(AnnotationUtility.extractAsClassName(dao.getElement(),
						BindDaoMany2Many.class, AnnotationAttributeType.ENTITY_2));

				// only if dao has an entity
				if (dao.getEntity() != null) {
					// check foreign key to entity1 and entity2
					checkForeignKeyForM2M(schema, dao.getEntity(), entity1);
					checkForeignKeyForM2M(schema, dao.getEntity(), entity2);
				}
			}
		}
	}
541866
public List<ENTITY> findBySQL(String sql, List<?> params) {
        RowMapper<ENTITY> mapper = new GenericMapper<ENTITY, KEY>(orMapping);
        return findBySQL(sql, params, mapper);
    }