/*
(non-Javadoc)

@see javax.persistence.EntityManager#createNamedQuery(java.lang.String)
437147
@Override
    public final Query createNamedQuery(String name)
    {
        checkClosed();
        checkTransactionNeeded();
        return getPersistenceDelegator().createQuery(name);
    }
517794
protected ViewQuery createQuery(String viewName) {
		return new ViewQuery()
				.dbPath(db.path())
				.designDocId(stdDesignDocumentId)
				.viewName(viewName);
	}
180530
public Sql[] generateSql(CreateSynonymStatement statement, Database database, SqlGeneratorChain chain) {
		StringBuilder sql = new StringBuilder("CREATE ");
		if (statement.isReplace() != null && statement.isReplace()) {
			sql.append("OR REPLACE ");
		}

		if (statement.isPublic() != null && statement.isPublic()) {
			sql.append("PUBLIC ");
		}

		sql.append("SYNONYM ");

		if (statement.getSynonymSchemaName() != null) {
			sql.append(statement.getSynonymSchemaName()).append(".");
		}

		sql.append(statement.getSynonymName());
		sql.append(" FOR ");

		if (statement.getObjectSchemaName() != null) {
			sql.append(statement.getObjectSchemaName()).append(".");
		}

		sql.append(statement.getObjectName());

		return new Sql[] { new UnparsedSql(sql.toString()) };
	}
382773
public static @NotNull SqlQuery namedQuery(@NotNull @SQL String sql, @NotNull Map<String, ?> valueMap) {
        return namedQuery(sql, VariableResolver.forMap(valueMap));
    }
964110
@Override
    public <T> CriteriaQuery<T> createQuery(Class<T> returnClazz)
    {
        return new KunderaCritieriaQuery<T>(this, returnClazz);
    }
668051
@Override
    public <T> Query<T> createNamedQuery(Class<T> entityType, String queryName) {
        return ebeanServer.createNamedQuery(entityType, queryName);
    }
1202035
public static void createSchema(DataSource dataSource, String name) {
        try (Connection connection = dataSource.getConnection();
             Statement statement = connection.createStatement()) {
            statement.executeUpdate(String.format(Constants.DDL_CREATE_SCHEMA, name));
        } catch (SQLException e) {
            throw new RuntimeException("Can not connect to database", e);
        }
    }
694866
@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Description("Creates a new namepsace.")
    public NamespaceDto createNamespace(@Context HttpServletRequest req, NamespaceDto namespaceDto) {
        if (namespaceDto == null) {
            throw new WebApplicationException("Null namespace object cannot be created.", Status.BAD_REQUEST);
        }

        PrincipalUser remoteUser = validateAndGetOwner(req, null);
        Set<PrincipalUser> users = _getPrincipalUserByUserName(namespaceDto.getUsernames());
        Namespace namespace = new Namespace(remoteUser, namespaceDto.getQualifier(), remoteUser, users);

        return NamespaceDto.transformToDto(_namespaceService.createNamespace(namespace));
    }
21567
public void addNamedQueryParameter(String name, Object value) {
        parameters.put(checkNotNull(name), checkNotNull(value));
    }
982656
private void addNamedNativeQueryMetadata(Class clazz)
    {
        ApplicationMetadata appMetadata = kunderaMetadata.getApplicationMetadata();
        String name, query = null;
        if (clazz.isAnnotationPresent(NamedQuery.class))
        {
            NamedQuery ann = (NamedQuery) clazz.getAnnotation(NamedQuery.class);
            appMetadata.addQueryToCollection(ann.name(), ann.query(), false, clazz);
        }

        if (clazz.isAnnotationPresent(NamedQueries.class))
        {
            NamedQueries ann = (NamedQueries) clazz.getAnnotation(NamedQueries.class);

            NamedQuery[] anns = ann.value();
            for (NamedQuery a : anns)
            {
                appMetadata.addQueryToCollection(a.name(), a.query(), false, clazz);
            }
        }

        if (clazz.isAnnotationPresent(NamedNativeQuery.class))
        {
            NamedNativeQuery ann = (NamedNativeQuery) clazz.getAnnotation(NamedNativeQuery.class);
            appMetadata.addQueryToCollection(ann.name(), ann.query(), true, clazz);
        }

        if (clazz.isAnnotationPresent(NamedNativeQueries.class))
        {
            NamedNativeQueries ann = (NamedNativeQueries) clazz.getAnnotation(NamedNativeQueries.class);

            NamedNativeQuery[] anns = ann.value();
            for (NamedNativeQuery a : anns)
            {
                appMetadata.addQueryToCollection(a.name(), a.query(), true, clazz);
            }
        }
    }
424244
@SuppressWarnings("unchecked")
  public <T> T getQuery(String name) {
    return (T) getQuery().get(name);
  }
760
@Override
    public Query createQuery(String qlString)
    {
        try
        {
            return ivEm.createQuery(qlString);
        } finally
        {
            if (!inJTATransaction())
            {
                ivEm.clear();
            }
        }
    }
733760
public void generateQueries(String name, boolean delete)
  {
    List<String> names = new ArrayList<>();
    names.add(name);
    List<Long> ids = queryDao.mapCorpusNamesToIds(names);
    if (!ids.isEmpty())
    {
      generateQueries(ids.get(0), delete);
    }
    else
    {
      log.error("{} is unknown to the system", name);
    }
  }
700823
private <T> Query<T> newQuery(final Class<T> type, final DBCollection collection, final DBObject query) {
        return getQueryFactory().createQuery(this, collection, type, query);
    }
275992
public static Command newQuery(String identifier,
                                   String name) {
        return getCommandFactoryProvider().newQuery( identifier,
                                                     name );

    }
1354437
public void setNamedQueryIds(java.util.Collection<String> namedQueryIds) {
        if (namedQueryIds == null) {
            this.namedQueryIds = null;
            return;
        }

        this.namedQueryIds = new java.util.ArrayList<String>(namedQueryIds);
    }
1242733
@Override
    public String buildStoredProcedureQuery(String name, int paramsCount) {
        StringBuilder sb = new StringBuilder("SELECT * FROM ");
        sb.append(name);
        sb.append("(");
        for (int i = 0; i < paramsCount; i++) {
            sb.append("?,");
        }
        if (paramsCount > 0) {
            sb.setLength(sb.length() - 1);
        }
        sb.append(")");

        return sb.toString();
    }